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