1 | /*! |
---|
2 | \file scalar_algorithm_reduce_scalar.cpp |
---|
3 | |
---|
4 | \brief Algorithm for reduce an scalar to a scalar |
---|
5 | */ |
---|
6 | #include "scalar_algorithm_reduce_scalar.hpp" |
---|
7 | #include "scalar.hpp" |
---|
8 | #include "reduce_scalar_to_scalar.hpp" |
---|
9 | #include "grid.hpp" |
---|
10 | #include "grid_transformation_factory_impl.hpp" |
---|
11 | #include "reduction.hpp" |
---|
12 | |
---|
13 | |
---|
14 | namespace xios { |
---|
15 | CGenericAlgorithmTransformation* CScalarAlgorithmReduceScalar::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
16 | CTransformation<CScalar>* transformation, |
---|
17 | int elementPositionInGrid, |
---|
18 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
19 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
20 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
21 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
22 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
23 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
24 | TRY |
---|
25 | { |
---|
26 | std::vector<CScalar*> scalarListDestP = gridDst->getScalars(); |
---|
27 | std::vector<CScalar*> scalarListSrcP = gridSrc->getScalars(); |
---|
28 | |
---|
29 | CReduceScalarToScalar* reduceScalar = dynamic_cast<CReduceScalarToScalar*> (transformation); |
---|
30 | int scalarDstIndex = elementPositionInGridDst2ScalarPosition[elementPositionInGrid]; |
---|
31 | int scalarSrcIndex = elementPositionInGridSrc2AxisPosition[elementPositionInGrid]; |
---|
32 | |
---|
33 | return (new CScalarAlgorithmReduceScalar(isSource, scalarListDestP[scalarDstIndex], scalarListSrcP[scalarSrcIndex], reduceScalar)); |
---|
34 | } |
---|
35 | CATCH |
---|
36 | |
---|
37 | bool CScalarAlgorithmReduceScalar::dummyRegistered_ = CScalarAlgorithmReduceScalar::registerTrans(); |
---|
38 | bool CScalarAlgorithmReduceScalar::registerTrans() |
---|
39 | TRY |
---|
40 | { |
---|
41 | return CGridTransformationFactory<CScalar>::registerTransformation(TRANS_REDUCE_SCALAR_TO_SCALAR, create); |
---|
42 | } |
---|
43 | CATCH |
---|
44 | |
---|
45 | CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(bool isSource, CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo) |
---|
46 | : CAlgorithmTransformationReduce(isSource) |
---|
47 | TRY |
---|
48 | { |
---|
49 | eliminateRedondantSrc_= false ; |
---|
50 | if (algo->operation.isEmpty()) |
---|
51 | ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", |
---|
52 | << "Operation must be defined." |
---|
53 | << "Scalar source " <<scalarSource->getId() << std::endl |
---|
54 | << "Scalar destination " << scalarDestination->getId()); |
---|
55 | StdString op; |
---|
56 | switch (algo->operation) |
---|
57 | { |
---|
58 | case CReduceScalarToScalar::operation_attr::sum: |
---|
59 | operator_ = EReduction::sum; |
---|
60 | break; |
---|
61 | case CReduceScalarToScalar::operation_attr::min: |
---|
62 | operator_ = EReduction::min; |
---|
63 | break; |
---|
64 | case CReduceScalarToScalar::operation_attr::max: |
---|
65 | operator_ = EReduction::max; |
---|
66 | break; |
---|
67 | case CReduceScalarToScalar::operation_attr::average: |
---|
68 | operator_ = EReduction::average; |
---|
69 | break; |
---|
70 | default: |
---|
71 | ERROR("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)", |
---|
72 | << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl |
---|
73 | << "Scalar source " <<scalarSource->getId() << std::endl |
---|
74 | << "Scalar destination " << scalarDestination->getId()); |
---|
75 | |
---|
76 | } |
---|
77 | transformationMapping_[0].push_back(0) ; |
---|
78 | |
---|
79 | scalarDestination->checkAttributes() ; |
---|
80 | this->computeAlgorithm(scalarSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
81 | } |
---|
82 | CATCH |
---|
83 | |
---|
84 | CScalarAlgorithmReduceScalar::~CScalarAlgorithmReduceScalar() |
---|
85 | TRY |
---|
86 | { |
---|
87 | } |
---|
88 | CATCH |
---|
89 | |
---|
90 | |
---|
91 | } |
---|