[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" |
---|
[866] | 15 | #include "client_client_dht_template.hpp" |
---|
[1984] | 16 | #include "local_view.hpp" |
---|
| 17 | #include "transform_connector.hpp" |
---|
| 18 | #include "weight_transform_connector.hpp" |
---|
[620] | 19 | |
---|
[1984] | 20 | namespace xios |
---|
| 21 | { |
---|
[862] | 22 | class CGrid; |
---|
| 23 | class CDomain; |
---|
| 24 | class CAxis; |
---|
[888] | 25 | class CScalar; |
---|
[1999] | 26 | class CGridAlgorithm ; |
---|
[862] | 27 | |
---|
[624] | 28 | /*! |
---|
| 29 | \class CGenericAlgorithmTransformation |
---|
[933] | 30 | This class defines the interface for all other inherited algorithms class |
---|
[624] | 31 | */ |
---|
[620] | 32 | class CGenericAlgorithmTransformation |
---|
| 33 | { |
---|
| 34 | public: |
---|
[933] | 35 | enum AlgoTransType { |
---|
| 36 | ELEMENT_GENERATION = 0, |
---|
| 37 | ELEMENT_MODIFICATION_WITHOUT_DATA = 1, |
---|
| 38 | ELEMENT_MODIFICATION_WITH_DATA = 2, |
---|
| 39 | ELEMENT_NO_MODIFICATION_WITH_DATA = 3, |
---|
| 40 | ELEMENT_NO_MODIFICATION_WITHOUT_DATA = 4 |
---|
| 41 | } ; |
---|
| 42 | |
---|
| 43 | public: |
---|
[829] | 44 | // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights |
---|
[1542] | 45 | typedef std::unordered_map<int, std::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap; |
---|
[843] | 46 | |
---|
[829] | 47 | protected: |
---|
[1542] | 48 | typedef std::unordered_map<size_t,int> GlobalLocalMap; |
---|
[862] | 49 | protected: |
---|
[1542] | 50 | typedef std::unordered_map<int, std::vector<int> > TransformationIndexMap; |
---|
| 51 | typedef std::unordered_map<int, std::vector<double> > TransformationWeightMap; |
---|
| 52 | typedef std::unordered_map<int, std::vector<int> > TransformationPositionMap; |
---|
[829] | 53 | |
---|
| 54 | public: |
---|
[1998] | 55 | //CGenericAlgorithmTransformation(); |
---|
[1988] | 56 | CGenericAlgorithmTransformation(bool isSource); |
---|
[620] | 57 | |
---|
| 58 | virtual ~CGenericAlgorithmTransformation() {} |
---|
| 59 | |
---|
[1399] | 60 | bool isDistributedTransformation(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst) ; |
---|
| 61 | |
---|
[620] | 62 | void computeGlobalSourceIndex(int elementPositionInGrid, |
---|
[862] | 63 | CGrid* gridSrc, |
---|
| 64 | CGrid* gridDst, |
---|
| 65 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
[622] | 66 | |
---|
[888] | 67 | /*! |
---|
[933] | 68 | Apply a operation on local data. |
---|
[888] | 69 | \param [in] localIndex vector contains local index of local data output and the corresponding weight |
---|
| 70 | \param [in] dataInput Pointer to the first element of data input array (in form of buffer) |
---|
| 71 | \param [in/out] dataOut Array contains local data |
---|
| 72 | \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization |
---|
[1158] | 73 | \param [in] ignoreMissingValue don't count missing value in operation if this flag is true |
---|
[1260] | 74 | \param [in] firstPass indicate if it is the first time the apply funtion is called for a same transformation, in order to make a clean initialization |
---|
[888] | 75 | */ |
---|
| 76 | virtual void apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
| 77 | const double* dataInput, |
---|
| 78 | CArray<double,1>& dataOut, |
---|
[1158] | 79 | std::vector<bool>& flagInitial, |
---|
[1260] | 80 | bool ignoreMissingValue, bool firstPass); |
---|
[888] | 81 | |
---|
[979] | 82 | /*! |
---|
| 83 | * Update whole dataOut (on necessary). |
---|
| 84 | * (Example: Impose a weight, whose value is only known after being applied an operation, on dataOut) |
---|
| 85 | * \param [in/out] dataOut dataOut |
---|
| 86 | */ |
---|
| 87 | virtual void updateData(CArray<double,1>& dataOut); |
---|
| 88 | |
---|
[827] | 89 | std::vector<StdString> getIdAuxInputs(); |
---|
[933] | 90 | AlgoTransType type(); |
---|
[623] | 91 | /*! |
---|
[622] | 92 | Compute global index mapping from one element of destination grid to the corresponding element of source grid |
---|
| 93 | */ |
---|
[827] | 94 | void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >()); |
---|
[1399] | 95 | void computeTransformationMappingNonDistributed(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst, |
---|
[1637] | 96 | vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, int& nbLocalIndexOnGridDest); |
---|
| 97 | void nonDistributedrecursiveFunct(int currentPos, bool masked, int elementPositionInGrid, vector< CArray<bool,1>* >& maskSrc, vector< CArray<bool,1>* >& maskDst, |
---|
| 98 | int& srcInd, int& srcIndCompressed, vector<int>& nIndexSrc, |
---|
| 99 | int& t, vector<vector<vector<pair<int,double> > > >& dstIndWeight, int currentInd, |
---|
| 100 | vector<int>& localSrc, vector<int>& localDst, vector<double>& weight) ; |
---|
[622] | 101 | |
---|
[620] | 102 | protected: |
---|
[1998] | 103 | virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) {}; |
---|
[867] | 104 | |
---|
[620] | 105 | /*! |
---|
[867] | 106 | Compute proc which contains global index of an element |
---|
| 107 | \param[in] globalElementIndex demanding global index of an element of source grid |
---|
[888] | 108 | \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar |
---|
[867] | 109 | \param[out] globalElementIndexOnProc Proc contains the demanding global index |
---|
[620] | 110 | */ |
---|
[862] | 111 | virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex, |
---|
[888] | 112 | int elementType, |
---|
[1998] | 113 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc){}; |
---|
[862] | 114 | |
---|
[867] | 115 | protected: |
---|
[862] | 116 | void computeGlobalGridIndexMapping(int elementPositionInGrid, |
---|
| 117 | const std::vector<int>& srcRank, |
---|
[1542] | 118 | std::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap, |
---|
[862] | 119 | CGrid* gridDst, |
---|
| 120 | CGrid* gridSrc, |
---|
[1542] | 121 | std::vector<std::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc, |
---|
[862] | 122 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
| 123 | |
---|
| 124 | void computeExchangeDomainIndex(CDomain* domainDst, |
---|
| 125 | CDomain* domainSrc, |
---|
| 126 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
[1542] | 127 | std::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc); |
---|
[862] | 128 | |
---|
| 129 | void computeExchangeAxisIndex(CAxis* axisDst, |
---|
| 130 | CAxis* axisSrc, |
---|
| 131 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
[1542] | 132 | std::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc); |
---|
[862] | 133 | |
---|
[888] | 134 | void computeExchangeScalarIndex(CScalar* scalarDst, |
---|
| 135 | CScalar* scalarSrc, |
---|
| 136 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
[1542] | 137 | std::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc); |
---|
[888] | 138 | |
---|
| 139 | void computePositionElements(CGrid* dst, CGrid* src); |
---|
| 140 | |
---|
[827] | 141 | protected: |
---|
[1399] | 142 | //! indicate if the transformation is performed on a distributed element |
---|
| 143 | bool isDistributed_ ; |
---|
| 144 | //! indicate if the method isDistributedTransformation has been called before |
---|
| 145 | bool isDistributedComputed_ ; |
---|
| 146 | |
---|
[827] | 147 | //! Map between global index of destination element and source element |
---|
[833] | 148 | std::vector<TransformationIndexMap> transformationMapping_; |
---|
[827] | 149 | //! Weight corresponding of source to destination |
---|
[833] | 150 | std::vector<TransformationWeightMap> transformationWeight_; |
---|
[827] | 151 | //! Map of global index of destination element and corresponding global index of other elements in the same grid |
---|
| 152 | //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty |
---|
[833] | 153 | std::vector<TransformationPositionMap> transformationPosition_; |
---|
[622] | 154 | |
---|
[867] | 155 | //! Id of auxillary inputs which helps doing transformation dynamically |
---|
[827] | 156 | std::vector<StdString> idAuxInputs_; |
---|
[933] | 157 | AlgoTransType type_; |
---|
[888] | 158 | |
---|
[1216] | 159 | std::set<StdSize> indexElementSrc_; |
---|
| 160 | |
---|
[1542] | 161 | std::vector<std::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_; |
---|
[1216] | 162 | |
---|
| 163 | std::vector<int> procContainSrcElementIdx_; // List of processes containing source index of transformed elements |
---|
[1389] | 164 | // std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements |
---|
[1399] | 165 | std::set<int> commonProc_; |
---|
[1389] | 166 | std::vector< set<int> > procElementList_ ; // List of processes containing source index of elements |
---|
[1216] | 167 | |
---|
[1400] | 168 | CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc_; |
---|
| 169 | |
---|
[1216] | 170 | bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements |
---|
| 171 | |
---|
[888] | 172 | std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_; |
---|
| 173 | std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_; |
---|
[1298] | 174 | |
---|
| 175 | bool eliminateRedondantSrc_ ; // flag to indicate if the transformation must select only one global source point for all proc. |
---|
| 176 | // In this case it will choose preferentially the current process |
---|
[1988] | 177 | bool isSource_ ; //flag to indicate that the algorithm is a source algorithm, that mean the grid is modified or generated but |
---|
| 178 | // no fluxes are tranformed |
---|
[1984] | 179 | |
---|
| 180 | // new methods for new algorithm |
---|
| 181 | |
---|
| 182 | public : |
---|
| 183 | |
---|
[1998] | 184 | virtual void computeAlgorithm(CLocalView* srcView, CLocalView* dstView) ; |
---|
| 185 | virtual void apply(int dimBefore, int dimAfter, const CArray<double,1>& dataIn, CArray<double,1>& dataOut); |
---|
[1999] | 186 | virtual CGridAlgorithm* createGridAlgorithm(CGrid* gridSrc, CGrid* newGrid, int pos) ; |
---|
| 187 | virtual void computeRecvElement(CLocalView* srcView, CLocalView* dstView) ; |
---|
| 188 | protected : |
---|
| 189 | |
---|
| 190 | CLocalElement* recvElement_=nullptr ; |
---|
| 191 | public: |
---|
| 192 | CLocalElement* getRecvElement(void) { return recvElement_ ;} |
---|
| 193 | |
---|
| 194 | protected: |
---|
[1984] | 195 | CTransformConnector* transformConnector_ ; |
---|
| 196 | CWeightTransformConnector* weightTransformConnector_ ; |
---|
| 197 | |
---|
[620] | 198 | }; |
---|
| 199 | |
---|
| 200 | } |
---|
| 201 | #endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|