source: XIOS/trunk/src/transformation/domain_algorithm_transformation.cpp @ 631

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

Implementing zooming on a domain

+) Add algorithm to do zooming on a domain
+) Remove some redundant codes

Test
+) On Curie
+) test_complete and test_client are correct

File size: 6.8 KB
Line 
1/*!
2   \file domain_algorithm_transformation.hpp
3   \author Ha NGUYEN
4   \since 02 Jul 2015
5   \date 02 Jul 2015
6
7   \brief Interface for all domain transformation algorithms.
8 */
9
10#include "domain_algorithm_transformation.hpp"
11
12namespace xios {
13
14CDomainAlgorithmTransformation::CDomainAlgorithmTransformation(CDomain* domainDestination, CDomain* domainSource)
15 : CGenericAlgorithmTransformation(), domainDest_(domainDestination), domainSrc_(domainSource)
16{
17}
18
19CDomainAlgorithmTransformation::~CDomainAlgorithmTransformation()
20{
21}
22
23void CDomainAlgorithmTransformation::computeIndexSourceMapping()
24{
25}
26
27/*!
28  Compute an array of global index from a global index on a domain
29  \param[in] domainDestGlobalIndex global index on an domain of destination grid
30  \param[in] domainSrcGlobalIndex global index on an domain of source grid (which are needed by one index on domain destination)
31  \param[in] domainPositionInGrid position of the domain in the grid
32  \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed)
33  \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed)
34  \param[in] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s)
35  \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
36  \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
37*/
38void CDomainAlgorithmTransformation::computeGlobalGridIndexFromGlobalIndexElement(int domainDestGlobalIndex,
39                                                                          const std::vector<int>& domainSrcGlobalIndex,
40                                                                          int domainPositionInGrid,
41                                                                          const std::vector<int>& gridDestGlobalDim,
42                                                                          const std::vector<int>& gridSrcGlobalDim,
43                                                                          const CArray<size_t,1>& globalIndexGridDestSendToServer,
44                                                                          CArray<size_t,1>& globalIndexDestGrid,
45                                                                          std::vector<std::vector<size_t> >& globalIndexSrcGrid)
46{
47  int globalDim = gridDestGlobalDim.size();
48  int numElement = globalDim - 1;
49  int domainElementPosition = 0;
50  std::vector<int> currentIndex(globalDim);
51  std::vector<int> gridDomainGlobalDim(numElement), indexMap(numElement);
52  std::vector<int> idxLoop(numElement, 0), domainSrcGlobalDim(2), domainDestGlobalDim(2);
53
54
55  size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;
56  for (int i = 0; i< globalDim; ++i)
57  {
58    if (domainPositionInGrid == i) continue;
59    if (domainPositionInGrid == (i+1))
60    {
61      domainDestGlobalDim[0] = gridDestGlobalDim[i];
62      domainDestGlobalDim[1] = gridDestGlobalDim[i+1];
63      domainSrcGlobalDim[0] = gridSrcGlobalDim[i];
64      domainSrcGlobalDim[1] = gridSrcGlobalDim[i+1];
65      gridDomainGlobalDim[idx] = 1;
66      domainElementPosition = idx;
67    }
68    else
69    {
70      gridDomainGlobalDim[idx] = gridDestGlobalDim[i];
71    }
72    indexMap[idx] = i;
73    ++idx;
74  }
75  int iIndex = domainDestGlobalIndex % domainDestGlobalDim[1];
76  int jIndex = domainDestGlobalIndex / domainDestGlobalDim[0];
77
78  for (int i = 0; i< numElement; ++i) ssize *= gridDomainGlobalDim[i];
79
80  CArray<size_t,1>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,
81                                   iteArr = globalIndexGridDestSendToServer.end();
82  idx = 0;
83  while (idx < ssize)
84  {
85    for (int i = 0; i < numElement; ++i)
86    {
87      if (idxLoop[i] == gridDomainGlobalDim[i])
88      {
89        idxLoop[i] = 0;
90        ++idxLoop[i+1];
91      }
92    }
93
94    for (int i = 0; i < numElement; ++i)
95    {
96      if (domainElementPosition == i)
97      {
98        currentIndex[indexMap[i]]   = iIndex;
99        currentIndex[indexMap[i]+1] = jIndex;
100      }
101      else
102        currentIndex[indexMap[i]] = idxLoop[i];
103    }
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    itArr = std::find(itbArr, iteArr, globIndex);
114    if (iteArr != itArr) ++realGlobalIndexSize;
115    ++idxLoop[0];
116    ++idx;
117  }
118
119  if (globalIndexDestGrid.numElements() != realGlobalIndexSize)
120    globalIndexDestGrid.resize(realGlobalIndexSize);
121
122  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);
123  for (int i = 0; i < globalIndexSrcGrid.size(); ++i)
124    if (globalIndexSrcGrid[i].size() != domainSrcGlobalIndex.size())
125      globalIndexSrcGrid[i].resize(domainSrcGlobalIndex.size());
126
127  size_t realGlobalIndex = 0;
128  idx = 0;
129  idxLoop.assign(globalDim, 0);
130  while (idx < ssize)
131  {
132    for (int i = 0; i < numElement; ++i)
133    {
134      if (idxLoop[i] == gridDomainGlobalDim[i])
135      {
136        idxLoop[i] = 0;
137        ++idxLoop[i+1];
138      }
139    }
140
141    for (int i = 0; i < numElement; ++i)
142    {
143      if (domainElementPosition == i)
144      {
145        currentIndex[indexMap[i]]   = iIndex;
146        currentIndex[indexMap[i]+1] = jIndex;
147      }
148      else
149        currentIndex[indexMap[i]] = idxLoop[i];
150    }
151
152    size_t globIndex = currentIndex[0];
153    size_t mulDim = 1;
154    for (int k = 1; k < globalDim; ++k)
155    {
156      mulDim *= gridDestGlobalDim[k-1];
157      globIndex += (currentIndex[k])*mulDim;
158    }
159
160    itArr = std::find(itbArr, iteArr, globIndex);
161    if (iteArr != itArr)
162    {
163      globalIndexDestGrid(realGlobalIndex) = globIndex;
164      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)
165      {
166        domainGlobalIndex(domainSrcGlobalIndex[i], domainSrcGlobalDim[0], domainSrcGlobalDim[1],
167                          currentIndex[indexMap[domainElementPosition]],
168                          currentIndex[indexMap[domainElementPosition]+1]);
169
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
187void CDomainAlgorithmTransformation::domainGlobalIndex(const int& index, const int& niGlob, const int& njGlob,
188                                                       int& iIndex, int& jIndex)
189{
190   iIndex = index % njGlob;
191   jIndex = index / niGlob;
192}
193}
Note: See TracBrowser for help on using the repository browser.