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 | #include "zoom_domain.hpp" |
---|
11 | #include "domain.hpp" |
---|
12 | #include "grid.hpp" |
---|
13 | #include "grid_transformation_factory_impl.hpp" |
---|
14 | |
---|
15 | namespace xios { |
---|
16 | CGenericAlgorithmTransformation* CDomainAlgorithmZoom::create(CGrid* gridDst, CGrid* gridSrc, |
---|
17 | CTransformation<CDomain>* transformation, |
---|
18 | int elementPositionInGrid, |
---|
19 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
20 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
21 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
22 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
23 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
24 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
25 | { |
---|
26 | std::vector<CDomain*> domainListDestP = gridDst->getDomains(); |
---|
27 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
28 | |
---|
29 | CZoomDomain* zoomDomain = dynamic_cast<CZoomDomain*> (transformation); |
---|
30 | int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid]; |
---|
31 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
32 | |
---|
33 | return (new CDomainAlgorithmZoom(domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], zoomDomain)); |
---|
34 | } |
---|
35 | |
---|
36 | bool CDomainAlgorithmZoom::registerTrans() |
---|
37 | { |
---|
38 | CGridTransformationFactory<CDomain>::registerTransformation(TRANS_ZOOM_DOMAIN, create); |
---|
39 | } |
---|
40 | |
---|
41 | CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain) |
---|
42 | : CDomainAlgorithmTransformation(domainDestination, domainSource) |
---|
43 | { |
---|
44 | zoomDomain->checkValid(domainSource); |
---|
45 | zoomIBegin_ = zoomDomain->ibegin.getValue(); |
---|
46 | zoomJBegin_ = zoomDomain->jbegin.getValue(); |
---|
47 | |
---|
48 | zoomNi_ = zoomDomain->ni.getValue(); |
---|
49 | zoomNj_ = zoomDomain->nj.getValue(); |
---|
50 | |
---|
51 | zoomIEnd_ = zoomIBegin_ + zoomNi_ - 1; |
---|
52 | zoomJEnd_ = zoomJBegin_ + zoomNj_ - 1; |
---|
53 | |
---|
54 | if (zoomNi_ > domainSource->ni_glo.getValue()) |
---|
55 | { |
---|
56 | ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)", |
---|
57 | << "Zoom size is greater than size of domain source" |
---|
58 | << "Size ni_glo of domain source " <<domainSource->getId() << " is " << domainSource->ni_glo.getValue() << std::endl |
---|
59 | << "Zoom size is " << zoomNi_ ); |
---|
60 | } |
---|
61 | |
---|
62 | if (zoomNj_ > domainSource->nj_glo.getValue()) |
---|
63 | { |
---|
64 | ERROR("CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain)", |
---|
65 | << "Zoom size is greater than size of domain source" |
---|
66 | << "Size nj_glo of domain source " <<domainSource->getId() << " is " << domainSource->nj_glo.getValue() << std::endl |
---|
67 | << "Zoom size is " << zoomNj_ ); |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | /*! |
---|
72 | Compute the index mapping between domain on grid source and one on grid destination |
---|
73 | */ |
---|
74 | void CDomainAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
75 | { |
---|
76 | int niSource = domainSrc_->ni.getValue(); |
---|
77 | int ibeginSource = domainSrc_->ibegin.getValue(); |
---|
78 | int iendSource = ibeginSource + niSource - 1; |
---|
79 | |
---|
80 | int ibegin = std::max(ibeginSource, zoomIBegin_); |
---|
81 | int iend = std::min(iendSource, zoomIEnd_); |
---|
82 | int ni = iend + 1 - ibegin; |
---|
83 | if (iend < ibegin) ni = 0; |
---|
84 | |
---|
85 | int njSource = domainSrc_->nj.getValue(); |
---|
86 | int jbeginSource = domainSrc_->jbegin.getValue(); |
---|
87 | int jendSource = jbeginSource + njSource - 1; |
---|
88 | |
---|
89 | int jbegin = std::max(jbeginSource, zoomJBegin_); |
---|
90 | int jend = std::min(jendSource, zoomJEnd_); |
---|
91 | int nj = jend + 1 - jbegin; |
---|
92 | if (jend < jbegin) nj = 0; |
---|
93 | |
---|
94 | int niGlob = domainSrc_->ni_glo.getValue(); |
---|
95 | int njGlob = domainSrc_->nj_glo.getValue(); |
---|
96 | |
---|
97 | this->transformationMapping_.resize(1); |
---|
98 | this->transformationWeight_.resize(1); |
---|
99 | |
---|
100 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
101 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
102 | |
---|
103 | int domainGlobalIndex; |
---|
104 | for (int j = 0; j < nj; ++j) |
---|
105 | { |
---|
106 | for (int i = 0; i < ni; ++i) |
---|
107 | { |
---|
108 | domainGlobalIndex = (j+jbegin) * niGlob + (i+ibegin); |
---|
109 | transMap[domainGlobalIndex].push_back(domainGlobalIndex); |
---|
110 | transWeight[domainGlobalIndex].push_back(1.0); |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | updateZoom(); |
---|
115 | updateDomainDestinationMask(); |
---|
116 | } |
---|
117 | |
---|
118 | /*! |
---|
119 | After a zoom on domain, it should be certain that (global) zoom begin and (global) zoom size are updated |
---|
120 | */ |
---|
121 | void CDomainAlgorithmZoom::updateZoom() |
---|
122 | { |
---|
123 | domainDest_->global_zoom_ibegin = zoomIBegin_; |
---|
124 | domainDest_->global_zoom_jbegin = zoomJBegin_; |
---|
125 | domainDest_->global_zoom_ni = zoomNi_; |
---|
126 | domainDest_->global_zoom_nj = zoomNj_; |
---|
127 | } |
---|
128 | |
---|
129 | /*! |
---|
130 | Update mask on domain |
---|
131 | Because only zoomed region on domain is not masked, the remaining must be masked to make sure |
---|
132 | correct index be extracted |
---|
133 | */ |
---|
134 | void CDomainAlgorithmZoom::updateDomainDestinationMask() |
---|
135 | { |
---|
136 | int niMask = domainDest_->ni.getValue(); |
---|
137 | int iBeginMask = domainDest_->ibegin.getValue(); |
---|
138 | int njMask = domainDest_->nj.getValue(); |
---|
139 | int jBeginMask = domainDest_->jbegin.getValue(); |
---|
140 | int niGlob = domainDest_->ni_glo.getValue(); |
---|
141 | int globalIndexMask = 0; |
---|
142 | |
---|
143 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
144 | TransformationIndexMap::const_iterator ite = (transMap).end(); |
---|
145 | for (int j = 0; j < njMask; ++j) |
---|
146 | { |
---|
147 | for (int i = 0; i < niMask; ++i) |
---|
148 | { |
---|
149 | globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask); |
---|
150 | if (transMap.find(globalIndexMask) == ite) |
---|
151 | (domainDest_->mask_1d)(i+j*niMask) = false; |
---|
152 | } |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | } |
---|