[1984] | 1 | /*! |
---|
| 2 | \file generic_algorithm_transformation.hpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 14 May 2015 |
---|
| 5 | \date 29 June 2015 |
---|
| 6 | |
---|
| 7 | \brief Interface for all transformation algorithms. |
---|
| 8 | */ |
---|
| 9 | #ifndef __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_NEW_HPP__ |
---|
| 10 | #define __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_NEW_HPP__ |
---|
| 11 | |
---|
| 12 | #include <map> |
---|
| 13 | #include <set> |
---|
| 14 | #include "array_new.hpp" |
---|
| 15 | #include "client_client_dht_template.hpp" |
---|
| 16 | |
---|
| 17 | namespace xios { |
---|
| 18 | class CGrid; |
---|
| 19 | class CDomain; |
---|
| 20 | class CAxis; |
---|
| 21 | class CScalar; |
---|
| 22 | |
---|
| 23 | /*! |
---|
| 24 | \class CGenericAlgorithmTransformation |
---|
| 25 | This class defines the interface for all other inherited algorithms class |
---|
| 26 | */ |
---|
| 27 | class CGenericAlgorithmTransformationNew |
---|
| 28 | { |
---|
| 29 | public: |
---|
| 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 | |
---|
| 38 | protected: |
---|
| 39 | typedef std::unordered_map<int, std::vector<int> > TransformationIndexMap; |
---|
| 40 | typedef std::unordered_map<int, std::vector<double> > TransformationWeightMap; |
---|
| 41 | typedef std::unordered_map<int, std::vector<int> > TransformationPositionMap; |
---|
| 42 | |
---|
| 43 | public: |
---|
| 44 | CGenericAlgorithmTransformationNew(); |
---|
| 45 | |
---|
| 46 | virtual ~CGenericAlgorithmTransformationNew() {} |
---|
| 47 | |
---|
| 48 | /*! |
---|
| 49 | Apply a operation on local data. |
---|
| 50 | \param [in] localIndex vector contains local index of local data output and the corresponding weight |
---|
| 51 | \param [in] dataInput Pointer to the first element of data input array (in form of buffer) |
---|
| 52 | \param [in/out] dataOut Array contains local data |
---|
| 53 | \param [in/out] flagInitial vector of boolean to mark the local index already initialized. True means there is a need for initalization |
---|
| 54 | \param [in] ignoreMissingValue don't count missing value in operation if this flag is true |
---|
| 55 | \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 |
---|
| 56 | */ |
---|
| 57 | virtual void apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
| 58 | const double* dataInput, |
---|
| 59 | CArray<double,1>& dataOut, |
---|
| 60 | std::vector<bool>& flagInitial, |
---|
| 61 | bool ignoreMissingValue, bool firstPass); |
---|
| 62 | |
---|
| 63 | /*! |
---|
| 64 | * Update whole dataOut (on necessary). |
---|
| 65 | * (Example: Impose a weight, whose value is only known after being applied an operation, on dataOut) |
---|
| 66 | * \param [in/out] dataOut dataOut |
---|
| 67 | */ |
---|
| 68 | virtual void updateData(CArray<double,1>& dataOut); |
---|
| 69 | |
---|
| 70 | std::vector<StdString> getIdAuxInputs(); |
---|
| 71 | AlgoTransType type(); |
---|
| 72 | /*! |
---|
| 73 | Compute global index mapping from one element of destination grid to the corresponding element of source grid |
---|
| 74 | */ |
---|
| 75 | void computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs = std::vector<CArray<double,1>* >()); |
---|
| 76 | |
---|
| 77 | protected: |
---|
| 78 | virtual void computeIndexSourceMapping_(const std::vector<CArray<double,1>* >&) = 0; |
---|
| 79 | |
---|
| 80 | /*! |
---|
| 81 | Compute proc which contains global index of an element |
---|
| 82 | \param[in] globalElementIndex demanding global index of an element of source grid |
---|
| 83 | \param[in] elementType type of source element, 2: domain, 1: axis and 0: scalar |
---|
| 84 | \param[out] globalElementIndexOnProc Proc contains the demanding global index |
---|
| 85 | */ |
---|
| 86 | virtual void computeExchangeGlobalIndex(const CArray<size_t,1>& globalElementIndex, |
---|
| 87 | int elementType, |
---|
| 88 | CClientClientDHTInt::Index2VectorInfoTypeMap& globalElementIndexOnProc) = 0; |
---|
| 89 | |
---|
| 90 | protected: |
---|
| 91 | //! indicate if the transformation is performed on a distributed element |
---|
| 92 | bool isDistributed_ ; |
---|
| 93 | //! indicate if the method isDistributedTransformation has been called before |
---|
| 94 | bool isDistributedComputed_ ; |
---|
| 95 | |
---|
| 96 | //! Map between global index of destination element and source element |
---|
| 97 | std::vector<TransformationIndexMap> transformationMapping_; |
---|
| 98 | //! Weight corresponding of source to destination |
---|
| 99 | std::vector<TransformationWeightMap> transformationWeight_; |
---|
| 100 | //! Map of global index of destination element and corresponding global index of other elements in the same grid |
---|
| 101 | //! By default, one index of an element corresponds to all index of remaining element in the grid. So it's empty |
---|
| 102 | std::vector<TransformationPositionMap> transformationPosition_; |
---|
| 103 | |
---|
| 104 | //! Id of auxillary inputs which helps doing transformation dynamically |
---|
| 105 | std::vector<StdString> idAuxInputs_; |
---|
| 106 | AlgoTransType type_; |
---|
| 107 | |
---|
| 108 | bool eliminateRedondantSrc_ ; // flag to indicate if the transformation must select only one global source point for all proc. |
---|
| 109 | // In this case it will choose preferentially the current process |
---|
| 110 | }; |
---|
| 111 | |
---|
| 112 | } |
---|
| 113 | #endif // __XIOS_GENERIC_ALGORITHM_TRANSFORMATION_HPP__ |
---|