[631] | 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" |
---|
[933] | 10 | #include "zoom_domain.hpp" |
---|
| 11 | #include "domain.hpp" |
---|
| 12 | #include "grid.hpp" |
---|
| 13 | #include "grid_transformation_factory_impl.hpp" |
---|
[631] | 14 | |
---|
| 15 | namespace xios { |
---|
[933] | 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(); |
---|
[631] | 28 | |
---|
[933] | 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 | |
---|
[631] | 41 | CDomainAlgorithmZoom::CDomainAlgorithmZoom(CDomain* domainDestination, CDomain* domainSource, CZoomDomain* zoomDomain) |
---|
| 42 | : CDomainAlgorithmTransformation(domainDestination, domainSource) |
---|
| 43 | { |
---|
| 44 | zoomDomain->checkValid(domainSource); |
---|
[787] | 45 | zoomIBegin_ = zoomDomain->ibegin.getValue(); |
---|
| 46 | zoomJBegin_ = zoomDomain->jbegin.getValue(); |
---|
[631] | 47 | |
---|
[787] | 48 | zoomNi_ = zoomDomain->ni.getValue(); |
---|
| 49 | zoomNj_ = zoomDomain->nj.getValue(); |
---|
[631] | 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 | */ |
---|
[827] | 74 | void CDomainAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[631] | 75 | { |
---|
| 76 | |
---|
| 77 | int niGlob = domainSrc_->ni_glo.getValue(); |
---|
| 78 | int njGlob = domainSrc_->nj_glo.getValue(); |
---|
[827] | 79 | |
---|
| 80 | this->transformationMapping_.resize(1); |
---|
| 81 | this->transformationWeight_.resize(1); |
---|
| 82 | |
---|
[833] | 83 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 84 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
[827] | 85 | |
---|
[631] | 86 | int domainGlobalIndex; |
---|
[1281] | 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) |
---|
[631] | 94 | { |
---|
[1281] | 95 | iglob=i_index(i) ; jglob=j_index(i) ; |
---|
| 96 | if (iglob>=zoomIBegin_ && iglob<=zoomIEnd_ && jglob>=zoomJBegin_ && jglob<=zoomJEnd_) |
---|
[631] | 97 | { |
---|
[1281] | 98 | domainGlobalIndex = jglob*niGlob + iglob; |
---|
[631] | 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 | */ |
---|
[1144] | 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; |
---|
[631] | 130 | |
---|
[1144] | 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 | // } |
---|
[631] | 143 | |
---|
| 144 | } |
---|