[1985] | 1 | /*! |
---|
| 2 | \file scalar_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 a scalar |
---|
| 8 | */ |
---|
| 9 | #include "scalar_algorithm_reduce_domain.hpp" |
---|
| 10 | #include "domain.hpp" |
---|
| 11 | #include "scalar.hpp" |
---|
| 12 | #include "reduce_domain_to_scalar.hpp" |
---|
| 13 | #include "grid.hpp" |
---|
| 14 | #include "grid_transformation_factory_impl.hpp" |
---|
| 15 | |
---|
| 16 | namespace xios { |
---|
| 17 | CGenericAlgorithmTransformation* CScalarAlgorithmReduceDomain::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
| 18 | CTransformation<CScalar>* transformation, |
---|
| 19 | int elementPositionInGrid, |
---|
| 20 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
| 21 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
| 22 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
| 23 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
| 24 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
| 25 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
| 26 | TRY |
---|
| 27 | { |
---|
| 28 | std::vector<CScalar*> scalarListDestP = gridDst->getScalars(); |
---|
| 29 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
| 30 | |
---|
| 31 | CReduceDomainToScalar* reduceDomain = dynamic_cast<CReduceDomainToScalar*> (transformation); |
---|
| 32 | int scalarDstIndex = elementPositionInGridDst2ScalarPosition[elementPositionInGrid]; |
---|
| 33 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
| 34 | |
---|
[1988] | 35 | return (new CScalarAlgorithmReduceDomain(isSource, scalarListDestP[scalarDstIndex], domainListSrcP[domainSrcIndex], reduceDomain)); |
---|
[1985] | 36 | } |
---|
| 37 | CATCH |
---|
| 38 | |
---|
| 39 | bool CScalarAlgorithmReduceDomain::dummyRegistered_ = CScalarAlgorithmReduceDomain::registerTrans(); |
---|
| 40 | bool CScalarAlgorithmReduceDomain::registerTrans() |
---|
| 41 | TRY |
---|
| 42 | { |
---|
| 43 | return CGridTransformationFactory<CScalar>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_SCALAR, create); |
---|
| 44 | } |
---|
| 45 | CATCH |
---|
| 46 | |
---|
[1988] | 47 | CScalarAlgorithmReduceDomain::CScalarAlgorithmReduceDomain(bool isSource, CScalar* scalarDestination, CDomain* domainSource, CReduceDomainToScalar* algo) |
---|
[1999] | 48 | : CAlgorithmTransformationReduce(isSource), domainSrc_(domainSource) |
---|
[1985] | 49 | TRY |
---|
| 50 | { |
---|
| 51 | algo->checkValid(scalarDestination, domainSource); |
---|
| 52 | |
---|
| 53 | StdString op; |
---|
| 54 | switch (algo->operation) |
---|
| 55 | { |
---|
| 56 | case CReduceDomainToScalar::operation_attr::sum: |
---|
[1999] | 57 | operator_ = EReduction::sum; |
---|
[1985] | 58 | break; |
---|
| 59 | case CReduceDomainToScalar::operation_attr::min: |
---|
[1999] | 60 | operator_ = EReduction::min; |
---|
[1985] | 61 | break; |
---|
| 62 | case CReduceDomainToScalar::operation_attr::max: |
---|
[1999] | 63 | operator_ = EReduction::max; |
---|
[1985] | 64 | break; |
---|
| 65 | case CReduceDomainToScalar::operation_attr::average: |
---|
[1999] | 66 | operator_ = EReduction::average; |
---|
[1985] | 67 | break; |
---|
| 68 | default: |
---|
| 69 | ERROR("CScalarAlgorithmReduceDomain::CScalarAlgorithmReduceDomain(CDomain* domainDestination, CDomain* domainSource, CReduceDomainToScalar* algo)", |
---|
| 70 | << "Operation must be defined." |
---|
| 71 | << "Domain source " <<domainSource->getId() << std::endl |
---|
| 72 | << "Scalar destination " << scalarDestination->getId()); |
---|
| 73 | |
---|
| 74 | } |
---|
| 75 | |
---|
[1999] | 76 | TransformationIndexMap& transMap = this->transformationMapping_; |
---|
[1985] | 77 | |
---|
| 78 | int ni_glo = domainSrc_->ni_glo ; |
---|
| 79 | int nj_glo = domainSrc_->nj_glo ; |
---|
| 80 | int nbDomainIdx ; |
---|
| 81 | |
---|
[1999] | 82 | bool local = algo->local ; |
---|
| 83 | |
---|
[1985] | 84 | if (local) |
---|
| 85 | { |
---|
| 86 | const CArray<int, 1>& i_index = domainSrc_-> i_index.getValue() ; |
---|
| 87 | const CArray<int, 1>& j_index = domainSrc_-> j_index.getValue() ; |
---|
| 88 | const CArray<bool,1>& localMask = domainSrc_-> localMask ; |
---|
| 89 | int nbDomainIdx = i_index.numElements(); |
---|
| 90 | |
---|
| 91 | for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) |
---|
| 92 | { |
---|
| 93 | if (localMask(idxDomain)) |
---|
| 94 | { |
---|
| 95 | transMap[0].push_back(j_index(idxDomain)* ni_glo + i_index(idxDomain)); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | nbDomainIdx = ni_glo * nj_glo; |
---|
[1999] | 102 | for (int idxDomain = 0; idxDomain < nbDomainIdx; ++idxDomain) transMap[0].push_back(idxDomain); |
---|
[1985] | 103 | } |
---|
| 104 | |
---|
[1999] | 105 | scalarDestination->checkAttributes() ; |
---|
| 106 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
[1985] | 107 | } |
---|
| 108 | CATCH |
---|
| 109 | |
---|
[1999] | 110 | |
---|
| 111 | |
---|
| 112 | CScalarAlgorithmReduceDomain::~CScalarAlgorithmReduceDomain() |
---|
| 113 | TRY |
---|
| 114 | { |
---|
[1985] | 115 | } |
---|
[1999] | 116 | CATCH |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | } |
---|