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