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

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

Reorganizing codes

+) Reorganize some structures to make them more performant

Test:
+) On Curie
+) All tests pass

File size: 6.6 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
22  /*!
23  \class CGenericAlgorithmTransformation
24  This class defines the interface for all other inherted algorithms class
25  */
26class CGenericAlgorithmTransformation
27{
28protected:
29  typedef std::vector<std::pair<int, std::pair<size_t,double> > > DestinationGlobalIndex;
30public:
31  // Stupid global index map, it must be replaced by tuple
32  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights
33  typedef boost::unordered_map<size_t, DestinationGlobalIndex> DestinationIndexMap;
34  //
35  typedef boost::unordered_map<int, boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap;
36
37protected:
38  typedef boost::unordered_map<size_t,int> GlobalLocalMap;
39protected:
40  typedef boost::unordered_map<int, std::vector<int> > TransformationIndexMap;
41  typedef boost::unordered_map<int, std::vector<double> > TransformationWeightMap;
42  typedef boost::unordered_map<int, std::vector<int> > TransformationPositionMap;
43
44public:
45  CGenericAlgorithmTransformation();
46
47  virtual ~CGenericAlgorithmTransformation() {}
48
49//  void computeGlobalSourceIndex(int elementPositionInGrid,
50//                                const std::vector<int>& gridDestGlobalDim,
51//                                const std::vector<int>& gridSrcGlobalDim,
52//                                const GlobalLocalMap& globalLocalIndexGridDestSendToServer,
53//                                DestinationIndexMap& globaIndexWeightFromDestToSource);
54
55  void computeGlobalSourceIndex(int elementPositionInGrid,
56                               CGrid* gridSrc,
57                               CGrid* gridDst,
58                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
59
60  std::vector<StdString> getIdAuxInputs();
61
62  /*!
63  Compute global index mapping from one element of destination grid to the corresponding element of source grid
64  */
65  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
66
67protected:
68  /*!
69  Compute an array of global index from a global index on an element
70    \param[in] destGlobalIndex global index on an element of destination grid
71    \param[in] srcGlobalIndex global index(es) on an element of source grid (which are needed by one index on element destination)
72    \param[in] elementPositionInGrid position of the element in the grid (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2)
73    \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the element on which transformation is performed)
74    \param[in] globalLocalIndexDestSendToServerMap pair of global index and local index of destination grid which are to be sent to server(s), this array is already acsending sorted
75    \param[in/out] globalLocalIndexDestMap array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated
76    \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated
77  */
78  virtual void computeGlobalGridIndexFromGlobalIndexElement(int destGlobalIndex,
79                                                        const std::vector<int>& srcGlobalIndex,
80                                                        const std::vector<int>& destGlobalIndexPositionInGrid,
81                                                        int elementPositionInGrid,
82                                                        const std::vector<int>& gridDestGlobalDim,
83                                                        const std::vector<int>& gridSrcGlobalDim,
84                                                        const GlobalLocalMap& globalLocalIndexDestSendToServerMap,
85                                                        std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap,
86                                                        std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0;
87
88  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
89
90  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
91                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
92
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
111protected:
112  //! Map between global index of destination element and source element
113  std::vector<TransformationIndexMap> transformationMapping_;
114  //! Weight corresponding of source to destination
115  std::vector<TransformationWeightMap> transformationWeight_;
116  //! Map of global index of destination element and corresponding global index of other elements in the same grid
117  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
118  std::vector<TransformationPositionMap> transformationPosition_;
119
120  //! Id of auxillary inputs which help doing transformation dynamically
121  std::vector<StdString> idAuxInputs_;
122};
123
124}
125#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.