[624] | 1 | /*! |
---|
| 2 | \file axis_algorithm_zoom.cpp |
---|
[1559] | 3 | \brief Algorithm for zooming an axis. |
---|
[624] | 4 | */ |
---|
[623] | 5 | #include "axis_algorithm_zoom.hpp" |
---|
[933] | 6 | #include "axis.hpp" |
---|
| 7 | #include "grid.hpp" |
---|
| 8 | #include "grid_transformation_factory_impl.hpp" |
---|
| 9 | #include "zoom_axis.hpp" |
---|
[623] | 10 | |
---|
| 11 | namespace xios { |
---|
[933] | 12 | CGenericAlgorithmTransformation* CAxisAlgorithmZoom::create(CGrid* gridDst, CGrid* gridSrc, |
---|
| 13 | CTransformation<CAxis>* transformation, |
---|
| 14 | int elementPositionInGrid, |
---|
| 15 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 16 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 17 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 18 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 19 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 20 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 21 | { |
---|
| 22 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
| 23 | std::vector<CAxis*> axisListSrcP = gridSrc->getAxis(); |
---|
[623] | 24 | |
---|
[933] | 25 | CZoomAxis* zoomAxis = dynamic_cast<CZoomAxis*> (transformation); |
---|
| 26 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 27 | int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; |
---|
| 28 | |
---|
| 29 | return (new CAxisAlgorithmZoom(axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], zoomAxis)); |
---|
| 30 | } |
---|
| 31 | bool CAxisAlgorithmZoom::registerTrans() |
---|
| 32 | { |
---|
| 33 | CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create); |
---|
| 34 | } |
---|
| 35 | |
---|
[623] | 36 | CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis) |
---|
[630] | 37 | : CAxisAlgorithmTransformation(axisDestination, axisSource) |
---|
[623] | 38 | { |
---|
| 39 | zoomAxis->checkValid(axisSource); |
---|
[787] | 40 | zoomBegin_ = zoomAxis->begin.getValue(); |
---|
[1559] | 41 | zoomN_ = zoomAxis->n.getValue(); |
---|
| 42 | zoomEnd_ = zoomBegin_ + zoomN_ - 1; |
---|
[623] | 43 | |
---|
[1559] | 44 | if (zoomN_ > axisSource->n_glo.getValue()) |
---|
[623] | 45 | { |
---|
| 46 | ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)", |
---|
[1559] | 47 | << "Zoom size is greater than global size of source axis" |
---|
| 48 | << "Global size of source axis " <<axisSource->getId() << " is " << axisSource->n_glo.getValue() << std::endl |
---|
| 49 | << "Zoom size is " << zoomN_ ); |
---|
[623] | 50 | } |
---|
[1202] | 51 | |
---|
[1559] | 52 | int idxSrc, nDest = 0, beginDestLoc, beginDestGlo = 0 ; |
---|
| 53 | int indGloDest, indGloSrc, iSrc; |
---|
| 54 | for (int i = 0; i < axisSrc_->n.getValue(); i++) |
---|
[1202] | 55 | { |
---|
[1559] | 56 | idxSrc = axisSrc_->index(i); |
---|
| 57 | if ((idxSrc >= zoomBegin_) && (idxSrc <= zoomEnd_)) |
---|
| 58 | { |
---|
| 59 | if (nDest == 0) beginDestLoc = i; |
---|
| 60 | ++nDest; |
---|
| 61 | } |
---|
[1202] | 62 | } |
---|
[1559] | 63 | beginDestGlo = beginDestLoc + axisSrc_->begin - zoomBegin_; |
---|
| 64 | axisDest_->n_glo.setValue(zoomN_); |
---|
| 65 | axisDest_->n.setValue(nDest); |
---|
| 66 | axisDest_->begin.setValue(beginDestGlo); |
---|
| 67 | axisDest_->index.resize(nDest); |
---|
[1202] | 68 | |
---|
[1559] | 69 | axisDest_->data_n.setValue(nDest); |
---|
| 70 | axisDest_->data_begin.setValue(0); |
---|
| 71 | axisDest_->data_index.resize(nDest); |
---|
[623] | 72 | |
---|
[1559] | 73 | axisDest_->mask.resize(nDest); |
---|
| 74 | if (axisSrc_->hasValue) axisDest_->value.resize(nDest); |
---|
| 75 | if (axisSrc_->hasLabel) axisDest_->label.resize(nDest); |
---|
| 76 | if (axisSrc_->hasBounds) axisDest_->bounds.resize(2,nDest); |
---|
[623] | 77 | |
---|
[827] | 78 | this->transformationMapping_.resize(1); |
---|
| 79 | this->transformationWeight_.resize(1); |
---|
[833] | 80 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 81 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
[827] | 82 | |
---|
[1559] | 83 | for (int iDest = 0; iDest < nDest; iDest++) |
---|
[623] | 84 | { |
---|
[1559] | 85 | iSrc = iDest + beginDestLoc; |
---|
| 86 | axisDest_->index(iDest) = iDest + beginDestGlo; |
---|
| 87 | axisDest_->data_index(iDest) = axisSrc_->data_index(iSrc) - beginDestLoc; |
---|
| 88 | axisDest_->mask(iDest) = axisSrc_->mask(iSrc); |
---|
| 89 | |
---|
| 90 | if (axisSrc_->hasValue) |
---|
| 91 | axisDest_->value(iDest) = axisSrc_->value(iSrc); |
---|
| 92 | if (axisSrc_->hasLabel) |
---|
| 93 | axisDest_->label(iDest) = axisSrc_->label(iSrc); |
---|
| 94 | if (axisSrc_->hasBounds) |
---|
[1202] | 95 | { |
---|
[1559] | 96 | axisDest_->bounds(0,iDest) = axisSrc_->bounds(0,iSrc); |
---|
| 97 | axisDest_->bounds(1,iDest) = axisSrc_->bounds(1,iSrc); |
---|
[1202] | 98 | } |
---|
[1559] | 99 | indGloDest = axisDest_->index(iDest); |
---|
| 100 | indGloSrc = axisSrc_->index(iSrc); |
---|
| 101 | transMap[indGloDest].push_back(indGloSrc); |
---|
| 102 | transWeight[indGloDest].push_back(1.0); |
---|
| 103 | |
---|
[623] | 104 | } |
---|
| 105 | } |
---|
| 106 | |
---|
[624] | 107 | /*! |
---|
[1559] | 108 | Compute the index mapping between domain on grid source and one on grid destination |
---|
[624] | 109 | */ |
---|
[1559] | 110 | void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
[623] | 111 | { |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | } |
---|