source: XIOS/trunk/src/transformation/axis_algorithm_extract_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.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 extract a domain to an axis
8 */
9#include "axis_algorithm_extract_domain.hpp"
10#include "extract_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* CAxisAlgorithmExtractDomain::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  CExtractDomainToAxis* extractDomain = dynamic_cast<CExtractDomainToAxis*> (transformation);
32  int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid];
33  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
34
35  return (new CAxisAlgorithmExtractDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], extractDomain));
36}
37
38//bool CAxisAlgorithmExtractDomain::_dummyRegistered = CAxisAlgorithmExtractDomain::registerTrans();
39bool CAxisAlgorithmExtractDomain::registerTrans()
40{
41  CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create);
42}
43
44
45CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo)
46 : CAxisAlgorithmTransformation(axisDestination, domainSource), pos_(-1), reduction_(0)
47{
48  algo->checkValid(axisDestination, domainSource);
49  StdString op = "extract";
50  StdString direction = algo->direction;
51  dir_ = (0 == direction.compare("i")) ? iDir : jDir;
52  pos_ = algo->position;
53  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
54}
55
56void CAxisAlgorithmExtractDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
57                                        const double* dataInput,
58                                        CArray<double,1>& dataOut,
59                                        std::vector<bool>& flagInitial,
60                                        const double& defaultValue)
61{
62  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
63}
64
65CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain()
66{
67  if (0 != reduction_) delete reduction_;
68}
69
70void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
71{
72  this->transformationMapping_.resize(1);
73  this->transformationWeight_.resize(1);
74
75  TransformationIndexMap& transMap = this->transformationMapping_[0];
76  TransformationWeightMap& transWeight = this->transformationWeight_[0];
77
78  CArray<int,1>& axisDstIndex = axisDest_->index;
79  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
80  if (jDir == dir_)
81  {
82    int nbAxisIdx = axisDstIndex.numElements();
83    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
84    {
85      int globalAxisIdx = axisDstIndex(idxAxis);
86      transMap[globalAxisIdx].resize(1);
87      transWeight[globalAxisIdx].resize(1);
88      transMap[globalAxisIdx][0] = globalAxisIdx * ni_glo + pos_;
89      transWeight[globalAxisIdx][0] = 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(1);
100      transWeight[globalAxisIdx].resize(1);
101      transMap[globalAxisIdx][0] = globalAxisIdx + ni_glo * pos_;
102      transWeight[globalAxisIdx][0] = 1.0;
103    }
104  }
105  else
106  {}
107}
108
109}
Note: See TracBrowser for help on using the repository browser.