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

Last change on this file since 666 was 666, checked in by mhnguyen, 6 years ago

Change name of several axis attributes and remove some redundant variable of domain

+) Change name of axis attributes to make them consistent with ones of domain
+) Remove zoom_client_* of domain

Test
+) On Curie
+) All tests pass and are correct

File size: 5.6 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()
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)
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                                                                          int axisPositionInGrid,
48                                                                          const std::vector<int>& gridDestGlobalDim,
49                                                                          const std::vector<int>& gridSrcGlobalDim,
50                                                                          const CArray<size_t,1>& globalIndexGridDestSendToServer,
51                                                                          CArray<size_t,1>& globalIndexDestGrid,
52                                                                          std::vector<std::vector<size_t> >& globalIndexSrcGrid)
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
68  CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,
69                                   iteArr = globalIndexGridDestSendToServer.end();
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
93    itArr = std::find(itbArr, iteArr, globIndex);
94    if (iteArr != itArr) ++realGlobalIndexSize;
95    ++idxLoop[0];
96    ++idx;
97  }
98
99  if (globalIndexDestGrid.numElements() != realGlobalIndexSize)
100    globalIndexDestGrid.resize(realGlobalIndexSize);
101
102  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);
103  for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
104    if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size())
105      globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size());
106
107  size_t realGlobalIndex = 0;
108  idx = 0;
109  idxLoop.assign(globalDim, 0);
110  while (idx < ssize)
111  {
112    for (int i = 0; i < globalDim-1; ++i)
113    {
114      if (idxLoop[i] == gridAxisGlobalDim[i])
115      {
116        idxLoop[i] = 0;
117        ++idxLoop[i+1];
118      }
119    }
120
121    for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];
122    currentIndex[axisPositionInGrid] = axisDestGlobalIndex;
123
124    size_t globIndex = currentIndex[0];
125    size_t mulDim = 1;
126    for (int k = 1; k < globalDim; ++k)
127    {
128      mulDim *= gridDestGlobalDim[k-1];
129      globIndex += (currentIndex[k])*mulDim;
130    }
131
132    itArr = std::find(itbArr, iteArr, globIndex);
133    if (iteArr != itArr)
134    {
135      globalIndexDestGrid(realGlobalIndex) = globIndex;
136      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)
137      {
138        currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];
139        globIndex = currentIndex[0];
140        mulDim = 1;
141        for (int k = 1; k < globalDim; ++k)
142        {
143          mulDim *= gridDestGlobalDim[k-1];
144          globIndex += (currentIndex[k])*mulDim;
145        }
146        (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex;
147      }
148      ++realGlobalIndex;
149    }
150
151    ++idxLoop[0];
152    ++idx;
153  }
154}
155}
Note: See TracBrowser for help on using the repository browser.