source: XIOS/trunk/src/transformation/axis_algorithm_extract_domain.cpp @ 895

Last change on this file since 895 was 895, checked in by mhnguyen, 8 years ago

Adding a new transformation: Reduce a domain to an axis

Test
+) On Curie
+) Tests pass and are correct

File size: 2.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
14#include "sum.hpp"
15
16namespace xios {
17
18CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo)
19 : CAxisAlgorithmTransformation(axisDestination, domainSource), pos_(-1), reduction_(0)
20{
21  algo->checkValid(axisDestination, domainSource);
22  StdString op = "extract";
23  StdString direction = algo->direction;
24  dir_ = (0 == direction.compare("i")) ? iDir : jDir;
25  pos_ = algo->position;
26  reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]);
27}
28
29void CAxisAlgorithmExtractDomain::apply(const std::vector<std::pair<int,double> >& localIndex,
30                                        const double* dataInput,
31                                        CArray<double,1>& dataOut,
32                                        std::vector<bool>& flagInitial)
33{
34  reduction_->apply(localIndex, dataInput, dataOut, flagInitial);
35}
36
37CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain()
38{
39  if (0 != reduction_) delete reduction_;
40}
41
42void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
43{
44  this->transformationMapping_.resize(1);
45  this->transformationWeight_.resize(1);
46
47  TransformationIndexMap& transMap = this->transformationMapping_[0];
48  TransformationWeightMap& transWeight = this->transformationWeight_[0];
49
50  CArray<int,1>& axisDstIndex = axisDest_->index;
51  int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo;
52  if (jDir == dir_)
53  {
54    int nbAxisIdx = axisDstIndex.numElements();
55    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
56    {
57      int globalAxisIdx = axisDstIndex(idxAxis);
58      transMap[globalAxisIdx].resize(1);
59      transWeight[globalAxisIdx].resize(1);
60      transMap[globalAxisIdx][0] = globalAxisIdx * ni_glo + pos_;
61      transWeight[globalAxisIdx][0] = 1.0;
62
63    }
64  }
65  else if (iDir == dir_)
66  {
67    int nbAxisIdx = axisDstIndex.numElements();
68    for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis)
69    {
70      int globalAxisIdx = axisDstIndex(idxAxis);
71      transMap[globalAxisIdx].resize(1);
72      transWeight[globalAxisIdx].resize(1);
73      transMap[globalAxisIdx][0] = globalAxisIdx + ni_glo * pos_;
74      transWeight[globalAxisIdx][0] = 1.0;
75    }
76  }
77  else
78  {}
79}
80
81}
Note: See TracBrowser for help on using the repository browser.