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

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

Updating two-level server.
Each client now can play the role of server: It can forward data to other clients or write data like a server.
Each client must combine all data received from other client(s) before forward them or write them on files

+) Correct some bugs of exchange data_index in domain and axis
+) Reorder some functions in context.cpp to make sure that all necessary attributes are available before computing index
+) Add the mapping index for client to write data.

Test
+) On Curie
+) test_client and test_complete
+) Mode:

  • Only one level: Correct
  • Two levels: Work if using ddt (bug)

+) Only zoom is tested but other transformations should work
+) No reading test

File size: 4.7 KB
RevLine 
[624]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 */
[623]9#include "axis_algorithm_zoom.hpp"
[933]10#include "axis.hpp"
11#include "grid.hpp"
12#include "grid_transformation_factory_impl.hpp"
13#include "zoom_axis.hpp"
[623]14
15namespace xios {
[933]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();
[623]28
[933]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
[623]40CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)
[630]41: CAxisAlgorithmTransformation(axisDestination, axisSource)
[623]42{
43  zoomAxis->checkValid(axisSource);
[787]44  zoomBegin_ = zoomAxis->begin.getValue();
45  zoomSize_  = zoomAxis->n.getValue();
46  zoomEnd_   = zoomBegin_ + zoomSize_ - 1;
[623]47
[666]48  if (zoomSize_ > axisSource->n_glo.getValue())
[623]49  {
50    ERROR("CAxisAlgorithmZoom::CAxisAlgorithmZoom(CAxis* axisDestination, CAxis* axisSource, CZoomAxis* zoomAxis)",
[666]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
[623]53           << "Zoom size is " << zoomSize_ );
54  }
55}
56
[624]57/*!
58  Compute the index mapping between axis on grid source and one on grid destination
59*/
[827]60void CAxisAlgorithmZoom::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
[623]61{
[1129]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.
[666]65  StdSize niSource = axisSrc_->n.getValue();
66  StdSize ibeginSource = axisSrc_->begin.getValue();
[623]67  StdSize iendSource = ibeginSource + niSource - 1;
68
69  StdSize ibegin = std::max(ibeginSource, zoomBegin_);
70  StdSize iend = std::min(iendSource, zoomEnd_);
[1129]71  // StdSize ibegin = ibeginSource;
72  // StdSize iend = iendSource;
[623]73  StdSize ni = iend + 1 - ibegin;
74  if (iend < ibegin) ni = 0;
75
[827]76  this->transformationMapping_.resize(1);
77  this->transformationWeight_.resize(1);
78
[833]79  TransformationIndexMap& transMap = this->transformationMapping_[0];
80  TransformationWeightMap& transWeight = this->transformationWeight_[0];
[827]81
[623]82  for (StdSize idx = 0; idx < ni; ++idx)
83  {
84    transMap[ibegin+idx].push_back(ibegin+idx);
[630]85    transWeight[ibegin+idx].push_back(1.0);
[623]86  }
87
88  updateZoom();
[1129]89  // updateAxisDestinationMask();
[623]90}
91
[624]92/*!
93  After a zoom on axis, it should be certain that (global) zoom begin and (global) zoom size are updated
94*/
[623]95void CAxisAlgorithmZoom::updateZoom()
96{
97  axisDest_->global_zoom_begin = zoomBegin_;
[821]98  axisDest_->global_zoom_n  = zoomSize_;
[623]99}
100
[624]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*/
[623]106void CAxisAlgorithmZoom::updateAxisDestinationMask()
107{
108  StdSize niMask = axisDest_->mask.numElements();
[666]109  StdSize iBeginMask = axisDest_->begin.getValue();
[623]110  StdSize globalIndexMask = 0;
[833]111  TransformationIndexMap& transMap = this->transformationMapping_[0];
112  TransformationIndexMap::const_iterator ite = (transMap).end();
[623]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.