1 | #include "grid.hpp" |
---|
2 | |
---|
3 | #include "attribute_template_impl.hpp" |
---|
4 | #include "object_template_impl.hpp" |
---|
5 | #include "group_template_impl.hpp" |
---|
6 | |
---|
7 | namespace xmlioserver { |
---|
8 | namespace tree { |
---|
9 | |
---|
10 | /// ////////////////////// Définitions ////////////////////// /// |
---|
11 | |
---|
12 | CGrid::CGrid(void) |
---|
13 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
14 | , withAxis(false), isChecked(false), axis(), domain() |
---|
15 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
16 | { /* Ne rien faire de plus */ } |
---|
17 | |
---|
18 | CGrid::CGrid(const StdString & id) |
---|
19 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
20 | , withAxis(false), isChecked(false), axis(), domain() |
---|
21 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
22 | { /* Ne rien faire de plus */ } |
---|
23 | |
---|
24 | CGrid::~CGrid(void) |
---|
25 | { |
---|
26 | this->axis.reset() ; |
---|
27 | this->domain.reset() ; |
---|
28 | |
---|
29 | for (StdSize i = 0; i < this->storeIndex.size(); i++) |
---|
30 | { |
---|
31 | this->storeIndex[i].reset(); |
---|
32 | this->out_i_index[i].reset(); |
---|
33 | this->out_j_index[i].reset(); |
---|
34 | this->out_l_index[i].reset(); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | ///--------------------------------------------------------------- |
---|
39 | |
---|
40 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
41 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
42 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
43 | |
---|
44 | //---------------------------------------------------------------- |
---|
45 | |
---|
46 | const std::deque<ARRAY(int, 1)> & CGrid::getStoreIndex(void) const |
---|
47 | { |
---|
48 | return (this->storeIndex ); |
---|
49 | } |
---|
50 | |
---|
51 | //--------------------------------------------------------------- |
---|
52 | |
---|
53 | const std::deque<ARRAY(int, 1)> & CGrid::getOutIIndex(void) const |
---|
54 | { |
---|
55 | return (this->out_i_index ); |
---|
56 | } |
---|
57 | |
---|
58 | //--------------------------------------------------------------- |
---|
59 | |
---|
60 | const std::deque<ARRAY(int, 1)> & CGrid::getOutJIndex(void) const |
---|
61 | { |
---|
62 | return (this->out_j_index ); |
---|
63 | } |
---|
64 | |
---|
65 | //--------------------------------------------------------------- |
---|
66 | |
---|
67 | const std::deque<ARRAY(int, 1)> & CGrid::getOutLIndex(void) const |
---|
68 | { |
---|
69 | return (this->out_l_index ); |
---|
70 | } |
---|
71 | |
---|
72 | //--------------------------------------------------------------- |
---|
73 | |
---|
74 | const boost::shared_ptr<CAxis> CGrid::getRelAxis (void) const |
---|
75 | { |
---|
76 | return (this->axis ); |
---|
77 | } |
---|
78 | |
---|
79 | //--------------------------------------------------------------- |
---|
80 | |
---|
81 | const boost::shared_ptr<CDomain> CGrid::getRelDomain(void) const |
---|
82 | { |
---|
83 | return (this->domain ); |
---|
84 | } |
---|
85 | |
---|
86 | //--------------------------------------------------------------- |
---|
87 | |
---|
88 | bool CGrid::hasAxis(void) const |
---|
89 | { |
---|
90 | return (this->withAxis); |
---|
91 | } |
---|
92 | |
---|
93 | //--------------------------------------------------------------- |
---|
94 | |
---|
95 | void CGrid::solveReference(void) |
---|
96 | { |
---|
97 | if (this->isChecked) return; |
---|
98 | this->solveDomainRef() ; |
---|
99 | this->solveAxisRef() ; |
---|
100 | if (this->storeIndex.size() == 1) |
---|
101 | { |
---|
102 | this->computeIndex() ; |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | this->computeIndexServer(); |
---|
107 | } |
---|
108 | this->isChecked = true; |
---|
109 | } |
---|
110 | |
---|
111 | //--------------------------------------------------------------- |
---|
112 | |
---|
113 | void CGrid::solveDomainRef(void) |
---|
114 | { |
---|
115 | if (!domain_ref.isEmpty()) |
---|
116 | { |
---|
117 | if (CObjectFactory::HasObject<CDomain>(domain_ref.getValue())) |
---|
118 | { |
---|
119 | this->domain = CObjectFactory::GetObject<CDomain>(domain_ref.getValue()) ; |
---|
120 | domain->checkAttributes() ; |
---|
121 | } |
---|
122 | else ERROR("CGrid::solveDomainRef(void)", |
---|
123 | << "Référence au domaine incorrecte") ; |
---|
124 | } |
---|
125 | else ERROR("CGrid::solveDomainRef(void)", |
---|
126 | << "Domaine non défini") ; |
---|
127 | } |
---|
128 | |
---|
129 | //--------------------------------------------------------------- |
---|
130 | |
---|
131 | void CGrid::solveAxisRef(void) |
---|
132 | { |
---|
133 | if (!axis_ref.isEmpty()) |
---|
134 | { |
---|
135 | this->withAxis = true ; |
---|
136 | if (CObjectFactory::GetObject<CAxis>(axis_ref.getValue())) |
---|
137 | { |
---|
138 | this->axis = CObjectFactory::GetObject<CAxis>(axis_ref.getValue()) ; |
---|
139 | axis->checkAttributes() ; |
---|
140 | } |
---|
141 | else ERROR("CGrid::solveAxisRef(void)", |
---|
142 | << "Référence a l'axe incorrecte") ; |
---|
143 | } |
---|
144 | else withAxis = false ; |
---|
145 | } |
---|
146 | |
---|
147 | //--------------------------------------------------------------- |
---|
148 | |
---|
149 | void CGrid::computeIndex(void) |
---|
150 | { |
---|
151 | const int ni = domain->ni.getValue() , |
---|
152 | nj = domain->nj.getValue() , |
---|
153 | size = (this->hasAxis()) ? axis->size.getValue() : 1 ; |
---|
154 | |
---|
155 | /*std::cout << ni << " : " |
---|
156 | << nj << " : " |
---|
157 | << size << std::endl;*/ |
---|
158 | |
---|
159 | const int data_dim = domain->data_dim.getValue() , |
---|
160 | data_n_index = domain->data_n_index.getValue() , |
---|
161 | data_ibegin = domain->data_ibegin.getValue() , |
---|
162 | data_jbegin = (data_dim == 2) |
---|
163 | ? domain->data_jbegin.getValue() : -1; |
---|
164 | |
---|
165 | ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() , |
---|
166 | data_j_index = domain->data_j_index.getValue() ; |
---|
167 | |
---|
168 | /*std::cout << data_n_index << " : " |
---|
169 | << data_i_index << " : " |
---|
170 | << data_j_index << std::endl; */ |
---|
171 | |
---|
172 | ARRAY(bool, 2) mask = domain->mask.getValue() ; |
---|
173 | |
---|
174 | int indexCount = 0; |
---|
175 | |
---|
176 | for(int l = 0; l < size ; l++) |
---|
177 | { |
---|
178 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++) |
---|
179 | { |
---|
180 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
181 | temp_j = (data_dim == 1) ? -1 |
---|
182 | : (*data_j_index)[n] + data_jbegin; |
---|
183 | i = (data_dim == 1) ? (temp_i - 2) % ni |
---|
184 | : (temp_i - 1) ; |
---|
185 | j = (data_dim == 1) ? (temp_i - 2) / ni |
---|
186 | : (temp_j - 1) ; |
---|
187 | |
---|
188 | if ((i >= 0 && i < ni) && |
---|
189 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
190 | indexCount++ ; |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | //std::cout << indexCount << std::endl; |
---|
195 | ARRAY_ASSIGN(this->storeIndex[0] , int, 1, [indexCount]); |
---|
196 | ARRAY_ASSIGN(this->out_l_index[0], int, 1, [indexCount]); |
---|
197 | ARRAY_ASSIGN(this->out_i_index[0], int, 1, [indexCount]); |
---|
198 | ARRAY_ASSIGN(this->out_j_index[0], int, 1, [indexCount]); |
---|
199 | |
---|
200 | for(int count = 0, indexCount = 0, l = 0; l < size; l++) |
---|
201 | { |
---|
202 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) |
---|
203 | { |
---|
204 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
205 | temp_j = (data_dim == 1) ? -1 |
---|
206 | : (*data_j_index)[n] + data_jbegin; |
---|
207 | i = (data_dim == 1) ? (temp_i - 2) % ni |
---|
208 | : (temp_i - 1) ; |
---|
209 | j = (data_dim == 1) ? (temp_i - 2) / ni |
---|
210 | : (temp_j - 1) ; |
---|
211 | |
---|
212 | if ((i >= 0 && i < ni) && |
---|
213 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
214 | { |
---|
215 | (*this->storeIndex[0]) [indexCount] = count ; |
---|
216 | (*this->out_l_index[0])[indexCount] = l ; |
---|
217 | (*this->out_i_index[0])[indexCount] = i ; |
---|
218 | (*this->out_j_index[0])[indexCount] = j ; |
---|
219 | indexCount++ ; |
---|
220 | } |
---|
221 | } |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | //---------------------------------------------------------------- |
---|
226 | |
---|
227 | boost::shared_ptr<CGrid> |
---|
228 | CGrid::CreateGrid(boost::shared_ptr<CDomain> domain) |
---|
229 | { |
---|
230 | StdString new_id = StdString("__") + domain->getId() + StdString("__") ; |
---|
231 | boost::shared_ptr<CGrid> grid = |
---|
232 | CGroupFactory::CreateChild(CObjectFactory::GetObject<CGridGroup> ("grid_definition"), new_id); |
---|
233 | grid->domain_ref.setValue(domain->getId()); |
---|
234 | return (grid); |
---|
235 | } |
---|
236 | |
---|
237 | boost::shared_ptr<CGrid> |
---|
238 | CGrid::CreateGrid(boost::shared_ptr<CDomain> domain, boost::shared_ptr<CAxis> axis) |
---|
239 | { |
---|
240 | StdString new_id = StdString("__") + domain->getId() + |
---|
241 | StdString("_") + axis->getId() + StdString("__") ; |
---|
242 | boost::shared_ptr<CGrid> grid = |
---|
243 | CGroupFactory::CreateChild(CObjectFactory::GetObject<CGridGroup> ("grid_definition"), new_id); |
---|
244 | grid->domain_ref.setValue(domain->getId()); |
---|
245 | grid->axis_ref.setValue(axis->getId()); |
---|
246 | return (grid); |
---|
247 | } |
---|
248 | |
---|
249 | //---------------------------------------------------------------- |
---|
250 | |
---|
251 | template <> |
---|
252 | void CGrid::outputField |
---|
253 | (const ARRAY(double, 1) stored, ARRAY(double, 3) field) const |
---|
254 | { |
---|
255 | for(StdSize n = 0; n < storeIndex[0]->num_elements(); n++) |
---|
256 | (*field)[(*out_i_index[0])[n]][(*out_j_index[0])[n]][(*out_l_index[0])[n]] = (*stored)[n] ; |
---|
257 | } |
---|
258 | |
---|
259 | //--------------------------------------------------------------- |
---|
260 | |
---|
261 | template <> |
---|
262 | void CGrid::outputField |
---|
263 | (const ARRAY(double, 1) stored, ARRAY(double, 2) field) const |
---|
264 | { |
---|
265 | for(StdSize n = 0; n < storeIndex[0]->num_elements(); n++) |
---|
266 | (*field)[(*out_i_index[0])[n]][(*out_j_index[0])[n]] = (*stored)[n] ; |
---|
267 | } |
---|
268 | |
---|
269 | //--------------------------------------------------------------- |
---|
270 | |
---|
271 | template <> |
---|
272 | void CGrid::outputField |
---|
273 | (const ARRAY(double, 1) stored, ARRAY(double, 1) field) const |
---|
274 | { |
---|
275 | for(StdSize n = 0; n < storeIndex[0]->num_elements(); n++) |
---|
276 | (*field)[(*out_i_index[0])[n]] = (*stored)[n] ; |
---|
277 | } |
---|
278 | |
---|
279 | //---------------------------------------------------------------- |
---|
280 | |
---|
281 | void CGrid::storeField_arr |
---|
282 | (const double * const data, ARRAY(double, 1) stored) const |
---|
283 | { |
---|
284 | const StdSize size = storeIndex[0]->num_elements() ; |
---|
285 | stored->resize(boost::extents[size]) ; |
---|
286 | for(StdSize i = 0; i < size; i++) |
---|
287 | (*stored)[i] = data[(*storeIndex[0])[i]] ; |
---|
288 | } |
---|
289 | |
---|
290 | //--------------------------------------------------------------- |
---|
291 | |
---|
292 | void CGrid::toBinary (StdOStream & os) const |
---|
293 | { |
---|
294 | SuperClass::toBinary(os); |
---|
295 | this->storeIndex[0]->toBinary(os); |
---|
296 | this->out_i_index[0]->toBinary(os); |
---|
297 | this->out_j_index[0]->toBinary(os); |
---|
298 | this->out_l_index[0]->toBinary(os); |
---|
299 | } |
---|
300 | |
---|
301 | //--------------------------------------------------------------- |
---|
302 | |
---|
303 | void CGrid::fromBinary(StdIStream & is) |
---|
304 | { |
---|
305 | SuperClass::fromBinary(is); |
---|
306 | |
---|
307 | ARRAY_CREATE(storeIndex_ , int, 1, [1]); |
---|
308 | ARRAY_CREATE(out_l_index_, int, 1, [1]); |
---|
309 | ARRAY_CREATE(out_i_index_, int, 1, [1]); |
---|
310 | ARRAY_CREATE(out_j_index_, int, 1, [1]); |
---|
311 | |
---|
312 | storeIndex_ ->fromBinary(is); |
---|
313 | out_i_index_->fromBinary(is); |
---|
314 | out_j_index_->fromBinary(is); |
---|
315 | out_l_index_->fromBinary(is); |
---|
316 | |
---|
317 | this->storeIndex .push_back(storeIndex_); |
---|
318 | this->out_i_index.push_back(out_i_index_); |
---|
319 | this->out_j_index.push_back(out_j_index_); |
---|
320 | this->out_l_index.push_back(out_l_index_); |
---|
321 | } |
---|
322 | |
---|
323 | //--------------------------------------------------------------- |
---|
324 | |
---|
325 | void CGrid::computeIndexServer(void) |
---|
326 | { |
---|
327 | ARRAY(int, 1) storeIndex_srv = this->storeIndex[0]; |
---|
328 | ARRAY(int, 1) out_i_index_srv = this->out_i_index[0]; |
---|
329 | ARRAY(int, 1) out_j_index_srv = this->out_j_index[0]; |
---|
330 | ARRAY(int, 1) out_l_index_srv = this->out_l_index[0]; |
---|
331 | |
---|
332 | const std::vector<int> & ibegin = this->domain->getIBeginSub(); |
---|
333 | const std::vector<int> & jbegin = this->domain->getJBeginSub(); |
---|
334 | |
---|
335 | StdSize dn = 0; |
---|
336 | for (StdSize j = 1; j < this->out_i_index.size(); j++) |
---|
337 | dn += this->out_i_index[j]->size(); |
---|
338 | |
---|
339 | ARRAY_ASSIGN(storeIndex_srv, int, 1, [dn]); |
---|
340 | ARRAY_ASSIGN(out_i_index_srv, int, 1, [dn]); |
---|
341 | ARRAY_ASSIGN(out_j_index_srv, int, 1, [dn]); |
---|
342 | ARRAY_ASSIGN(out_l_index_srv, int, 1, [dn]); |
---|
343 | |
---|
344 | for (StdSize i = 0, dn = 0; i < ibegin.size(); i++) |
---|
345 | { |
---|
346 | ARRAY(int, 1) storeIndex_cl = this->storeIndex[i+1]; |
---|
347 | ARRAY(int, 1) out_i_index_cl = this->out_i_index[i+1]; |
---|
348 | ARRAY(int, 1) out_j_index_cl = this->out_j_index[i+1]; |
---|
349 | ARRAY(int, 1) out_l_index_cl = this->out_l_index[i+1]; |
---|
350 | |
---|
351 | const int ibegin_cl = ibegin[i]; |
---|
352 | const int jbegin_cl = jbegin[i]; |
---|
353 | |
---|
354 | for (StdSize n = dn, m = 0; n < (dn + storeIndex_cl->size()); n++, m++) |
---|
355 | { |
---|
356 | (*storeIndex_srv)[n] = (*storeIndex_cl)[m] + dn; |
---|
357 | (*out_i_index_srv)[n] = (*out_i_index_cl)[m] + ibegin_cl - 1; |
---|
358 | (*out_j_index_srv)[n] = (*out_j_index_cl)[m] + jbegin_cl - 1; |
---|
359 | (*out_l_index_srv)[n] = (*out_l_index_cl)[m]; |
---|
360 | } |
---|
361 | |
---|
362 | dn += storeIndex_cl->size(); |
---|
363 | |
---|
364 | } |
---|
365 | |
---|
366 | //~ StdOFStream ofs(this->getId().c_str()); |
---|
367 | //~ for (StdSize h = 0; h < storeIndex_srv->size(); h++) |
---|
368 | //~ { |
---|
369 | //~ ofs << "(" << (*storeIndex_srv)[h] << ";" |
---|
370 | //~ << (*out_i_index_srv)[h] << "," |
---|
371 | //~ << (*out_j_index_srv)[h] << "," |
---|
372 | //~ << (*out_l_index_srv)[h] << ")" << std::endl; |
---|
373 | //~ } |
---|
374 | //~ ofs.close(); |
---|
375 | |
---|
376 | } |
---|
377 | |
---|
378 | ///--------------------------------------------------------------- |
---|
379 | |
---|
380 | } // namespace tree |
---|
381 | } // namespace xmlioserver |
---|