source: XIOS/trunk/src/transformation/axis_algorithm_reduce_domain.cpp @ 979

Last change on this file since 979 was 979, checked in by mhnguyen, 5 years ago

Implementing AVERAGE operation

+) Add average operation for reduction transformation

Test
+) On Curie
+) Correct

  • Property svn:executable set to *
File size: 4.6 KB
Line 
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"
13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
15#include "reduction.hpp"
16
17namespace xios {
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();
30
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
44CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)
45 : CAxisAlgorithmTransformation(axisDestination, domainSource), reduction_(0)
46{
47  algo->checkValid(axisDestination, domainSource);
48  StdString op = algo->operation;
49  dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction)  ? iDir : jDir;
50  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
51}
52
53void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
54                                       const double* dataInput,
55                                       CArray<double,1>& dataOut,
56                                       std::vector<bool>& flagInitial,
57                                       const double& defaultValue)
58{
59  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
60}
61
62void CAxisAlgorithmReduceDomain::updateData(CArray<double,1>& dataOut)
63{
64  reduction_->updateData(dataOut);
65}
66
67CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain()
68{
69  if (0 != reduction_) delete reduction_;
70}
71
72void CAxisAlgorithmReduceDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
73{
74  this->transformationMapping_.resize(1);
75  this->transformationWeight_.resize(1);
76
77  TransformationIndexMap& transMap = this->transformationMapping_[0];
78  TransformationWeightMap& transWeight = this->transformationWeight_[0];
79
80  CArray<int,1>& axisDstIndex = axisDest_->index;
81  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
82  if (jDir == dir_)
83  {
84    int nbAxisIdx = axisDstIndex.numElements();
85    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
86    {
87      int globalAxisIdx = axisDstIndex(idxAxis);
88      transMap[globalAxisIdx].resize(ni_glo);
89      transWeight[globalAxisIdx].resize(ni_glo);
90      for (int idx = 0; idx < ni_glo; ++idx)
91      {
92        transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx;
93        transWeight[globalAxisIdx][idx] = 1.0;
94      }
95    }
96  }
97  else if (iDir == dir_)
98  {
99    int nbAxisIdx = axisDstIndex.numElements();
100    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
101    {
102      int globalAxisIdx = axisDstIndex(idxAxis);
103      transMap[globalAxisIdx].resize(nj_glo);
104      transWeight[globalAxisIdx].resize(nj_glo);
105      for (int idx = 0; idx < nj_glo; ++idx)
106      {
107        transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx;
108        transWeight[globalAxisIdx][idx] = 1.0;
109      }
110    }
111  }
112  else
113  {}
114}
115
116}
Note: See TracBrowser for help on using the repository browser.