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

Last change on this file since 933 was 933, checked in by mhnguyen, 6 years ago

Improving transformation selection. Instead of modifying directly grid_transformation
we only need to register a new transformation with the framework

+) Update all transformations with this new method

Test
+) On Curie
+) Basic tests pass

File size: 4.5 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
16#include "sum.hpp"
17
18namespace xios {
19CGenericAlgorithmTransformation* CAxisAlgorithmReduceDomain::create(CGrid* gridDst, CGrid* gridSrc,
20                                                                   CTransformation<CAxis>* 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<CAxis*> axisListDestP = gridDst->getAxis();
30  std::vector<CDomain*> domainListSrcP = gridSrc->getDomains();
31
32  CReduceDomainToAxis* reduceDomain = dynamic_cast<CReduceDomainToAxis*> (transformation);
33  int axisDstIndex   = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
34  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
35
36  return (new CAxisAlgorithmReduceDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], reduceDomain));
37}
38
39bool CAxisAlgorithmReduceDomain::registerTrans()
40{
41  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, create);
42}
43
44
45CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)
46 : CAxisAlgorithmTransformation(axisDestination, domainSource), reduction_(0)
47{
48  algo->checkValid(axisDestination, domainSource);
49  StdString op = algo->operation;
50  StdString direction = algo->direction;
51  dir_ = (0 == direction.compare("i")) ? iDir : jDir;
52  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
53}
54
55void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
56                                       const double* dataInput,
57                                       CArray<double,1>& dataOut,
58                                       std::vector<bool>& flagInitial,
59                                       const double& defaultValue)
60{
61  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
62}
63
64CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain()
65{
66  if (0 != reduction_) delete reduction_;
67}
68
69void CAxisAlgorithmReduceDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
70{
71  this->transformationMapping_.resize(1);
72  this->transformationWeight_.resize(1);
73
74  TransformationIndexMap& transMap = this->transformationMapping_[0];
75  TransformationWeightMap& transWeight = this->transformationWeight_[0];
76
77  CArray<int,1>& axisDstIndex = axisDest_->index;
78  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
79  if (jDir == dir_)
80  {
81    int nbAxisIdx = axisDstIndex.numElements();
82    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
83    {
84      int globalAxisIdx = axisDstIndex(idxAxis);
85      transMap[globalAxisIdx].resize(ni_glo);
86      transWeight[globalAxisIdx].resize(ni_glo);
87      for (int idx = 0; idx < ni_glo; ++idx)
88      {
89        transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx;
90        transWeight[globalAxisIdx][idx] = 1.0;
91      }
92    }
93  }
94  else if (iDir == dir_)
95  {
96    int nbAxisIdx = axisDstIndex.numElements();
97    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
98    {
99      int globalAxisIdx = axisDstIndex(idxAxis);
100      transMap[globalAxisIdx].resize(nj_glo);
101      transWeight[globalAxisIdx].resize(nj_glo);
102      for (int idx = 0; idx < nj_glo; ++idx)
103      {
104        transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx;
105        transWeight[globalAxisIdx][idx] = 1.0;
106      }
107    }
108  }
109  else
110  {}
111}
112
113}
Note: See TracBrowser for help on using the repository browser.