source: XIOS/dev/XIOS_DEV_CMIP6/src/transformation/axis_algorithm_zoom.cpp @ 1620

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

Porting non-continuous axis zoom to dev branch

+) Port axis zoom
+) Resolve some merge conflicts
+) Revert some codes

Test
+) On Curie
+) Ok

File size: 5.6 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  if (!zoomAxis->index.isEmpty())
57  {
58    int sz = zoomAxis->index.numElements();
59    zoomIndex_.resize(sz);
60    for (int i = 0; i < sz; ++i)
61      zoomIndex_[i] = zoomAxis->index(i);
62
63    std::sort(zoomIndex_.begin(), zoomIndex_.end());
64  }
65
66}
67
68/*!
69  Compute the index mapping between axis on grid source and one on grid destination
70*/
71void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
72{
73  // We use all index of source and destination to calculate the mapping index of zoom.
74  // The server who receives the "zoomed" fields will decide whether it will forward these fields or write "real zoomed" fields into file
75  // That means servers need to change to cover this problem.
76  StdSize niSource = axisSrc_->n.getValue();
77  StdSize ibeginSource = axisSrc_->begin.getValue();
78  StdSize iendSource = ibeginSource + niSource - 1;
79
80  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
81  StdSize iend = std::min(iendSource, zoomEnd_);
82  StdSize ni = iend + 1 - ibegin;
83  if (iend < ibegin) ni = 0;
84
85  this->transformationMapping_.resize(1);
86  this->transformationWeight_.resize(1);
87
88  TransformationIndexMap& transMap = this->transformationMapping_[0];
89  TransformationWeightMap& transWeight = this->transformationWeight_[0];
90
91  if (!zoomIndex_.empty())
92  {
93    std::vector<int>::iterator itZoomBegin, itZoomEnd;
94    itZoomBegin = std::lower_bound(zoomIndex_.begin(), zoomIndex_.end(), ibeginSource);
95    itZoomEnd   = std::upper_bound(zoomIndex_.begin(), zoomIndex_.end(), iendSource);           
96    for (; itZoomBegin != itZoomEnd; ++itZoomBegin)
97    {
98      transMap[*itZoomBegin].push_back(*itZoomBegin);
99      transWeight[*itZoomBegin].push_back(1.0);
100    }
101  }
102  else
103  {
104    for (StdSize idx = 0; idx < ni; ++idx)
105    {
106      transMap[ibegin+idx].push_back(ibegin+idx);
107      transWeight[ibegin+idx].push_back(1.0);
108    }
109  }
110
111  updateZoom();
112  // updateAxisDestinationMask();
113}
114
115/*!
116  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
117*/
118void CAxisAlgorithmZoom::updateZoom()
119{
120  axisDest_->global_zoom_begin = zoomBegin_;
121  axisDest_->global_zoom_n  = zoomSize_;
122  if (!zoomIndex_.empty())
123  {
124    axisDest_->global_zoom_index.resize(zoomIndex_.size());
125    std::copy(zoomIndex_.begin(), zoomIndex_.end(), axisDest_->global_zoom_index.begin());
126  }
127}
128
129/*!
130  Update mask on axis
131  Because only zoomed region on axis is not masked, the remaining must be masked to make sure
132correct index be extracted
133*/
134// void CAxisAlgorithmZoom::updateAxisDestinationMask()
135// {
136//   StdSize niMask = axisDest_->mask.numElements();
137//   StdSize iBeginMask = axisDest_->begin.getValue();
138//   StdSize globalIndexMask = 0;
139//   TransformationIndexMap& transMap = this->transformationMapping_[0];
140//   TransformationIndexMap::const_iterator ite = (transMap).end();
141//   for (StdSize idx = 0; idx < niMask; ++idx)
142//   {
143//     globalIndexMask = iBeginMask + idx;
144//     if (transMap.find(globalIndexMask) == ite)
145//       (axisDest_->mask)(idx) = false;
146//   }
147// }
148
149}
Note: See TracBrowser for help on using the repository browser.