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

Last change on this file since 1260 was 1260, checked in by ymipsl, 3 years ago

Buf fix in reduction. Missing value update was not set correctly

YM

File size: 6.9 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
[1260]66    \param [in] firstPass indicate if it is the first time the apply funtion is called for a same transformation, in order to make a clean initialization
[888]67  */
68  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
69                     const double* dataInput,
70                     CArray<double,1>& dataOut,
[1158]71                     std::vector<bool>& flagInitial,                     
[1260]72                     bool ignoreMissingValue, bool firstPass);
[888]73
[979]74  /*!
75   * Update whole dataOut (on necessary).
76   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
77   * \param [in/out] dataOut dataOut
78   */
79  virtual void updateData(CArray<double,1>& dataOut);
80
[827]81  std::vector<StdString> getIdAuxInputs();
[933]82  AlgoTransType type();
[623]83  /*!
[622]84  Compute global index mapping from one element of destination grid to the corresponding element of source grid
85  */
[827]86  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
[622]87
[620]88protected:
[867]89  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
90
[620]91  /*!
[867]92  Compute proc which contains global index of an element
93    \param[in] globalElementIndex demanding global index of an element of source grid
[888]94    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
[867]95    \param[out] globalElementIndexOnProc Proc contains the demanding global index
[620]96  */
[862]97  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
[888]98                                          int elementType,
[866]99                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
[862]100
[867]101protected:
[862]102  void computeGlobalGridIndexMapping(int elementPositionInGrid,
103                                     const std::vector<int>& srcRank,
104                                     boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
105                                     CGrid* gridDst,
106                                     CGrid* gridSrc,
107                                     std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
108                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
109
110  void computeExchangeDomainIndex(CDomain* domainDst,
111                                  CDomain* domainSrc,
112                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
113                                  boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
114
115  void computeExchangeAxisIndex(CAxis* axisDst,
116                                CAxis* axisSrc,
117                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
118                                boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
119
[888]120  void computeExchangeScalarIndex(CScalar* scalarDst,
121                                  CScalar* scalarSrc,
122                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
123                                  boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
124
125  void computePositionElements(CGrid* dst, CGrid* src);
126
[827]127protected:
128  //! Map between global index of destination element and source element
[833]129  std::vector<TransformationIndexMap> transformationMapping_;
[827]130  //! Weight corresponding of source to destination
[833]131  std::vector<TransformationWeightMap> transformationWeight_;
[827]132  //! Map of global index of destination element and corresponding global index of other elements in the same grid
133  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
[833]134  std::vector<TransformationPositionMap> transformationPosition_;
[622]135
[867]136  //! Id of auxillary inputs which helps doing transformation dynamically
[827]137  std::vector<StdString> idAuxInputs_;
[933]138  AlgoTransType type_;
[888]139
[1216]140  std::set<StdSize> indexElementSrc_;
141
142  std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_;
143
144  std::vector<int> procContainSrcElementIdx_;  // List of processes containing source index of transformed elements
145  std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements
146
147
148  bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements
149
[888]150  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
151  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
[620]152};
153
154}
155#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.