source: XIOS/dev/dev_olga/src/transformation/axis_algorithm_reduce_domain.cpp @ 1204

Last change on this file since 1204 was 1204, checked in by mhnguyen, 3 years ago

Correcting a minor bug of domain reduction

Test
+) No test

  • Property svn:executable set to *
File size: 5.3 KB
RevLine 
[895]1/*!
2   \file axis_algorithm_reduce_domain.cpp
3   \author Ha NGUYEN
4   \since 23 June 2016
5   \date 23 June 2016
6
7   \brief Algorithm for reduce a domain to an axis
8 */
9#include "axis_algorithm_reduce_domain.hpp"
10#include "reduce_domain_to_axis.hpp"
11#include "axis.hpp"
12#include "domain.hpp"
[933]13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
[977]15#include "reduction.hpp"
[895]16
17namespace xios {
[933]18CGenericAlgorithmTransformation* CAxisAlgorithmReduceDomain::create(CGrid* gridDst, CGrid* gridSrc,
19                                                                   CTransformation<CAxis>* transformation,
20                                                                   int elementPositionInGrid,
21                                                                   std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
22                                                                   std::map<int, int>& elementPositionInGridSrc2AxisPosition,
23                                                                   std::map<int, int>& elementPositionInGridSrc2DomainPosition,
24                                                                   std::map<int, int>& elementPositionInGridDst2ScalarPosition,
25                                                                   std::map<int, int>& elementPositionInGridDst2AxisPosition,
26                                                                   std::map<int, int>& elementPositionInGridDst2DomainPosition)
27{
28  std::vector<CAxis*> axisListDestP = gridDst->getAxis();
29  std::vector<CDomain*> domainListSrcP = gridSrc->getDomains();
[895]30
[933]31  CReduceDomainToAxis* reduceDomain = dynamic_cast<CReduceDomainToAxis*> (transformation);
32  int axisDstIndex   = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
33  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
34
35  return (new CAxisAlgorithmReduceDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], reduceDomain));
36}
37
38bool CAxisAlgorithmReduceDomain::registerTrans()
39{
40  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, create);
41}
42
43
[895]44CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)
45 : CAxisAlgorithmTransformation(axisDestination, domainSource), reduction_(0)
46{
47  algo->checkValid(axisDestination, domainSource);
[980]48  StdString op;
49  switch (algo->operation)
50  {
51    case CReduceDomainToAxis::operation_attr::sum:
52      op = "sum";
53      break;
54    case CReduceDomainToAxis::operation_attr::min:
55      op = "min";
56      break;
57    case CReduceDomainToAxis::operation_attr::max:
58      op = "max";
59      break;
60    case CReduceDomainToAxis::operation_attr::average:
61      op = "average";
62      break;
63    default:
64        ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)",
65         << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl
66         << "Domain source " <<domainSource->getId() << std::endl
67         << "Axis destination " << axisDestination->getId());
68
69  }
70
[938]71  dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction)  ? iDir : jDir;
[895]72  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
73}
74
75void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
[918]76                                       const double* dataInput,
77                                       CArray<double,1>& dataOut,
[1158]78                                       std::vector<bool>& flagInitial,                     
79                                       bool ignoreMissingValue)
[895]80{
[1158]81  reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue);
[895]82}
83
[979]84void CAxisAlgorithmReduceDomain::updateData(CArray<double,1>& dataOut)
85{
86  reduction_->updateData(dataOut);
87}
88
[895]89CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain()
90{
91  if (0 != reduction_) delete reduction_;
92}
93
94void CAxisAlgorithmReduceDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
95{
96  this->transformationMapping_.resize(1);
97  this->transformationWeight_.resize(1);
98
99  TransformationIndexMap& transMap = this->transformationMapping_[0];
100  TransformationWeightMap& transWeight = this->transformationWeight_[0];
101
102  CArray<int,1>& axisDstIndex = axisDest_->index;
103  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
[1204]104  if (iDir == dir_)
[895]105  {
106    int nbAxisIdx = axisDstIndex.numElements();
107    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
108    {
109      int globalAxisIdx = axisDstIndex(idxAxis);
110      transMap[globalAxisIdx].resize(ni_glo);
111      transWeight[globalAxisIdx].resize(ni_glo);
112      for (int idx = 0; idx < ni_glo; ++idx)
113      {
114        transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx;
115        transWeight[globalAxisIdx][idx] = 1.0;
116      }
117    }
118  }
[1204]119  else if (jDir == dir_)
[895]120  {
121    int nbAxisIdx = axisDstIndex.numElements();
122    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
123    {
124      int globalAxisIdx = axisDstIndex(idxAxis);
125      transMap[globalAxisIdx].resize(nj_glo);
126      transWeight[globalAxisIdx].resize(nj_glo);
127      for (int idx = 0; idx < nj_glo; ++idx)
128      {
129        transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx;
130        transWeight[globalAxisIdx][idx] = 1.0;
131      }
132    }
133  }
134  else
135  {}
136}
137
138}
Note: See TracBrowser for help on using the repository browser.