1 | #include "axis_algorithm_transformation.hpp" |
---|
2 | #include "axis_inverse.hpp" |
---|
3 | #include "axis_zoom.hpp" |
---|
4 | |
---|
5 | namespace xios { |
---|
6 | |
---|
7 | CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource) |
---|
8 | : CGenericAlgorithmTransformation() |
---|
9 | { |
---|
10 | // if (axisDestination->size.getValue() != axisSource->size.getValue()) |
---|
11 | // { |
---|
12 | // ERROR("CAxisZoom::CAxisZoom(CAxis* axisDestination, CAxis* axisSource)", |
---|
13 | // << "Two axis have different size" |
---|
14 | // << "Size of axis source " <<axisSource->getId() << " is " << axisSource->size.getValue() << std::endl |
---|
15 | // << "Size of axis destionation " <<axisDestination->getId() << " is " << axisDestination->size.getValue()); |
---|
16 | // } |
---|
17 | // |
---|
18 | // |
---|
19 | // axisDestGlobalSize_ = axisDestination->size.getValue(); |
---|
20 | // int niDest = axisDestination->ni.getValue(); |
---|
21 | // int ibeginDest = axisDestination->ibegin.getValue(); |
---|
22 | // |
---|
23 | // for (int idx = 0; idx < niDest; ++idx) axisDestGlobalIndex_.push_back(ibeginDest+idx); |
---|
24 | } |
---|
25 | |
---|
26 | CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation() |
---|
27 | { |
---|
28 | // for (int idx = 0; idx < algosOfAnAxis_.size(); ++idx) delete algosOfAnAxis_[idx]; |
---|
29 | } |
---|
30 | |
---|
31 | void CAxisAlgorithmTransformation::computeIndexSourceMapping() |
---|
32 | { |
---|
33 | // if (!algosOfAnAxis_.empty()) |
---|
34 | // { |
---|
35 | // algosOfAnAxis_[0]->computeIndexSourceMapping(this->transformationMapping_); |
---|
36 | // for (int idx = 1; idx < algosOfAnAxis_.size(); ++idx) |
---|
37 | // { |
---|
38 | // algosOfAnAxis_[idx]->computeIndexSourceMapping(algosOfAnAxis_[idx-1]->getTransformationMapping()); |
---|
39 | // } |
---|
40 | // this->transformationMapping_ = algosOfAnAxis_[algosOfAnAxis_.size()-1]->getTransformationMapping(); |
---|
41 | // } |
---|
42 | } |
---|
43 | |
---|
44 | /*! |
---|
45 | Compute an array of global index from a global index on a axis |
---|
46 | \param[in] axisDestGlobalIndex global index on an axis of destination grid |
---|
47 | \param[in] axisSrcGlobalIndex global index on an axis of source grid (which are needed by one index on axis destination) |
---|
48 | \param[in] axisPositionInGrid position of the axis in the grid |
---|
49 | \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) |
---|
50 | \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s) |
---|
51 | \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 |
---|
52 | \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 |
---|
53 | */ |
---|
54 | void CAxisAlgorithmTransformation::computeGlobalIndexFromGlobalIndexElement(int axisDestGlobalIndex, |
---|
55 | const std::vector<int>& axisSrcGlobalIndex, |
---|
56 | int axisPositionInGrid, |
---|
57 | const std::vector<int>& gridDestGlobalDim, |
---|
58 | const CArray<size_t,1>& globalIndexGridDestSendToServer, |
---|
59 | CArray<size_t,1>& globalIndexDestGrid, |
---|
60 | std::vector<CArray<size_t,1> >& globalIndexSrcGrid) |
---|
61 | { |
---|
62 | int globalDim = gridDestGlobalDim.size(); |
---|
63 | |
---|
64 | std::vector<size_t> currentIndex(globalDim); |
---|
65 | std::vector<int> gridAxisGlobalDim(globalDim); |
---|
66 | std::vector<int> idxLoop(globalDim, 0); |
---|
67 | |
---|
68 | size_t ssize = 1, idx = 0, realGlobalIndexSize = 0; |
---|
69 | for (int i = 0; i< globalDim; ++i) |
---|
70 | { |
---|
71 | if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1; |
---|
72 | else gridAxisGlobalDim[i] = gridDestGlobalDim[i]; |
---|
73 | ssize *= gridAxisGlobalDim[i]; |
---|
74 | } |
---|
75 | |
---|
76 | CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, |
---|
77 | iteArr = globalIndexGridDestSendToServer.end(); |
---|
78 | |
---|
79 | while (idx < ssize) |
---|
80 | { |
---|
81 | for (int i = 0; i < globalDim-1; ++i) |
---|
82 | { |
---|
83 | if (idxLoop[i] == gridAxisGlobalDim[i]) |
---|
84 | { |
---|
85 | idxLoop[i] = 0; |
---|
86 | ++idxLoop[i+1]; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i]; |
---|
91 | currentIndex[axisPositionInGrid] = axisDestGlobalIndex; |
---|
92 | |
---|
93 | size_t globIndex = currentIndex[0]; |
---|
94 | size_t mulDim = 1; |
---|
95 | for (int k = 1; k < globalDim; ++k) |
---|
96 | { |
---|
97 | mulDim *= gridDestGlobalDim[k-1]; |
---|
98 | globIndex += (currentIndex[k])*mulDim; |
---|
99 | } |
---|
100 | |
---|
101 | itArr = std::find(itbArr, iteArr, globIndex); |
---|
102 | if (iteArr != itArr) ++realGlobalIndexSize; |
---|
103 | ++idxLoop[0]; |
---|
104 | ++idx; |
---|
105 | } |
---|
106 | |
---|
107 | if (globalIndexDestGrid.numElements() != realGlobalIndexSize) |
---|
108 | globalIndexDestGrid.resize(realGlobalIndexSize); |
---|
109 | |
---|
110 | if (axisSrcGlobalIndex.size() != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(axisSrcGlobalIndex.size()); |
---|
111 | for (int i = 0; i < globalIndexSrcGrid.size(); ++i) |
---|
112 | if (globalIndexSrcGrid[i].numElements() != realGlobalIndexSize) |
---|
113 | globalIndexSrcGrid[i].resize(realGlobalIndexSize); |
---|
114 | |
---|
115 | |
---|
116 | size_t realGlobalIndex = 0; |
---|
117 | idx = 0; |
---|
118 | idxLoop.assign(globalDim, 0); |
---|
119 | while (idx < ssize) |
---|
120 | { |
---|
121 | for (int i = 0; i < globalDim-1; ++i) |
---|
122 | { |
---|
123 | if (idxLoop[i] == gridAxisGlobalDim[i]) |
---|
124 | { |
---|
125 | idxLoop[i] = 0; |
---|
126 | ++idxLoop[i+1]; |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i]; |
---|
131 | currentIndex[axisPositionInGrid] = axisDestGlobalIndex; |
---|
132 | |
---|
133 | size_t globIndex = currentIndex[0]; |
---|
134 | size_t mulDim = 1; |
---|
135 | for (int k = 1; k < globalDim; ++k) |
---|
136 | { |
---|
137 | mulDim *= gridDestGlobalDim[k-1]; |
---|
138 | globIndex += (currentIndex[k])*mulDim; |
---|
139 | } |
---|
140 | |
---|
141 | itArr = std::find(itbArr, iteArr, globIndex); |
---|
142 | if (iteArr != itArr) |
---|
143 | { |
---|
144 | globalIndexDestGrid(realGlobalIndex) = globIndex; |
---|
145 | for (int i = 0; i < globalIndexSrcGrid.size(); ++i) |
---|
146 | { |
---|
147 | currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i]; |
---|
148 | globIndex = currentIndex[0]; |
---|
149 | mulDim = 1; |
---|
150 | for (int k = 1; k < globalDim; ++k) |
---|
151 | { |
---|
152 | mulDim *= gridDestGlobalDim[k-1]; |
---|
153 | globIndex += (currentIndex[k])*mulDim; |
---|
154 | } |
---|
155 | (globalIndexSrcGrid[i])(realGlobalIndex) = globIndex; |
---|
156 | } |
---|
157 | ++realGlobalIndex; |
---|
158 | } |
---|
159 | |
---|
160 | ++idxLoop[0]; |
---|
161 | ++idx; |
---|
162 | } |
---|
163 | } |
---|
164 | |
---|
165 | |
---|
166 | } |
---|