1 | |
---|
2 | #include "grid.hpp" |
---|
3 | |
---|
4 | #include "attribute_template.hpp" |
---|
5 | #include "object_template.hpp" |
---|
6 | #include "group_template.hpp" |
---|
7 | #include "message.hpp" |
---|
8 | #include <iostream> |
---|
9 | #include "xmlioserver_spl.hpp" |
---|
10 | #include "type.hpp" |
---|
11 | #include "context.hpp" |
---|
12 | #include "context_client.hpp" |
---|
13 | #include "array_new.hpp" |
---|
14 | |
---|
15 | namespace xios { |
---|
16 | |
---|
17 | /// ////////////////////// Définitions ////////////////////// /// |
---|
18 | |
---|
19 | CGrid::CGrid(void) |
---|
20 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
21 | , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() |
---|
22 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) |
---|
23 | , vDomainGroup_(), vAxisGroup_(), axisOrder_(), axisList_(), isAxisListSet(false), isDomListSet(false) |
---|
24 | { |
---|
25 | setVirtualDomainGroup(); |
---|
26 | setVirtualAxisGroup(); |
---|
27 | } |
---|
28 | |
---|
29 | CGrid::CGrid(const StdString & id) |
---|
30 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
31 | , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() |
---|
32 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) |
---|
33 | , vDomainGroup_(), vAxisGroup_(), axisOrder_(), axisList_(), isAxisListSet(false), isDomListSet(false) |
---|
34 | { |
---|
35 | setVirtualDomainGroup(); |
---|
36 | setVirtualAxisGroup(); |
---|
37 | } |
---|
38 | |
---|
39 | CGrid::~CGrid(void) |
---|
40 | { |
---|
41 | // this->axis.reset() ; |
---|
42 | // this->domain.reset() ; |
---|
43 | deque< CArray<int, 1>* >::iterator it ; |
---|
44 | |
---|
45 | for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++) delete *it ; |
---|
46 | for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; |
---|
47 | for(deque< CArray<int,1>* >::iterator it=out_j_index.begin();it!=out_j_index.end();it++) delete *it ; |
---|
48 | for(deque< CArray<int,1>* >::iterator it=out_l_index.begin();it!=out_l_index.end();it++) delete *it ; |
---|
49 | |
---|
50 | for(map<int,CArray<int,1>* >::iterator it=out_i_fromClient.begin();it!=out_i_fromClient.end();it++) delete it->second ; |
---|
51 | for(map<int,CArray<int,1>* >::iterator it=out_j_fromClient.begin();it!=out_j_fromClient.end();it++) delete it->second ; |
---|
52 | for(map<int,CArray<int,1>* >::iterator it=out_l_fromClient.begin();it!=out_l_fromClient.end();it++) delete it->second ; |
---|
53 | |
---|
54 | } |
---|
55 | |
---|
56 | ///--------------------------------------------------------------- |
---|
57 | |
---|
58 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
59 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
60 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
61 | |
---|
62 | //---------------------------------------------------------------- |
---|
63 | |
---|
64 | const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const |
---|
65 | { |
---|
66 | return (this->storeIndex ); |
---|
67 | } |
---|
68 | |
---|
69 | //--------------------------------------------------------------- |
---|
70 | |
---|
71 | const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void) const |
---|
72 | { |
---|
73 | return (this->out_i_index ); |
---|
74 | } |
---|
75 | |
---|
76 | //--------------------------------------------------------------- |
---|
77 | |
---|
78 | const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const |
---|
79 | { |
---|
80 | return (this->out_j_index ); |
---|
81 | } |
---|
82 | |
---|
83 | //--------------------------------------------------------------- |
---|
84 | |
---|
85 | const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void) const |
---|
86 | { |
---|
87 | return (this->out_l_index ); |
---|
88 | } |
---|
89 | |
---|
90 | //--------------------------------------------------------------- |
---|
91 | |
---|
92 | const CAxis* CGrid::getRelAxis (void) const |
---|
93 | { |
---|
94 | return (this->axis ); |
---|
95 | } |
---|
96 | |
---|
97 | //--------------------------------------------------------------- |
---|
98 | |
---|
99 | const CDomain* CGrid::getRelDomain(void) const |
---|
100 | { |
---|
101 | return (this->domain ); |
---|
102 | } |
---|
103 | |
---|
104 | //--------------------------------------------------------------- |
---|
105 | |
---|
106 | bool CGrid::hasAxis(void) const |
---|
107 | { |
---|
108 | return (this->withAxis); |
---|
109 | } |
---|
110 | |
---|
111 | //--------------------------------------------------------------- |
---|
112 | |
---|
113 | StdSize CGrid::getDimension(void) const |
---|
114 | { |
---|
115 | return ((this->withAxis)?3:2); |
---|
116 | } |
---|
117 | |
---|
118 | //--------------------------------------------------------------- |
---|
119 | |
---|
120 | /* |
---|
121 | std::vector<StdSize> CGrid::getLocalShape(void) const |
---|
122 | { |
---|
123 | std::vector<StdSize> retvalue; |
---|
124 | retvalue.push_back(domain->zoom_ni_loc.getValue()); |
---|
125 | retvalue.push_back(domain->zoom_nj_loc.getValue()); |
---|
126 | if (this->withAxis) |
---|
127 | retvalue.push_back(this->axis->zoom_size.getValue()); |
---|
128 | return (retvalue); |
---|
129 | } |
---|
130 | */ |
---|
131 | //--------------------------------------------------------------- |
---|
132 | |
---|
133 | /* |
---|
134 | StdSize CGrid::getLocalSize(void) const |
---|
135 | { |
---|
136 | StdSize retvalue = 1; |
---|
137 | std::vector<StdSize> shape_ = this->getLocalShape(); |
---|
138 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
139 | retvalue *= shape_[s]; |
---|
140 | return (retvalue); |
---|
141 | } |
---|
142 | */ |
---|
143 | //--------------------------------------------------------------- |
---|
144 | /* |
---|
145 | std::vector<StdSize> CGrid::getGlobalShape(void) const |
---|
146 | { |
---|
147 | std::vector<StdSize> retvalue; |
---|
148 | retvalue.push_back(domain->ni.getValue()); |
---|
149 | retvalue.push_back(domain->nj.getValue()); |
---|
150 | if (this->withAxis) |
---|
151 | retvalue.push_back(this->axis->size.getValue()); |
---|
152 | return (retvalue); |
---|
153 | } |
---|
154 | */ |
---|
155 | //--------------------------------------------------------------- |
---|
156 | |
---|
157 | /* |
---|
158 | StdSize CGrid::getGlobalSize(void) const |
---|
159 | { |
---|
160 | StdSize retvalue = 1; |
---|
161 | std::vector<StdSize> shape_ = this->getGlobalShape(); |
---|
162 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
163 | retvalue *= shape_[s]; |
---|
164 | return (retvalue); |
---|
165 | } |
---|
166 | */ |
---|
167 | StdSize CGrid::getDataSize(void) const |
---|
168 | { |
---|
169 | StdSize retvalue=domain->data_ni.getValue() ; |
---|
170 | if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ; |
---|
171 | if (this->withAxis) retvalue*=this->axis->size.getValue() ; |
---|
172 | |
---|
173 | return (retvalue); |
---|
174 | } |
---|
175 | |
---|
176 | std::map<int, StdSize> CGrid::getConnectedServerDataSize() |
---|
177 | { |
---|
178 | std::map<int, StdSize> ret; |
---|
179 | std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(), |
---|
180 | itE = domConnectedServerSide_.end(); |
---|
181 | std::vector<int> nData = domain->nbDataSrv; |
---|
182 | std::vector<int>::const_iterator itData = nData.begin(); |
---|
183 | StdSize retVal = StdSize(0.0); |
---|
184 | for (; it != itE; ++it, ++itData) |
---|
185 | { |
---|
186 | retVal = (it->second < *itData) ? *itData : it->second; |
---|
187 | if (this->withAxis) retVal *= this->axis->size.getValue(); |
---|
188 | retVal *= sizeof(double); |
---|
189 | retVal *= 2.5 * CXios::bufferServerFactorSize; // Secure factor, myterious number |
---|
190 | ret.insert(make_pair(it->first, retVal)); |
---|
191 | } |
---|
192 | return ret; |
---|
193 | } |
---|
194 | |
---|
195 | |
---|
196 | //--------------------------------------------------------------- |
---|
197 | |
---|
198 | // void CGrid::solveReference(void) |
---|
199 | // { |
---|
200 | // if (this->isChecked) return; |
---|
201 | // CContext* context = CContext::getCurrent() ; |
---|
202 | // CContextClient* client=context->client ; |
---|
203 | // |
---|
204 | // this->solveDomainRef() ; |
---|
205 | // this->solveAxisRef() ; |
---|
206 | // |
---|
207 | // if (context->hasClient) |
---|
208 | // { |
---|
209 | // checkMask() ; |
---|
210 | // this->computeIndex() ; |
---|
211 | // |
---|
212 | // this->storeIndex.push_front(new CArray<int,1>() ); |
---|
213 | // this->out_i_index.push_front(new CArray<int,1>()); |
---|
214 | // this->out_j_index.push_front(new CArray<int,1>()); |
---|
215 | // this->out_l_index.push_front(new CArray<int,1>()); |
---|
216 | // } |
---|
217 | //// this->computeIndexServer(); |
---|
218 | // this->isChecked = true; |
---|
219 | // } |
---|
220 | |
---|
221 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
222 | { |
---|
223 | if (this->isDomainAxisChecked) return; |
---|
224 | |
---|
225 | this->solveDomainRef(areAttributesChecked); |
---|
226 | this->solveAxisRef(areAttributesChecked); |
---|
227 | |
---|
228 | this->isDomainAxisChecked = areAttributesChecked; |
---|
229 | } |
---|
230 | |
---|
231 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
232 | { |
---|
233 | CContext* context = CContext::getCurrent() ; |
---|
234 | CContextClient* client=context->client ; |
---|
235 | |
---|
236 | if (context->hasClient) |
---|
237 | if (this->isChecked && doSendingIndex) sendIndex(); |
---|
238 | |
---|
239 | if (this->isChecked) return; |
---|
240 | |
---|
241 | if (context->hasClient) |
---|
242 | { |
---|
243 | checkMask() ; |
---|
244 | this->computeIndex() ; |
---|
245 | |
---|
246 | this->storeIndex.push_front(new CArray<int,1>() ); |
---|
247 | this->out_i_index.push_front(new CArray<int,1>()); |
---|
248 | this->out_j_index.push_front(new CArray<int,1>()); |
---|
249 | this->out_l_index.push_front(new CArray<int,1>()); |
---|
250 | } |
---|
251 | // this->computeIndexServer(); |
---|
252 | this->isChecked = true; |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | void CGrid::checkMask(void) |
---|
257 | { |
---|
258 | using namespace std; |
---|
259 | |
---|
260 | unsigned int niu = domain->ni, nju = domain->nj; |
---|
261 | unsigned int nlu = 1 ; |
---|
262 | if (hasAxis()) nlu=axis->size ; |
---|
263 | |
---|
264 | if (!mask.isEmpty()) |
---|
265 | { |
---|
266 | if ((mask.extent(0) != niu) || |
---|
267 | (mask.extent(1) != nju) || |
---|
268 | (mask.extent(2) != nlu)) |
---|
269 | ERROR("CGrid::checkAttributes(void)", |
---|
270 | <<"The mask has not the same size than the local grid"<<endl |
---|
271 | <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl |
---|
272 | <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); |
---|
273 | } |
---|
274 | else |
---|
275 | { |
---|
276 | mask.resize(niu,nju,nlu) ; |
---|
277 | mask=true ; |
---|
278 | } |
---|
279 | |
---|
280 | CArray<bool,2>& domainMask = domain->mask ; |
---|
281 | for (int l=0; l < nlu ; l++) |
---|
282 | for (int j=0; j < nju ; j++) |
---|
283 | for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; |
---|
284 | |
---|
285 | |
---|
286 | } |
---|
287 | |
---|
288 | //--------------------------------------------------------------- |
---|
289 | |
---|
290 | // void CGrid::solveDomainRef(void) |
---|
291 | // { |
---|
292 | // if (!domain_ref.isEmpty()) |
---|
293 | // { |
---|
294 | // if (CDomain::has(domain_ref.getValue())) |
---|
295 | // { |
---|
296 | // this->domain = CDomain::get(domain_ref.getValue()) ; |
---|
297 | // domain->checkAttributes() ; |
---|
298 | // } |
---|
299 | // else ERROR("CGrid::solveDomainRef(void)", |
---|
300 | // << "Wrong domain reference") ; |
---|
301 | // } |
---|
302 | // else ERROR("CGrid::solveDomainRef(void)", |
---|
303 | // << "Domain reference is not defined") ; |
---|
304 | // } |
---|
305 | // |
---|
306 | // //--------------------------------------------------------------- |
---|
307 | // |
---|
308 | // void CGrid::solveAxisRef(void) |
---|
309 | // { |
---|
310 | // if (!axis_ref.isEmpty()) |
---|
311 | // { |
---|
312 | // this->withAxis = true ; |
---|
313 | // if (CAxis::get(axis_ref.getValue())) |
---|
314 | // { |
---|
315 | // this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
316 | // axis->checkAttributes() ; |
---|
317 | // } |
---|
318 | // else ERROR("CGrid::solveAxisRef(void)", |
---|
319 | // << "Wrong axis reference") ; |
---|
320 | // } |
---|
321 | // else withAxis = false ; |
---|
322 | // } |
---|
323 | |
---|
324 | |
---|
325 | void CGrid::solveDomainRef(bool sendAtt) |
---|
326 | { |
---|
327 | // if (!domain_ref.isEmpty()) |
---|
328 | // { |
---|
329 | // if (CDomain::has(domain_ref.getValue())) |
---|
330 | // { |
---|
331 | // this->domain = CDomain::get(domain_ref.getValue()) ; |
---|
332 | // if (sendAtt) domain->sendCheckedAttributes(); |
---|
333 | // else domain->checkAttributesOnClient() ; |
---|
334 | // } |
---|
335 | // else ERROR("CGrid::solveDomainRef(void)", |
---|
336 | // << "Wrong domain reference") ; |
---|
337 | // } |
---|
338 | // else ERROR("CGrid::solveDomainRef(void)", |
---|
339 | // << "Domain reference is not defined") ; |
---|
340 | setDomainList(); |
---|
341 | this->domain = CDomain::get(domList_.at(0)); |
---|
342 | if (0 != this->domain) |
---|
343 | { |
---|
344 | // this->domain = this->getDomain(); |
---|
345 | if (sendAtt) domain->sendCheckedAttributes(); |
---|
346 | else domain->checkAttributesOnClient() ; |
---|
347 | } |
---|
348 | else ERROR("CGrid::solveDomainRef(void)", |
---|
349 | << "Domain reference is not defined") ; |
---|
350 | } |
---|
351 | |
---|
352 | //--------------------------------------------------------------- |
---|
353 | |
---|
354 | void CGrid::solveAxisRef(bool checkAtt) |
---|
355 | { |
---|
356 | // if (!axis_ref.isEmpty()) |
---|
357 | // { |
---|
358 | // this->withAxis = true ; |
---|
359 | // if (CAxis::get(axis_ref.getValue())) |
---|
360 | // { |
---|
361 | // this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
362 | // axis->checkAttributes() ; |
---|
363 | // } |
---|
364 | // else ERROR("CGrid::solveAxisRef(void)", |
---|
365 | // << "Wrong axis reference") ; |
---|
366 | // } |
---|
367 | // else withAxis = false ; |
---|
368 | // getAllAxis(); |
---|
369 | setAxisList(); |
---|
370 | if (!axisList_.empty()) |
---|
371 | { |
---|
372 | int sizeList = axisList_.size(); |
---|
373 | for (int i = 0; i < sizeList; ++i) |
---|
374 | { |
---|
375 | CAxis::get(axisList_.at(i))->checkAttributes(); |
---|
376 | this->axis = CAxis::get(axisList_.at(i)); |
---|
377 | } |
---|
378 | withAxis = true; |
---|
379 | |
---|
380 | } |
---|
381 | // if (!axis_ref.isEmpty()) |
---|
382 | // { |
---|
383 | // this->withAxis = true ; |
---|
384 | // if (CAxis::get(axis_ref.getValue())) |
---|
385 | // { |
---|
386 | // this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
387 | // axis->checkAttributes() ; |
---|
388 | // } |
---|
389 | // else ERROR("CGrid::solveAxisRef(void)", |
---|
390 | // << "Wrong axis reference") ; |
---|
391 | // } |
---|
392 | else withAxis = false ; |
---|
393 | } |
---|
394 | |
---|
395 | //--------------------------------------------------------------- |
---|
396 | |
---|
397 | void CGrid::computeIndex(void) |
---|
398 | { |
---|
399 | |
---|
400 | const int ni = domain->ni.getValue() , |
---|
401 | nj = domain->nj.getValue() , |
---|
402 | size = (this->hasAxis()) ? axis->size.getValue() : 1 , |
---|
403 | lbegin = (this->hasAxis()) ? axis->zoom_begin.getValue()-1 : 0 , |
---|
404 | lend = (this->hasAxis()) ? axis->zoom_end.getValue()-1 : 0 ; |
---|
405 | |
---|
406 | |
---|
407 | const int data_dim = domain->data_dim.getValue() , |
---|
408 | data_n_index = domain->data_n_index.getValue() , |
---|
409 | data_ibegin = domain->data_ibegin.getValue() , |
---|
410 | data_jbegin = (data_dim == 2) |
---|
411 | ? domain->data_jbegin.getValue() : -1; |
---|
412 | |
---|
413 | CArray<int,1> data_i_index = domain->data_i_index ; |
---|
414 | CArray<int,1> data_j_index = domain->data_j_index ; |
---|
415 | |
---|
416 | |
---|
417 | int indexCount = 0; |
---|
418 | |
---|
419 | for(int l = 0; l < size ; l++) |
---|
420 | { |
---|
421 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++) |
---|
422 | { |
---|
423 | int temp_i = data_i_index(n) + data_ibegin, |
---|
424 | temp_j = (data_dim == 1) ? -1 |
---|
425 | : data_j_index(n) + data_jbegin; |
---|
426 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
427 | : (temp_i - 1) ; |
---|
428 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
429 | : (temp_j - 1) ; |
---|
430 | |
---|
431 | if ((l >=lbegin && l<= lend) && |
---|
432 | (i >= 0 && i < ni) && |
---|
433 | (j >= 0 && j < nj) && mask(i,j,l)) |
---|
434 | indexCount++ ; |
---|
435 | } |
---|
436 | } |
---|
437 | |
---|
438 | storeIndex[0] = new CArray<int,1>(indexCount) ; |
---|
439 | out_i_index[0] = new CArray<int,1>(indexCount) ; |
---|
440 | out_j_index[0] = new CArray<int,1>(indexCount) ; |
---|
441 | out_l_index[0] = new CArray<int,1>(indexCount) ; |
---|
442 | |
---|
443 | storeIndex_client.resize(indexCount) ; |
---|
444 | out_i_client.resize(indexCount) ; |
---|
445 | out_j_client.resize(indexCount) ; |
---|
446 | out_l_client.resize(indexCount) ; |
---|
447 | |
---|
448 | |
---|
449 | for(int count = 0, indexCount = 0, l = 0; l < size; l++) |
---|
450 | { |
---|
451 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) |
---|
452 | { |
---|
453 | int temp_i = data_i_index(n) + data_ibegin, |
---|
454 | temp_j = (data_dim == 1) ? -1 |
---|
455 | : data_j_index(n) + data_jbegin; |
---|
456 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
457 | : (temp_i - 1) ; |
---|
458 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
459 | : (temp_j - 1) ; |
---|
460 | |
---|
461 | if ((l >= lbegin && l <= lend) && |
---|
462 | (i >= 0 && i < ni) && |
---|
463 | (j >= 0 && j < nj) && mask(i,j,l)) |
---|
464 | { |
---|
465 | (*storeIndex[0])(indexCount) = count ; |
---|
466 | (*out_l_index[0])(indexCount) = l ; |
---|
467 | (*out_i_index[0])(indexCount) = i ; |
---|
468 | (*out_j_index[0])(indexCount) = j ; |
---|
469 | |
---|
470 | storeIndex_client(indexCount) = count ; |
---|
471 | out_i_client(indexCount)=i+domain->ibegin_client-1 ; |
---|
472 | out_j_client(indexCount)=j+domain->jbegin_client-1 ; |
---|
473 | out_l_client(indexCount)=l-lbegin ; |
---|
474 | indexCount++ ; |
---|
475 | } |
---|
476 | } |
---|
477 | } |
---|
478 | computeDomConServer(); |
---|
479 | // sendIndex() ; |
---|
480 | |
---|
481 | |
---|
482 | } |
---|
483 | |
---|
484 | //---------------------------------------------------------------- |
---|
485 | |
---|
486 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
487 | { |
---|
488 | StdString new_id = StdString("__") + domain->getId() + StdString("__") ; |
---|
489 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
490 | |
---|
491 | std::vector<CDomain*> vecDom(1,domain); |
---|
492 | grid->setDomainList(vecDom); |
---|
493 | // grid->domain_ref.setValue(domain->getId()); |
---|
494 | return (grid); |
---|
495 | } |
---|
496 | |
---|
497 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
498 | { |
---|
499 | StdString new_id = StdString("__") + domain->getId() + |
---|
500 | StdString("_") + axis->getId() + StdString("__") ; |
---|
501 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
502 | |
---|
503 | std::vector<CDomain*> vecDom(1,domain); |
---|
504 | std::vector<CAxis*> vecAxis(1,axis); |
---|
505 | grid->setDomainList(vecDom); |
---|
506 | grid->setAxisList(vecAxis); |
---|
507 | // grid->domain_ref.setValue(domain->getId()); |
---|
508 | // grid->axis_ref.setValue(axis->getId()); |
---|
509 | return (grid); |
---|
510 | } |
---|
511 | |
---|
512 | CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis) |
---|
513 | { |
---|
514 | StdString new_id = StdString("__"); |
---|
515 | if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); |
---|
516 | if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_") ; |
---|
517 | new_id += StdString("_"); |
---|
518 | |
---|
519 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
520 | grid->setDomainList(domains); |
---|
521 | grid->setAxisList(axis); |
---|
522 | return (grid); |
---|
523 | } |
---|
524 | |
---|
525 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
526 | { |
---|
527 | return (this->vDomainGroup_); |
---|
528 | } |
---|
529 | |
---|
530 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
531 | { |
---|
532 | return (this->vAxisGroup_); |
---|
533 | } |
---|
534 | |
---|
535 | //---------------------------------------------------------------- |
---|
536 | |
---|
537 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 3>& field) |
---|
538 | { |
---|
539 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
540 | CArray<int,1>& out_j=*out_j_fromClient[rank] ; |
---|
541 | CArray<int,1>& out_l=*out_l_fromClient[rank] ; |
---|
542 | |
---|
543 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
544 | field(out_i(n), out_j(n), out_l(n)) = stored(n) ; |
---|
545 | } |
---|
546 | |
---|
547 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, CArray<double, 2>& field) |
---|
548 | { |
---|
549 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
550 | CArray<int,1>& out_j=*out_j_fromClient[rank] ; |
---|
551 | |
---|
552 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
553 | field(out_i(n), out_j(n)) = stored(n) ; } |
---|
554 | |
---|
555 | //--------------------------------------------------------------- |
---|
556 | |
---|
557 | void CGrid::outputField(int rank,const CArray<double, 1>& stored, CArray<double, 1>& field) |
---|
558 | { |
---|
559 | CArray<int,1>& out_i=*out_i_fromClient[rank] ; |
---|
560 | |
---|
561 | for(StdSize n = 0; n < stored.numElements(); n++) |
---|
562 | field(out_i(n)) = stored(n) ; |
---|
563 | } |
---|
564 | |
---|
565 | //---------------------------------------------------------------- |
---|
566 | |
---|
567 | |
---|
568 | void CGrid::storeField_arr |
---|
569 | (const double * const data, CArray<double, 1>& stored) const |
---|
570 | { |
---|
571 | const StdSize size = storeIndex_client.numElements() ; |
---|
572 | |
---|
573 | stored.resize(size) ; |
---|
574 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; |
---|
575 | } |
---|
576 | |
---|
577 | //--------------------------------------------------------------- |
---|
578 | |
---|
579 | // void CGrid::sendIndex(void) |
---|
580 | // { |
---|
581 | // CContext* context = CContext::getCurrent() ; |
---|
582 | // CContextClient* client=context->client ; |
---|
583 | // |
---|
584 | // CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
585 | // int rank ; |
---|
586 | // list<shared_ptr<CMessage> > list_msg ; |
---|
587 | // list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; |
---|
588 | // |
---|
589 | // for(int ns=0;ns<domain->connectedServer.size();ns++) |
---|
590 | // { |
---|
591 | // rank=domain->connectedServer[ns] ; |
---|
592 | // |
---|
593 | // int i,j ; |
---|
594 | // int nb=0 ; |
---|
595 | // for(int k=0;k<storeIndex_client.numElements();k++) |
---|
596 | // { |
---|
597 | // i=out_i_client(k)- domain->ibegin +1; |
---|
598 | // j=out_j_client(k)- domain->jbegin +1; |
---|
599 | // if (domain->mapConnectedServer(i,j)==ns) nb++ ; |
---|
600 | // } |
---|
601 | // |
---|
602 | // CArray<int,1> storeIndex(nb) ; |
---|
603 | // CArray<int,1> out_i(nb) ; |
---|
604 | // CArray<int,1> out_j(nb) ; |
---|
605 | // CArray<int,1> out_l(nb) ; |
---|
606 | // |
---|
607 | // |
---|
608 | // nb=0 ; |
---|
609 | // for(int k=0;k<storeIndex_client.numElements();k++) |
---|
610 | // { |
---|
611 | // i=out_i_client(k)- domain->ibegin +1 ; |
---|
612 | // j=out_j_client(k)- domain->jbegin +1 ; |
---|
613 | // if (domain->mapConnectedServer(i,j)==ns) |
---|
614 | // { |
---|
615 | // storeIndex(nb)=k ; |
---|
616 | // out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; |
---|
617 | // out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; |
---|
618 | // out_l(nb)=out_l_client(k) ; |
---|
619 | // nb++ ; |
---|
620 | // } |
---|
621 | // } |
---|
622 | // |
---|
623 | // storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; |
---|
624 | // nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; |
---|
625 | // list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; |
---|
626 | // list_out_i.push_back(new CArray<int,1>(out_i)) ; |
---|
627 | // list_out_j.push_back(new CArray<int,1>(out_j)) ; |
---|
628 | // list_out_l.push_back(new CArray<int,1>(out_l)) ; |
---|
629 | // |
---|
630 | // *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; |
---|
631 | // event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; |
---|
632 | // } |
---|
633 | // client->sendEvent(event) ; |
---|
634 | // |
---|
635 | // for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; |
---|
636 | // for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; |
---|
637 | // for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; |
---|
638 | // |
---|
639 | // } |
---|
640 | |
---|
641 | void CGrid::computeDomConServer() |
---|
642 | { |
---|
643 | if (!isDomConServerComputed_) |
---|
644 | { |
---|
645 | for(int ns=0;ns<domain->connectedServer.size(); ++ns) |
---|
646 | { |
---|
647 | int rank=domain->connectedServer[ns] ; |
---|
648 | |
---|
649 | int i,j ; |
---|
650 | int nb=0 ; |
---|
651 | for(int k=0;k<storeIndex_client.numElements();++k) |
---|
652 | { |
---|
653 | i=out_i_client(k)- domain->ibegin +1; |
---|
654 | j=out_j_client(k)- domain->jbegin +1; |
---|
655 | if (domain->mapConnectedServer(i,j)==ns) ++nb ; |
---|
656 | } |
---|
657 | |
---|
658 | domConnectedServerSide_.insert(std::make_pair(rank, nb)); |
---|
659 | } |
---|
660 | isDomConServerComputed_ = true; |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | |
---|
665 | std::map<int, int> CGrid::getDomConServerSide() |
---|
666 | { |
---|
667 | return domConnectedServerSide_; |
---|
668 | } |
---|
669 | |
---|
670 | void CGrid::sendIndex(void) |
---|
671 | { |
---|
672 | CContext* context = CContext::getCurrent() ; |
---|
673 | CContextClient* client=context->client ; |
---|
674 | |
---|
675 | CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
676 | int rank ; |
---|
677 | list<shared_ptr<CMessage> > list_msg ; |
---|
678 | list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; |
---|
679 | |
---|
680 | if (!isDomConServerComputed_) computeDomConServer(); |
---|
681 | |
---|
682 | for(int ns=0;ns<domain->connectedServer.size();ns++) |
---|
683 | { |
---|
684 | rank=domain->connectedServer[ns] ; |
---|
685 | |
---|
686 | int nb = domConnectedServerSide_.find(rank)->second; |
---|
687 | CArray<int,1> storeIndex(nb) ; |
---|
688 | CArray<int,1> out_i(nb) ; |
---|
689 | CArray<int,1> out_j(nb) ; |
---|
690 | CArray<int,1> out_l(nb) ; |
---|
691 | |
---|
692 | int i, j; |
---|
693 | nb=0 ; |
---|
694 | for(int k=0;k<storeIndex_client.numElements();k++) |
---|
695 | { |
---|
696 | i=out_i_client(k)- domain->ibegin +1 ; |
---|
697 | j=out_j_client(k)- domain->jbegin +1 ; |
---|
698 | if (domain->mapConnectedServer(i,j)==ns) |
---|
699 | { |
---|
700 | storeIndex(nb)=k ; |
---|
701 | out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; |
---|
702 | out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; |
---|
703 | out_l(nb)=out_l_client(k) ; |
---|
704 | nb++ ; |
---|
705 | } |
---|
706 | } |
---|
707 | |
---|
708 | storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; |
---|
709 | nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; |
---|
710 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; |
---|
711 | list_out_i.push_back(new CArray<int,1>(out_i)) ; |
---|
712 | list_out_j.push_back(new CArray<int,1>(out_j)) ; |
---|
713 | list_out_l.push_back(new CArray<int,1>(out_l)) ; |
---|
714 | |
---|
715 | *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; |
---|
716 | event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; |
---|
717 | } |
---|
718 | client->sendEvent(event) ; |
---|
719 | |
---|
720 | for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; |
---|
721 | for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; |
---|
722 | for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; |
---|
723 | |
---|
724 | } |
---|
725 | |
---|
726 | void CGrid::recvIndex(CEventServer& event) |
---|
727 | { |
---|
728 | list<CEventServer::SSubEvent>::iterator it ; |
---|
729 | for (it=event.subEvents.begin();it!=event.subEvents.end();++it) |
---|
730 | { |
---|
731 | int rank=it->rank; |
---|
732 | CBufferIn* buffer=it->buffer; |
---|
733 | string domainId ; |
---|
734 | *buffer>>domainId ; |
---|
735 | get(domainId)->recvIndex(rank,*buffer) ; |
---|
736 | } |
---|
737 | } |
---|
738 | |
---|
739 | void CGrid::recvIndex(int rank, CBufferIn& buffer) |
---|
740 | { |
---|
741 | CArray<int,1> out_i ; |
---|
742 | CArray<int,1> out_j ; |
---|
743 | CArray<int,1> out_l ; |
---|
744 | |
---|
745 | buffer>>out_i>>out_j>>out_l ; |
---|
746 | |
---|
747 | out_i -= domain->zoom_ibegin_srv-1 ; |
---|
748 | out_j -= domain->zoom_jbegin_srv-1 ; |
---|
749 | |
---|
750 | out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; |
---|
751 | out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; |
---|
752 | out_l_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_l) )) ; |
---|
753 | } |
---|
754 | |
---|
755 | /*! |
---|
756 | \brief Dispatch event received from client |
---|
757 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
758 | its event type. A new event type should be added in the switch list to make sure |
---|
759 | it processed on server side. |
---|
760 | \param [in] event: Received message |
---|
761 | */ |
---|
762 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
763 | { |
---|
764 | |
---|
765 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
766 | else |
---|
767 | { |
---|
768 | switch(event.type) |
---|
769 | { |
---|
770 | case EVENT_ID_INDEX : |
---|
771 | recvIndex(event) ; |
---|
772 | return true ; |
---|
773 | break ; |
---|
774 | |
---|
775 | case EVENT_ID_ADD_DOMAIN : |
---|
776 | recvAddDomain(event) ; |
---|
777 | return true ; |
---|
778 | break ; |
---|
779 | |
---|
780 | case EVENT_ID_ADD_AXIS : |
---|
781 | recvAddAxis(event) ; |
---|
782 | return true ; |
---|
783 | break ; |
---|
784 | default : |
---|
785 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
786 | <<"Unknown Event") ; |
---|
787 | return false ; |
---|
788 | } |
---|
789 | } |
---|
790 | } |
---|
791 | |
---|
792 | void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const |
---|
793 | { |
---|
794 | if ((this->storeIndex.size()-1 ) != storedClient.size()) |
---|
795 | ERROR("void CGrid::inputFieldServer(const std::deque< CArray<double, 1>* > storedClient, CArray<double, 1>& storedServer) const", |
---|
796 | << "[ Expected received field = " << (this->storeIndex.size()-1) << ", " |
---|
797 | << "[ received fiedl = " << storedClient.size() << "] " |
---|
798 | << "Data from clients are missing!") ; |
---|
799 | storedServer.resize(storeIndex[0]->numElements()); |
---|
800 | |
---|
801 | for (StdSize i = 0, n = 0; i < storedClient.size(); i++) |
---|
802 | for (StdSize j = 0; j < storedClient[i]->numElements(); j++) |
---|
803 | storedServer(n++) = (*storedClient[i])(j); |
---|
804 | } |
---|
805 | |
---|
806 | void CGrid::outputFieldToServer(CArray<double,1>& fieldIn, int rank, CArray<double,1>& fieldOut) |
---|
807 | { |
---|
808 | CArray<int,1>& index = *storeIndex_toSrv[rank] ; |
---|
809 | int nb=index.numElements() ; |
---|
810 | fieldOut.resize(nb) ; |
---|
811 | |
---|
812 | for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; |
---|
813 | } |
---|
814 | ///--------------------------------------------------------------- |
---|
815 | |
---|
816 | CDomain* CGrid::addDomain(const std::string& id) |
---|
817 | { |
---|
818 | return vDomainGroup_->createChild(id) ; |
---|
819 | } |
---|
820 | |
---|
821 | CAxis* CGrid::addAxis(const std::string& id) |
---|
822 | { |
---|
823 | return vAxisGroup_->createChild(id) ; |
---|
824 | } |
---|
825 | |
---|
826 | //! Change virtual field group to a new one |
---|
827 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
828 | { |
---|
829 | this->vDomainGroup_ = newVDomainGroup; |
---|
830 | } |
---|
831 | |
---|
832 | //! Change virtual variable group to new one |
---|
833 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
834 | { |
---|
835 | this->vAxisGroup_ = newVAxisGroup; |
---|
836 | } |
---|
837 | |
---|
838 | //---------------------------------------------------------------- |
---|
839 | //! Create virtual field group, which is done normally on initializing file |
---|
840 | void CGrid::setVirtualDomainGroup(void) |
---|
841 | { |
---|
842 | this->setVirtualDomainGroup(CDomainGroup::create()); |
---|
843 | } |
---|
844 | |
---|
845 | //! Create virtual variable group, which is done normally on initializing file |
---|
846 | void CGrid::setVirtualAxisGroup(void) |
---|
847 | { |
---|
848 | this->setVirtualAxisGroup(CAxisGroup::create()); |
---|
849 | } |
---|
850 | |
---|
851 | /*! |
---|
852 | \brief Send a message to create a domain on server side |
---|
853 | \param[in] id String identity of domain that will be created on server |
---|
854 | */ |
---|
855 | void CGrid::sendAddDomain(const string& id) |
---|
856 | { |
---|
857 | CContext* context=CContext::getCurrent() ; |
---|
858 | |
---|
859 | if (! context->hasServer ) |
---|
860 | { |
---|
861 | CContextClient* client=context->client ; |
---|
862 | |
---|
863 | CEventClient event(this->getType(),EVENT_ID_ADD_DOMAIN) ; |
---|
864 | if (client->isServerLeader()) |
---|
865 | { |
---|
866 | CMessage msg ; |
---|
867 | msg<<this->getId() ; |
---|
868 | msg<<id ; |
---|
869 | event.push(client->getServerLeader(),1,msg) ; |
---|
870 | client->sendEvent(event) ; |
---|
871 | } |
---|
872 | else client->sendEvent(event) ; |
---|
873 | } |
---|
874 | } |
---|
875 | |
---|
876 | /*! |
---|
877 | \brief Send a message to create an axis on server side |
---|
878 | \param[in] id String identity of axis that will be created on server |
---|
879 | */ |
---|
880 | void CGrid::sendAddAxis(const string& id) |
---|
881 | { |
---|
882 | CContext* context=CContext::getCurrent() ; |
---|
883 | |
---|
884 | if (! context->hasServer ) |
---|
885 | { |
---|
886 | CContextClient* client=context->client ; |
---|
887 | |
---|
888 | CEventClient event(this->getType(),EVENT_ID_ADD_AXIS) ; |
---|
889 | if (client->isServerLeader()) |
---|
890 | { |
---|
891 | CMessage msg ; |
---|
892 | msg<<this->getId() ; |
---|
893 | msg<<id ; |
---|
894 | event.push(client->getServerLeader(),1,msg) ; |
---|
895 | client->sendEvent(event) ; |
---|
896 | } |
---|
897 | else client->sendEvent(event) ; |
---|
898 | } |
---|
899 | } |
---|
900 | |
---|
901 | /*! |
---|
902 | \brief Receive a message annoucing the creation of a domain on server side |
---|
903 | \param[in] event Received event |
---|
904 | */ |
---|
905 | void CGrid::recvAddDomain(CEventServer& event) |
---|
906 | { |
---|
907 | |
---|
908 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
909 | string id; |
---|
910 | *buffer>>id ; |
---|
911 | get(id)->recvAddDomain(*buffer) ; |
---|
912 | } |
---|
913 | |
---|
914 | /*! |
---|
915 | \brief Receive a message annoucing the creation of a domain on server side |
---|
916 | \param[in] buffer Buffer containing message |
---|
917 | */ |
---|
918 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
919 | { |
---|
920 | string id ; |
---|
921 | buffer>>id ; |
---|
922 | addDomain(id) ; |
---|
923 | } |
---|
924 | |
---|
925 | /*! |
---|
926 | \brief Receive a message annoucing the creation of an axis on server side |
---|
927 | \param[in] event Received event |
---|
928 | */ |
---|
929 | void CGrid::recvAddAxis(CEventServer& event) |
---|
930 | { |
---|
931 | |
---|
932 | CBufferIn* buffer=event.subEvents.begin()->buffer; |
---|
933 | string id; |
---|
934 | *buffer>>id ; |
---|
935 | get(id)->recvAddAxis(*buffer) ; |
---|
936 | } |
---|
937 | |
---|
938 | /*! |
---|
939 | \brief Receive a message annoucing the creation of an axis on server side |
---|
940 | \param[in] buffer Buffer containing message |
---|
941 | */ |
---|
942 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
943 | { |
---|
944 | string id ; |
---|
945 | buffer>>id ; |
---|
946 | addAxis(id) ; |
---|
947 | } |
---|
948 | |
---|
949 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
950 | { |
---|
951 | CContext* context = CContext::getCurrent(); |
---|
952 | unsigned int vecSize, i; |
---|
953 | std::vector<StdString>::iterator it, itE; |
---|
954 | setDomainList(); |
---|
955 | it = domList_.begin(); itE = domList_.end(); |
---|
956 | for (; it != itE; ++it) |
---|
957 | { |
---|
958 | CDomain* pDom = CDomain::get(*it); |
---|
959 | if (context->hasClient) |
---|
960 | { |
---|
961 | pDom->solveRefInheritance(apply); |
---|
962 | pDom->solveBaseReference(); |
---|
963 | if ((!pDom->domain_ref.isEmpty()) && (pDom->name.isEmpty())) |
---|
964 | pDom->name.setValue(pDom->getBaseDomainReference()->getId()); |
---|
965 | |
---|
966 | } |
---|
967 | } |
---|
968 | |
---|
969 | setAxisList(); |
---|
970 | it = axisList_.begin(); itE = axisList_.end(); |
---|
971 | for (; it != itE; ++it) |
---|
972 | { |
---|
973 | CAxis* pAxis = CAxis::get(*it); |
---|
974 | if (context->hasClient) |
---|
975 | { |
---|
976 | pAxis->solveRefInheritance(apply); |
---|
977 | pAxis->solveBaseReference(); |
---|
978 | if ((!pAxis->axis_ref.isEmpty()) && (pAxis->name.isEmpty())) |
---|
979 | pAxis->name.setValue(pAxis->getBaseAxisReference()->getId()); |
---|
980 | } |
---|
981 | } |
---|
982 | } |
---|
983 | |
---|
984 | std::vector<CDomain*> CGrid::getDomains() |
---|
985 | { |
---|
986 | std::vector<CDomain*> domList; |
---|
987 | if (!domList_.empty()) |
---|
988 | { |
---|
989 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
990 | } |
---|
991 | return domList; |
---|
992 | } |
---|
993 | |
---|
994 | std::vector<CAxis*> CGrid::getAxis() |
---|
995 | { |
---|
996 | std::vector<CAxis*> aList; |
---|
997 | if (!axisList_.empty()) |
---|
998 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
999 | |
---|
1000 | return aList; |
---|
1001 | } |
---|
1002 | |
---|
1003 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
1004 | { |
---|
1005 | if (isDomListSet) return; |
---|
1006 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
1007 | if (!domains.empty() && domList.empty()) domList = domains; |
---|
1008 | if (!domList.empty()) |
---|
1009 | { |
---|
1010 | int sizeDom = domList.size(); |
---|
1011 | domList_.resize(sizeDom); |
---|
1012 | for (int i = 0 ; i < sizeDom; ++i) |
---|
1013 | { |
---|
1014 | domList_[i] = domList[i]->getId(); |
---|
1015 | } |
---|
1016 | isDomListSet = true; |
---|
1017 | } |
---|
1018 | |
---|
1019 | } |
---|
1020 | |
---|
1021 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
1022 | { |
---|
1023 | if (isAxisListSet) return; |
---|
1024 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
1025 | if (!axis.empty() && aList.empty()) aList = axis; |
---|
1026 | if (!aList.empty()) |
---|
1027 | { |
---|
1028 | int sizeAxis = aList.size(); |
---|
1029 | axisList_.resize(sizeAxis); |
---|
1030 | for (int i = 0; i < sizeAxis; ++i) |
---|
1031 | { |
---|
1032 | axisList_[i] = aList[i]->getId(); |
---|
1033 | } |
---|
1034 | isAxisListSet = true; |
---|
1035 | } |
---|
1036 | } |
---|
1037 | |
---|
1038 | std::vector<StdString> CGrid::getDomainList() |
---|
1039 | { |
---|
1040 | setDomainList(); |
---|
1041 | return domList_; |
---|
1042 | } |
---|
1043 | |
---|
1044 | std::vector<StdString> CGrid::getAxisList() |
---|
1045 | { |
---|
1046 | setAxisList(); |
---|
1047 | return axisList_; |
---|
1048 | } |
---|
1049 | |
---|
1050 | void CGrid::sendAllDomains() |
---|
1051 | { |
---|
1052 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
1053 | int dSize = domList.size(); |
---|
1054 | for (int i = 0; i < dSize; ++i) |
---|
1055 | { |
---|
1056 | sendAddDomain(domList[i]->getId()); |
---|
1057 | domList[i]->sendAllAttributesToServer(); |
---|
1058 | } |
---|
1059 | } |
---|
1060 | |
---|
1061 | void CGrid::sendAllAxis() |
---|
1062 | { |
---|
1063 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
1064 | int aSize = aList.size(); |
---|
1065 | |
---|
1066 | for (int i = 0; i < aSize; ++i) |
---|
1067 | { |
---|
1068 | sendAddAxis(aList[i]->getId()); |
---|
1069 | aList[i]->sendAllAttributesToServer(); |
---|
1070 | } |
---|
1071 | } |
---|
1072 | |
---|
1073 | void CGrid::parse(xml::CXMLNode & node) |
---|
1074 | { |
---|
1075 | SuperClass::parse(node); |
---|
1076 | |
---|
1077 | if (node.goToChildElement()) |
---|
1078 | { |
---|
1079 | int domainIdx = -1; |
---|
1080 | int posAxis = 0; |
---|
1081 | StdString domainName("domain"); |
---|
1082 | StdString axisName("axis"); |
---|
1083 | do |
---|
1084 | { |
---|
1085 | if (node.getElementName() == domainName) { |
---|
1086 | axisOrder_.push_back(domainIdx); |
---|
1087 | this->getVirtualDomainGroup()->parseChild(node); |
---|
1088 | } |
---|
1089 | if (node.getElementName() == axisName) { |
---|
1090 | axisOrder_.push_back(posAxis); |
---|
1091 | ++posAxis; |
---|
1092 | this->getVirtualAxisGroup()->parseChild(node); |
---|
1093 | } |
---|
1094 | } while (node.goToNextElement()) ; |
---|
1095 | node.goToParentElement(); |
---|
1096 | } |
---|
1097 | |
---|
1098 | if (!axisOrder_.empty()) |
---|
1099 | { |
---|
1100 | int sizeOrd = axisOrder_.size(); |
---|
1101 | axisDomOrder.resize(sizeOrd); |
---|
1102 | for (int i = 0; i < sizeOrd; ++i) |
---|
1103 | { |
---|
1104 | axisDomOrder(i) = axisOrder_[i]; |
---|
1105 | } |
---|
1106 | } |
---|
1107 | |
---|
1108 | setDomainList(); |
---|
1109 | setAxisList(); |
---|
1110 | } |
---|
1111 | |
---|
1112 | } // namespace xios |
---|