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

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

Modifying vertical interpolation

+) Only process interpolation, the extrapolation will be ignored (value will be unidentified (masked))
+) Make sure even unidenfitified from one transformation can be known in the next transformation

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