source: XIOS/dev/dev_ym/XIOS_COUPLING/src/transformation/generic_algorithm_transformation.hpp @ 1984

Last change on this file since 1984 was 1984, checked in by ymipsl, 4 years ago

intermediate commit for new tranformation engine?
YM

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