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

Last change on this file since 1998 was 1998, checked in by ymipsl, 3 years ago

Adapt transformation algorithm to new infrastructure (on going...)

YM

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