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 | |
---|
16 | namespace xios { |
---|
17 | |
---|
18 | CAxisAlgorithmExtractDomain::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 | |
---|
29 | void 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 | const double& defaultValue) |
---|
34 | { |
---|
35 | reduction_->apply(localIndex, dataInput, dataOut, flagInitial); |
---|
36 | } |
---|
37 | |
---|
38 | CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain() |
---|
39 | { |
---|
40 | if (0 != reduction_) delete reduction_; |
---|
41 | } |
---|
42 | |
---|
43 | void CAxisAlgorithmExtractDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
44 | { |
---|
45 | this->transformationMapping_.resize(1); |
---|
46 | this->transformationWeight_.resize(1); |
---|
47 | |
---|
48 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
49 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
50 | |
---|
51 | CArray<int,1>& axisDstIndex = axisDest_->index; |
---|
52 | int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo; |
---|
53 | if (jDir == dir_) |
---|
54 | { |
---|
55 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
56 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
57 | { |
---|
58 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
59 | transMap[globalAxisIdx].resize(1); |
---|
60 | transWeight[globalAxisIdx].resize(1); |
---|
61 | transMap[globalAxisIdx][0] = globalAxisIdx * ni_glo + pos_; |
---|
62 | transWeight[globalAxisIdx][0] = 1.0; |
---|
63 | |
---|
64 | } |
---|
65 | } |
---|
66 | else if (iDir == dir_) |
---|
67 | { |
---|
68 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
69 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
70 | { |
---|
71 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
72 | transMap[globalAxisIdx].resize(1); |
---|
73 | transWeight[globalAxisIdx].resize(1); |
---|
74 | transMap[globalAxisIdx][0] = globalAxisIdx + ni_glo * pos_; |
---|
75 | transWeight[globalAxisIdx][0] = 1.0; |
---|
76 | } |
---|
77 | } |
---|
78 | else |
---|
79 | {} |
---|
80 | } |
---|
81 | |
---|
82 | } |
---|