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

Last change on this file since 829 was 827, checked in by mhnguyen, 8 years ago

Implementing dynamic interpolation on axis

+) Change grid transformation to make it more flexible
+) Make some small improvements

Test
+) On Curie
+) All test pass

File size: 4.4 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_(const std::vector<CArray<double,1>* >& dataAuxInputs)
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
71  this->transformationMapping_.resize(1);
72  this->transformationWeight_.resize(1);
73
74  std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0];
75  std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0];
76
77//  std::map<int, std::vector<int> >& transMap = this->transformationMapping_;
78//  std::map<int, std::vector<double> >& transWeight = this->transformationWeight_;
79  int domainGlobalIndex;
80  for (int j = 0; j < nj; ++j)
81  {
82    for (int i = 0; i < ni; ++i)
83    {
84      domainGlobalIndex = (j+jbegin) * niGlob + (i+ibegin);
85      transMap[domainGlobalIndex].push_back(domainGlobalIndex);
86      transWeight[domainGlobalIndex].push_back(1.0);
87    }
88  }
89
90  updateZoom();
91  updateDomainDestinationMask();
92}
93
94/*!
95  After a zoom on domain, it should be certain that (global) zoom begin and (global) zoom size are updated
96*/
97void CDomainAlgorithmZoom::updateZoom()
98{
99  domainDest_->global_zoom_ibegin = zoomIBegin_;
100  domainDest_->global_zoom_jbegin = zoomJBegin_;
101  domainDest_->global_zoom_ni  = zoomNi_;
102  domainDest_->global_zoom_nj  = zoomNj_;
103}
104
105/*!
106  Update mask on domain
107  Because only zoomed region on domain is not masked, the remaining must be masked to make sure
108correct index be extracted
109*/
110void CDomainAlgorithmZoom::updateDomainDestinationMask()
111{
112  int niMask     = domainDest_->ni.getValue();
113  int iBeginMask = domainDest_->ibegin.getValue();
114  int njMask     = domainDest_->nj.getValue();
115  int jBeginMask = domainDest_->jbegin.getValue();
116  int niGlob = domainDest_->ni_glo.getValue();
117  int globalIndexMask = 0;
118
119  std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0];
120  std::map<int, std::vector<int> >::const_iterator ite = (transMap).end();
121  for (int j = 0; j < njMask; ++j)
122  {
123    for (int i = 0; i < niMask; ++i)
124    {
125      globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask);
126      if (transMap.find(globalIndexMask) == ite)
127        (domainDest_->mask_1d)(i+j*niMask) = false;
128    }
129  }
130}
131
132}
Note: See TracBrowser for help on using the repository browser.