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