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 extract a domain to an axis |
---|
8 | */ |
---|
9 | #include "axis_algorithm_extract_domain.hpp" |
---|
10 | #include "extract_domain_to_axis.hpp" |
---|
11 | #include "axis.hpp" |
---|
12 | #include "domain.hpp" |
---|
13 | #include "grid.hpp" |
---|
14 | #include "grid_transformation_factory_impl.hpp" |
---|
15 | #include "reduction.hpp" |
---|
16 | |
---|
17 | namespace xios |
---|
18 | { |
---|
19 | |
---|
20 | shared_ptr<CGenericAlgorithmTransformation> CAxisAlgorithmExtractDomain::create(bool isSource, CGrid* gridDst, CGrid* gridSrc, |
---|
21 | CTransformation<CAxis>* transformation, |
---|
22 | int elementPositionInGrid, |
---|
23 | std::map<int, int>& elementPositionInGridSrc2ScalarPosition, |
---|
24 | std::map<int, int>& elementPositionInGridSrc2AxisPosition, |
---|
25 | std::map<int, int>& elementPositionInGridSrc2DomainPosition, |
---|
26 | std::map<int, int>& elementPositionInGridDst2ScalarPosition, |
---|
27 | std::map<int, int>& elementPositionInGridDst2AxisPosition, |
---|
28 | std::map<int, int>& elementPositionInGridDst2DomainPosition) |
---|
29 | TRY |
---|
30 | { |
---|
31 | std::vector<CAxis*> axisListDestP = gridDst->getAxis(); |
---|
32 | std::vector<CDomain*> domainListSrcP = gridSrc->getDomains(); |
---|
33 | |
---|
34 | CExtractDomainToAxis* extractDomain = dynamic_cast<CExtractDomainToAxis*> (transformation); |
---|
35 | int axisDstIndex = elementPositionInGridDst2AxisPosition[elementPositionInGrid]; |
---|
36 | int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid]; |
---|
37 | |
---|
38 | return make_shared<CAxisAlgorithmExtractDomain>(isSource, axisListDestP[axisDstIndex], domainListSrcP[domainSrcIndex], extractDomain); |
---|
39 | } |
---|
40 | CATCH |
---|
41 | |
---|
42 | bool CAxisAlgorithmExtractDomain::dummyRegistered_ = CAxisAlgorithmExtractDomain::registerTrans(); |
---|
43 | bool CAxisAlgorithmExtractDomain::registerTrans() |
---|
44 | TRY |
---|
45 | { |
---|
46 | return CGridTransformationFactory<CAxis>::registerTransformation(TRANS_EXTRACT_DOMAIN_TO_AXIS, create); |
---|
47 | } |
---|
48 | CATCH |
---|
49 | |
---|
50 | |
---|
51 | CAxisAlgorithmExtractDomain::CAxisAlgorithmExtractDomain(bool isSource, CAxis* axisDestination, CDomain* domainSource, CExtractDomainToAxis* algo) |
---|
52 | : CAlgorithmTransformationTransfer(isSource), pos_(-1), axisDest_(axisDestination), domainSrc_(domainSource) |
---|
53 | TRY |
---|
54 | { |
---|
55 | axisDestination->axis_type.reset(); |
---|
56 | axisDestination->n_glo.reset(); |
---|
57 | axisDestination->index.reset(); |
---|
58 | axisDestination->n.reset(); |
---|
59 | axisDestination->begin.reset(); |
---|
60 | |
---|
61 | axisDestination->mask.reset(); |
---|
62 | axisDestination->data_index.reset(); |
---|
63 | axisDestination->data_n.reset(); |
---|
64 | axisDestination->data_begin.reset(); |
---|
65 | |
---|
66 | axisDestination->value.reset(); |
---|
67 | axisDestination->label.reset(); |
---|
68 | axisDestination->bounds.reset(); |
---|
69 | |
---|
70 | algo->checkValid(axisDestination, domainSource); |
---|
71 | StdString op = "extract"; |
---|
72 | |
---|
73 | int nglo,nloc; |
---|
74 | switch (algo->direction) |
---|
75 | { |
---|
76 | case CExtractDomainToAxis::direction_attr::jDir: |
---|
77 | dir_ = jDir; |
---|
78 | nglo = domainSource->nj_glo.getValue(); |
---|
79 | nloc = domainSource->nj.getValue(); |
---|
80 | break; |
---|
81 | case CExtractDomainToAxis::direction_attr::iDir: |
---|
82 | dir_ = iDir; |
---|
83 | nglo = domainSource->ni_glo.getValue(); |
---|
84 | nloc = domainSource->ni.getValue(); |
---|
85 | break; |
---|
86 | default: |
---|
87 | break; |
---|
88 | } |
---|
89 | |
---|
90 | axisDestination->n_glo.setValue( nglo ); |
---|
91 | axisDestination->index.resize( nloc ); |
---|
92 | axisDestination->data_index.resize( nloc ); |
---|
93 | axisDestination->data_index = -1; |
---|
94 | |
---|
95 | if ( axisDestination->index.isEmpty() ) |
---|
96 | { |
---|
97 | axisDestination->n.setValue( 0 ); |
---|
98 | axisDestination->begin.setValue( 0 ); |
---|
99 | } |
---|
100 | |
---|
101 | pos_ = algo->position; |
---|
102 | |
---|
103 | auto& transMap = this->transformationMapping_; |
---|
104 | |
---|
105 | CArray<size_t,1> sourceGlobalIdx = domainSource->getLocalElement()->getGlobalIndex(); |
---|
106 | int indexSize = sourceGlobalIdx.numElements(); |
---|
107 | |
---|
108 | CArray<int,1> sourceWorkflowIdx = domainSource->getLocalView(CElementView::WORKFLOW)->getIndex(); |
---|
109 | int srcWorkflowSize = sourceWorkflowIdx.numElements(); |
---|
110 | |
---|
111 | int iIdxSrcMin = INT_MAX; |
---|
112 | int jIdxSrcMin = INT_MAX; |
---|
113 | int IdxMin = INT_MAX; |
---|
114 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
115 | { |
---|
116 | if ( sourceGlobalIdx(countSrc)%domainSource->ni_glo < iIdxSrcMin ) |
---|
117 | iIdxSrcMin = sourceGlobalIdx(countSrc)%domainSource->ni_glo; |
---|
118 | if ( sourceGlobalIdx(countSrc)/domainSource->ni_glo < jIdxSrcMin ) |
---|
119 | jIdxSrcMin = sourceGlobalIdx(countSrc)/domainSource->ni_glo; |
---|
120 | if ( sourceGlobalIdx(countSrc) < IdxMin ) |
---|
121 | IdxMin = sourceGlobalIdx(countSrc); |
---|
122 | } |
---|
123 | |
---|
124 | if (jDir == dir_) |
---|
125 | { |
---|
126 | int countDest(0); |
---|
127 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
128 | { |
---|
129 | if ( sourceGlobalIdx(countSrc)%domainSource->ni_glo == pos_ ) |
---|
130 | { |
---|
131 | axisDest_->index(countDest) = sourceGlobalIdx(countSrc)/domainSource->ni_glo; |
---|
132 | int iIdxSrc2 = (countSrc%domainSource->ni)+(IdxMin)%domainSource->ni_glo; |
---|
133 | int jIdxSrc2 = (countSrc/domainSource->ni)+(IdxMin)/domainSource->ni_glo; |
---|
134 | int convert_locally_global_idx = (jIdxSrc2-jIdxSrcMin)*domainSource->ni + (iIdxSrc2-iIdxSrcMin) ; |
---|
135 | bool concerned_by_WF(false); |
---|
136 | for ( int i = 0 ; i<sourceWorkflowIdx.numElements() ; ++i ) |
---|
137 | { |
---|
138 | if (sourceWorkflowIdx(i)==convert_locally_global_idx) |
---|
139 | { |
---|
140 | concerned_by_WF = true; |
---|
141 | break; |
---|
142 | } |
---|
143 | } |
---|
144 | if (concerned_by_WF) |
---|
145 | { |
---|
146 | axisDest_->data_index(countDest) = countDest; |
---|
147 | transMap[axisDest_->index(countDest)] = sourceGlobalIdx(countSrc); |
---|
148 | } |
---|
149 | countDest++; |
---|
150 | } |
---|
151 | } |
---|
152 | } |
---|
153 | else if (iDir == dir_) |
---|
154 | { |
---|
155 | int countDest(0); |
---|
156 | for (int countSrc = 0; countSrc < indexSize ; ++countSrc) |
---|
157 | { |
---|
158 | if ( sourceGlobalIdx(countSrc)/domainSource->ni_glo == pos_ ) |
---|
159 | { |
---|
160 | axisDest_->index(countDest) = sourceGlobalIdx(countSrc)%domainSource->ni_glo; |
---|
161 | int iIdxSrc2 = (countSrc%domainSource->ni)+(IdxMin)%domainSource->ni_glo; |
---|
162 | int jIdxSrc2 = (countSrc/domainSource->ni)+(IdxMin)/domainSource->ni_glo; |
---|
163 | int convert_locally_global_idx = (jIdxSrc2-jIdxSrcMin)*domainSource->ni + (iIdxSrc2-iIdxSrcMin) ; |
---|
164 | bool concerned_by_WF(false); |
---|
165 | for ( int i = 0 ; i<sourceWorkflowIdx.numElements() ; ++i ) |
---|
166 | { |
---|
167 | if (sourceWorkflowIdx(i)==convert_locally_global_idx) |
---|
168 | { |
---|
169 | concerned_by_WF = true; |
---|
170 | break; |
---|
171 | } |
---|
172 | } |
---|
173 | if (concerned_by_WF) |
---|
174 | { |
---|
175 | axisDest_->data_index(countDest) = countDest; |
---|
176 | transMap[axisDest_->index(countDest)] = sourceGlobalIdx(countSrc); |
---|
177 | } |
---|
178 | countDest++; |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | else |
---|
183 | {} |
---|
184 | |
---|
185 | axisDestination->checkAttributes() ; |
---|
186 | this->computeAlgorithm(domainSource->getLocalView(CElementView::WORKFLOW), axisDestination->getLocalView(CElementView::WORKFLOW)) ; |
---|
187 | } |
---|
188 | CATCH |
---|
189 | |
---|
190 | |
---|
191 | CAxisAlgorithmExtractDomain::~CAxisAlgorithmExtractDomain() |
---|
192 | TRY |
---|
193 | { |
---|
194 | } |
---|
195 | CATCH |
---|
196 | |
---|
197 | } |
---|