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

Last change on this file since 624 was 624, checked in by mhnguyen, 9 years ago

Final tests of zoom and inverse on axis

+) Modify test_client and test_complete to work with new grid definition
+) Correct some bugs causing memory leak
+) Clean abundant code
+) Add more comments to new files

Test
+) On Curie
+) test_client and test_complete pass with correct results

File size: 5.1 KB
Line 
1/*!
2   \file axis_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 14 May 2015
5   \date 09 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()
18{
19}
20
21CAxisAlgorithmTransformation::~CAxisAlgorithmTransformation()
22{
23}
24
25void CAxisAlgorithmTransformation::computeIndexSourceMapping()
26{
27}
28
29/*!
30  Compute an array of global index from a global index on a axis
31  \param[in] axisDestGlobalIndex global index on an axis of destination grid
32  \param[in] axisSrcGlobalIndex global index on an axis of source grid (which are needed by one index on axis destination)
33  \param[in] axisPositionInGrid position of the axis in the grid
34  \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)
35  \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s)
36  \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
37  \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
38*/
39void CAxisAlgorithmTransformation::computeGlobalIndexFromGlobalIndexElement(int axisDestGlobalIndex,
40                                                                          const std::vector<int>& axisSrcGlobalIndex,
41                                                                          int axisPositionInGrid,
42                                                                          const std::vector<int>& gridDestGlobalDim,
43                                                                          const CArray<size_t,1>& globalIndexGridDestSendToServer,
44                                                                          CArray<size_t,1>& globalIndexDestGrid,
45                                                                          std::vector<CArray<size_t,1> >& globalIndexSrcGrid)
46{
47  int globalDim = gridDestGlobalDim.size();
48
49  std::vector<size_t> currentIndex(globalDim);
50  std::vector<int> gridAxisGlobalDim(globalDim);
51  std::vector<int> idxLoop(globalDim, 0);
52
53  size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;
54  for (int i = 0; i< globalDim; ++i)
55  {
56    if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1;
57    else gridAxisGlobalDim[i] = gridDestGlobalDim[i];
58    ssize *= gridAxisGlobalDim[i];
59  }
60
61  CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,
62                                   iteArr = globalIndexGridDestSendToServer.end();
63
64  while (idx < ssize)
65  {
66    for (int i = 0; i < globalDim-1; ++i)
67    {
68      if (idxLoop[i] == gridAxisGlobalDim[i])
69      {
70        idxLoop[i] = 0;
71        ++idxLoop[i+1];
72      }
73    }
74
75    for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];
76    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
77
78    size_t globIndex = currentIndex[0];
79    size_t mulDim = 1;
80    for (int k = 1; k < globalDim; ++k)
81    {
82      mulDim *= gridDestGlobalDim[k-1];
83      globIndex += (currentIndex[k])*mulDim;
84    }
85
86    itArr = std::find(itbArr, iteArr, globIndex);
87    if (iteArr != itArr) ++realGlobalIndexSize;
88    ++idxLoop[0];
89    ++idx;
90  }
91
92  if (globalIndexDestGrid.numElements() != realGlobalIndexSize)
93    globalIndexDestGrid.resize(realGlobalIndexSize);
94
95  if (axisSrcGlobalIndex.size() != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(axisSrcGlobalIndex.size());
96  for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
97    if (globalIndexSrcGrid[i].numElements() != realGlobalIndexSize)
98      globalIndexSrcGrid[i].resize(realGlobalIndexSize);
99
100
101  size_t realGlobalIndex = 0;
102  idx = 0;
103  idxLoop.assign(globalDim, 0);
104  while (idx < ssize)
105  {
106    for (int i = 0; i < globalDim-1; ++i)
107    {
108      if (idxLoop[i] == gridAxisGlobalDim[i])
109      {
110        idxLoop[i] = 0;
111        ++idxLoop[i+1];
112      }
113    }
114
115    for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];
116    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
117
118    size_t globIndex = currentIndex[0];
119    size_t mulDim = 1;
120    for (int k = 1; k < globalDim; ++k)
121    {
122      mulDim *= gridDestGlobalDim[k-1];
123      globIndex += (currentIndex[k])*mulDim;
124    }
125
126    itArr = std::find(itbArr, iteArr, globIndex);
127    if (iteArr != itArr)
128    {
129      globalIndexDestGrid(realGlobalIndex) = globIndex;
130      for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
131      {
132        currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];
133        globIndex = currentIndex[0];
134        mulDim = 1;
135        for (int k = 1; k < globalDim; ++k)
136        {
137          mulDim *= gridDestGlobalDim[k-1];
138          globIndex += (currentIndex[k])*mulDim;
139        }
140        (globalIndexSrcGrid[i])(realGlobalIndex) = globIndex;
141      }
142      ++realGlobalIndex;
143    }
144
145    ++idxLoop[0];
146    ++idx;
147  }
148}
149}
Note: See TracBrowser for help on using the repository browser.