source: XIOS/trunk/src/transformation/scalar_algorithm_reduce_axis.cpp @ 918

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

Modifying vertical interpolation

+) Only process interpolation, the extrapolation will be ignored (value will be unidentified (masked))
+) Make sure even unidenfitified from one transformation can be known in the next transformation

Test
+) On Curie
+) Vertical interpolation: Correct
+) Vertical interpolation + horizontal interpolation: Correct

File size: 2.6 KB
Line 
1/*!
2   \file scalar_algorithm_reduce_scalar.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for reduce an axis to a scalar
8 */
9#include "scalar_algorithm_reduce_axis.hpp"
10#include "axis.hpp"
11#include "scalar.hpp"
12#include "reduce_axis_to_scalar.hpp"
13#include "sum.hpp"
14
15namespace xios {
16
17CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CAxis* axisSource, CReduceAxisToScalar* algo)
18 : CScalarAlgorithmTransformation(scalarDestination, axisSource),
19   reduction_(0)
20{
21  if (algo->operation.isEmpty())
22    ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
23           << "Operation must be defined."
24           << "Axis source " <<axisSource->getId() << std::endl
25           << "Scalar destination " << scalarDestination->getId());
26  StdString op = algo->operation;
27  if (CReductionAlgorithm::ReductionOperations.end() == CReductionAlgorithm::ReductionOperations.find(op))
28    ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToScalar* algo)",
29       << "Operation '" << op << "' not found. Please make sure to use a supported one"
30       << "Axis source " <<axisSource->getId() << std::endl
31       << "Scalar destination " << scalarDestination->getId());
32
33  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
34}
35
36void CScalarAlgorithmReduceScalar::apply(const std::vector<std::pair<int,double> >& localIndex,
37                                         const double* dataInput,
38                                         CArray<double,1>& dataOut,
39                                         std::vector<bool>& flagInitial,
40                                         const double& defaultValue)
41{
42  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
43}
44
45CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar()
46{
47  if (0 != reduction_) delete reduction_;
48}
49
50void CScalarAlgorithmReduceScalar::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
51{
52  this->transformationMapping_.resize(1);
53  this->transformationWeight_.resize(1);
54
55  TransformationIndexMap& transMap = this->transformationMapping_[0];
56  TransformationWeightMap& transWeight = this->transformationWeight_[0];
57
58  CArray<int,1>& axisSrcIndex = axisSrc_->index;
59  int globalIndexSize = axisSrcIndex.numElements();
60
61  for (int idx = 0; idx < globalIndexSize; ++idx)
62  {
63    transMap[0].push_back(axisSrcIndex(idx));
64    transWeight[0].push_back(1.0);
65  }
66}
67
68}
Note: See TracBrowser for help on using the repository browser.