source: XIOS/dev/dev_olga/src/transformation/scalar_algorithm_extract_axis.cpp @ 1620

Last change on this file since 1620 was 1612, checked in by oabramkina, 22 months ago

Dev: adding exception handling.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

File size: 3.6 KB
Line 
1/*!
2   \file scalar_algorithm_extract_scalar.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for extract an axis to a scalar
8 */
9#include "scalar_algorithm_extract_axis.hpp"
10#include "axis.hpp"
11#include "scalar.hpp"
12#include "extract_axis_to_scalar.hpp"
13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
15
16#include "reduction.hpp"
17
18namespace xios {
19CGenericAlgorithmTransformation* CScalarAlgorithmExtractAxis::create(CGrid* gridDst, CGrid* gridSrc,
20                                                                     CTransformation<CScalar>* transformation,
21                                                                     int elementPositionInGrid,
22                                                                     std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
23                                                                     std::map<int, int>& elementPositionInGridSrc2AxisPosition,
24                                                                     std::map<int, int>& elementPositionInGridSrc2DomainPosition,
25                                                                     std::map<int, int>& elementPositionInGridDst2ScalarPosition,
26                                                                     std::map<int, int>& elementPositionInGridDst2AxisPosition,
27                                                                     std::map<int, int>& elementPositionInGridDst2DomainPosition)
28TRY
29{
30  std::vector<CScalar*> scalarListDestP = gridDst->getScalars();
31  std::vector<CAxis*> axisListSrcP  = gridSrc->getAxis();
32
33  CExtractAxisToScalar* extractAxis = dynamic_cast<CExtractAxisToScalar*> (transformation);
34  int scalarDstIndex = elementPositionInGridDst2ScalarPosition[elementPositionInGrid];
35  int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid];
36
37  return (new CScalarAlgorithmExtractAxis(scalarListDestP[scalarDstIndex], axisListSrcP[axisSrcIndex], extractAxis));
38}
39CATCH
40
41bool CScalarAlgorithmExtractAxis::registerTrans()
42TRY
43{
44  CGridTransformationFactory<CScalar>::registerTransformation(TRANS_EXTRACT_AXIS_TO_SCALAR, create);
45}
46CATCH
47
48CScalarAlgorithmExtractAxis::CScalarAlgorithmExtractAxis(CScalar* scalarDestination, CAxis* axisSource, CExtractAxisToScalar* algo)
49 : CScalarAlgorithmTransformation(scalarDestination, axisSource),
50   reduction_(0)
51TRY
52{
53  algo->checkValid(scalarDestination, axisSource);
54  StdString op = "extract";
55  pos_ = algo->position;
56  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
57}
58CATCH
59
60void CScalarAlgorithmExtractAxis::apply(const std::vector<std::pair<int,double> >& localIndex,
61                                         const double* dataInput,
62                                         CArray<double,1>& dataOut,
63                                         std::vector<bool>& flagInitial,                     
64                                         bool ignoreMissingValue, bool firstPass)
65TRY
66{
67  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue, firstPass);
68}
69CATCH
70
71CScalarAlgorithmExtractAxis::~CScalarAlgorithmExtractAxis()
72TRY
73{
74  if (0 != reduction_) delete reduction_;
75}
76CATCH
77
78void CScalarAlgorithmExtractAxis::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
79TRY
80{
81  this->transformationMapping_.resize(1);
82  this->transformationWeight_.resize(1);
83
84  TransformationIndexMap& transMap = this->transformationMapping_[0];
85  TransformationWeightMap& transWeight = this->transformationWeight_[0];
86
87  transMap[0].push_back(pos_);
88  transWeight[0].push_back(1.0);
89}
90CATCH
91
92}
Note: See TracBrowser for help on using the repository browser.