source: XIOS/dev/dev_olga/src/transformation/axis_algorithm_zoom.cpp @ 1144

Last change on this file since 1144 was 1144, checked in by mhnguyen, 7 years ago

Cleaning up some redundant codes

File size: 4.8 KB
Line 
1/*!
2   \file axis_algorithm_zoom.cpp
3   \author Ha NGUYEN
4   \since 03 June 2015
5   \date 12 June 2015
6
7   \brief Algorithm for zooming on an axis.
8 */
9#include "axis_algorithm_zoom.hpp"
10#include "axis.hpp"
11#include "grid.hpp"
12#include "grid_transformation_factory_impl.hpp"
13#include "zoom_axis.hpp"
14
15namespace xios {
16CGenericAlgorithmTransformation* CAxisAlgorithmZoom::create(CGrid* gridDst, CGrid* gridSrc,
17                                                           CTransformation<CAxis>* 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<CAxis*> axisListDestP = gridDst->getAxis();
27  std::vector<CAxis*> axisListSrcP  = gridSrc->getAxis();
28
29  CZoomAxis* zoomAxis = dynamic_cast<CZoomAxis*> (transformation);
30  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
31  int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid];
32
33  return (new CAxisAlgorithmZoom(axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], zoomAxis));
34}
35bool CAxisAlgorithmZoom::registerTrans()
36{
37  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_ZOOM_AXIS, create);
38}
39
40CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
41: CAxisAlgorithmTransformation(axisDestination, axisSource)
42{
43  zoomAxis->checkValid(axisSource);
44  zoomBegin_ = zoomAxis->begin.getValue();
45  zoomSize_  = zoomAxis->n.getValue();
46  zoomEnd_   = zoomBegin_ + zoomSize_ - 1;
47
48  if (zoomSize_ > axisSource->n_glo.getValue())
49  {
50    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)",
51           << "Zoom size is greater than global size of axis source"
52           << "Global size of axis source " <<axisSource->getId() << " is " << axisSource->n_glo.getValue()  << std::endl
53           << "Zoom size is " << zoomSize_ );
54  }
55}
56
57/*!
58  Compute the index mapping between axis on grid source and one on grid destination
59*/
60void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
61{
62  // We use all index of source and destination to calculate the mapping index of zoom.
63  // The server who receives the "zoomed" fields will decide whether it will forward these fields or write "real zoomed" fields into file
64  // That means servers need to change to cover this problem.
65  StdSize niSource = axisSrc_->n.getValue();
66  StdSize ibeginSource = axisSrc_->begin.getValue();
67  StdSize iendSource = ibeginSource + niSource - 1;
68
69  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
70  StdSize iend = std::min(iendSource, zoomEnd_);
71  // StdSize ibegin = ibeginSource;
72  // StdSize iend = iendSource;
73  StdSize ni = iend + 1 - ibegin;
74  if (iend < ibegin) ni = 0;
75
76  this->transformationMapping_.resize(1);
77  this->transformationWeight_.resize(1);
78
79  TransformationIndexMap& transMap = this->transformationMapping_[0];
80  TransformationWeightMap& transWeight = this->transformationWeight_[0];
81
82  for (StdSize idx = 0; idx < ni; ++idx)
83  {
84    transMap[ibegin+idx].push_back(ibegin+idx);
85    transWeight[ibegin+idx].push_back(1.0);
86  }
87
88  updateZoom();
89  // updateAxisDestinationMask();
90}
91
92/*!
93  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
94*/
95void CAxisAlgorithmZoom::updateZoom()
96{
97  axisDest_->global_zoom_begin = zoomBegin_;
98  axisDest_->global_zoom_n  = zoomSize_;
99}
100
101/*!
102  Update mask on axis
103  Because only zoomed region on axis is not masked, the remaining must be masked to make sure
104correct index be extracted
105*/
106// void CAxisAlgorithmZoom::updateAxisDestinationMask()
107// {
108//   StdSize niMask = axisDest_->mask.numElements();
109//   StdSize iBeginMask = axisDest_->begin.getValue();
110//   StdSize globalIndexMask = 0;
111//   TransformationIndexMap& transMap = this->transformationMapping_[0];
112//   TransformationIndexMap::const_iterator ite = (transMap).end();
113//   for (StdSize idx = 0; idx < niMask; ++idx)
114//   {
115//     globalIndexMask = iBeginMask + idx;
116//     if (transMap.find(globalIndexMask) == ite)
117//       (axisDest_->mask)(idx) = false;
118//   }
119// }
120
121}
Note: See TracBrowser for help on using the repository browser.