[624] | 1 | /*! |
---|
| 2 | \file axis_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 axis transformation algorithms. |
---|
| 8 | */ |
---|
| 9 | |
---|
[620] | 10 | #include "axis_algorithm_transformation.hpp" |
---|
[624] | 11 | #include "axis_algorithm_inverse.hpp" |
---|
| 12 | #include "axis_algorithm_zoom.hpp" |
---|
[620] | 13 | |
---|
| 14 | namespace xios { |
---|
| 15 | |
---|
[622] | 16 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) |
---|
[630] | 17 | : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource) |
---|
[620] | 18 | { |
---|
[666] | 19 | axisDestGlobalSize_ = axisDestination->n_glo.getValue(); |
---|
| 20 | int niDest = axisDestination->n.getValue(); |
---|
| 21 | int ibeginDest = axisDestination->begin.getValue(); |
---|
[630] | 22 | |
---|
| 23 | for (int idx = 0; idx < niDest; ++idx) |
---|
| 24 | if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
[621] | 25 | } |
---|
[620] | 26 | |
---|
[621] | 27 | CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() |
---|
| 28 | { |
---|
[620] | 29 | } |
---|
| 30 | |
---|
[621] | 31 | void CAxisAlgorithmTransformation::computeIndexSourceMapping() |
---|
| 32 | { |
---|
| 33 | } |
---|
| 34 | |
---|
[620] | 35 | /*! |
---|
| 36 | Compute an array of global index from a global index on a axis |
---|
| 37 | \param[in] axisDestGlobalIndex global index on an axis of destination grid |
---|
| 38 | \param[in] axisSrcGlobalIndex global index on an axis of source grid (which are needed by one index on axis destination) |
---|
| 39 | \param[in] axisPositionInGrid position of the axis in the grid |
---|
| 40 | \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the axis on which transformation is performed) |
---|
[668] | 41 | \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted |
---|
[620] | 42 | \param[in/out] globalIndexDestGrid array of global index (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated |
---|
| 43 | \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated |
---|
| 44 | */ |
---|
[630] | 45 | void CAxisAlgorithmTransformation::computeGlobalGridIndexFromGlobalIndexElement(int axisDestGlobalIndex, |
---|
[620] | 46 | const std::vector<int>& axisSrcGlobalIndex, |
---|
| 47 | int axisPositionInGrid, |
---|
| 48 | const std::vector<int>& gridDestGlobalDim, |
---|
[631] | 49 | const std::vector<int>& gridSrcGlobalDim, |
---|
[668] | 50 | const std::vector<size_t>& globalIndexGridDestSendToServer, |
---|
[620] | 51 | CArray<size_t,1>& globalIndexDestGrid, |
---|
[630] | 52 | std::vector<std::vector<size_t> >& globalIndexSrcGrid) |
---|
[620] | 53 | { |
---|
| 54 | int globalDim = gridDestGlobalDim.size(); |
---|
| 55 | |
---|
| 56 | std::vector<size_t> currentIndex(globalDim); |
---|
| 57 | std::vector<int> gridAxisGlobalDim(globalDim); |
---|
| 58 | std::vector<int> idxLoop(globalDim, 0); |
---|
| 59 | |
---|
| 60 | size_t ssize = 1, idx = 0, realGlobalIndexSize = 0; |
---|
| 61 | for (int i = 0; i< globalDim; ++i) |
---|
| 62 | { |
---|
| 63 | if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1; |
---|
| 64 | else gridAxisGlobalDim[i] = gridDestGlobalDim[i]; |
---|
| 65 | ssize *= gridAxisGlobalDim[i]; |
---|
| 66 | } |
---|
| 67 | |
---|
[668] | 68 | std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, |
---|
| 69 | iteArr = globalIndexGridDestSendToServer.end(); |
---|
[620] | 70 | |
---|
| 71 | while (idx < ssize) |
---|
| 72 | { |
---|
| 73 | for (int i = 0; i < globalDim-1; ++i) |
---|
| 74 | { |
---|
| 75 | if (idxLoop[i] == gridAxisGlobalDim[i]) |
---|
| 76 | { |
---|
| 77 | idxLoop[i] = 0; |
---|
| 78 | ++idxLoop[i+1]; |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i]; |
---|
| 83 | currentIndex[axisPositionInGrid] = axisDestGlobalIndex; |
---|
| 84 | |
---|
| 85 | size_t globIndex = currentIndex[0]; |
---|
| 86 | size_t mulDim = 1; |
---|
| 87 | for (int k = 1; k < globalDim; ++k) |
---|
| 88 | { |
---|
| 89 | mulDim *= gridDestGlobalDim[k-1]; |
---|
| 90 | globIndex += (currentIndex[k])*mulDim; |
---|
| 91 | } |
---|
| 92 | |
---|
[668] | 93 | if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize; |
---|
[620] | 94 | ++idxLoop[0]; |
---|
| 95 | ++idx; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | if (globalIndexDestGrid.numElements() != realGlobalIndexSize) |
---|
| 99 | globalIndexDestGrid.resize(realGlobalIndexSize); |
---|
| 100 | |
---|
[630] | 101 | if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); |
---|
[620] | 102 | for (int i = 0; i < globalIndexSrcGrid.size(); ++i) |
---|
[630] | 103 | if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size()) |
---|
| 104 | globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size()); |
---|
[620] | 105 | |
---|
| 106 | size_t realGlobalIndex = 0; |
---|
| 107 | idx = 0; |
---|
| 108 | idxLoop.assign(globalDim, 0); |
---|
| 109 | while (idx < ssize) |
---|
| 110 | { |
---|
| 111 | for (int i = 0; i < globalDim-1; ++i) |
---|
| 112 | { |
---|
| 113 | if (idxLoop[i] == gridAxisGlobalDim[i]) |
---|
| 114 | { |
---|
| 115 | idxLoop[i] = 0; |
---|
| 116 | ++idxLoop[i+1]; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i]; |
---|
| 121 | currentIndex[axisPositionInGrid] = axisDestGlobalIndex; |
---|
| 122 | |
---|
| 123 | size_t globIndex = currentIndex[0]; |
---|
| 124 | size_t mulDim = 1; |
---|
| 125 | for (int k = 1; k < globalDim; ++k) |
---|
| 126 | { |
---|
| 127 | mulDim *= gridDestGlobalDim[k-1]; |
---|
| 128 | globIndex += (currentIndex[k])*mulDim; |
---|
| 129 | } |
---|
| 130 | |
---|
[668] | 131 | if (std::binary_search(itbArr, iteArr, globIndex)) |
---|
[620] | 132 | { |
---|
| 133 | globalIndexDestGrid(realGlobalIndex) = globIndex; |
---|
[630] | 134 | for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) |
---|
[620] | 135 | { |
---|
| 136 | currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i]; |
---|
| 137 | globIndex = currentIndex[0]; |
---|
| 138 | mulDim = 1; |
---|
| 139 | for (int k = 1; k < globalDim; ++k) |
---|
| 140 | { |
---|
| 141 | mulDim *= gridDestGlobalDim[k-1]; |
---|
| 142 | globIndex += (currentIndex[k])*mulDim; |
---|
| 143 | } |
---|
[630] | 144 | (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex; |
---|
[620] | 145 | } |
---|
| 146 | ++realGlobalIndex; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | ++idxLoop[0]; |
---|
| 150 | ++idx; |
---|
| 151 | } |
---|
| 152 | } |
---|
| 153 | } |
---|