/*! \file scalar_algorithm_reduce_scalar.cpp \brief Algorithm for reduce an scalar to a scalar */ #include "scalar_algorithm_reduce_scalar.hpp" #include "scalar.hpp" #include "reduce_scalar_to_scalar.hpp" #include "grid.hpp" #include "grid_transformation_factory_impl.hpp" #include "reduction.hpp" #include "grid_algorithm_reduce.hpp" namespace xios { shared_ptr CScalarAlgorithmReduceScalar::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, CTransformation* transformation, int elementPositionInGrid, std::map& elementPositionInGridSrc2ScalarPosition, std::map& elementPositionInGridSrc2AxisPosition, std::map& elementPositionInGridSrc2DomainPosition, std::map& elementPositionInGridDst2ScalarPosition, std::map& elementPositionInGridDst2AxisPosition, std::map& elementPositionInGridDst2DomainPosition) TRY { std::vector scalarListDestP = gridDst->getScalars(); std::vector scalarListSrcP = gridSrc->getScalars(); CReduceScalarToScalar* reduceScalar = dynamic_cast (transformation); int scalarDstIndex = elementPositionInGridDst2ScalarPosition[elementPositionInGrid]; int scalarSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; return make_shared(isSource, scalarListDestP[scalarDstIndex], scalarListSrcP[scalarSrcIndex], reduceScalar); } CATCH bool CScalarAlgorithmReduceScalar::dummyRegistered_ = CScalarAlgorithmReduceScalar::registerTrans(); bool CScalarAlgorithmReduceScalar::registerTrans() TRY { return CGridTransformationFactory::registerTransformation(TRANS_REDUCE_SCALAR_TO_SCALAR, create); } CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(bool isSource, CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo) : CAlgorithmTransformationReduce(isSource) TRY { scalarDestination->checkAttributes() ; if (algo->operation.isEmpty()) ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", << "Operation must be defined." << "Scalar source " <getId() << std::endl << "Scalar destination " << scalarDestination->getId()); StdString op; switch (algo->operation) { case CReduceScalarToScalar::operation_attr::sum: operator_ = EReduction::sum; break; case CReduceScalarToScalar::operation_attr::min: operator_ = EReduction::min; break; case CReduceScalarToScalar::operation_attr::max: operator_ = EReduction::max; break; case CReduceScalarToScalar::operation_attr::average: operator_ = EReduction::average; break; default: ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl << "Scalar source " <getId() << std::endl << "Scalar destination " << scalarDestination->getId()); } auto& transMap = this->transformationMapping_; CArray dstGlobalIndex ; scalarDestination->getLocalView(CElementView::WORKFLOW)->getGlobalIndexView(dstGlobalIndex) ; size_t nbIdx = dstGlobalIndex.numElements(); for (size_t idx = 0; idx < nbIdx; ++idx) { size_t globalIdx = dstGlobalIndex(idx); transMap[globalIdx].resize(1); transMap[globalIdx][0]=globalIdx ; } this->computeAlgorithm(scalarSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; } CATCH shared_ptr CScalarAlgorithmReduceScalar::createGridAlgorithm(CGrid* gridSrc, CGrid* gridDst, int pos) { auto algo=make_shared(gridSrc, gridDst, pos, shared_from_this(), operator_) ; algo->computeAlgorithm(false) ; return algo ; } CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar() TRY { } CATCH }