source: XIOS/dev/XIOS_DEV_CMIP6/src/transformation/generic_algorithm_transformation.hpp @ 1216

Last change on this file since 1216 was 1216, checked in by mhnguyen, 7 years ago

Performance improvement of vertical interpolation

+) Reduce a number of unnesscessary function callings on calculating weights of interpolation

Test
+) On Curie
+) Ok

File size: 6.8 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"
[866]15#include "client_client_dht_template.hpp"
[620]16
17namespace xios {
[862]18  class CGrid;
19  class CDomain;
20  class CAxis;
[888]21  class CScalar;
[862]22
[624]23  /*!
24  \class CGenericAlgorithmTransformation
[933]25  This class defines the interface for all other inherited algorithms class
[624]26  */
[620]27class CGenericAlgorithmTransformation
28{
29public:
[933]30  enum AlgoTransType {
31    ELEMENT_GENERATION = 0,
32    ELEMENT_MODIFICATION_WITHOUT_DATA = 1,
33    ELEMENT_MODIFICATION_WITH_DATA = 2,
34    ELEMENT_NO_MODIFICATION_WITH_DATA = 3,
35    ELEMENT_NO_MODIFICATION_WITHOUT_DATA = 4
36  } ;
37
38public:
[829]39  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights
[862]40  typedef boost::unordered_map<int, boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap;
[843]41
[829]42protected:
43  typedef boost::unordered_map<size_t,int> GlobalLocalMap;
[862]44protected:
45  typedef boost::unordered_map<int, std::vector<int> > TransformationIndexMap;
46  typedef boost::unordered_map<int, std::vector<double> > TransformationWeightMap;
47  typedef boost::unordered_map<int, std::vector<int> > TransformationPositionMap;
[829]48
49public:
[620]50  CGenericAlgorithmTransformation();
51
52  virtual ~CGenericAlgorithmTransformation() {}
53
54  void computeGlobalSourceIndex(int elementPositionInGrid,
[862]55                               CGrid* gridSrc,
56                               CGrid* gridDst,
57                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
[622]58
[888]59    /*!
[933]60    Apply a operation on local data.
[888]61    \param [in] localIndex vector contains local index of local data output and the corresponding weight
62    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
63    \param [in/out] dataOut Array contains local data
64    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization
[1158]65    \param [in] ignoreMissingValue don't count missing value in operation if this flag is true
[888]66  */
67  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
68                     const double* dataInput,
69                     CArray<double,1>& dataOut,
[1158]70                     std::vector<bool>& flagInitial,                     
71                     bool ignoreMissingValue);
[888]72
[979]73  /*!
74   * Update whole dataOut (on necessary).
75   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
76   * \param [in/out] dataOut dataOut
77   */
78  virtual void updateData(CArray<double,1>& dataOut);
79
[827]80  std::vector<StdString> getIdAuxInputs();
[933]81  AlgoTransType type();
[623]82  /*!
[622]83  Compute global index mapping from one element of destination grid to the corresponding element of source grid
84  */
[827]85  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
[622]86
[620]87protected:
[867]88  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
89
[620]90  /*!
[867]91  Compute proc which contains global index of an element
92    \param[in] globalElementIndex demanding global index of an element of source grid
[888]93    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
[867]94    \param[out] globalElementIndexOnProc Proc contains the demanding global index
[620]95  */
[862]96  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
[888]97                                          int elementType,
[866]98                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
[862]99
[867]100protected:
[862]101  void computeGlobalGridIndexMapping(int elementPositionInGrid,
102                                     const std::vector<int>& srcRank,
103                                     boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
104                                     CGrid* gridDst,
105                                     CGrid* gridSrc,
106                                     std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
107                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
108
109  void computeExchangeDomainIndex(CDomain* domainDst,
110                                  CDomain* domainSrc,
111                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
112                                  boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
113
114  void computeExchangeAxisIndex(CAxis* axisDst,
115                                CAxis* axisSrc,
116                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
117                                boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
118
[888]119  void computeExchangeScalarIndex(CScalar* scalarDst,
120                                  CScalar* scalarSrc,
121                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
122                                  boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
123
124  void computePositionElements(CGrid* dst, CGrid* src);
125
[827]126protected:
127  //! Map between global index of destination element and source element
[833]128  std::vector<TransformationIndexMap> transformationMapping_;
[827]129  //! Weight corresponding of source to destination
[833]130  std::vector<TransformationWeightMap> transformationWeight_;
[827]131  //! Map of global index of destination element and corresponding global index of other elements in the same grid
132  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
[833]133  std::vector<TransformationPositionMap> transformationPosition_;
[622]134
[867]135  //! Id of auxillary inputs which helps doing transformation dynamically
[827]136  std::vector<StdString> idAuxInputs_;
[933]137  AlgoTransType type_;
[888]138
[1216]139  std::set<StdSize> indexElementSrc_;
140
141  std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_;
142
143  std::vector<int> procContainSrcElementIdx_;  // List of processes containing source index of transformed elements
144  std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements
145
146
147  bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements
148
[888]149  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
150  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
[620]151};
152
153}
154#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.