source: XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp @ 933

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

Improving transformation selection. Instead of modifying directly grid_transformation
we only need to register a new transformation with the framework

+) Update all transformations with this new method

Test
+) On Curie
+) Basic tests pass

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