[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 | #include "generic_algorithm_transformation.hpp" |
---|
| 10 | |
---|
| 11 | namespace xios { |
---|
| 12 | |
---|
| 13 | CGenericAlgorithmTransformation::CGenericAlgorithmTransformation() |
---|
[827] | 14 | : transformationMapping_(), transformationWeight_(), transformationPosition_(), idAuxInputs_() |
---|
[620] | 15 | { |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | /*! |
---|
| 19 | This function computes the global indexes of grid source, which the grid destination is in demand. |
---|
| 20 | \param[in] elementPositionInGrid position of an element in a grid .E.g: if grid is composed of domain and axis (in order), |
---|
| 21 | then position of axis in grid is 2 (since a domain is considered to contain 2 elements (axis) |
---|
| 22 | \param[in] gridDestGlobalDim global size of each dimension of grid source (all dimension must have the same size except of the one on which transformation is performed) |
---|
[631] | 23 | \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed) |
---|
[620] | 24 | \param[in] globalIndexGridDestSendToServer global index of grid destination on the current client to send to server |
---|
[630] | 25 | \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination |
---|
| 26 | and the weighted value as long as global index from grid index source |
---|
[620] | 27 | */ |
---|
| 28 | void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid, |
---|
| 29 | const std::vector<int>& gridDestGlobalDim, |
---|
[631] | 30 | const std::vector<int>& gridSrcGlobalDim, |
---|
[668] | 31 | const std::vector<size_t>& globalIndexGridDestSendToServer, |
---|
[630] | 32 | std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource) |
---|
[620] | 33 | { |
---|
[827] | 34 | bool isTransPosEmpty = transformationPosition_.empty(); |
---|
[668] | 35 | std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); |
---|
| 36 | std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); |
---|
[827] | 37 | for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) |
---|
[620] | 38 | { |
---|
[827] | 39 | std::map<int, std::vector<int> >::const_iterator itbTransMap = transformationMapping_[idxTrans].begin(), itTransMap, |
---|
| 40 | iteTransMap = transformationMapping_[idxTrans].end(); |
---|
| 41 | std::map<int, std::vector<double> >::const_iterator itTransWeight = transformationWeight_[idxTrans].begin(); |
---|
| 42 | |
---|
| 43 | // If transformation position exists |
---|
| 44 | std::map<int, std::vector<int> >::const_iterator itTransPos, iteTransPos; |
---|
| 45 | if (!isTransPosEmpty) |
---|
[620] | 46 | { |
---|
[827] | 47 | itTransPos = transformationPosition_[idxTrans].begin(), |
---|
| 48 | iteTransPos = transformationPosition_[idxTrans].end(); |
---|
| 49 | } |
---|
| 50 | std::vector<int> emptyTransPos; |
---|
| 51 | |
---|
| 52 | std::vector<std::vector<size_t> > globalIndexSrcGrid; |
---|
| 53 | CArray<size_t,1> globalIndexDestGrid; |
---|
| 54 | // std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); |
---|
| 55 | // std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); |
---|
| 56 | for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) |
---|
| 57 | { |
---|
| 58 | if (!isTransPosEmpty) |
---|
[620] | 59 | { |
---|
[827] | 60 | this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, |
---|
| 61 | itTransMap->second, |
---|
| 62 | itTransPos->second, |
---|
| 63 | elementPositionInGrid, |
---|
| 64 | gridDestGlobalDim, |
---|
| 65 | gridSrcGlobalDim, |
---|
| 66 | vecGlobalIndexGridSendToServer, |
---|
| 67 | globalIndexDestGrid, |
---|
| 68 | globalIndexSrcGrid); |
---|
| 69 | ++itTransPos; |
---|
[620] | 70 | } |
---|
[827] | 71 | else |
---|
| 72 | { |
---|
| 73 | this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, |
---|
| 74 | itTransMap->second, |
---|
| 75 | emptyTransPos, |
---|
| 76 | elementPositionInGrid, |
---|
| 77 | gridDestGlobalDim, |
---|
| 78 | gridSrcGlobalDim, |
---|
| 79 | vecGlobalIndexGridSendToServer, |
---|
| 80 | globalIndexDestGrid, |
---|
| 81 | globalIndexSrcGrid); |
---|
| 82 | } |
---|
| 83 | size_t globalIndexSize = globalIndexDestGrid.numElements(); |
---|
| 84 | const std::vector<double>& currentVecWeight = itTransWeight->second; |
---|
| 85 | for (size_t idx = 0; idx < globalIndexSize; ++idx) |
---|
| 86 | { |
---|
| 87 | size_t globalIndex = globalIndexDestGrid(idx); |
---|
| 88 | for (int i = 0; i < globalIndexSrcGrid[idx].size(); ++i) |
---|
| 89 | { |
---|
| 90 | globaIndexWeightFromDestToSource[globalIndex].push_back(make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])); |
---|
| 91 | } |
---|
| 92 | } |
---|
[620] | 93 | } |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | |
---|
[827] | 97 | void CGenericAlgorithmTransformation::computeIndexSourceMapping(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
| 98 | { |
---|
| 99 | computeIndexSourceMapping_(dataAuxInputs); |
---|
[620] | 100 | } |
---|
[827] | 101 | |
---|
| 102 | std::vector<StdString> CGenericAlgorithmTransformation::getIdAuxInputs() |
---|
| 103 | { |
---|
| 104 | return idAuxInputs_; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | } |
---|