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

Last change on this file since 888 was 888, checked in by mhnguyen, 6 years ago

Adding new transformation for scalar: Reducing an axis to a scalar

+) Add new xml node for new transformation
+) Add new algorithms for axis reduction
+) Make change in some place to make sure everything work fine

Test
+) On Curie
+) Tests pass and are correct

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 inherted algorithms class
26  */
27class CGenericAlgorithmTransformation
28{
29protected:
30  typedef std::vector<std::pair<int, std::pair<size_t,double> > > DestinationGlobalIndex;
31public:
32  // Stupid global index map, it must be replaced by tuple
33  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights
34  typedef boost::unordered_map<size_t, DestinationGlobalIndex> DestinationIndexMap;
35  //
36  typedef boost::unordered_map<int, boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap;
37
38protected:
39  typedef boost::unordered_map<size_t,int> GlobalLocalMap;
40protected:
41  typedef boost::unordered_map<int, std::vector<int> > TransformationIndexMap;
42  typedef boost::unordered_map<int, std::vector<double> > TransformationWeightMap;
43  typedef boost::unordered_map<int, std::vector<int> > TransformationPositionMap;
44
45public:
46  CGenericAlgorithmTransformation();
47
48  virtual ~CGenericAlgorithmTransformation() {}
49
50  void computeGlobalSourceIndex(int elementPositionInGrid,
51                               CGrid* gridSrc,
52                               CGrid* gridDst,
53                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
54
55    /*!
56    Apply a reduction operation on local data.
57    \param [in] localIndex vector contains local index of local data output and the corresponding weight
58    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
59    \param [in/out] dataOut Array contains local data
60    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization
61  */
62  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
63                     const double* dataInput,
64                     CArray<double,1>& dataOut,
65                     std::vector<bool>& flagInitial);
66
67  std::vector<StdString> getIdAuxInputs();
68
69  /*!
70  Compute global index mapping from one element of destination grid to the corresponding element of source grid
71  */
72  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
73
74protected:
75  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
76
77  /*!
78  Compute proc which contains global index of an element
79    \param[in] globalElementIndex demanding global index of an element of source grid
80    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
81    \param[out] globalElementIndexOnProc Proc contains the demanding global index
82  */
83  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
84                                          int elementType,
85                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
86
87protected:
88  void computeGlobalGridIndexMapping(int elementPositionInGrid,
89                                     const std::vector<int>& srcRank,
90                                     boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
91                                     CGrid* gridDst,
92                                     CGrid* gridSrc,
93                                     std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
94                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
95
96  void computeExchangeDomainIndex(CDomain* domainDst,
97                                  CDomain* domainSrc,
98                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
99                                  boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
100
101  void computeExchangeAxisIndex(CAxis* axisDst,
102                                CAxis* axisSrc,
103                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
104                                boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
105
106  void computeExchangeScalarIndex(CScalar* scalarDst,
107                                  CScalar* scalarSrc,
108                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
109                                  boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
110
111  void computePositionElements(CGrid* dst, CGrid* src);
112
113protected:
114  //! Map between global index of destination element and source element
115  std::vector<TransformationIndexMap> transformationMapping_;
116  //! Weight corresponding of source to destination
117  std::vector<TransformationWeightMap> transformationWeight_;
118  //! Map of global index of destination element and corresponding global index of other elements in the same grid
119  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
120  std::vector<TransformationPositionMap> transformationPosition_;
121
122  //! Id of auxillary inputs which helps doing transformation dynamically
123  std::vector<StdString> idAuxInputs_;
124
125  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
126  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
127};
128
129}
130#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.