1 | /*! |
---|
2 | \file grid_transformation.hpp |
---|
3 | \author Ha NGUYEN |
---|
4 | \since 14 May 2015 |
---|
5 | \date 26 Aug 2015 |
---|
6 | |
---|
7 | \brief Interface for all transformations. |
---|
8 | */ |
---|
9 | #ifndef __XIOS_GRID_TRANSFORMATION_HPP__ |
---|
10 | #define __XIOS_GRID_TRANSFORMATION_HPP__ |
---|
11 | |
---|
12 | #include <map> |
---|
13 | #include <vector> |
---|
14 | #include "grid.hpp" |
---|
15 | #include "generic_algorithm_transformation.hpp" |
---|
16 | #include "transformation_enum.hpp" |
---|
17 | |
---|
18 | namespace xios { |
---|
19 | |
---|
20 | class CGrid; |
---|
21 | |
---|
22 | /*! |
---|
23 | \class CGridTransformation |
---|
24 | This class is an interface for all transformations to interact with the rest of XIOS. |
---|
25 | The class, firstly, tries to get all information relating to requested transformations by retrieving directly from grid. |
---|
26 | Then with all these information, all necessary transformations will be created by generic class \class CGenericAlgorithmTransformation. |
---|
27 | Because there are information exchange among clients to accomplish the transformations (e.g: some index need retrieving from other clients), |
---|
28 | this class uses class \class CTransformationMapping to fulfill this demand. |
---|
29 | For each transformation, a new temporary grid source is created. |
---|
30 | For a consequential transformations (e.g: inversing -> zoom -> inversing -> ...), |
---|
31 | the grid destination of current transformation will be grid source of the next transformation |
---|
32 | */ |
---|
33 | class CGridTransformation |
---|
34 | { |
---|
35 | public: |
---|
36 | typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType; |
---|
37 | typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; |
---|
38 | |
---|
39 | public: |
---|
40 | /** Default constructor */ |
---|
41 | CGridTransformation(CGrid* destination, CGrid* source); |
---|
42 | ~CGridTransformation(); |
---|
43 | |
---|
44 | void computeAll(const std::vector<CArray<double,1>* >& dataAuxInput=std::vector<CArray<double,1>* >()); |
---|
45 | |
---|
46 | const std::map<int, CArray<int,1> >& getLocalIndexToSendFromGridSource() const; |
---|
47 | const std::map<int, std::vector<std::vector<std::pair<int,double> > > >& getLocalIndexToReceiveOnGridDest() const; |
---|
48 | CGrid* getGridSource() { return originalGridSource_; } |
---|
49 | CGrid* getGridDestination() { return gridDestination_; } |
---|
50 | ListAlgoType getAlgoList() const {return listAlgos_; } |
---|
51 | int getNbAlgo() { return nbAlgos_; } |
---|
52 | const std::vector<StdString>& getAuxInputs() const { return auxInputs_; } |
---|
53 | |
---|
54 | protected: |
---|
55 | void computeTransformation(); |
---|
56 | void initializeAlgorithms(); |
---|
57 | void initializeAxisAlgorithms(int axisPositionInGrid); |
---|
58 | void initializeDomainAlgorithms(int domPositionInGrid); |
---|
59 | void initializeMappingOfOriginalGridSource(); |
---|
60 | |
---|
61 | void selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder); |
---|
62 | void selectDomainAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder); |
---|
63 | void selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder, bool isDomainAlgo); |
---|
64 | void setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation); |
---|
65 | void computeFinalTransformationMapping(); |
---|
66 | void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource); |
---|
67 | void updateFinalGridDestination(); |
---|
68 | bool isSpecialTransformation(ETranformationType transType); |
---|
69 | |
---|
70 | protected: |
---|
71 | //! Grid source on transformation |
---|
72 | CGrid* gridSource_; |
---|
73 | |
---|
74 | //! Grid destination on transformation |
---|
75 | CGrid* gridDestination_; |
---|
76 | |
---|
77 | //! The grid source of the first transformation (original grid source) |
---|
78 | CGrid* originalGridSource_; |
---|
79 | |
---|
80 | protected: |
---|
81 | //! List of algorithm types and their order |
---|
82 | ListAlgoType listAlgos_; |
---|
83 | |
---|
84 | //! Number of algorithm |
---|
85 | int nbAlgos_; |
---|
86 | |
---|
87 | // true if domain algorithm and false if axis algorithm (can be replaced by tuple with listAlgos_ |
---|
88 | std::vector<bool> algoTypes_; |
---|
89 | |
---|
90 | // Mapping between position of an element in grid and its transformation (if any) |
---|
91 | std::vector<CGenericAlgorithmTransformation*> algoTransformation_; |
---|
92 | |
---|
93 | //! Mapping of (grid) global index representing tranformation. |
---|
94 | std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource_; |
---|
95 | |
---|
96 | //! Local index of data to send from grid source |
---|
97 | std::map<int, CArray<int,1> > localIndexToSendFromGridSource_; |
---|
98 | |
---|
99 | //! Local index of data to receive on grid destination |
---|
100 | std::map<int,std::vector<std::vector<std::pair<int,double> > > > localIndexToReceiveOnGridDest_; |
---|
101 | |
---|
102 | //! Position of axis and domain in grid |
---|
103 | std::map<int, int> elementPosition2AxisPositionInGrid_, elementPosition2DomainPositionInGrid_; |
---|
104 | |
---|
105 | //! (Grid) Global index of grid source |
---|
106 | DestinationIndexMap currentGridIndexToOriginalGridIndex_; |
---|
107 | |
---|
108 | std::vector<CGrid*> tempGrids_; |
---|
109 | std::vector<StdString> auxInputs_; |
---|
110 | bool dynamicalTransformation_; |
---|
111 | }; |
---|
112 | |
---|
113 | } |
---|
114 | #endif // __XIOS_GRID_TRANSFORMATION_HPP__ |
---|