[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 | |
---|
| 17 | namespace xios { |
---|
[862] | 18 | class CGrid; |
---|
| 19 | class CDomain; |
---|
| 20 | class CAxis; |
---|
[888] | 21 | class CScalar; |
---|
[862] | 22 | |
---|
[624] | 23 | /*! |
---|
| 24 | \class CGenericAlgorithmTransformation |
---|
| 25 | This class defines the interface for all other inherted algorithms class |
---|
| 26 | */ |
---|
[620] | 27 | class CGenericAlgorithmTransformation |
---|
| 28 | { |
---|
[843] | 29 | protected: |
---|
| 30 | typedef std::vector<std::pair<int, std::pair<size_t,double> > > DestinationGlobalIndex; |
---|
[620] | 31 | public: |
---|
[829] | 32 | // Stupid global index map, it must be replaced by tuple |
---|
| 33 | // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights |
---|
[843] | 34 | typedef boost::unordered_map<size_t, DestinationGlobalIndex> DestinationIndexMap; |
---|
[862] | 35 | // |
---|
| 36 | typedef boost::unordered_map<int, boost::unordered_map<size_t, std::vector<std::pair<size_t,double> > > > SourceDestinationIndexMap; |
---|
[843] | 37 | |
---|
[829] | 38 | protected: |
---|
| 39 | typedef boost::unordered_map<size_t,int> GlobalLocalMap; |
---|
[862] | 40 | protected: |
---|
| 41 | typedef boost::unordered_map<int, std::vector<int> > TransformationIndexMap; |
---|
| 42 | typedef boost::unordered_map<int, std::vector<double> > TransformationWeightMap; |
---|
| 43 | typedef boost::unordered_map<int, std::vector<int> > TransformationPositionMap; |
---|
[829] | 44 | |
---|
| 45 | public: |
---|
[620] | 46 | CGenericAlgorithmTransformation(); |
---|
| 47 | |
---|
| 48 | virtual ~CGenericAlgorithmTransformation() {} |
---|
| 49 | |
---|
| 50 | void computeGlobalSourceIndex(int elementPositionInGrid, |
---|
[862] | 51 | CGrid* gridSrc, |
---|
| 52 | CGrid* gridDst, |
---|
| 53 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
[622] | 54 | |
---|
[888] | 55 | /*! |
---|
| 56 | Apply a reduction operation on local data. |
---|
| 57 | \param [in] localIndex vector contains local index of local data output and the corresponding weight |
---|
| 58 | \param [in] dataInput Pointer to the first element of data input array (in form of buffer) |
---|
| 59 | \param [in/out] dataOut Array contains local data |
---|
| 60 | \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization |
---|
| 61 | */ |
---|
| 62 | virtual void apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
| 63 | const double* dataInput, |
---|
| 64 | CArray<double,1>& dataOut, |
---|
[918] | 65 | std::vector<bool>& flagInitial, |
---|
| 66 | const double& defaultValue); |
---|
[888] | 67 | |
---|
[827] | 68 | std::vector<StdString> getIdAuxInputs(); |
---|
| 69 | |
---|
[623] | 70 | /*! |
---|
[622] | 71 | Compute global index mapping from one element of destination grid to the corresponding element of source grid |
---|
| 72 | */ |
---|
[827] | 73 | void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >()); |
---|
[622] | 74 | |
---|
[620] | 75 | protected: |
---|
[867] | 76 | virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0; |
---|
| 77 | |
---|
[620] | 78 | /*! |
---|
[867] | 79 | Compute proc which contains global index of an element |
---|
| 80 | \param[in] globalElementIndex demanding global index of an element of source grid |
---|
[888] | 81 | \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar |
---|
[867] | 82 | \param[out] globalElementIndexOnProc Proc contains the demanding global index |
---|
[620] | 83 | */ |
---|
[862] | 84 | virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex, |
---|
[888] | 85 | int elementType, |
---|
[866] | 86 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0; |
---|
[862] | 87 | |
---|
[867] | 88 | protected: |
---|
[862] | 89 | void computeGlobalGridIndexMapping(int elementPositionInGrid, |
---|
| 90 | const std::vector<int>& srcRank, |
---|
| 91 | boost::unordered_map<int, std::vector<std::pair<int,double> > >& src2DstMap, |
---|
| 92 | CGrid* gridDst, |
---|
| 93 | CGrid* gridSrc, |
---|
| 94 | std::vector<boost::unordered_map<int,std::vector<size_t> > >& globalElementIndexOnProc, |
---|
| 95 | SourceDestinationIndexMap& globaIndexWeightFromSrcToDst); |
---|
| 96 | |
---|
| 97 | void computeExchangeDomainIndex(CDomain* domainDst, |
---|
| 98 | CDomain* domainSrc, |
---|
| 99 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
| 100 | boost::unordered_map<int,std::vector<size_t> >& globalDomainIndexOnProc); |
---|
| 101 | |
---|
| 102 | void computeExchangeAxisIndex(CAxis* axisDst, |
---|
| 103 | CAxis* axisSrc, |
---|
| 104 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
| 105 | boost::unordered_map<int,std::vector<size_t> >& globalAxisIndexOnProc); |
---|
| 106 | |
---|
[888] | 107 | void computeExchangeScalarIndex(CScalar* scalarDst, |
---|
| 108 | CScalar* scalarSrc, |
---|
| 109 | CArray<size_t,1>& destGlobalIndexPositionInGrid, |
---|
| 110 | boost::unordered_map<int,std::vector<size_t> >& globalScalarIndexOnProc); |
---|
| 111 | |
---|
| 112 | void computePositionElements(CGrid* dst, CGrid* src); |
---|
| 113 | |
---|
[827] | 114 | protected: |
---|
| 115 | //! Map between global index of destination element and source element |
---|
[833] | 116 | std::vector<TransformationIndexMap> transformationMapping_; |
---|
[827] | 117 | //! Weight corresponding of source to destination |
---|
[833] | 118 | std::vector<TransformationWeightMap> transformationWeight_; |
---|
[827] | 119 | //! Map of global index of destination element and corresponding global index of other elements in the same grid |
---|
| 120 | //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty |
---|
[833] | 121 | std::vector<TransformationPositionMap> transformationPosition_; |
---|
[622] | 122 | |
---|
[867] | 123 | //! Id of auxillary inputs which helps doing transformation dynamically |
---|
[827] | 124 | std::vector<StdString> idAuxInputs_; |
---|
[888] | 125 | |
---|
| 126 | std::map<int, int> elementPositionInGridSrc2AxisPosition_, elementPositionInGridSrc2DomainPosition_, elementPositionInGridSrc2ScalarPosition_; |
---|
| 127 | std::map<int, int> elementPositionInGridDst2AxisPosition_, elementPositionInGridDst2DomainPosition_, elementPositionInGridDst2ScalarPosition_; |
---|
[620] | 128 | }; |
---|
| 129 | |
---|
| 130 | } |
---|
| 131 | #endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|