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