source: XIOS/trunk/src/transformation/axis_algorithm_transformation.cpp @ 827

Last change on this file since 827 was 827, checked in by mhnguyen, 5 years ago

Implementing dynamic interpolation on axis

+) Change grid transformation to make it more flexible
+) Make some small improvements

Test
+) On Curie
+) All test pass

File size: 9.5 KB
Line 
1/*!
2   \file axis_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 29 June 2015
6
7   \brief Interface for all axis transformation algorithms.
8 */
9
10#include "axis_algorithm_transformation.hpp"
11#include "axis_algorithm_inverse.hpp"
12#include "axis_algorithm_zoom.hpp"
13
14namespace xios {
15
16CAxisAlgorithmTransformation::CAxisAlgorithmTransformation(CAxis* axisDestination, CAxis* axisSource)
17 : CGenericAlgorithmTransformation(), axisDest_(axisDestination), axisSrc_(axisSource)
18{
19  axisDestGlobalSize_ = axisDestination->n_glo.getValue();
20  int niDest = axisDestination->n.getValue();
21  int ibeginDest = axisDestination->begin.getValue();
22
23  for (int idx = 0; idx < niDest; ++idx)
24    if ((axisDestination->mask)(idx)) axisDestGlobalIndex_.push_back(ibeginDest+idx);
25}
26
27CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation()
28{
29}
30
31void CAxisAlgorithmTransformation::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
32{
33}
34
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)
41  \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted
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*/
45void CAxisAlgorithmTransformation::computeGlobalGridIndexFromGlobalIndexElement(int axisDestGlobalIndex,
46                                                                          const std::vector<int>& axisSrcGlobalIndex,
47                                                                          const std::vector<int>& destGlobalIndexPositionInGrid,
48                                                                          int axisPositionInGrid,
49                                                                          const std::vector<int>& gridDestGlobalDim,
50                                                                          const std::vector<int>& gridSrcGlobalDim,
51                                                                          const std::vector<size_t>& globalIndexGridDestSendToServer,
52                                                                          CArray<size_t,1>& globalIndexDestGrid,
53                                                                          std::vector<std::vector<size_t> >& globalIndexSrcGrid)
54{
55  bool hasDestGlobalIndexPos = !destGlobalIndexPositionInGrid.empty();
56  int globalDim = gridDestGlobalDim.size();
57
58  std::vector<size_t> currentIndex(globalDim);
59  std::vector<int> gridAxisGlobalDim(globalDim);
60  std::vector<int> idxLoop(globalDim, 0);
61
62  size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;
63  for (int i = 0; i< globalDim; ++i)
64  {
65    if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1;
66    else
67    {
68      if (!hasDestGlobalIndexPos) gridAxisGlobalDim[i] = gridDestGlobalDim[i];
69      else gridAxisGlobalDim[i] = 1;
70    }
71    ssize *= gridAxisGlobalDim[i];
72  }
73
74  std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,
75                                      iteArr = globalIndexGridDestSendToServer.end();
76
77  while (idx < ssize)
78  {
79    for (int i = 0; i < globalDim-1; ++i)
80    {
81      if (idxLoop[i] == gridAxisGlobalDim[i])
82      {
83        idxLoop[i] = 0;
84        ++idxLoop[i+1];
85      }
86    }
87
88    int j = 0;
89    for (int i = 0; i < globalDim; ++i)
90    {
91      if (!hasDestGlobalIndexPos) currentIndex[i] = idxLoop[i];
92      else
93      {
94        if (axisPositionInGrid == i) currentIndex[i] = axisDestGlobalIndex;
95        else
96        {
97          currentIndex[i] = destGlobalIndexPositionInGrid[j];
98          ++j;
99        }
100      }
101    }
102
103    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
104
105    size_t globIndex = currentIndex[0];
106    size_t mulDim = 1;
107    for (int k = 1; k < globalDim; ++k)
108    {
109      mulDim *= gridDestGlobalDim[k-1];
110      globIndex += (currentIndex[k])*mulDim;
111    }
112
113    if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize;
114    ++idxLoop[0];
115    ++idx;
116  }
117
118  if (globalIndexDestGrid.numElements() != realGlobalIndexSize)
119    globalIndexDestGrid.resize(realGlobalIndexSize);
120
121  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);
122  for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
123    if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size())
124      globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size());
125
126  size_t realGlobalIndex = 0;
127  idx = 0;
128  idxLoop.assign(globalDim, 0);
129  while (idx < ssize)
130  {
131    for (int i = 0; i < globalDim-1; ++i)
132    {
133      if (idxLoop[i] == gridAxisGlobalDim[i])
134      {
135        idxLoop[i] = 0;
136        ++idxLoop[i+1];
137      }
138    }
139
140    int j = 0;
141    for (int i = 0; i < globalDim; ++i)
142    {
143      if (!hasDestGlobalIndexPos) currentIndex[i] = idxLoop[i];
144      else
145      {
146        if (axisPositionInGrid == i) currentIndex[i] = axisDestGlobalIndex;
147        else
148        {
149          currentIndex[i] = destGlobalIndexPositionInGrid[j];
150          ++j;
151        }
152      }
153    }
154    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
155
156    size_t globIndex = currentIndex[0];
157    size_t mulDim = 1;
158    for (int k = 1; k < globalDim; ++k)
159    {
160      mulDim *= gridDestGlobalDim[k-1];
161      globIndex += (currentIndex[k])*mulDim;
162    }
163
164    if (std::binary_search(itbArr, iteArr, globIndex))
165    {
166      globalIndexDestGrid(realGlobalIndex) = globIndex;
167      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)
168      {
169        currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];
170        globIndex = currentIndex[0];
171        mulDim = 1;
172        for (int k = 1; k < globalDim; ++k)
173        {
174          mulDim *= gridDestGlobalDim[k-1];
175          globIndex += (currentIndex[k])*mulDim;
176        }
177        (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex;
178      }
179      ++realGlobalIndex;
180    }
181
182    ++idxLoop[0];
183    ++idx;
184  }
185
186
187
188//  int globalDim = gridDestGlobalDim.size();
189//
190//  std::vector<size_t> currentIndex(globalDim);
191//  std::vector<int> gridAxisGlobalDim(globalDim);
192//  std::vector<int> idxLoop(globalDim, 0);
193//
194//  size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;
195//  for (int i = 0; i< globalDim; ++i)
196//  {
197//    if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1;
198//    else gridAxisGlobalDim[i] = gridDestGlobalDim[i];
199//    ssize *= gridAxisGlobalDim[i];
200//  }
201//
202//  std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,
203//                                      iteArr = globalIndexGridDestSendToServer.end();
204//
205//  while (idx < ssize)
206//  {
207//    for (int i = 0; i < globalDim-1; ++i)
208//    {
209//      if (idxLoop[i] == gridAxisGlobalDim[i])
210//      {
211//        idxLoop[i] = 0;
212//        ++idxLoop[i+1];
213//      }
214//    }
215//
216//    for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];
217//    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
218//
219//    size_t globIndex = currentIndex[0];
220//    size_t mulDim = 1;
221//    for (int k = 1; k < globalDim; ++k)
222//    {
223//      mulDim *= gridDestGlobalDim[k-1];
224//      globIndex += (currentIndex[k])*mulDim;
225//    }
226//
227//    if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize;
228//    ++idxLoop[0];
229//    ++idx;
230//  }
231//
232//  if (globalIndexDestGrid.numElements() != realGlobalIndexSize)
233//    globalIndexDestGrid.resize(realGlobalIndexSize);
234//
235//  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);
236//  for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
237//    if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size())
238//      globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size());
239//
240//  size_t realGlobalIndex = 0;
241//  idx = 0;
242//  idxLoop.assign(globalDim, 0);
243//  while (idx < ssize)
244//  {
245//    for (int i = 0; i < globalDim-1; ++i)
246//    {
247//      if (idxLoop[i] == gridAxisGlobalDim[i])
248//      {
249//        idxLoop[i] = 0;
250//        ++idxLoop[i+1];
251//      }
252//    }
253//
254//    for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];
255//    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
256//
257//    size_t globIndex = currentIndex[0];
258//    size_t mulDim = 1;
259//    for (int k = 1; k < globalDim; ++k)
260//    {
261//      mulDim *= gridDestGlobalDim[k-1];
262//      globIndex += (currentIndex[k])*mulDim;
263//    }
264//
265//    if (std::binary_search(itbArr, iteArr, globIndex))
266//    {
267//      globalIndexDestGrid(realGlobalIndex) = globIndex;
268//      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)
269//      {
270//        currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];
271//        globIndex = currentIndex[0];
272//        mulDim = 1;
273//        for (int k = 1; k < globalDim; ++k)
274//        {
275//          mulDim *= gridDestGlobalDim[k-1];
276//          globIndex += (currentIndex[k])*mulDim;
277//        }
278//        (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex;
279//      }
280//      ++realGlobalIndex;
281//    }
282//
283//    ++idxLoop[0];
284//    ++idx;
285//  }
286}
287}
Note: See TracBrowser for help on using the repository browser.