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 | shared_ptr<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 | |
---|
35 | return make_shared<CScalarAlgorithmReduceDomain>(isSource, scalarListDestP[scalarDstIndex], domainListSrcP[domainSrcIndex], reduceDomain); |
---|
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 | |
---|
47 | CScalarAlgorithmReduceDomain::CScalarAlgorithmReduceDomain(bool isSource, CScalar* scalarDestination, CDomain* domainSource, CReduceDomainToScalar* algo) |
---|
48 | : CAlgorithmTransformationReduce(isSource), domainSrc_(domainSource) |
---|
49 | TRY |
---|
50 | { |
---|
51 | algo->checkValid(scalarDestination, domainSource); |
---|
52 | |
---|
53 | StdString op; |
---|
54 | switch (algo->operation) |
---|
55 | { |
---|
56 | case CReduceDomainToScalar::operation_attr::sum: |
---|
57 | operator_ = EReduction::sum; |
---|
58 | break; |
---|
59 | case CReduceDomainToScalar::operation_attr::min: |
---|
60 | operator_ = EReduction::min; |
---|
61 | break; |
---|
62 | case CReduceDomainToScalar::operation_attr::max: |
---|
63 | operator_ = EReduction::max; |
---|
64 | break; |
---|
65 | case CReduceDomainToScalar::operation_attr::average: |
---|
66 | operator_ = EReduction::average; |
---|
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 | |
---|
76 | bool local=false ; |
---|
77 | if (!algo->local.isEmpty()) local=algo->local ; |
---|
78 | |
---|
79 | auto& transMap = this->transformationMapping_; |
---|
80 | |
---|
81 | if (local) |
---|
82 | { |
---|
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() ; |
---|
91 | |
---|
92 | for (size_t idx = 0; idx < nbIdx; ++idx) |
---|
93 | { |
---|
94 | size_t globalIdx = srcGlobalIndex(idx); |
---|
95 | transformationMapping_[0].push_back(globalIdx); |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|
99 | else |
---|
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); |
---|
108 | } |
---|
109 | |
---|
110 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), scalarDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
111 | |
---|
112 | } |
---|
113 | CATCH |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | CScalarAlgorithmReduceDomain::~CScalarAlgorithmReduceDomain() |
---|
118 | TRY |
---|
119 | { |
---|
120 | } |
---|
121 | CATCH |
---|
122 | |
---|
123 | |
---|
124 | } |
---|