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

Last change on this file since 1567 was 1542, checked in by oabramkina, 6 years ago

Replacing Boost's unordered_map and shared_pointer by its STL counterparts.

Two notes for Curie:

  • one can see the content of unordered_map with ddt only if XIOS has been compiled with gnu
  • XIOS will not compile any more with pgi (all available versions use old STL which are not up to the c++11 norms)
File size: 8.4 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
[1542]40  typedef std::unordered_map<int, std::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap;
[843]41
[829]42protected:
[1542]43  typedef std::unordered_map<size_t,int> GlobalLocalMap;
[862]44protected:
[1542]45  typedef std::unordered_map<int, std::vector<int> > TransformationIndexMap;
46  typedef std::unordered_map<int, std::vector<double> > TransformationWeightMap;
47  typedef std::unordered_map<int, std::vector<int> > TransformationPositionMap;
[829]48
49public:
[620]50  CGenericAlgorithmTransformation();
51
52  virtual ~CGenericAlgorithmTransformation() {}
53
[1399]54  bool isDistributedTransformation(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst) ;
55
[620]56  void computeGlobalSourceIndex(int elementPositionInGrid,
[862]57                               CGrid* gridSrc,
58                               CGrid* gridDst,
59                               SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
[622]60
[888]61    /*!
[933]62    Apply a operation on local data.
[888]63    \param [in] localIndex vector contains local index of local data output and the corresponding weight
64    \param [in] dataInput Pointer to the first element of data input array (in form of buffer)
65    \param [in/out] dataOut Array contains local data
66    \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization
[1158]67    \param [in] ignoreMissingValue don't count missing value in operation if this flag is true
[1260]68    \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]69  */
70  virtual void apply(const std::vector<std::pair<int,double> >& localIndex,
71                     const double* dataInput,
72                     CArray<double,1>& dataOut,
[1158]73                     std::vector<bool>& flagInitial,                     
[1260]74                     bool ignoreMissingValue, bool firstPass);
[888]75
[979]76  /*!
77   * Update whole dataOut (on necessary).
78   * (Example:  Impose a weight, whose value is only known after being applied an operation, on dataOut)
79   * \param [in/out] dataOut dataOut
80   */
81  virtual void updateData(CArray<double,1>& dataOut);
82
[827]83  std::vector<StdString> getIdAuxInputs();
[933]84  AlgoTransType type();
[623]85  /*!
[622]86  Compute global index mapping from one element of destination grid to the corresponding element of source grid
87  */
[827]88  void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >());
[1399]89  void computeTransformationMappingNonDistributed(int elementPositionInGrid, CGrid* gridSrc, CGrid* gridDst,
90                                                  vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, vector<bool>& localMaskOnGridDest);
[1420]91  void nonDistributedrecursiveFunct(int currentPos, bool masked, int elementPositionInGrid,  vector< CArray<bool,1>* >& maskSrc, vector< CArray<bool,1>* >& maskDst, int& srcInd, int& srcIndCompressed, vector<int>& nIndexSrc, int& t, vector<vector<vector<pair<int,double> > > >& dstIndWeight, int currentInd,
[1399]92                                     vector<int>& localSrc, vector<int>& localDst, vector<double>& weight, CArray<bool,1>& localMaskOnGridSrc, vector<bool>& localMaskOnGridDest) ;
[622]93
[620]94protected:
[867]95  virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0;
96
[620]97  /*!
[867]98  Compute proc which contains global index of an element
99    \param[in] globalElementIndex demanding global index of an element of source grid
[888]100    \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar
[867]101    \param[out] globalElementIndexOnProc Proc contains the demanding global index
[620]102  */
[862]103  virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex,
[888]104                                          int elementType,
[866]105                                          CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0;
[862]106
[867]107protected:
[862]108  void computeGlobalGridIndexMapping(int elementPositionInGrid,
109                                     const std::vector<int>& srcRank,
[1542]110                                     std::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap,
[862]111                                     CGrid* gridDst,
112                                     CGrid* gridSrc,
[1542]113                                     std::vector<std::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc,
[862]114                                     SourceDestinationIndexMap& globaIndexWeightFromSrcToDst);
115
116  void computeExchangeDomainIndex(CDomain* domainDst,
117                                  CDomain* domainSrc,
118                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
[1542]119                                  std::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc);
[862]120
121  void computeExchangeAxisIndex(CAxis* axisDst,
122                                CAxis* axisSrc,
123                                CArray<size_t,1>& destGlobalIndexPositionInGrid,
[1542]124                                std::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc);
[862]125
[888]126  void computeExchangeScalarIndex(CScalar* scalarDst,
127                                  CScalar* scalarSrc,
128                                  CArray<size_t,1>& destGlobalIndexPositionInGrid,
[1542]129                                  std::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc);
[888]130
131  void computePositionElements(CGrid* dst, CGrid* src);
132
[827]133protected:
[1399]134  //! indicate if the transformation is performed on a distributed element
135  bool isDistributed_ ;
136  //! indicate if the method  isDistributedTransformation has been called before
137  bool isDistributedComputed_ ;
138 
[827]139  //! Map between global index of destination element and source element
[833]140  std::vector<TransformationIndexMap> transformationMapping_;
[827]141  //! Weight corresponding of source to destination
[833]142  std::vector<TransformationWeightMap> transformationWeight_;
[827]143  //! Map of global index of destination element and corresponding global index of other elements in the same grid
144  //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty
[833]145  std::vector<TransformationPositionMap> transformationPosition_;
[622]146
[867]147  //! Id of auxillary inputs which helps doing transformation dynamically
[827]148  std::vector<StdString> idAuxInputs_;
[933]149  AlgoTransType type_;
[888]150
[1216]151  std::set<StdSize> indexElementSrc_;
152
[1542]153  std::vector<std::unordered_map<int,std::vector<size_t> > > globalElementIndexOnProc_;
[1216]154
155  std::vector<int> procContainSrcElementIdx_;  // List of processes containing source index of transformed elements
[1389]156//  std::set<int> procOfNonTransformedElements_; // Processes contain the source index of non-transformed elements
[1399]157  std::set<int> commonProc_;
[1389]158  std::vector< set<int> > procElementList_ ; // List of processes containing source index of elements
[1216]159
[1400]160  CClientClientDHTInt::Index2VectorInfoTypeMap globalIndexOfTransformedElementOnProc_;
161 
[1216]162  bool computedProcSrcNonTransformedElement_; // Flag to indicate whether we computed proc containing non transformed elements
163
[888]164  std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_;
165  std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_;
[1298]166
167  bool eliminateRedondantSrc_ ; // flag to indicate if the transformation must select only one global source point for all proc.
168                               // In this case it will choose preferentially the current process
[620]169};
170
171}
172#endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__
Note: See TracBrowser for help on using the repository browser.