[1985] | 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" |
---|
| 13 | #include "grid.hpp" |
---|
| 14 | #include "grid_transformation_factory_impl.hpp" |
---|
| 15 | #include "reduction.hpp" |
---|
| 16 | |
---|
| 17 | namespace xios { |
---|
| 18 | CGenericAlgorithmTransformation* CAxisAlgorithmReduceDomain::create(bool isSource, 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 | TRY |
---|
| 28 | { |
---|
| 29 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
| 30 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
| 31 | |
---|
| 32 | CReduceDomainToAxis* reduceDomain = dynamic_cast<CReduceDomainToAxis*> (transformation); |
---|
| 33 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 34 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 35 | |
---|
[1988] | 36 | return (new CAxisAlgorithmReduceDomain(isSource, axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], reduceDomain)); |
---|
[1985] | 37 | } |
---|
| 38 | CATCH |
---|
| 39 | |
---|
| 40 | bool CAxisAlgorithmReduceDomain::dummyRegistered_ = CAxisAlgorithmReduceDomain::registerTrans(); |
---|
| 41 | bool CAxisAlgorithmReduceDomain::registerTrans() |
---|
| 42 | TRY |
---|
| 43 | { |
---|
| 44 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, create); |
---|
| 45 | } |
---|
| 46 | CATCH |
---|
| 47 | |
---|
| 48 | |
---|
[1988] | 49 | CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo) |
---|
[1999] | 50 | : CAlgorithmTransformationReduce(isSource), domainSrc_(domainSource), axisDest_(axisDestination) |
---|
[1985] | 51 | TRY |
---|
| 52 | { |
---|
| 53 | algo->checkValid(axisDestination, domainSource); |
---|
| 54 | switch (algo->operation) |
---|
| 55 | { |
---|
| 56 | case CReduceDomainToAxis::operation_attr::sum: |
---|
[1999] | 57 | operator_ = EReduction::sum; |
---|
[1985] | 58 | break; |
---|
| 59 | case CReduceDomainToAxis::operation_attr::min: |
---|
[1999] | 60 | operator_ = EReduction::min; |
---|
[1985] | 61 | break; |
---|
| 62 | case CReduceDomainToAxis::operation_attr::max: |
---|
[1999] | 63 | operator_ = EReduction::max; |
---|
[1985] | 64 | break; |
---|
| 65 | case CReduceDomainToAxis::operation_attr::average: |
---|
[1999] | 66 | operator_ = EReduction::average; |
---|
[1985] | 67 | break; |
---|
| 68 | default: |
---|
| 69 | ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", |
---|
| 70 | << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl |
---|
| 71 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 72 | << "Axis destination " << axisDestination->getId()); |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction) ? iDir : jDir; |
---|
[1999] | 77 | bool local = algo->local ; |
---|
[1985] | 78 | |
---|
[1999] | 79 | TransformationIndexMap& transMap = transformationMapping_; |
---|
[1985] | 80 | |
---|
| 81 | CArray<int,1>& axisDstIndex = axisDest_->index; |
---|
| 82 | int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo; |
---|
| 83 | if (iDir == dir_) |
---|
| 84 | { |
---|
| 85 | if (local) |
---|
| 86 | { |
---|
| 87 | const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; |
---|
| 88 | const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; |
---|
| 89 | const CArray<bool,1>& localMask = domainSrc_-> localMask ; |
---|
| 90 | int nbDomainIdx = i_index.numElements(); |
---|
| 91 | |
---|
| 92 | for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) |
---|
| 93 | { |
---|
| 94 | if (localMask(idxDomain)) |
---|
| 95 | { |
---|
| 96 | transMap[j_index(idxDomain)].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | else |
---|
| 101 | { |
---|
| 102 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
| 103 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
| 104 | { |
---|
| 105 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
| 106 | transMap[globalAxisIdx].resize(ni_glo); |
---|
| 107 | for (int idx = 0; idx < ni_glo; ++idx) |
---|
| 108 | { |
---|
| 109 | transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx; |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | else if (jDir == dir_) |
---|
| 115 | { |
---|
| 116 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
| 117 | if (local) |
---|
| 118 | { |
---|
| 119 | const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; |
---|
| 120 | const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; |
---|
| 121 | const CArray<bool,1>& localMask = domainSrc_-> localMask ; |
---|
| 122 | int nbDomainIdx = i_index.numElements(); |
---|
| 123 | |
---|
| 124 | for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) |
---|
| 125 | { |
---|
| 126 | if (localMask(idxDomain)) |
---|
| 127 | { |
---|
| 128 | transMap[i_index(idxDomain)].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | else |
---|
| 133 | { |
---|
| 134 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
| 135 | { |
---|
| 136 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
| 137 | transMap[globalAxisIdx].resize(nj_glo); |
---|
| 138 | for (int idx = 0; idx < nj_glo; ++idx) |
---|
| 139 | { |
---|
| 140 | transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | else |
---|
| 146 | {} |
---|
[1999] | 147 | |
---|
| 148 | axisDestination->checkAttributes() ; |
---|
| 149 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
| 150 | |
---|
[1985] | 151 | } |
---|
| 152 | CATCH |
---|
| 153 | |
---|
[1999] | 154 | |
---|
| 155 | CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain() |
---|
| 156 | TRY |
---|
| 157 | { |
---|
[1985] | 158 | } |
---|
[1999] | 159 | CATCH |
---|
| 160 | |
---|
| 161 | |
---|
| 162 | } |
---|