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

Last change on this file since 1211 was 1158, checked in by oabramkina, 7 years ago

Two server levels: merging with trunk r1137.
There are bugs.

File size: 6.3 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  */
67  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
68                     const double* dataInput,
69                     CArray<double,1>& dataOut,
70                     std::vector<bool>& flagInitial,                     
71                     bool ignoreMissingValue);
72
73  /*!
74   * Update whole dataOut (on necessary).
75   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
76   * \param [in/out] dataOut dataOut
77   */
78  virtual void updateData(CArray<double,1>& dataOut);
79
80  std::vector<StdString> getIdAuxInputs();
81  AlgoTransType type();
82  /*!
83  Compute global index mapping from one element of destination grid to the corresponding element of source grid
84  */
85  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
86
87protected:
88  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
89
90  /*!
91  Compute proc which contains global index of an element
92    \param[in] globalElementIndex demanding global index of an element of source grid
93    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
94    \param[out] globalElementIndexOnProc Proc contains the demanding global index
95  */
96  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
97                                          int elementType,
98                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
99
100protected:
101  void computeGlobalGridIndexMapping(int elementPositionInGrid,
102                                     const std::vector<int>& srcRank,
103                                     boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
104                                     CGrid* gridDst,
105                                     CGrid* gridSrc,
106                                     std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
107                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
108
109  void computeExchangeDomainIndex(CDomain* domainDst,
110                                  CDomain* domainSrc,
111                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
112                                  boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
113
114  void computeExchangeAxisIndex(CAxis* axisDst,
115                                CAxis* axisSrc,
116                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
117                                boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
118
119  void computeExchangeScalarIndex(CScalar* scalarDst,
120                                  CScalar* scalarSrc,
121                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
122                                  boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
123
124  void computePositionElements(CGrid* dst, CGrid* src);
125
126protected:
127  //! Map between global index of destination element and source element
128  std::vector<TransformationIndexMap> transformationMapping_;
129  //! Weight corresponding of source to destination
130  std::vector<TransformationWeightMap> transformationWeight_;
131  //! Map of global index of destination element and corresponding global index of other elements in the same grid
132  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
133  std::vector<TransformationPositionMap> transformationPosition_;
134
135  //! Id of auxillary inputs which helps doing transformation dynamically
136  std::vector<StdString> idAuxInputs_;
137  AlgoTransType type_;
138
139  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
140  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
141};
142
143}
144#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.