[1985] | 1 | /*! |
---|
| 2 | \file axis_algorithm_reduce_axis.cpp |
---|
| 3 | \author Ha NGUYEN |
---|
| 4 | \since 23 June 2016 |
---|
| 5 | \date 23 June 2016 |
---|
| 6 | |
---|
| 7 | \brief Algorithm for reduce a axis to an axis |
---|
| 8 | */ |
---|
| 9 | #include "axis_algorithm_reduce_axis.hpp" |
---|
| 10 | #include "reduce_axis_to_axis.hpp" |
---|
| 11 | #include "axis.hpp" |
---|
| 12 | #include "grid.hpp" |
---|
| 13 | #include "grid_transformation_factory_impl.hpp" |
---|
[2291] | 14 | #include "grid_algorithm_reduce.hpp" |
---|
[1985] | 15 | |
---|
[1999] | 16 | |
---|
[1985] | 17 | namespace xios { |
---|
[2270] | 18 | shared_ptr<CGenericAlgorithmTransformation> CAxisAlgorithmReduceAxis::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
[1985] | 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<CAxis*> axisListSrcP = gridSrc->getAxis(); |
---|
| 31 | |
---|
| 32 | CReduceAxisToAxis* reduceAxis = dynamic_cast<CReduceAxisToAxis*> (transformation); |
---|
| 33 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
| 34 | int axisSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; |
---|
| 35 | |
---|
[2270] | 36 | return make_shared<CAxisAlgorithmReduceAxis>(isSource, axisListDestP[axisDstIndex], axisListSrcP[axisSrcIndex], reduceAxis); |
---|
[1985] | 37 | } |
---|
| 38 | CATCH |
---|
| 39 | |
---|
| 40 | bool CAxisAlgorithmReduceAxis::dummyRegistered_ = CAxisAlgorithmReduceAxis::registerTrans(); |
---|
| 41 | bool CAxisAlgorithmReduceAxis::registerTrans() |
---|
| 42 | TRY |
---|
| 43 | { |
---|
| 44 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_AXIS_TO_AXIS, create); |
---|
| 45 | } |
---|
| 46 | CATCH |
---|
| 47 | |
---|
| 48 | |
---|
[1988] | 49 | CAxisAlgorithmReduceAxis::CAxisAlgorithmReduceAxis(bool isSource, CAxis* axisDestination, CAxis* axisSource, CReduceAxisToAxis* algo) |
---|
[1999] | 50 | : CAlgorithmTransformationReduce(isSource) |
---|
[1985] | 51 | TRY |
---|
| 52 | { |
---|
[2291] | 53 | if (!axisDestination->checkGeometricAttributes(false)) |
---|
| 54 | { |
---|
| 55 | axisDestination->resetGeometricAttributes(); |
---|
| 56 | axisDestination->setGeometricAttributes(*axisSource) ; |
---|
| 57 | } |
---|
| 58 | axisDestination->checkAttributes() ; |
---|
[1985] | 59 | algo->checkValid(axisDestination, axisSource); |
---|
[2291] | 60 | |
---|
[1999] | 61 | |
---|
[1985] | 62 | switch (algo->operation) |
---|
| 63 | { |
---|
| 64 | case CReduceAxisToAxis::operation_attr::sum: |
---|
[1999] | 65 | operator_ = EReduction::sum; |
---|
[1985] | 66 | break; |
---|
| 67 | case CReduceAxisToAxis::operation_attr::min: |
---|
[1999] | 68 | operator_ = EReduction::min; |
---|
[1985] | 69 | break; |
---|
| 70 | case CReduceAxisToAxis::operation_attr::max: |
---|
[1999] | 71 | operator_ = EReduction::max; |
---|
[1985] | 72 | break; |
---|
| 73 | case CReduceAxisToAxis::operation_attr::average: |
---|
[1999] | 74 | operator_ = EReduction::average; |
---|
[1985] | 75 | break; |
---|
| 76 | default: |
---|
| 77 | ERROR("CAxisAlgorithmReduceAxis::CAxisAlgorithmReduceAxis(CAxis* axisDestination, CAxis* axisSource, CReduceAxisToAxis* algo)", |
---|
| 78 | << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl |
---|
| 79 | << "Axis source " <<axisSource->getId() << std::endl |
---|
| 80 | << "Axis destination " << axisDestination->getId()); |
---|
[2136] | 81 | } |
---|
[1985] | 82 | |
---|
[2291] | 83 | //TransformationIndexMap& transMap = this->transformationMapping_; |
---|
| 84 | //CArray<int,1>& axisDstIndex = axisDestination->index; |
---|
| 85 | //int nbAxisIdx = axisDstIndex.numElements(); |
---|
| 86 | |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | auto& transMap = this->transformationMapping_; |
---|
| 90 | |
---|
| 91 | CArray<size_t,1> dstGlobalIndex ; |
---|
| 92 | axisDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; |
---|
| 93 | size_t nbIdx = dstGlobalIndex.numElements(); |
---|
| 94 | |
---|
| 95 | for (size_t idx = 0; idx < nbIdx; ++idx) |
---|
[2136] | 96 | { |
---|
[2291] | 97 | size_t globalIdx = dstGlobalIndex(idx); |
---|
| 98 | transMap[globalIdx].resize(1); |
---|
| 99 | transMap[globalIdx][0]=globalIdx ; |
---|
[2136] | 100 | } |
---|
[1999] | 101 | |
---|
| 102 | this->computeAlgorithm(axisSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
[1985] | 103 | } |
---|
| 104 | CATCH |
---|
| 105 | |
---|
[2291] | 106 | shared_ptr<CGridAlgorithm> CAxisAlgorithmReduceAxis::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) |
---|
| 107 | { |
---|
| 108 | auto algo=make_shared<CGridAlgorithmReduce>(gridSrc, gridDst, pos, shared_from_this(), operator_) ; |
---|
| 109 | algo->computeAlgorithm(false) ; |
---|
| 110 | return algo ; |
---|
| 111 | } |
---|
[1985] | 112 | |
---|
| 113 | CAxisAlgorithmReduceAxis::~CAxisAlgorithmReduceAxis() |
---|
| 114 | TRY |
---|
| 115 | { |
---|
[1999] | 116 | |
---|
[1985] | 117 | } |
---|
| 118 | CATCH |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | } |
---|