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

Last change on this file since 829 was 827, checked in by mhnguyen, 8 years ago

Implementing dynamic interpolation on axis

+) Change grid transformation to make it more flexible
+) Make some small improvements

Test
+) On Curie
+) All test pass

File size: 2.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
11namespace xios {
12
13CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
14: CAxisAlgorithmTransformation(axisDestination, axisSource)
15{
16  zoomAxis->checkValid(axisSource);
17  zoomBegin_ = zoomAxis->begin.getValue();
18  zoomSize_  = zoomAxis->n.getValue();
19  zoomEnd_   = zoomBegin_ + zoomSize_ - 1;
20
21  if (zoomSize_ > axisSource->n_glo.getValue())
22  {
23    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)",
24           << "Zoom size is greater than global size of axis source"
25           << "Global size of axis source " <<axisSource->getId() << " is " << axisSource->n_glo.getValue()  << std::endl
26           << "Zoom size is " << zoomSize_ );
27  }
28
29//  computeIndexSourceMapping();
30}
31
32/*!
33  Compute the index mapping between axis on grid source and one on grid destination
34*/
35void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
36{
37  StdSize niSource = axisSrc_->n.getValue();
38  StdSize ibeginSource = axisSrc_->begin.getValue();
39  StdSize iendSource = ibeginSource + niSource - 1;
40
41  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
42  StdSize iend = std::min(iendSource, zoomEnd_);
43  StdSize ni = iend + 1 - ibegin;
44  if (iend < ibegin) ni = 0;
45
46  this->transformationMapping_.resize(1);
47  this->transformationWeight_.resize(1);
48
49  std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0];
50  std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0];
51
52  for (StdSize idx = 0; idx < ni; ++idx)
53  {
54    transMap[ibegin+idx].push_back(ibegin+idx);
55    transWeight[ibegin+idx].push_back(1.0);
56  }
57
58  updateZoom();
59  updateAxisDestinationMask();
60}
61
62/*!
63  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
64*/
65void CAxisAlgorithmZoom::updateZoom()
66{
67  axisDest_->global_zoom_begin = zoomBegin_;
68  axisDest_->global_zoom_n  = zoomSize_;
69}
70
71/*!
72  Update mask on axis
73  Because only zoomed region on axis is not masked, the remaining must be masked to make sure
74correct index be extracted
75*/
76void CAxisAlgorithmZoom::updateAxisDestinationMask()
77{
78  StdSize niMask = axisDest_->mask.numElements();
79  StdSize iBeginMask = axisDest_->begin.getValue();
80  StdSize globalIndexMask = 0;
81  std::map<int, std::vector<int> >& transMap = this->transformationMapping_[0];
82  std::map<int, std::vector<int> >::const_iterator ite = (transMap).end();
83  for (StdSize idx = 0; idx < niMask; ++idx)
84  {
85    globalIndexMask = iBeginMask + idx;
86    if (transMap.find(globalIndexMask) == ite)
87      (axisDest_->mask)(idx) = false;
88  }
89}
90
91}
Note: See TracBrowser for help on using the repository browser.