1 | /*! |
---|
2 | \file axis_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 an axis |
---|
8 | */ |
---|
9 | #include "axis_algorithm_reduce_domain.hpp" |
---|
10 | #include "reduce_domain_to_axis.hpp" |
---|
11 | #include "axis.hpp" |
---|
12 | #include "domain.hpp" |
---|
13 | #include "grid.hpp" |
---|
14 | #include "grid_transformation_factory_impl.hpp" |
---|
15 | |
---|
16 | namespace xios { |
---|
17 | CGenericAlgorithmTransformation* CAxisAlgorithmReduceDomain::create(CGrid* gridDst, CGrid* gridSrc, |
---|
18 | CTransformation<CAxis>* 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 | { |
---|
27 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
28 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
29 | |
---|
30 | CReduceDomainToAxis* reduceDomain = dynamic_cast<CReduceDomainToAxis*> (transformation); |
---|
31 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
32 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
33 | |
---|
34 | return (new CAxisAlgorithmReduceDomain(axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], reduceDomain)); |
---|
35 | } |
---|
36 | |
---|
37 | bool CAxisAlgorithmReduceDomain::registerTrans() |
---|
38 | { |
---|
39 | CGridTransformationFactory<CAxis>::registerTransformation(TRANS_REDUCE_DOMAIN_TO_AXIS, create); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo) |
---|
44 | : CAxisAlgorithmTransformation(axisDestination, domainSource), reduction_(0) |
---|
45 | { |
---|
46 | algo->checkValid(axisDestination, domainSource); |
---|
47 | StdString op; |
---|
48 | switch (algo->operation) |
---|
49 | { |
---|
50 | case CReduceDomainToAxis::operation_attr::sum: |
---|
51 | op = "sum"; |
---|
52 | break; |
---|
53 | case CReduceDomainToAxis::operation_attr::min: |
---|
54 | op = "min"; |
---|
55 | break; |
---|
56 | case CReduceDomainToAxis::operation_attr::max: |
---|
57 | op = "max"; |
---|
58 | break; |
---|
59 | case CReduceDomainToAxis::operation_attr::average: |
---|
60 | op = "average"; |
---|
61 | break; |
---|
62 | default: |
---|
63 | ERROR("CAxisAlgorithmReduceDomain::CAxisAlgorithmReduceDomain(CAxis* axisDestination, CDomain* domainSource, CReduceDomainToAxis* algo)", |
---|
64 | << "Operation is wrongly defined. Supported operations: sum, min, max, average." << std::endl |
---|
65 | << "Domain source " <<domainSource->getId() << std::endl |
---|
66 | << "Axis destination " << axisDestination->getId()); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | dir_ = (CReduceDomainToAxis::direction_attr::iDir == algo->direction) ? iDir : jDir; |
---|
71 | |
---|
72 | if(CReductionAlgorithm::ReductionOperations_ptr == 0) |
---|
73 | CReductionAlgorithm::initReductionOperation(); |
---|
74 | |
---|
75 | reduction_ = CReductionAlgorithm::createOperation((*CReductionAlgorithm::ReductionOperations_ptr)[op]); |
---|
76 | } |
---|
77 | |
---|
78 | void CAxisAlgorithmReduceDomain::apply(const std::vector<std::pair<int,double> >& localIndex, |
---|
79 | const double* dataInput, |
---|
80 | CArray<double,1>& dataOut, |
---|
81 | std::vector<bool>& flagInitial, |
---|
82 | bool ignoreMissingValue) |
---|
83 | { |
---|
84 | reduction_->apply(localIndex, dataInput, dataOut, flagInitial, ignoreMissingValue); |
---|
85 | } |
---|
86 | |
---|
87 | void CAxisAlgorithmReduceDomain::updateData(CArray<double,1>& dataOut) |
---|
88 | { |
---|
89 | reduction_->updateData(dataOut); |
---|
90 | } |
---|
91 | |
---|
92 | CAxisAlgorithmReduceDomain::~CAxisAlgorithmReduceDomain() |
---|
93 | { |
---|
94 | if (0 != reduction_) delete reduction_; |
---|
95 | } |
---|
96 | |
---|
97 | void CAxisAlgorithmReduceDomain::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs) |
---|
98 | { |
---|
99 | this->transformationMapping_.resize(1); |
---|
100 | this->transformationWeight_.resize(1); |
---|
101 | |
---|
102 | TransformationIndexMap& transMap = this->transformationMapping_[0]; |
---|
103 | TransformationWeightMap& transWeight = this->transformationWeight_[0]; |
---|
104 | |
---|
105 | CArray<int,1>& axisDstIndex = axisDest_->index; |
---|
106 | int ni_glo = domainSrc_->ni_glo, nj_glo = domainSrc_->nj_glo; |
---|
107 | if (jDir == dir_) |
---|
108 | { |
---|
109 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
110 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
111 | { |
---|
112 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
113 | transMap[globalAxisIdx].resize(ni_glo); |
---|
114 | transWeight[globalAxisIdx].resize(ni_glo); |
---|
115 | for (int idx = 0; idx < ni_glo; ++idx) |
---|
116 | { |
---|
117 | transMap[globalAxisIdx][idx] = globalAxisIdx * ni_glo + idx; |
---|
118 | transWeight[globalAxisIdx][idx] = 1.0; |
---|
119 | } |
---|
120 | } |
---|
121 | } |
---|
122 | else if (iDir == dir_) |
---|
123 | { |
---|
124 | int nbAxisIdx = axisDstIndex.numElements(); |
---|
125 | for (int idxAxis = 0; idxAxis < nbAxisIdx; ++idxAxis) |
---|
126 | { |
---|
127 | int globalAxisIdx = axisDstIndex(idxAxis); |
---|
128 | transMap[globalAxisIdx].resize(nj_glo); |
---|
129 | transWeight[globalAxisIdx].resize(nj_glo); |
---|
130 | for (int idx = 0; idx < nj_glo; ++idx) |
---|
131 | { |
---|
132 | transMap[globalAxisIdx][idx] = globalAxisIdx + ni_glo*idx; |
---|
133 | transWeight[globalAxisIdx][idx] = 1.0; |
---|
134 | } |
---|
135 | } |
---|
136 | } |
---|
137 | else |
---|
138 | {} |
---|
139 | } |
---|
140 | |
---|
141 | } |
---|