source: XIOS/dev/dev_trunk_graph/src/transformation/domain_algorithm/domain_algorithm_zoom.cpp @ 2030

Last change on this file since 2030 was 2030, checked in by yushan, 3 years ago

Graph intermediate commit to a tmp branch.

  • Property svn:executable set to *
File size: 10.7 KB
Line 
1#include "domain_algorithm_zoom.hpp"
2#include "zoom_domain.hpp"
3#include "domain.hpp"
4#include "grid.hpp"
5#include "grid_transformation_factory_impl.hpp"
6#include "attribute_template.hpp"
7
8namespace xios {
9CGenericAlgorithmTransformation* CDomainAlgorithmZoom::create(bool isSource, CGrid* gridDst, CGrid* gridSrc,
10                                                             CTransformation<CDomain>* transformation,
11                                                             int elementPositionInGrid,
12                                                             std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
13                                                             std::map<int, int>& elementPositionInGridSrc2AxisPosition,
14                                                             std::map<int, int>& elementPositionInGridSrc2DomainPosition,
15                                                             std::map<int, int>& elementPositionInGridDst2ScalarPosition,
16                                                             std::map<int, int>& elementPositionInGridDst2AxisPosition,
17                                                             std::map<int, int>& elementPositionInGridDst2DomainPosition)
18TRY
19{
20  std::vector<CDomain*> domainListDestP = gridDst->getDomains();
21  std::vector<CDomain*> domainListSrcP  = gridSrc->getDomains();
22
23  CZoomDomain* zoomDomain = dynamic_cast<CZoomDomain*> (transformation);
24  int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid];
25  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
26
27  return (new CDomainAlgorithmZoom(isSource, domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], zoomDomain));
28}
29CATCH
30
31bool CDomainAlgorithmZoom::dummyRegistered_ = CDomainAlgorithmZoom::registerTrans();
32bool CDomainAlgorithmZoom::registerTrans()
33TRY
34{
35  return CGridTransformationFactory<CDomain>::registerTransformation(TRANS_ZOOM_DOMAIN, create);
36}
37CATCH
38
39CDomainAlgorithmZoom::CDomainAlgorithmZoom(bool isSource, CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)
40: CAlgorithmTransformationTransfer(isSource), domainSrc_(domainSource), domainDest_(domainDestination)
41TRY
42{
43  zoomDomain->checkValid(domainSource);
44  zoomIBegin_ = zoomDomain->ibegin.getValue();
45  zoomJBegin_ = zoomDomain->jbegin.getValue();
46
47  zoomNi_  = zoomDomain->ni.getValue();
48  zoomNj_  = zoomDomain->nj.getValue();
49
50  zoomIEnd_ = zoomIBegin_ + zoomNi_ - 1;
51  zoomJEnd_ = zoomJBegin_ + zoomNj_ - 1;
52
53  if (zoomNi_ > domainSource->ni_glo.getValue())
54  {
55    ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)",
56           << "Zoom size is greater than size of domain source"
57           << "Size ni_glo of domain source " <<domainSource->getId() << " is " << domainSource->ni_glo.getValue()  << std::endl
58           << "Zoom size is " << zoomNi_ );
59  }
60
61  if (zoomNj_ > domainSource->nj_glo.getValue())
62  {
63    ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)",
64           << "Zoom size is greater than size of domain source"
65           << "Size nj_glo of domain source " <<domainSource->getId() << " is " << domainSource->nj_glo.getValue()  << std::endl
66           << "Zoom size is " << zoomNj_ );
67  }
68
69  // Calculate the size of local domain
70  int ind, indLocSrc, indLocDest, iIdxSrc, jIdxSrc, destIBegin = -1, destJBegin = -1, niDest = 0, njDest = 0, ibeginDest, jbeginDest ;
71  int indGloDest, indGloSrc, niGloSrc = domainSrc_->ni_glo, iSrc, jSrc, nvertex = 0;
72  for (int j = 0; j < domainSrc_->nj.getValue(); j++)
73  {
74    for (int i = 0; i < domainSrc_->ni.getValue(); i++)
75    {
76      ind = j*domainSrc_->ni + i;
77      iIdxSrc = domainSrc_->i_index(ind);
78      if ((iIdxSrc >= zoomIBegin_) && (iIdxSrc <= zoomIEnd_))
79      {
80        jIdxSrc = domainSrc_->j_index(ind);
81        if ((jIdxSrc >= zoomJBegin_) && (jIdxSrc <= zoomJEnd_))
82        {
83          if ((niDest == 0) && (njDest == 0))
84          {
85            destIBegin = i;
86            destJBegin = j;
87          }
88          if (i == destIBegin) ++njDest;
89        }
90        if (j == destJBegin) ++niDest;
91
92      }
93    }
94  }
95  ibeginDest = destIBegin + domainSrc_->ibegin - zoomIBegin_;
96  jbeginDest = destJBegin + domainSrc_->jbegin - zoomJBegin_;
97 
98  if (niDest==0) ibeginDest=0 ;
99  if (njDest==0) jbeginDest=0 ;
100   
101  domainDest_->type = domainSrc_ -> type ;
102  domainDest_->data_dim = domainSrc_->data_dim ;
103
104  domainDest_->ni_glo.setValue(zoomNi_);
105  domainDest_->nj_glo.setValue(zoomNj_);
106  domainDest_->ni.setValue(niDest);
107  domainDest_->nj.setValue(njDest);
108  if ( (niDest==0) || (njDest==0))
109  {
110    domainDest_->ibegin.setValue(0);
111    domainDest_->jbegin.setValue(0);
112  }
113  else
114  {
115    domainDest_->ibegin.setValue(ibeginDest);
116    domainDest_->jbegin.setValue(jbeginDest);
117  }
118  domainDest_->i_index.resize(niDest*njDest);
119  domainDest_->j_index.resize(niDest*njDest);
120
121  domainDest_->data_ni.setValue(niDest);
122  domainDest_->data_nj.setValue(njDest);
123  domainDest_->data_ibegin.setValue(0);
124  domainDest_->data_jbegin.setValue(0);
125  domainDest_->data_i_index.resize(niDest*njDest);
126  domainDest_->data_j_index.resize(niDest*njDest);
127
128  domainDest_->domainMask.resize(niDest*njDest);
129
130  if (!domainSrc_->lonvalue_1d.isEmpty())
131  {
132    if (domainDest_->type == CDomain::type_attr::rectilinear)
133    {
134      domainDest_->lonvalue_1d.resize(niDest);
135      domainDest_->latvalue_1d.resize(njDest);
136    }
137    else if (domainDest_->type == CDomain::type_attr::unstructured)
138    {
139      domainDest_->lonvalue_1d.resize(niDest);
140      domainDest_->latvalue_1d.resize(niDest);
141    }
142    else if (domainDest_->type == CDomain::type_attr::curvilinear)
143    {
144      domainDest_->lonvalue_1d.resize(niDest*njDest);
145      domainDest_->latvalue_1d.resize(niDest*njDest);
146    }
147  }
148  else if (!domainSrc_->lonvalue_2d.isEmpty())
149  {
150    domainDest_->lonvalue_2d.resize(niDest,njDest);
151    domainDest_->latvalue_2d.resize(niDest,njDest);
152  }
153
154  if (domainSrc_->hasBounds)
155  {
156    nvertex = domainSrc_->nvertex;
157    domainDest_->nvertex.setValue(nvertex);
158    if (!domainSrc_->bounds_lon_1d.isEmpty())
159    {
160      if (domainDest_->type == CDomain::type_attr::rectilinear)
161      {
162        domainDest_->bounds_lon_1d.resize(nvertex, niDest);
163        domainDest_->bounds_lat_1d.resize(nvertex, njDest);
164      }
165      else if (domainDest_->type == CDomain::type_attr::unstructured)
166      {
167        domainDest_->bounds_lon_1d.resize(nvertex, niDest);
168        domainDest_->bounds_lat_1d.resize(nvertex, niDest);
169      }
170      else if (domainDest_->type == CDomain::type_attr::curvilinear)
171      {
172        domainDest_->bounds_lon_1d.resize(nvertex, niDest*njDest);
173        domainDest_->bounds_lat_1d.resize(nvertex, niDest*njDest);
174      }
175    }
176    else if (!domainSrc_->bounds_lon_2d.isEmpty())
177    {
178      domainDest_->bounds_lon_2d.resize(nvertex, niDest, njDest);
179      domainDest_->bounds_lat_2d.resize(nvertex, niDest, njDest);
180    }
181  }
182  if (domainSrc_->hasArea) domainDest_->area.resize(niDest,njDest);
183
184
185  for (int iDest = 0; iDest < niDest; iDest++)
186  {
187    iSrc = iDest + destIBegin;
188    for (int jDest = 0; jDest < njDest; jDest++)
189    {
190      jSrc = jDest + destJBegin;
191      ind = jSrc * domainSrc_->ni + iSrc;
192      iIdxSrc = domainSrc_->i_index(ind);
193      jIdxSrc = domainSrc_->j_index(ind);
194      indLocDest = jDest*niDest + iDest;
195      indGloDest = (jDest + jbeginDest)*zoomNi_ + (iDest + ibeginDest);
196      indLocSrc = (jDest+destJBegin)*domainSrc_->ni + (iDest+destIBegin);
197      indGloSrc = (jIdxSrc )* niGloSrc + iIdxSrc;
198      domainDest_->i_index(indLocDest) = iDest + ibeginDest;                                             // i_index contains global positions
199      domainDest_->j_index(indLocDest) = jDest + jbeginDest;                                             // i_index contains global positions
200      domainDest_->data_i_index(indLocDest) = (domainSrc_->data_dim == 1) ? indLocDest : iDest;          // data_i_index contains local positions
201      domainDest_->data_j_index(indLocDest) = (domainSrc_->data_dim == 1) ? 0 :jDest;                    // data_i_index contains local positions
202      domainDest_->domainMask(indLocDest) = domainSrc_->domainMask(indLocSrc);
203
204      if (domainSrc_->hasArea)
205        domainDest_->area(iDest,jDest) = domainSrc_->area(iSrc,jSrc);
206
207      if (domainSrc_->hasLonLat)
208      {
209        if (!domainSrc_->latvalue_1d.isEmpty())
210        {
211          if (domainDest_->type == CDomain::type_attr::rectilinear)
212          {
213            domainDest_->latvalue_1d(jDest) = domainSrc_->latvalue_1d(jSrc);
214          }
215          else
216          {
217            domainDest_->lonvalue_1d(indLocDest) = domainSrc_->lonvalue_1d(ind);
218            domainDest_->latvalue_1d(indLocDest) = domainSrc_->latvalue_1d(ind);
219          }
220        }
221        else if (!domainSrc_->latvalue_2d.isEmpty())
222        {
223          domainDest_->lonvalue_2d(iDest,jDest) = domainSrc_->lonvalue_2d(iSrc,jSrc);
224          domainDest_->latvalue_2d(iDest,jDest) = domainSrc_->latvalue_2d(iSrc,jSrc);
225        }
226      }
227
228      if (domainSrc_->hasBounds)
229      {
230        if (!domainSrc_->bounds_lon_1d.isEmpty())
231        {
232          if (domainDest_->type == CDomain::type_attr::rectilinear)
233          {
234            for (int n = 0; n < nvertex; ++n)
235              domainDest_->bounds_lat_1d(n,jDest) = domainSrc_->bounds_lat_1d(n,jSrc);
236          }
237          else
238          {
239            for (int n = 0; n < nvertex; ++n)
240            {
241              domainDest_->bounds_lon_1d(n,indLocDest) = domainSrc_->bounds_lon_1d(n,ind);
242              domainDest_->bounds_lat_1d(n,indLocDest) = domainSrc_->bounds_lat_1d(n,ind);
243            }
244          }
245        }
246        else if (!domainSrc_->bounds_lon_2d.isEmpty())
247        {
248          for (int n = 0; n < nvertex; ++n)
249          {
250            domainDest_->bounds_lon_2d(n,iDest,jDest) = domainSrc_->bounds_lon_2d(n,iSrc,jSrc);
251            domainDest_->bounds_lat_2d(n,iDest,jDest) = domainSrc_->bounds_lat_2d(n,iSrc,jSrc);
252          }
253        }
254
255      }
256
257      transformationMapping_[indGloDest]=indGloSrc;
258
259    }
260
261    if (domainSrc_->hasLonLat && !domainSrc_->latvalue_1d.isEmpty())
262    {
263      if (domainDest_->type == CDomain::type_attr::rectilinear)
264      {
265        domainDest_->lonvalue_1d(iDest) = domainSrc_->lonvalue_1d(iSrc);
266      }
267    }
268
269    if (domainSrc_->hasBounds && !domainSrc_->bounds_lon_1d.isEmpty())
270    {
271      if (domainDest_->type == CDomain::type_attr::rectilinear)
272      {
273        for (int n = 0; n < nvertex; ++n)
274          domainDest_->bounds_lon_1d(n,iDest) = domainSrc_->bounds_lon_1d(n,iSrc);
275      }
276    }
277  }
278  domainDest_->computeLocalMask();
279
280  domainDestination->checkAttributes() ;
281
282  this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), domainDestination->getLocalView(CElementView::WORKFLOW)) ;
283 
284}
285CATCH
286
287}
Note: See TracBrowser for help on using the repository browser.