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

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

Minor improvements: Removing some redundant codes

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 "reduction.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  dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction)  ? iDir : jDir;
51  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
52}
53
54void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
55                                       const double* dataInput,
56                                       CArray<double,1>& dataOut,
57                                       std::vector<bool>& flagInitial,
58                                       const double& defaultValue)
59{
60  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
61}
62
63CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain()
64{
65  if (0 != reduction_) delete reduction_;
66}
67
68void CAxisAlgorithmReduceDomain::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  CArray<int,1>& axisDstIndex = axisDest_->index;
77  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
78  if (jDir == dir_)
79  {
80    int nbAxisIdx = axisDstIndex.numElements();
81    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
82    {
83      int globalAxisIdx = axisDstIndex(idxAxis);
84      transMap[globalAxisIdx].resize(ni_glo);
85      transWeight[globalAxisIdx].resize(ni_glo);
86      for (int idx = 0; idx < ni_glo; ++idx)
87      {
88        transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx;
89        transWeight[globalAxisIdx][idx] = 1.0;
90      }
91    }
92  }
93  else if (iDir == dir_)
94  {
95    int nbAxisIdx = axisDstIndex.numElements();
96    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
97    {
98      int globalAxisIdx = axisDstIndex(idxAxis);
99      transMap[globalAxisIdx].resize(nj_glo);
100      transWeight[globalAxisIdx].resize(nj_glo);
101      for (int idx = 0; idx < nj_glo; ++idx)
102      {
103        transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx;
104        transWeight[globalAxisIdx][idx] = 1.0;
105      }
106    }
107  }
108  else
109  {}
110}
111
112}
Note: See TracBrowser for help on using the repository browser.