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

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

Refactoring transformation code

+) On exchanging information during transformation, not only global index are sent but also local index
+) Correct a bug in distributed hash table (dht)
+) Add new type for dht
+) Clean up some redundant codes

Test
+) On Curie
+) Every test passes
+) Code runs faster in some cases (up to 30%)

File size: 4.6 KB
RevLine 
[624]1/*!
2   \file generic_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
[630]5   \date 29 June 2015
[624]6
7   \brief Interface for all transformation algorithms.
8 */
[620]9#ifndef __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
10#define __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
11
12#include <map>
[630]13#include <set>
[620]14#include "array_new.hpp"
15
16namespace xios {
[624]17  /*!
18  \class CGenericAlgorithmTransformation
19  This class defines the interface for all other inherted algorithms class
20  */
[620]21class CGenericAlgorithmTransformation
22{
23public:
[829]24  // Stupid global index map, it must be replaced by tuple
25  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights
26  typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap;
27protected:
28  typedef boost::unordered_map<size_t,int> GlobalLocalMap;
29
30public:
[620]31  CGenericAlgorithmTransformation();
32
33  virtual ~CGenericAlgorithmTransformation() {}
34
35  void computeGlobalSourceIndex(int elementPositionInGrid,
36                                const std::vector<int>& gridDestGlobalDim,
[631]37                                const std::vector<int>& gridSrcGlobalDim,
[668]38                                const std::vector<size_t>& globalIndexGridDestSendToServer,
[829]39                                const std::vector<int>& localIndexGridSendToServer,
40                                DestinationIndexMap& globaIndexWeightFromDestToSource);
[622]41
[827]42  std::vector<StdString> getIdAuxInputs();
43
[623]44  /*!
[622]45  Compute global index mapping from one element of destination grid to the corresponding element of source grid
46  */
[827]47  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
[622]48
[620]49protected:
50  /*!
51  Compute an array of global index from a global index on an element
52    \param[in] destGlobalIndex global index on an element of destination grid
53    \param[in] srcGlobalIndex global index(es) on an element of source grid (which are needed by one index on element destination)
54    \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)
55    \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)
[829]56    \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
57    \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
[620]58    \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
59  */
[630]60  virtual void computeGlobalGridIndexFromGlobalIndexElement(int destGlobalIndex,
[620]61                                                        const std::vector<int>& srcGlobalIndex,
[827]62                                                        const std::vector<int>& destGlobalIndexPositionInGrid,
[620]63                                                        int elementPositionInGrid,
64                                                        const std::vector<int>& gridDestGlobalDim,
[631]65                                                        const std::vector<int>& gridSrcGlobalDim,
[829]66                                                        const GlobalLocalMap& globalLocalIndexDestSendToServerMap,
67                                                        std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap,
[630]68                                                        std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0;
[620]69
[827]70  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
[620]71
[827]72protected:
73  //! Map between global index of destination element and source element
74  std::vector<std::map<int, std::vector<int> > > transformationMapping_;
75  //! Weight corresponding of source to destination
76  std::vector<std::map<int, std::vector<double> > > transformationWeight_;
77  //! Map of global index of destination element and corresponding global index of other elements in the same grid
78  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
79  std::vector<std::map<int, std::vector<int> > > transformationPosition_;
[622]80
[827]81  //! Id of auxillary inputs which help doing transformation dynamically
82  std::vector<StdString> idAuxInputs_;
[620]83};
84
85}
86#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.