[624] | 1 | /*! |
---|
| 2 | \file generic_algorithm_transformation.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 14 May 2015 |
---|
[630] | 5 | \date 29 June 2015 |
---|
[624] | 6 | |
---|
| 7 | \brief Interface for all transformation algorithms. |
---|
| 8 | */ |
---|
[620] | 9 | #ifndef __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|
| 10 | #define __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|
| 11 | |
---|
| 12 | #include <map> |
---|
[630] | 13 | #include <set> |
---|
[620] | 14 | #include "array_new.hpp" |
---|
| 15 | |
---|
| 16 | namespace xios { |
---|
[862] | 17 | class CGrid; |
---|
| 18 | class CDomain; |
---|
| 19 | class CAxis; |
---|
| 20 | |
---|
[624] | 21 | /*! |
---|
| 22 | \class CGenericAlgorithmTransformation |
---|
| 23 | This class defines the interface for all other inherted algorithms class |
---|
| 24 | */ |
---|
[620] | 25 | class CGenericAlgorithmTransformation |
---|
| 26 | { |
---|
[843] | 27 | protected: |
---|
| 28 | typedef std::vector<std::pair<int, std::pair<size_t,double> > > DestinationGlobalIndex; |
---|
[620] | 29 | public: |
---|
[829] | 30 | // Stupid global index map, it must be replaced by tuple |
---|
| 31 | // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights |
---|
[843] | 32 | typedef boost::unordered_map<size_t, DestinationGlobalIndex> DestinationIndexMap; |
---|
[862] | 33 | // |
---|
| 34 | typedef boost::unordered_map<int, boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap; |
---|
[843] | 35 | |
---|
[829] | 36 | protected: |
---|
| 37 | typedef boost::unordered_map<size_t,int> GlobalLocalMap; |
---|
[862] | 38 | protected: |
---|
| 39 | typedef boost::unordered_map<int, std::vector<int> > TransformationIndexMap; |
---|
| 40 | typedef boost::unordered_map<int, std::vector<double> > TransformationWeightMap; |
---|
| 41 | typedef boost::unordered_map<int, std::vector<int> > TransformationPositionMap; |
---|
[829] | 42 | |
---|
| 43 | public: |
---|
[620] | 44 | CGenericAlgorithmTransformation(); |
---|
| 45 | |
---|
| 46 | virtual ~CGenericAlgorithmTransformation() {} |
---|
| 47 | |
---|
[862] | 48 | // void computeGlobalSourceIndex(int elementPositionInGrid, |
---|
| 49 | // const std::vector<int>& gridDestGlobalDim, |
---|
| 50 | // const std::vector<int>& gridSrcGlobalDim, |
---|
| 51 | // const GlobalLocalMap& globalLocalIndexGridDestSendToServer, |
---|
| 52 | // DestinationIndexMap& globaIndexWeightFromDestToSource); |
---|
| 53 | |
---|
[620] | 54 | void computeGlobalSourceIndex(int elementPositionInGrid, |
---|
[862] | 55 | CGrid* gridSrc, |
---|
| 56 | CGrid* gridDst, |
---|
| 57 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
[622] | 58 | |
---|
[827] | 59 | std::vector<StdString> getIdAuxInputs(); |
---|
| 60 | |
---|
[623] | 61 | /*! |
---|
[622] | 62 | Compute global index mapping from one element of destination grid to the corresponding element of source grid |
---|
| 63 | */ |
---|
[827] | 64 | void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >()); |
---|
[622] | 65 | |
---|
[620] | 66 | protected: |
---|
| 67 | /*! |
---|
| 68 | Compute an array of global index from a global index on an element |
---|
| 69 | \param[in] destGlobalIndex global index on an element of destination grid |
---|
| 70 | \param[in] srcGlobalIndex global index(es) on an element of source grid (which are needed by one index on element destination) |
---|
| 71 | \param[in] elementPositionInGrid position of the element in the grid (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) |
---|
| 72 | \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the element on which transformation is performed) |
---|
[829] | 73 | \param[in] globalLocalIndexDestSendToServerMap pair of global index and local index of destination grid which are to be sent to server(s), this array is already acsending sorted |
---|
| 74 | \param[in/out] globalLocalIndexDestMap array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated |
---|
[620] | 75 | \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated |
---|
| 76 | */ |
---|
[630] | 77 | virtual void computeGlobalGridIndexFromGlobalIndexElement(int destGlobalIndex, |
---|
[620] | 78 | const std::vector<int>& srcGlobalIndex, |
---|
[827] | 79 | const std::vector<int>& destGlobalIndexPositionInGrid, |
---|
[620] | 80 | int elementPositionInGrid, |
---|
| 81 | const std::vector<int>& gridDestGlobalDim, |
---|
[631] | 82 | const std::vector<int>& gridSrcGlobalDim, |
---|
[829] | 83 | const GlobalLocalMap& globalLocalIndexDestSendToServerMap, |
---|
| 84 | std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, |
---|
[630] | 85 | std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0; |
---|
[620] | 86 | |
---|
[827] | 87 | virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0; |
---|
[620] | 88 | |
---|
[862] | 89 | virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex, |
---|
| 90 | boost::unordered_map<int,std::vector<size_t> >& globalElementIndexOnProc) = 0; |
---|
| 91 | |
---|
| 92 | void computeGlobalGridIndexMapping(int elementPositionInGrid, |
---|
| 93 | const std::vector<int>& srcRank, |
---|
| 94 | boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap, |
---|
| 95 | CGrid* gridDst, |
---|
| 96 | CGrid* gridSrc, |
---|
| 97 | std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc, |
---|
| 98 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
| 99 | |
---|
| 100 | void computeExchangeDomainIndex(CDomain* domainDst, |
---|
| 101 | CDomain* domainSrc, |
---|
| 102 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
| 103 | boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc); |
---|
| 104 | |
---|
| 105 | void computeExchangeAxisIndex(CAxis* axisDst, |
---|
| 106 | CAxis* axisSrc, |
---|
| 107 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
| 108 | boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc); |
---|
| 109 | |
---|
[827] | 110 | protected: |
---|
| 111 | //! Map between global index of destination element and source element |
---|
[833] | 112 | std::vector<TransformationIndexMap> transformationMapping_; |
---|
[827] | 113 | //! Weight corresponding of source to destination |
---|
[833] | 114 | std::vector<TransformationWeightMap> transformationWeight_; |
---|
[827] | 115 | //! Map of global index of destination element and corresponding global index of other elements in the same grid |
---|
| 116 | //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty |
---|
[833] | 117 | std::vector<TransformationPositionMap> transformationPosition_; |
---|
[622] | 118 | |
---|
[827] | 119 | //! Id of auxillary inputs which help doing transformation dynamically |
---|
| 120 | std::vector<StdString> idAuxInputs_; |
---|
[620] | 121 | }; |
---|
| 122 | |
---|
| 123 | } |
---|
| 124 | #endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|