[631] | 1 | #include "domain_algorithm_zoom.hpp" |
---|
[933] | 2 | #include "zoom_domain.hpp" |
---|
| 3 | #include "domain.hpp" |
---|
| 4 | #include "grid.hpp" |
---|
| 5 | #include "grid_transformation_factory_impl.hpp" |
---|
[1553] | 6 | #include "attribute_template.hpp" |
---|
[2442] | 7 | #include "type.hpp" |
---|
[631] | 8 | |
---|
| 9 | namespace xios { |
---|
[933] | 10 | CGenericAlgorithmTransformation* CDomainAlgorithmZoom::create(CGrid* gridDst, CGrid* gridSrc, |
---|
| 11 | CTransformation<CDomain>* transformation, |
---|
| 12 | int elementPositionInGrid, |
---|
| 13 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 14 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 15 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 16 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 17 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 18 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
[1622] | 19 | TRY |
---|
[933] | 20 | { |
---|
| 21 | std::vector<CDomain*> domainListDestP = gridDst->getDomains(); |
---|
| 22 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
[631] | 23 | |
---|
[933] | 24 | CZoomDomain* zoomDomain = dynamic_cast<CZoomDomain*> (transformation); |
---|
| 25 | int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid]; |
---|
| 26 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 27 | |
---|
| 28 | return (new CDomainAlgorithmZoom(domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], zoomDomain)); |
---|
| 29 | } |
---|
[1622] | 30 | CATCH |
---|
[933] | 31 | |
---|
| 32 | bool CDomainAlgorithmZoom::registerTrans() |
---|
[1622] | 33 | TRY |
---|
[933] | 34 | { |
---|
[1852] | 35 | return CGridTransformationFactory<CDomain>::registerTransformation(TRANS_ZOOM_DOMAIN, create); |
---|
[933] | 36 | } |
---|
[1622] | 37 | CATCH |
---|
[933] | 38 | |
---|
[631] | 39 | CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain) |
---|
| 40 | : CDomainAlgorithmTransformation(domainDestination, domainSource) |
---|
[1622] | 41 | TRY |
---|
[631] | 42 | { |
---|
| 43 | zoomDomain->checkValid(domainSource); |
---|
[787] | 44 | zoomIBegin_ = zoomDomain->ibegin.getValue(); |
---|
| 45 | zoomJBegin_ = zoomDomain->jbegin.getValue(); |
---|
[631] | 46 | |
---|
[787] | 47 | zoomNi_ = zoomDomain->ni.getValue(); |
---|
| 48 | zoomNj_ = zoomDomain->nj.getValue(); |
---|
[631] | 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 | |
---|
[1553] | 69 | // Calculate the size of local domain |
---|
| 70 | int ind, indLocSrc, indLocDest, iIdxSrc, jIdxSrc, destIBegin = -1, destJBegin = -1, niDest = 0, njDest = 0, ibeginDest, jbeginDest ; |
---|
[1583] | 71 | int indGloDest, indGloSrc, niGloSrc = domainSrc_->ni_glo, iSrc, jSrc, nvertex = 0; |
---|
[1553] | 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; |
---|
[631] | 91 | |
---|
[1553] | 92 | } |
---|
| 93 | } |
---|
| 94 | } |
---|
| 95 | ibeginDest = destIBegin + domainSrc_->ibegin - zoomIBegin_; |
---|
| 96 | jbeginDest = destJBegin + domainSrc_->jbegin - zoomJBegin_; |
---|
| 97 | domainDest_->ni_glo.setValue(zoomNi_); |
---|
| 98 | domainDest_->nj_glo.setValue(zoomNj_); |
---|
| 99 | domainDest_->ni.setValue(niDest); |
---|
| 100 | domainDest_->nj.setValue(njDest); |
---|
[1609] | 101 | if ( (niDest==0) || (njDest==0)) |
---|
| 102 | { |
---|
| 103 | domainDest_->ibegin.setValue(0); |
---|
| 104 | domainDest_->jbegin.setValue(0); |
---|
| 105 | } |
---|
| 106 | else |
---|
| 107 | { |
---|
| 108 | domainDest_->ibegin.setValue(ibeginDest); |
---|
| 109 | domainDest_->jbegin.setValue(jbeginDest); |
---|
| 110 | } |
---|
[1553] | 111 | domainDest_->i_index.resize(niDest*njDest); |
---|
| 112 | domainDest_->j_index.resize(niDest*njDest); |
---|
[827] | 113 | |
---|
[1553] | 114 | domainDest_->data_ni.setValue(niDest); |
---|
| 115 | domainDest_->data_nj.setValue(njDest); |
---|
[1621] | 116 | domainDest_->data_ibegin.setValue(0); |
---|
| 117 | domainDest_->data_jbegin.setValue(0); |
---|
| 118 | domainDest_->data_i_index.resize(niDest*njDest); |
---|
| 119 | domainDest_->data_j_index.resize(niDest*njDest); |
---|
[1553] | 120 | |
---|
| 121 | domainDest_->domainMask.resize(niDest*njDest); |
---|
| 122 | |
---|
| 123 | if (!domainSrc_->lonvalue_1d.isEmpty()) |
---|
| 124 | { |
---|
| 125 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
| 126 | { |
---|
| 127 | domainDest_->lonvalue_1d.resize(niDest); |
---|
| 128 | domainDest_->latvalue_1d.resize(njDest); |
---|
| 129 | } |
---|
| 130 | else if (domainDest_->type == CDomain::type_attr::unstructured) |
---|
| 131 | { |
---|
| 132 | domainDest_->lonvalue_1d.resize(niDest); |
---|
| 133 | domainDest_->latvalue_1d.resize(niDest); |
---|
| 134 | } |
---|
[1583] | 135 | else if (domainDest_->type == CDomain::type_attr::curvilinear) |
---|
| 136 | { |
---|
| 137 | domainDest_->lonvalue_1d.resize(niDest*njDest); |
---|
| 138 | domainDest_->latvalue_1d.resize(niDest*njDest); |
---|
| 139 | } |
---|
[1553] | 140 | } |
---|
| 141 | else if (!domainSrc_->lonvalue_2d.isEmpty()) |
---|
| 142 | { |
---|
| 143 | domainDest_->lonvalue_2d.resize(niDest,njDest); |
---|
| 144 | domainDest_->latvalue_2d.resize(niDest,njDest); |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if (domainSrc_->hasBounds) |
---|
| 148 | { |
---|
[2442] | 149 | nvertex = ( domainSrc_->type==CDomain::type_attr::rectilinear || domainSrc_->type==CDomain::type_attr::curvilinear) ? 4 : domainSrc_->nvertex ; |
---|
[1583] | 150 | domainDest_->nvertex.setValue(nvertex); |
---|
| 151 | if (!domainSrc_->bounds_lon_1d.isEmpty()) |
---|
[1553] | 152 | { |
---|
[1583] | 153 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
| 154 | { |
---|
| 155 | domainDest_->bounds_lon_1d.resize(nvertex, niDest); |
---|
| 156 | domainDest_->bounds_lat_1d.resize(nvertex, njDest); |
---|
| 157 | } |
---|
| 158 | else if (domainDest_->type == CDomain::type_attr::unstructured) |
---|
| 159 | { |
---|
| 160 | domainDest_->bounds_lon_1d.resize(nvertex, niDest); |
---|
| 161 | domainDest_->bounds_lat_1d.resize(nvertex, niDest); |
---|
| 162 | } |
---|
| 163 | else if (domainDest_->type == CDomain::type_attr::curvilinear) |
---|
| 164 | { |
---|
| 165 | domainDest_->bounds_lon_1d.resize(nvertex, niDest*njDest); |
---|
| 166 | domainDest_->bounds_lat_1d.resize(nvertex, niDest*njDest); |
---|
| 167 | } |
---|
[1553] | 168 | } |
---|
[1583] | 169 | else if (!domainSrc_->bounds_lon_2d.isEmpty()) |
---|
[1553] | 170 | { |
---|
[1583] | 171 | domainDest_->bounds_lon_2d.resize(nvertex, niDest, njDest); |
---|
| 172 | domainDest_->bounds_lat_2d.resize(nvertex, niDest, njDest); |
---|
[1553] | 173 | } |
---|
| 174 | } |
---|
| 175 | if (domainSrc_->hasArea) domainDest_->area.resize(niDest,njDest); |
---|
| 176 | |
---|
[827] | 177 | this->transformationMapping_.resize(1); |
---|
| 178 | this->transformationWeight_.resize(1); |
---|
[833] | 179 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 180 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
[827] | 181 | |
---|
[1553] | 182 | for (int iDest = 0; iDest < niDest; iDest++) |
---|
[631] | 183 | { |
---|
[1553] | 184 | iSrc = iDest + destIBegin; |
---|
| 185 | for (int jDest = 0; jDest < njDest; jDest++) |
---|
[631] | 186 | { |
---|
[1553] | 187 | jSrc = jDest + destJBegin; |
---|
| 188 | ind = jSrc * domainSrc_->ni + iSrc; |
---|
| 189 | iIdxSrc = domainSrc_->i_index(ind); |
---|
| 190 | jIdxSrc = domainSrc_->j_index(ind); |
---|
| 191 | indLocDest = jDest*niDest + iDest; |
---|
| 192 | indGloDest = (jDest + jbeginDest)*zoomNi_ + (iDest + ibeginDest); |
---|
| 193 | indLocSrc = (jDest+destJBegin)*domainSrc_->ni + (iDest+destIBegin); |
---|
| 194 | indGloSrc = (jIdxSrc )* niGloSrc + iIdxSrc; |
---|
| 195 | domainDest_->i_index(indLocDest) = iDest + ibeginDest; // i_index contains global positions |
---|
| 196 | domainDest_->j_index(indLocDest) = jDest + jbeginDest; // i_index contains global positions |
---|
| 197 | domainDest_->data_i_index(indLocDest) = (domainSrc_->data_dim == 1) ? indLocDest : iDest; // data_i_index contains local positions |
---|
| 198 | domainDest_->data_j_index(indLocDest) = (domainSrc_->data_dim == 1) ? 0 :jDest; // data_i_index contains local positions |
---|
| 199 | domainDest_->domainMask(indLocDest) = domainSrc_->domainMask(indLocSrc); |
---|
| 200 | |
---|
| 201 | if (domainSrc_->hasArea) |
---|
| 202 | domainDest_->area(iDest,jDest) = domainSrc_->area(iSrc,jSrc); |
---|
| 203 | |
---|
[1583] | 204 | if (domainSrc_->hasLonLat) |
---|
[1553] | 205 | { |
---|
[1583] | 206 | if (!domainSrc_->latvalue_1d.isEmpty()) |
---|
[1553] | 207 | { |
---|
[1583] | 208 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
[1553] | 209 | { |
---|
[1583] | 210 | domainDest_->latvalue_1d(jDest) = domainSrc_->latvalue_1d(jSrc); |
---|
[1553] | 211 | } |
---|
[1583] | 212 | else |
---|
[1553] | 213 | { |
---|
[1583] | 214 | domainDest_->lonvalue_1d(indLocDest) = domainSrc_->lonvalue_1d(ind); |
---|
| 215 | domainDest_->latvalue_1d(indLocDest) = domainSrc_->latvalue_1d(ind); |
---|
[1553] | 216 | } |
---|
| 217 | } |
---|
[1583] | 218 | else if (!domainSrc_->latvalue_2d.isEmpty()) |
---|
| 219 | { |
---|
| 220 | domainDest_->lonvalue_2d(iDest,jDest) = domainSrc_->lonvalue_2d(iSrc,jSrc); |
---|
| 221 | domainDest_->latvalue_2d(iDest,jDest) = domainSrc_->latvalue_2d(iSrc,jSrc); |
---|
| 222 | } |
---|
[1553] | 223 | } |
---|
| 224 | |
---|
[1583] | 225 | if (domainSrc_->hasBounds) |
---|
[1553] | 226 | { |
---|
[1583] | 227 | if (!domainSrc_->bounds_lon_1d.isEmpty()) |
---|
[1553] | 228 | { |
---|
[1583] | 229 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
| 230 | { |
---|
| 231 | for (int n = 0; n < nvertex; ++n) |
---|
| 232 | domainDest_->bounds_lat_1d(n,jDest) = domainSrc_->bounds_lat_1d(n,jSrc); |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | for (int n = 0; n < nvertex; ++n) |
---|
| 237 | { |
---|
| 238 | domainDest_->bounds_lon_1d(n,indLocDest) = domainSrc_->bounds_lon_1d(n,ind); |
---|
| 239 | domainDest_->bounds_lat_1d(n,indLocDest) = domainSrc_->bounds_lat_1d(n,ind); |
---|
| 240 | } |
---|
| 241 | } |
---|
[1553] | 242 | } |
---|
[1583] | 243 | else if (!domainSrc_->bounds_lon_2d.isEmpty()) |
---|
[1553] | 244 | { |
---|
[1583] | 245 | for (int n = 0; n < nvertex; ++n) |
---|
| 246 | { |
---|
| 247 | domainDest_->bounds_lon_2d(n,iDest,jDest) = domainSrc_->bounds_lon_2d(n,iSrc,jSrc); |
---|
| 248 | domainDest_->bounds_lat_2d(n,iDest,jDest) = domainSrc_->bounds_lat_2d(n,iSrc,jSrc); |
---|
| 249 | } |
---|
[1553] | 250 | } |
---|
[1583] | 251 | |
---|
[1553] | 252 | } |
---|
| 253 | |
---|
| 254 | transMap[indGloDest].push_back(indGloSrc); |
---|
| 255 | transWeight[indGloDest].push_back(1.0); |
---|
[1583] | 256 | } |
---|
[1553] | 257 | |
---|
[1583] | 258 | if (domainSrc_->hasLonLat && !domainSrc_->latvalue_1d.isEmpty()) |
---|
[1553] | 259 | { |
---|
[1583] | 260 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
[1553] | 261 | { |
---|
| 262 | domainDest_->lonvalue_1d(iDest) = domainSrc_->lonvalue_1d(iSrc); |
---|
| 263 | } |
---|
[1583] | 264 | } |
---|
| 265 | |
---|
| 266 | if (domainSrc_->hasBounds && !domainSrc_->bounds_lon_1d.isEmpty()) |
---|
| 267 | { |
---|
| 268 | if (domainDest_->type == CDomain::type_attr::rectilinear) |
---|
[1553] | 269 | { |
---|
[1583] | 270 | for (int n = 0; n < nvertex; ++n) |
---|
| 271 | domainDest_->bounds_lon_1d(n,iDest) = domainSrc_->bounds_lon_1d(n,iSrc); |
---|
[1553] | 272 | } |
---|
| 273 | } |
---|
[631] | 274 | } |
---|
[1621] | 275 | domainDest_->computeLocalMask(); |
---|
[631] | 276 | } |
---|
[1622] | 277 | CATCH |
---|
[631] | 278 | |
---|
| 279 | /*! |
---|
[1553] | 280 | Compute the index mapping between domain on grid source and one on grid destination |
---|
[631] | 281 | */ |
---|
[1553] | 282 | void CDomainAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[631] | 283 | { |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | |
---|
| 287 | } |
---|