source: XIOS/trunk/src/transformation/axis_algorithm_zoom.cpp @ 1559

Last change on this file since 1559 was 1559, checked in by oabramkina, 3 years ago

Replacing axis zoom by axis extract.
Zoom private attributes are gone for good.

File size: 4.5 KB
Line 
1/*!
2   \file axis_algorithm_zoom.cpp
3   \brief Algorithm for zooming an axis.
4 */
5#include "axis_algorithm_zoom.hpp"
6#include "axis.hpp"
7#include "grid.hpp"
8#include "grid_transformation_factory_impl.hpp"
9#include "zoom_axis.hpp"
10
11namespace xios {
12CGenericAlgorithmTransformation* 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();
24
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}
31bool CAxisAlgorithmZoom::registerTrans()
32{
33  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create);
34}
35
36CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
37: CAxisAlgorithmTransformation(axisDestination, axisSource)
38{
39  zoomAxis->checkValid(axisSource);
40  zoomBegin_ = zoomAxis->begin.getValue();
41  zoomN_  = zoomAxis->n.getValue();
42  zoomEnd_   = zoomBegin_ + zoomN_ - 1;
43
44  if (zoomN_ > axisSource->n_glo.getValue())
45  {
46    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)",
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_ );
50  }
51
52  int idxSrc, nDest = 0, beginDestLoc, beginDestGlo = 0 ;
53  int indGloDest, indGloSrc, iSrc;
54  for (int i = 0; i < axisSrc_->n.getValue(); i++)
55  {
56    idxSrc = axisSrc_->index(i);
57    if ((idxSrc >= zoomBegin_) && (idxSrc <= zoomEnd_))
58    {
59      if (nDest == 0) beginDestLoc = i;
60      ++nDest;
61    }
62  }
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);
68
69  axisDest_->data_n.setValue(nDest);
70  axisDest_->data_begin.setValue(0);
71  axisDest_->data_index.resize(nDest);
72
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);
77
78  this->transformationMapping_.resize(1);
79  this->transformationWeight_.resize(1);
80  TransformationIndexMap& transMap = this->transformationMapping_[0];
81  TransformationWeightMap& transWeight = this->transformationWeight_[0];
82
83  for (int iDest = 0; iDest < nDest; iDest++)
84  {
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)
95    {
96      axisDest_->bounds(0,iDest) = axisSrc_->bounds(0,iSrc);
97      axisDest_->bounds(1,iDest) = axisSrc_->bounds(1,iSrc);
98    }
99    indGloDest = axisDest_->index(iDest);
100    indGloSrc = axisSrc_->index(iSrc);
101    transMap[indGloDest].push_back(indGloSrc);
102    transWeight[indGloDest].push_back(1.0);
103
104  }
105}
106
107/*!
108  Compute the index mapping between domain on grid source and one on grid destination
109*/
110void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
111{
112}
113
114}
Note: See TracBrowser for help on using the repository browser.