source: XIOS/trunk/src/transformation/domain_algorithm_zoom.cpp @ 787

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

Changing name of attributes of zoom

Test
+) test_client and test_complete are correct

File size: 4.1 KB
Line 
1/*!
2   \file domain_algorithm_zoom.cpp
3   \author Ha NGUYEN
4   \since 02 Jul 2015
5   \date 02 Jul 2015
6
7   \brief Algorithm for zooming on an domain.
8 */
9#include "domain_algorithm_zoom.hpp"
10
11namespace xios {
12
13CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)
14: CDomainAlgorithmTransformation(domainDestination, domainSource)
15{
16  zoomDomain->checkValid(domainSource);
17  zoomIBegin_ = zoomDomain->ibegin.getValue();
18  zoomJBegin_ = zoomDomain->jbegin.getValue();
19
20  zoomNi_  = zoomDomain->ni.getValue();
21  zoomNj_  = zoomDomain->nj.getValue();
22
23  zoomIEnd_ = zoomIBegin_ + zoomNi_ - 1;
24  zoomJEnd_ = zoomJBegin_ + zoomNj_ - 1;
25
26  if (zoomNi_ > domainSource->ni_glo.getValue())
27  {
28    ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)",
29           << "Zoom size is greater than size of domain source"
30           << "Size ni_glo of domain source " <<domainSource->getId() << " is " << domainSource->ni_glo.getValue()  << std::endl
31           << "Zoom size is " << zoomNi_ );
32  }
33
34  if (zoomNj_ > domainSource->nj_glo.getValue())
35  {
36    ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)",
37           << "Zoom size is greater than size of domain source"
38           << "Size nj_glo of domain source " <<domainSource->getId() << " is " << domainSource->nj_glo.getValue()  << std::endl
39           << "Zoom size is " << zoomNj_ );
40  }
41
42  computeIndexSourceMapping();
43}
44
45/*!
46  Compute the index mapping between domain on grid source and one on grid destination
47*/
48void CDomainAlgorithmZoom::computeIndexSourceMapping()
49{
50  int niSource = domainSrc_->ni.getValue();
51  int ibeginSource = domainSrc_->ibegin.getValue();
52  int iendSource = ibeginSource + niSource - 1;
53
54  int ibegin = std::max(ibeginSource, zoomIBegin_);
55  int iend = std::min(iendSource, zoomIEnd_);
56  int ni = iend + 1 - ibegin;
57  if (iend < ibegin) ni = 0;
58
59  int njSource = domainSrc_->nj.getValue();
60  int jbeginSource = domainSrc_->jbegin.getValue();
61  int jendSource = jbeginSource + njSource - 1;
62
63  int jbegin = std::max(jbeginSource, zoomJBegin_);
64  int jend = std::min(jendSource, zoomJEnd_);
65  int nj = jend + 1 - jbegin;
66  if (jend < jbegin) nj = 0;
67
68  int niGlob = domainSrc_->ni_glo.getValue();
69  int njGlob = domainSrc_->nj_glo.getValue();
70  std::map<int, std::vector<int> >& transMap = this->transformationMapping_;
71  std::map<int, std::vector<double> >& transWeight = this->transformationWeight_;
72  int domainGlobalIndex;
73  for (int j = 0; j < nj; ++j)
74  {
75    for (int i = 0; i < ni; ++i)
76    {
77      domainGlobalIndex = (j+jbegin) * niGlob + (i+ibegin);
78      transMap[domainGlobalIndex].push_back(domainGlobalIndex);
79      transWeight[domainGlobalIndex].push_back(1.0);
80    }
81  }
82
83  updateZoom();
84  updateDomainDestinationMask();
85}
86
87/*!
88  After a zoom on domain, it should be certain that (global) zoom begin and (global) zoom size are updated
89*/
90void CDomainAlgorithmZoom::updateZoom()
91{
92  domainDest_->global_zoom_ibegin = zoomIBegin_;
93  domainDest_->global_zoom_jbegin = zoomJBegin_;
94  domainDest_->global_zoom_ni  = zoomNi_;
95  domainDest_->global_zoom_nj  = zoomNj_;
96}
97
98/*!
99  Update mask on domain
100  Because only zoomed region on domain is not masked, the remaining must be masked to make sure
101correct index be extracted
102*/
103void CDomainAlgorithmZoom::updateDomainDestinationMask()
104{
105  int niMask     = domainDest_->ni.getValue();
106  int iBeginMask = domainDest_->ibegin.getValue();
107  int njMask     = domainDest_->nj.getValue();
108  int jBeginMask = domainDest_->jbegin.getValue();
109  int niGlob = domainDest_->ni_glo.getValue();
110  int globalIndexMask = 0;
111
112  std::map<int, std::vector<int> >& transMap = this->transformationMapping_;
113  std::map<int, std::vector<int> >::const_iterator ite = (transMap).end();
114  for (int j = 0; j < njMask; ++j)
115  {
116    for (int i = 0; i < niMask; ++i)
117    {
118      globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask);
119      if (transMap.find(globalIndexMask) == ite)
120        (domainDest_->mask_1d)(i+j*niMask) = false;
121    }
122  }
123}
124
125}
Note: See TracBrowser for help on using the repository browser.