[895] | 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 | { |
---|
| 34 | reduction_->apply(localIndex, dataInput, dataOut, flagInitial); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain() |
---|
| 38 | { |
---|
| 39 | if (0 != reduction_) delete reduction_; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | void 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 | } |
---|