source: XIOS/dev/dev_olga/src/transformation/generic_algorithm_transformation.hpp @ 1130

Last change on this file since 1130 was 979, checked in by mhnguyen, 8 years ago

Implementing AVERAGE operation

+) Add average operation for reduction transformation

Test
+) On Curie
+) Correct

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