source: XIOS/trunk/src/transformation/grid_transformation.hpp @ 871

Last change on this file since 871 was 871, checked in by mhnguyen, 5 years ago

Correcting a bug which sometimes make transformations between different size grids incorrect

+) Correct inputs of some functions
+) Add some auxilliary functions.
+) Add new test cases for test_remap

Test
+) Basic test pass
+) Single horizontal and vertical interpolation are correct
+) Chained interpolation are not correct

File size: 5.0 KB
Line 
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 "generic_algorithm_transformation.hpp"
15#include "transformation_enum.hpp"
16#include "duration.hpp"
17
18namespace xios {
19
20class CGrid;
21
22/*!
23  \class CGridTransformation
24  This class is an interface for all transformations to interact with the rest of XIOS.
25The class, firstly, tries to get all information relating to requested transformations by retrieving directly from grid.
26Secondly, with all these information, all necessary transformations will be created by generic class \class CGenericAlgorithmTransformation.
27Then this class accomplishes the transformations by exchanging information among clients (e.g: some index need retrieving index from other clients),
28For each transformation, a new temporary grid source is created.
29For a consequential transformations (e.g: inversing -> zoom -> inversing -> ...),
30the grid destination of current transformation will be grid source of the next transformation
31*/
32class CGridTransformation
33{
34public:
35  typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType;
36  typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap;
37  typedef std::map<int, CArray<int,1> > SendingIndexGridSourceMap;
38  typedef std::map<int,std::vector<std::pair<int,double> > > RecvIndexGridDestinationMap;
39  typedef CGenericAlgorithmTransformation::SourceDestinationIndexMap SourceDestinationIndexMap;
40
41public:
42  /** Default constructor */
43  CGridTransformation(CGrid* destination, CGrid* source);
44  ~CGridTransformation();
45
46  void computeAll(const std::vector<CArray<double,1>* >& dataAuxInput=std::vector<CArray<double,1>* >(), Time timeStamp = 0);
47
48  const std::list<SendingIndexGridSourceMap>& getLocalIndexToSendFromGridSource() const;
49  const std::list<RecvIndexGridDestinationMap>& getLocalIndexToReceiveOnGridDest() const;
50  const std::list<size_t>& getNbLocalIndexToReceiveOnGridDest() const;
51  const std::list<std::vector<bool> >& getLocalMaskIndexOnGridDest() const;
52
53  CGrid* getGridSource() { return originalGridSource_; }
54  CGrid* getGridDestination() { return gridDestination_; }
55  ListAlgoType getAlgoList() const {return listAlgos_; }
56  int getNbAlgo() { return nbAlgos_; }
57  const std::vector<StdString>& getAuxInputs() const { return auxInputs_; }
58
59protected:
60  void computeTransformation();
61  void initializeAlgorithms();
62  void initializeAxisAlgorithms(int axisPositionInGrid);
63  void initializeDomainAlgorithms(int domPositionInGrid);
64  void initializeTransformations();
65
66  void selectAxisAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder);
67  void selectDomainAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder);
68  void selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder, bool isDomainAlgo);
69  void setUpGridSource(int elementPositionInGrid, ETranformationType transType, int nbTransformation);
70  void setUpGridDestination(int elementPositionInGrid, ETranformationType transType, int nbTransformation);
71  void computeTransformationMapping(const SourceDestinationIndexMap& globalIndexWeightFromSrcToDest);
72  bool isSpecialTransformation(ETranformationType transType);
73
74protected:
75  //! Grid source on transformation
76  CGrid* gridSource_;
77
78  //! Grid destination on transformation
79  CGrid* gridDestination_, *tmpGridDestination_;
80
81  //! The grid source of the first transformation (original grid source)
82  CGrid* originalGridSource_;
83
84protected:
85  //! List of algorithm types and their order
86  ListAlgoType listAlgos_;
87
88  //! Number of algorithm
89  int nbAlgos_;
90
91  // true if domain algorithm and false if axis algorithm (can be replaced by tuple with listAlgos_
92  std::vector<bool> algoTypes_;
93
94  // Mapping between position of an element in grid and its transformation (if any)
95  std::vector<CGenericAlgorithmTransformation*> algoTransformation_;
96
97  //! Mapping of (grid) global index representing tranformation.
98  std::map<size_t, std::set<size_t> > globaIndexMapFromDestToSource_;
99
100  //! Local index of data to send from grid source
101  std::list<SendingIndexGridSourceMap> localIndexToSendFromGridSource_;
102
103  //! Local index of data to receive on grid destination
104  std::list<RecvIndexGridDestinationMap> localIndexToReceiveOnGridDest_;
105
106  //! Number of local index of data to receive on grid destination
107  std::list<size_t> nbLocalIndexOnGridDest_;
108  std::list<std::vector<bool> > localMaskOnGridDest_;
109
110  //! Position of axis and domain in grid
111  std::map<int, int> elementPosition2AxisPositionInGrid_, elementPosition2DomainPositionInGrid_;
112
113  std::vector<CGrid*> tempGridSrcs_, tempGridDests_;
114  std::vector<StdString> auxInputs_;
115  bool dynamicalTransformation_;
116
117  std::set<Time> timeStamp_; //! Time stamps for auxillary inputs
118};
119
120}
121#endif // __XIOS_GRID_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.