[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 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" |
---|
[933] | 13 | #include "grid.hpp" |
---|
| 14 | #include "grid_transformation_factory_impl.hpp" |
---|
[977] | 15 | #include "reduction.hpp" |
---|
[895] | 16 | |
---|
| 17 | namespace xios { |
---|
[933] | 18 | CGenericAlgorithmTransformation* CAxisAlgorithmReduceDomain::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(); |
---|
[895] | 30 | |
---|
[933] | 31 | CReduceDomainToAxis* reduceDomain = dynamic_cast<CReduceDomainToAxis*> (transformation); |
---|
| 32 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 33 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 34 | |
---|
| 35 | return (new CAxisAlgorithmReduceDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], reduceDomain)); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | bool CAxisAlgorithmReduceDomain::registerTrans() |
---|
| 39 | { |
---|
| 40 | CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, create); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
[895] | 44 | CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo) |
---|
| 45 | : CAxisAlgorithmTransformation(axisDestination, domainSource), reduction_(0) |
---|
| 46 | { |
---|
| 47 | algo->checkValid(axisDestination, domainSource); |
---|
[980] | 48 | StdString op; |
---|
| 49 | switch (algo->operation) |
---|
| 50 | { |
---|
| 51 | case CReduceDomainToAxis::operation_attr::sum: |
---|
| 52 | op = "sum"; |
---|
| 53 | break; |
---|
| 54 | case CReduceDomainToAxis::operation_attr::min: |
---|
| 55 | op = "min"; |
---|
| 56 | break; |
---|
| 57 | case CReduceDomainToAxis::operation_attr::max: |
---|
| 58 | op = "max"; |
---|
| 59 | break; |
---|
| 60 | case CReduceDomainToAxis::operation_attr::average: |
---|
| 61 | op = "average"; |
---|
| 62 | break; |
---|
| 63 | default: |
---|
| 64 | ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", |
---|
| 65 | << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl |
---|
| 66 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 67 | << "Axis destination " << axisDestination->getId()); |
---|
| 68 | |
---|
| 69 | } |
---|
| 70 | |
---|
[938] | 71 | dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction) ? iDir : jDir; |
---|
[895] | 72 | reduction_ = CReductionAlgorithm::createOperation(CReductionAlgorithm::ReductionOperations[op]); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
[918] | 76 | const double* dataInput, |
---|
| 77 | CArray<double,1>& dataOut, |
---|
[1076] | 78 | std::vector<bool>& flagInitial, |
---|
| 79 | bool ignoreMissingValue) |
---|
[895] | 80 | { |
---|
[1076] | 81 | reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue); |
---|
[895] | 82 | } |
---|
| 83 | |
---|
[979] | 84 | void CAxisAlgorithmReduceDomain::updateData(CArray<double,1>& dataOut) |
---|
| 85 | { |
---|
| 86 | reduction_->updateData(dataOut); |
---|
| 87 | } |
---|
| 88 | |
---|
[895] | 89 | CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain() |
---|
| 90 | { |
---|
| 91 | if (0 != reduction_) delete reduction_; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void CAxisAlgorithmReduceDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
| 95 | { |
---|
| 96 | this->transformationMapping_.resize(1); |
---|
| 97 | this->transformationWeight_.resize(1); |
---|
| 98 | |
---|
| 99 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
| 100 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
| 101 | |
---|
| 102 | CArray<int,1>& axisDstIndex = axisDest_->index; |
---|
| 103 | int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo; |
---|
| 104 | if (jDir == dir_) |
---|
| 105 | { |
---|
| 106 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
| 107 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
| 108 | { |
---|
| 109 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
| 110 | transMap[globalAxisIdx].resize(ni_glo); |
---|
| 111 | transWeight[globalAxisIdx].resize(ni_glo); |
---|
| 112 | for (int idx = 0; idx < ni_glo; ++idx) |
---|
| 113 | { |
---|
| 114 | transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx; |
---|
| 115 | transWeight[globalAxisIdx][idx] = 1.0; |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | else if (iDir == dir_) |
---|
| 120 | { |
---|
| 121 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
| 122 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
| 123 | { |
---|
| 124 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
| 125 | transMap[globalAxisIdx].resize(nj_glo); |
---|
| 126 | transWeight[globalAxisIdx].resize(nj_glo); |
---|
| 127 | for (int idx = 0; idx < nj_glo; ++idx) |
---|
| 128 | { |
---|
| 129 | transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx; |
---|
| 130 | transWeight[globalAxisIdx][idx] = 1.0; |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | else |
---|
| 135 | {} |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | } |
---|