Changeset 1553 for XIOS/trunk/src/transformation/domain_algorithm_zoom.cpp
- Timestamp:
- 06/28/18 17:53:42 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/transformation/domain_algorithm_zoom.cpp
r1281 r1553 1 /*!2 \file domain_algorithm_zoom.cpp3 \author Ha NGUYEN4 \since 02 Jul 20155 \date 02 Jul 20156 7 \brief Algorithm for zooming on an domain.8 */9 1 #include "domain_algorithm_zoom.hpp" 10 2 #include "zoom_domain.hpp" … … 12 4 #include "grid.hpp" 13 5 #include "grid_transformation_factory_impl.hpp" 6 #include "attribute_template.hpp" 14 7 15 8 namespace xios { … … 67 60 << "Zoom size is " << zoomNj_ ); 68 61 } 62 63 // Calculate the size of local domain 64 int ind, indLocSrc, indLocDest, iIdxSrc, jIdxSrc, destIBegin = -1, destJBegin = -1, niDest = 0, njDest = 0, ibeginDest, jbeginDest ; 65 int indGloDest, indGloSrc, niGloSrc = domainSrc_->ni_glo, iSrc, jSrc; 66 for (int j = 0; j < domainSrc_->nj.getValue(); j++) 67 { 68 for (int i = 0; i < domainSrc_->ni.getValue(); i++) 69 { 70 ind = j*domainSrc_->ni + i; 71 iIdxSrc = domainSrc_->i_index(ind); 72 if ((iIdxSrc >= zoomIBegin_) && (iIdxSrc <= zoomIEnd_)) 73 { 74 jIdxSrc = domainSrc_->j_index(ind); 75 if ((jIdxSrc >= zoomJBegin_) && (jIdxSrc <= zoomJEnd_)) 76 { 77 if ((niDest == 0) && (njDest == 0)) 78 { 79 destIBegin = i; 80 destJBegin = j; 81 } 82 if (i == destIBegin) ++njDest; 83 } 84 if (j == destJBegin) ++niDest; 85 86 } 87 } 88 } 89 ibeginDest = destIBegin + domainSrc_->ibegin - zoomIBegin_; 90 jbeginDest = destJBegin + domainSrc_->jbegin - zoomJBegin_; 91 domainDest_->ni_glo.setValue(zoomNi_); 92 domainDest_->nj_glo.setValue(zoomNj_); 93 domainDest_->ni.setValue(niDest); 94 domainDest_->nj.setValue(njDest); 95 domainDest_->ibegin.setValue(ibeginDest); 96 domainDest_->jbegin.setValue(jbeginDest); 97 domainDest_->i_index.resize(niDest*njDest); 98 domainDest_->j_index.resize(niDest*njDest); 99 100 domainDest_->data_ni.setValue(niDest); 101 domainDest_->data_nj.setValue(njDest); 102 domainDest_->data_ibegin.setValue(0); // local position 103 domainDest_->data_jbegin.setValue(0); // local position 104 domainDest_->data_i_index.resize(niDest*njDest); // local position 105 domainDest_->data_j_index.resize(niDest*njDest); // local position 106 107 domainDest_->domainMask.resize(niDest*njDest); 108 109 if (!domainSrc_->lonvalue_1d.isEmpty()) 110 { 111 if (domainDest_->type == CDomain::type_attr::rectilinear) 112 { 113 domainDest_->lonvalue_1d.resize(niDest); 114 domainDest_->latvalue_1d.resize(njDest); 115 } 116 else if (domainDest_->type == CDomain::type_attr::unstructured) 117 { 118 domainDest_->lonvalue_1d.resize(niDest); 119 domainDest_->latvalue_1d.resize(niDest); 120 } 121 } 122 else if (!domainSrc_->lonvalue_2d.isEmpty()) 123 { 124 domainDest_->lonvalue_2d.resize(niDest,njDest); 125 domainDest_->latvalue_2d.resize(niDest,njDest); 126 } 127 128 if (domainSrc_->hasBounds) 129 { 130 if (!domainSrc_->bounds_lon_2d.isEmpty()) 131 { 132 domainDest_->bounds_lon_2d.resize(domainDest_->nvertex, niDest, njDest); 133 domainDest_->bounds_lon_2d.resize(domainDest_->nvertex, niDest, njDest); 134 } 135 else if (!domainSrc_->bounds_lon_1d.isEmpty()) 136 { 137 domainDest_->bounds_lon_1d.resize(domainDest_->nvertex, niDest); 138 domainDest_->bounds_lon_1d.resize(domainDest_->nvertex, niDest); 139 } 140 } 141 if (domainSrc_->hasArea) domainDest_->area.resize(niDest,njDest); 142 143 this->transformationMapping_.resize(1); 144 this->transformationWeight_.resize(1); 145 TransformationIndexMap& transMap = this->transformationMapping_[0]; 146 TransformationWeightMap& transWeight = this->transformationWeight_[0]; 147 148 for (int iDest = 0; iDest < niDest; iDest++) 149 { 150 iSrc = iDest + destIBegin; 151 for (int jDest = 0; jDest < njDest; jDest++) 152 { 153 jSrc = jDest + destJBegin; 154 ind = jSrc * domainSrc_->ni + iSrc; 155 iIdxSrc = domainSrc_->i_index(ind); 156 jIdxSrc = domainSrc_->j_index(ind); 157 indLocDest = jDest*niDest + iDest; 158 indGloDest = (jDest + jbeginDest)*zoomNi_ + (iDest + ibeginDest); 159 indLocSrc = (jDest+destJBegin)*domainSrc_->ni + (iDest+destIBegin); 160 indGloSrc = (jIdxSrc )* niGloSrc + iIdxSrc; 161 domainDest_->i_index(indLocDest) = iDest + ibeginDest; // i_index contains global positions 162 domainDest_->j_index(indLocDest) = jDest + jbeginDest; // i_index contains global positions 163 domainDest_->data_i_index(indLocDest) = (domainSrc_->data_dim == 1) ? indLocDest : iDest; // data_i_index contains local positions 164 domainDest_->data_j_index(indLocDest) = (domainSrc_->data_dim == 1) ? 0 :jDest; // data_i_index contains local positions 165 domainDest_->domainMask(indLocDest) = domainSrc_->domainMask(indLocSrc); 166 167 if (domainSrc_->hasArea) 168 domainDest_->area(iDest,jDest) = domainSrc_->area(iSrc,jSrc); 169 170 if (domainSrc_->hasBounds) 171 { 172 if (!domainSrc_->bounds_lon_2d.isEmpty()) 173 { 174 for (int n = 0; n < domainSrc_->nvertex; ++n) 175 { 176 domainDest_->bounds_lon_2d(n,iDest,jDest) = domainSrc_->bounds_lon_2d(n,iSrc,jSrc); 177 domainDest_->bounds_lat_2d(n,iDest,jDest) = domainSrc_->bounds_lat_2d(n,iSrc,jSrc); 178 } 179 } 180 else if (!domainSrc_->bounds_lon_1d.isEmpty()) 181 { 182 for (int n = 0; n < domainSrc_->nvertex; ++n) 183 { 184 domainDest_->bounds_lon_1d(n,iDest) = domainSrc_->bounds_lon_1d(n,iSrc); 185 domainDest_->bounds_lat_1d(n,iDest) = domainSrc_->bounds_lat_1d(n,iSrc); 186 } 187 } 188 } 189 190 if (domainSrc_->hasLonLat) 191 { 192 if (domainDest_->type == CDomain::type_attr::rectilinear) 193 { 194 domainDest_->latvalue_1d(jDest) = domainSrc_->latvalue_1d(jSrc); 195 } 196 else if (domainDest_->type == CDomain::type_attr::curvilinear) 197 { 198 domainDest_->lonvalue_2d(iDest,jDest) = domainSrc_->lonvalue_2d(iSrc,jSrc); 199 domainDest_->latvalue_2d(iDest,jDest) = domainSrc_->latvalue_2d(iSrc,jSrc); 200 } 201 } 202 203 transMap[indGloDest].push_back(indGloSrc); 204 transWeight[indGloDest].push_back(1.0); 205 206 } 207 if (domainSrc_->hasLonLat) 208 { 209 if (domainDest_->type == CDomain::type_attr::unstructured) 210 { 211 domainDest_->lonvalue_1d(iDest) = domainSrc_->lonvalue_1d(iSrc); 212 domainDest_->latvalue_1d(iDest) = domainSrc_->latvalue_1d(iSrc); 213 } 214 else if (domainDest_->type == CDomain::type_attr::rectilinear) 215 { 216 domainDest_->lonvalue_1d(iDest) = domainSrc_->lonvalue_1d(iSrc); 217 } 218 } 219 } 220 69 221 } 70 222 … … 74 226 void CDomainAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) 75 227 { 76 77 int niGlob = domainSrc_->ni_glo.getValue(); 78 int njGlob = domainSrc_->nj_glo.getValue(); 79 80 this->transformationMapping_.resize(1); 81 this->transformationWeight_.resize(1); 82 83 TransformationIndexMap& transMap = this->transformationMapping_[0]; 84 TransformationWeightMap& transWeight = this->transformationWeight_[0]; 85 86 int domainGlobalIndex; 87 int iglob ; 88 int jglob ; 89 const CArray<int,1>& i_index = domainSrc_->i_index.getValue() ; 90 const CArray<int,1>& j_index = domainSrc_->j_index.getValue() ; 91 92 int nglo = i_index.numElements() ; 93 for (size_t i = 0; i < nglo ; ++i) 94 { 95 iglob=i_index(i) ; jglob=j_index(i) ; 96 if (iglob>=zoomIBegin_ && iglob<=zoomIEnd_ && jglob>=zoomJBegin_ && jglob<=zoomJEnd_) 97 { 98 domainGlobalIndex = jglob*niGlob + iglob; 99 transMap[domainGlobalIndex].push_back(domainGlobalIndex); 100 transWeight[domainGlobalIndex].push_back(1.0); 101 } 102 } 103 updateZoom(); 104 } 105 106 /*! 107 After a zoom on domain, it should be certain that (global) zoom begin and (global) zoom size are updated 108 */ 109 void CDomainAlgorithmZoom::updateZoom() 110 { 111 domainDest_->global_zoom_ibegin = zoomIBegin_; 112 domainDest_->global_zoom_jbegin = zoomJBegin_; 113 domainDest_->global_zoom_ni = zoomNi_; 114 domainDest_->global_zoom_nj = zoomNj_; 115 } 116 117 /*! 118 Update mask on domain 119 Because only zoomed region on domain is not masked, the remaining must be masked to make sure 120 correct index be extracted 121 */ 122 // void CDomainAlgorithmZoom::updateDomainDestinationMask() 123 // { 124 // int niMask = domainDest_->ni.getValue(); 125 // int iBeginMask = domainDest_->ibegin.getValue(); 126 // int njMask = domainDest_->nj.getValue(); 127 // int jBeginMask = domainDest_->jbegin.getValue(); 128 // int niGlob = domainDest_->ni_glo.getValue(); 129 // int globalIndexMask = 0; 130 131 // TransformationIndexMap& transMap = this->transformationMapping_[0]; 132 // TransformationIndexMap::const_iterator ite = (transMap).end(); 133 // for (int j = 0; j < njMask; ++j) 134 // { 135 // for (int i = 0; i < niMask; ++i) 136 // { 137 // globalIndexMask = (j+jBeginMask) * niGlob + (i + iBeginMask); 138 // if (transMap.find(globalIndexMask) == ite) 139 // (domainDest_->mask_1d)(i+j*niMask) = false; 140 // } 141 // } 142 // } 143 144 } 228 } 229 230 231 }
Note: See TracChangeset
for help on using the changeset viewer.