source: XIOS/dev/XIOS_DEV_CMIP6/src/transformation/scalar_algorithm_extract_axis.cpp @ 1260

Last change on this file since 1260 was 1260, checked in by ymipsl, 3 years ago

Buf fix in reduction. Missing value update was not set correctly

YM

File size: 3.5 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)
28{
29  std::vector<CScalar*> scalarListDestP = gridDst->getScalars();
30  std::vector<CAxis*> axisListSrcP  = gridSrc->getAxis();
31
32  CExtractAxisToScalar* extractAxis = dynamic_cast<CExtractAxisToScalar*> (transformation);
33  int scalarDstIndex = elementPositionInGridDst2ScalarPosition[elementPositionInGrid];
34  int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid];
35
36  return (new CScalarAlgorithmExtractAxis(scalarListDestP[scalarDstIndex], axisListSrcP[axisSrcIndex], extractAxis));
37}
38
39bool CScalarAlgorithmExtractAxis::registerTrans()
40{
41  CGridTransformationFactory<CScalar>::registerTransformation(TRANS_EXTRACT_AXIS_TO_SCALAR, create);
42}
43
44CScalarAlgorithmExtractAxis::CScalarAlgorithmExtractAxis(CScalar* scalarDestination, CAxis* axisSource, CExtractAxisToScalar* algo)
45 : CScalarAlgorithmTransformation(scalarDestination, axisSource),
46   reduction_(0)
47{
48  algo->checkValid(scalarDestination, axisSource);
49  StdString op = "extract";
50  pos_ = algo->position;
51  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
52}
53
54void CScalarAlgorithmExtractAxis::apply(const std::vector<std::pair<int,double> >& localIndex,
55                                         const double* dataInput,
56                                         CArray<double,1>& dataOut,
57                                         std::vector<bool>& flagInitial,                     
58                                         bool ignoreMissingValue, bool firstPass)
59{
60  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue, firstPass);
61}
62
63CScalarAlgorithmExtractAxis::~CScalarAlgorithmExtractAxis()
64{
65  if (0 != reduction_) delete reduction_;
66}
67
68void CScalarAlgorithmExtractAxis::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
69{
70  this->transformationMapping_.resize(1);
71  this->transformationWeight_.resize(1);
72
73  TransformationIndexMap& transMap = this->transformationMapping_[0];
74  TransformationWeightMap& transWeight = this->transformationWeight_[0];
75
76  transMap[0].push_back(pos_);
77  transWeight[0].push_back(1.0);
78}
79
80}
Note: See TracBrowser for help on using the repository browser.