[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 { |
---|
[2270] | 17 | shared_ptr<CGenericAlgorithmTransformation> CScalarAlgorithmReduceDomain::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
[1985] | 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 | |
---|
[2270] | 35 | return make_shared<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 | |
---|
[2291] | 76 | bool local=false ; |
---|
| 77 | if (!algo->local.isEmpty()) local=algo->local ; |
---|
[1985] | 78 | |
---|
[2291] | 79 | auto& transMap = this->transformationMapping_; |
---|
[1999] | 80 | |
---|
[1985] | 81 | if (local) |
---|
| 82 | { |
---|
[2291] | 83 | scalarDestination->n=1 ; // no mask |
---|
| 84 | scalarDestination->mask.reset() ; |
---|
| 85 | |
---|
| 86 | CArray<size_t,1> srcGlobalIndex ; |
---|
| 87 | domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(srcGlobalIndex) ; |
---|
| 88 | size_t nbIdx = srcGlobalIndex.numElements(); |
---|
| 89 | if (nbIdx==0) scalarDestination->n=0 ; |
---|
| 90 | scalarDestination->checkAttributes() ; |
---|
[1985] | 91 | |
---|
[2291] | 92 | for (size_t idx = 0; idx < nbIdx; ++idx) |
---|
| 93 | { |
---|
| 94 | size_t globalIdx = srcGlobalIndex(idx); |
---|
| 95 | transformationMapping_[0].push_back(globalIdx); |
---|
| 96 | } |
---|
| 97 | |
---|
[1985] | 98 | } |
---|
| 99 | else |
---|
[2291] | 100 | { |
---|
| 101 | scalarDestination->checkAttributes() ; |
---|
| 102 | |
---|
| 103 | int globalIndexSize = domainSource->getLocalView(CElementView::WORKFLOW)->getGlobalSize(); |
---|
| 104 | CArray<size_t,1> dstGlobalIndex ; |
---|
| 105 | scalarDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; |
---|
| 106 | if (dstGlobalIndex.numElements()!=0) |
---|
| 107 | for (int idx = 0; idx < globalIndexSize; ++idx) transformationMapping_[0].push_back(idx); |
---|
[1985] | 108 | } |
---|
[2291] | 109 | |
---|
[1999] | 110 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
[2291] | 111 | |
---|
[1985] | 112 | } |
---|
| 113 | CATCH |
---|
| 114 | |
---|
[1999] | 115 | |
---|
| 116 | |
---|
| 117 | CScalarAlgorithmReduceDomain::~CScalarAlgorithmReduceDomain() |
---|
| 118 | TRY |
---|
| 119 | { |
---|
[1985] | 120 | } |
---|
[1999] | 121 | CATCH |
---|
| 122 | |
---|
| 123 | |
---|
| 124 | } |
---|