source: XIOS/dev/XIOS_DEV_CMIP6/src/transformation/generic_algorithm_transformation.hpp @ 1260

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

Buf fix in reduction. Missing value update was not set correctly

YM

File size: 6.9 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
17namespace 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  */
27class CGenericAlgorithmTransformation
28{
29public:
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
38public:
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
42protected:
43  typedef boost::unordered_map<size_t,int> GlobalLocalMap;
44protected:
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
49public:
50  CGenericAlgorithmTransformation();
51
52  virtual ~CGenericAlgorithmTransformation() {}
53
54  void computeGlobalSourceIndex(int elementPositionInGrid,
55                               CGrid* gridSrc,
56                               CGrid* gridDst,
57                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
58
59    /*!
60    Apply a operation on local data.
61    \param [in] localIndex vector contains local index of local data output and the corresponding weight
62    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
63    \param [in/out] dataOut Array contains local data
64    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization
65    \param [in] ignoreMissingValue don't count missing value in operation if this flag is true
66    \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
67  */
68  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
69                     const double* dataInput,
70                     CArray<double,1>& dataOut,
71                     std::vector<bool>& flagInitial,                     
72                     bool ignoreMissingValue, bool firstPass);
73
74  /*!
75   * Update whole dataOut (on necessary).
76   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
77   * \param [in/out] dataOut dataOut
78   */
79  virtual void updateData(CArray<double,1>& dataOut);
80
81  std::vector<StdString> getIdAuxInputs();
82  AlgoTransType type();
83  /*!
84  Compute global index mapping from one element of destination grid to the corresponding element of source grid
85  */
86  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
87
88protected:
89  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
90
91  /*!
92  Compute proc which contains global index of an element
93    \param[in] globalElementIndex demanding global index of an element of source grid
94    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
95    \param[out] globalElementIndexOnProc Proc contains the demanding global index
96  */
97  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
98                                          int elementType,
99                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
100
101protected:
102  void computeGlobalGridIndexMapping(int elementPositionInGrid,
103                                     const std::vector<int>& srcRank,
104                                     boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
105                                     CGrid* gridDst,
106                                     CGrid* gridSrc,
107                                     std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
108                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
109
110  void computeExchangeDomainIndex(CDomain* domainDst,
111                                  CDomain* domainSrc,
112                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
113                                  boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
114
115  void computeExchangeAxisIndex(CAxis* axisDst,
116                                CAxis* axisSrc,
117                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
118                                boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
119
120  void computeExchangeScalarIndex(CScalar* scalarDst,
121                                  CScalar* scalarSrc,
122                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
123                                  boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
124
125  void computePositionElements(CGrid* dst, CGrid* src);
126
127protected:
128  //! Map between global index of destination element and source element
129  std::vector<TransformationIndexMap> transformationMapping_;
130  //! Weight corresponding of source to destination
131  std::vector<TransformationWeightMap> transformationWeight_;
132  //! Map of global index of destination element and corresponding global index of other elements in the same grid
133  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
134  std::vector<TransformationPositionMap> transformationPosition_;
135
136  //! Id of auxillary inputs which helps doing transformation dynamically
137  std::vector<StdString> idAuxInputs_;
138  AlgoTransType type_;
139
140  std::set<StdSize> indexElementSrc_;
141
142  std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_;
143
144  std::vector<int> procContainSrcElementIdx_;  // List of processes containing source index of transformed elements
145  std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements
146
147
148  bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements
149
150  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
151  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
152};
153
154}
155#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.