1 | |
---|
2 | #include "grid.hpp" |
---|
3 | |
---|
4 | #include "attribute_template_impl.hpp" |
---|
5 | #include "object_template_impl.hpp" |
---|
6 | #include "group_template_impl.hpp" |
---|
7 | #include <iostream> |
---|
8 | |
---|
9 | namespace xios { |
---|
10 | |
---|
11 | /// ////////////////////// Définitions ////////////////////// /// |
---|
12 | |
---|
13 | CGrid::CGrid(void) |
---|
14 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
15 | , withAxis(false), isChecked(false), axis(), domain() |
---|
16 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
17 | { /* Ne rien faire de plus */ } |
---|
18 | |
---|
19 | CGrid::CGrid(const StdString & id) |
---|
20 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
21 | , withAxis(false), isChecked(false), axis(), domain() |
---|
22 | , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) |
---|
23 | { /* Ne rien faire de plus */ } |
---|
24 | |
---|
25 | CGrid::~CGrid(void) |
---|
26 | { |
---|
27 | // this->axis.reset() ; |
---|
28 | // this->domain.reset() ; |
---|
29 | |
---|
30 | for (StdSize i = 0; i < this->storeIndex.size(); i++) |
---|
31 | { |
---|
32 | this->storeIndex[i].reset(); |
---|
33 | this->out_i_index[i].reset(); |
---|
34 | this->out_j_index[i].reset(); |
---|
35 | this->out_l_index[i].reset(); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | ///--------------------------------------------------------------- |
---|
40 | |
---|
41 | StdString CGrid::GetName(void) { return (StdString("grid")); } |
---|
42 | StdString CGrid::GetDefName(void) { return (CGrid::GetName()); } |
---|
43 | ENodeType CGrid::GetType(void) { return (eGrid); } |
---|
44 | |
---|
45 | //---------------------------------------------------------------- |
---|
46 | |
---|
47 | const std::deque<ARRAY(int, 1)> & CGrid::getStoreIndex(void) const |
---|
48 | { |
---|
49 | return (this->storeIndex ); |
---|
50 | } |
---|
51 | |
---|
52 | //--------------------------------------------------------------- |
---|
53 | |
---|
54 | const std::deque<ARRAY(int, 1)> & CGrid::getOutIIndex(void) const |
---|
55 | { |
---|
56 | return (this->out_i_index ); |
---|
57 | } |
---|
58 | |
---|
59 | //--------------------------------------------------------------- |
---|
60 | |
---|
61 | const std::deque<ARRAY(int, 1)> & CGrid::getOutJIndex(void) const |
---|
62 | { |
---|
63 | return (this->out_j_index ); |
---|
64 | } |
---|
65 | |
---|
66 | //--------------------------------------------------------------- |
---|
67 | |
---|
68 | const std::deque<ARRAY(int, 1)> & CGrid::getOutLIndex(void) const |
---|
69 | { |
---|
70 | return (this->out_l_index ); |
---|
71 | } |
---|
72 | |
---|
73 | //--------------------------------------------------------------- |
---|
74 | |
---|
75 | const CAxis* CGrid::getRelAxis (void) const |
---|
76 | { |
---|
77 | return (this->axis ); |
---|
78 | } |
---|
79 | |
---|
80 | //--------------------------------------------------------------- |
---|
81 | |
---|
82 | const CDomain* CGrid::getRelDomain(void) const |
---|
83 | { |
---|
84 | return (this->domain ); |
---|
85 | } |
---|
86 | |
---|
87 | //--------------------------------------------------------------- |
---|
88 | |
---|
89 | bool CGrid::hasAxis(void) const |
---|
90 | { |
---|
91 | return (this->withAxis); |
---|
92 | } |
---|
93 | |
---|
94 | //--------------------------------------------------------------- |
---|
95 | |
---|
96 | StdSize CGrid::getDimension(void) const |
---|
97 | { |
---|
98 | return ((this->withAxis)?3:2); |
---|
99 | } |
---|
100 | |
---|
101 | //--------------------------------------------------------------- |
---|
102 | |
---|
103 | std::vector<StdSize> CGrid::getLocalShape(void) const |
---|
104 | { |
---|
105 | std::vector<StdSize> retvalue; |
---|
106 | retvalue.push_back(domain->zoom_ni_loc.getValue()); |
---|
107 | retvalue.push_back(domain->zoom_nj_loc.getValue()); |
---|
108 | if (this->withAxis) |
---|
109 | retvalue.push_back(this->axis->size.getValue()); |
---|
110 | return (retvalue); |
---|
111 | } |
---|
112 | //--------------------------------------------------------------- |
---|
113 | |
---|
114 | StdSize CGrid::getLocalSize(void) const |
---|
115 | { |
---|
116 | StdSize retvalue = 1; |
---|
117 | std::vector<StdSize> shape_ = this->getLocalShape(); |
---|
118 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
119 | retvalue *= shape_[s]; |
---|
120 | return (retvalue); |
---|
121 | } |
---|
122 | |
---|
123 | //--------------------------------------------------------------- |
---|
124 | |
---|
125 | std::vector<StdSize> CGrid::getGlobalShape(void) const |
---|
126 | { |
---|
127 | std::vector<StdSize> retvalue; |
---|
128 | retvalue.push_back(domain->ni.getValue()); |
---|
129 | retvalue.push_back(domain->nj.getValue()); |
---|
130 | if (this->withAxis) |
---|
131 | retvalue.push_back(this->axis->size.getValue()); |
---|
132 | return (retvalue); |
---|
133 | } |
---|
134 | //--------------------------------------------------------------- |
---|
135 | |
---|
136 | StdSize CGrid::getGlobalSize(void) const |
---|
137 | { |
---|
138 | StdSize retvalue = 1; |
---|
139 | std::vector<StdSize> shape_ = this->getGlobalShape(); |
---|
140 | for (StdSize s = 0; s < shape_.size(); s++) |
---|
141 | retvalue *= shape_[s]; |
---|
142 | return (retvalue); |
---|
143 | } |
---|
144 | |
---|
145 | StdSize CGrid::getDataSize(void) const |
---|
146 | { |
---|
147 | StdSize retvalue ; |
---|
148 | retvalue=domain->data_ni.getValue() ; |
---|
149 | if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ; |
---|
150 | if (this->withAxis) retvalue*=this->axis->size.getValue() ; |
---|
151 | |
---|
152 | return (retvalue); |
---|
153 | } |
---|
154 | |
---|
155 | //--------------------------------------------------------------- |
---|
156 | |
---|
157 | void CGrid::solveReference(void) |
---|
158 | { |
---|
159 | if (this->isChecked) return; |
---|
160 | CContext* context = CContext::getCurrent() ; |
---|
161 | CContextClient* client=context->client ; |
---|
162 | |
---|
163 | this->solveDomainRef() ; |
---|
164 | this->solveAxisRef() ; |
---|
165 | if (context->hasClient) |
---|
166 | { |
---|
167 | |
---|
168 | this->computeIndex() ; |
---|
169 | ARRAY_CREATE(storeIndex_ , int, 1, [0]); |
---|
170 | ARRAY_CREATE(out_l_index_, int, 1, [0]); |
---|
171 | ARRAY_CREATE(out_i_index_, int, 1, [0]); |
---|
172 | ARRAY_CREATE(out_j_index_, int, 1, [0]); |
---|
173 | |
---|
174 | this->storeIndex .push_front(storeIndex_); |
---|
175 | this->out_i_index.push_front(out_i_index_); |
---|
176 | this->out_j_index.push_front(out_j_index_); |
---|
177 | this->out_l_index.push_front(out_l_index_); |
---|
178 | } |
---|
179 | // this->computeIndexServer(); |
---|
180 | this->isChecked = true; |
---|
181 | } |
---|
182 | |
---|
183 | //--------------------------------------------------------------- |
---|
184 | |
---|
185 | void CGrid::solveDomainRef(void) |
---|
186 | { |
---|
187 | if (!domain_ref.isEmpty()) |
---|
188 | { |
---|
189 | if (CDomain::has(domain_ref.getValue())) |
---|
190 | { |
---|
191 | this->domain = CDomain::get(domain_ref.getValue()) ; |
---|
192 | domain->checkAttributes() ; |
---|
193 | } |
---|
194 | else ERROR("CGrid::solveDomainRef(void)", |
---|
195 | << "Référence au domaine incorrecte") ; |
---|
196 | } |
---|
197 | else ERROR("CGrid::solveDomainRef(void)", |
---|
198 | << "Domaine non défini") ; |
---|
199 | } |
---|
200 | |
---|
201 | //--------------------------------------------------------------- |
---|
202 | |
---|
203 | void CGrid::solveAxisRef(void) |
---|
204 | { |
---|
205 | if (!axis_ref.isEmpty()) |
---|
206 | { |
---|
207 | this->withAxis = true ; |
---|
208 | if (CAxis::get(axis_ref.getValue())) |
---|
209 | { |
---|
210 | this->axis = CAxis::get(axis_ref.getValue()) ; |
---|
211 | axis->checkAttributes() ; |
---|
212 | } |
---|
213 | else ERROR("CGrid::solveAxisRef(void)", |
---|
214 | << "Référence a l'axe incorrecte") ; |
---|
215 | } |
---|
216 | else withAxis = false ; |
---|
217 | } |
---|
218 | |
---|
219 | //--------------------------------------------------------------- |
---|
220 | |
---|
221 | void CGrid::computeIndex(void) |
---|
222 | { |
---|
223 | |
---|
224 | const int ni = domain->ni.getValue() , |
---|
225 | nj = domain->nj.getValue() , |
---|
226 | size = (this->hasAxis()) ? axis->size.getValue() : 1 ; |
---|
227 | |
---|
228 | |
---|
229 | const int data_dim = domain->data_dim.getValue() , |
---|
230 | data_n_index = domain->data_n_index.getValue() , |
---|
231 | data_ibegin = domain->data_ibegin.getValue() , |
---|
232 | data_jbegin = (data_dim == 2) |
---|
233 | ? domain->data_jbegin.getValue() : -1; |
---|
234 | |
---|
235 | ARRAY(int, 1) data_i_index = domain->data_i_index.getValue() , |
---|
236 | data_j_index = domain->data_j_index.getValue() ; |
---|
237 | |
---|
238 | |
---|
239 | ARRAY(bool, 2) mask = domain->mask.getValue() ; |
---|
240 | ARRAY(int, 2) local_mask = this->domain->getLocalMask(); |
---|
241 | |
---|
242 | int indexCount = 0; |
---|
243 | |
---|
244 | for(int l = 0; l < size ; l++) |
---|
245 | { |
---|
246 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++) |
---|
247 | { |
---|
248 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
249 | temp_j = (data_dim == 1) ? -1 |
---|
250 | : (*data_j_index)[n] + data_jbegin; |
---|
251 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
252 | : (temp_i - 1) ; |
---|
253 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
254 | : (temp_j - 1) ; |
---|
255 | |
---|
256 | if ((i >= 0 && i < ni) && |
---|
257 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
258 | indexCount++ ; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | ARRAY_ASSIGN(this->storeIndex[0] , int, 1, [indexCount]); |
---|
263 | ARRAY_ASSIGN(this->out_l_index[0], int, 1, [indexCount]); |
---|
264 | ARRAY_ASSIGN(this->out_i_index[0], int, 1, [indexCount]); |
---|
265 | ARRAY_ASSIGN(this->out_j_index[0], int, 1, [indexCount]); |
---|
266 | |
---|
267 | ARRAY_ASSIGN(storeIndex_client,int,1,[indexCount]); |
---|
268 | ARRAY_ASSIGN(out_i_client,int,1,[indexCount]); |
---|
269 | ARRAY_ASSIGN(out_j_client,int,1,[indexCount]); |
---|
270 | ARRAY_ASSIGN(out_l_client,int,1,[indexCount]); |
---|
271 | |
---|
272 | |
---|
273 | for(int count = 0, indexCount = 0, l = 0; l < size; l++) |
---|
274 | { |
---|
275 | for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) |
---|
276 | { |
---|
277 | int temp_i = (*data_i_index)[n] + data_ibegin, |
---|
278 | temp_j = (data_dim == 1) ? -1 |
---|
279 | : (*data_j_index)[n] + data_jbegin; |
---|
280 | i = (data_dim == 1) ? (temp_i - 1) % ni |
---|
281 | : (temp_i - 1) ; |
---|
282 | j = (data_dim == 1) ? (temp_i - 1) / ni |
---|
283 | : (temp_j - 1) ; |
---|
284 | |
---|
285 | if ((i >= 0 && i < ni) && |
---|
286 | (j >= 0 && j < nj) && (*mask)[i][j]) |
---|
287 | { |
---|
288 | (*this->storeIndex[0]) [indexCount] = count ; |
---|
289 | (*this->out_l_index[0])[indexCount] = l ; |
---|
290 | (*this->out_i_index[0])[indexCount] = i ; |
---|
291 | (*this->out_j_index[0])[indexCount] = j ; |
---|
292 | |
---|
293 | (*storeIndex_client)[indexCount] = count ; |
---|
294 | (*out_i_client)[indexCount]=i+domain->ibegin_client-1 ; |
---|
295 | (*out_j_client)[indexCount]=j+domain->jbegin_client-1 ; |
---|
296 | (*out_l_client)[indexCount]=l ; |
---|
297 | indexCount++ ; |
---|
298 | } |
---|
299 | } |
---|
300 | } |
---|
301 | sendIndex() ; |
---|
302 | |
---|
303 | |
---|
304 | } |
---|
305 | |
---|
306 | //---------------------------------------------------------------- |
---|
307 | |
---|
308 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
309 | { |
---|
310 | StdString new_id = StdString("__") + domain->getId() + StdString("__") ; |
---|
311 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
312 | grid->domain_ref.setValue(domain->getId()); |
---|
313 | return (grid); |
---|
314 | } |
---|
315 | |
---|
316 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
317 | { |
---|
318 | StdString new_id = StdString("__") + domain->getId() + |
---|
319 | StdString("_") + axis->getId() + StdString("__") ; |
---|
320 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; |
---|
321 | grid->domain_ref.setValue(domain->getId()); |
---|
322 | grid->axis_ref.setValue(axis->getId()); |
---|
323 | return (grid); |
---|
324 | } |
---|
325 | |
---|
326 | //---------------------------------------------------------------- |
---|
327 | |
---|
328 | void CGrid::outputField(int rank, const ARRAY(double, 1) stored, ARRAY(double, 3) field) |
---|
329 | { |
---|
330 | ARRAY(int,1) out_i=out_i_fromClient[rank] ; |
---|
331 | ARRAY(int,1) out_j=out_j_fromClient[rank] ; |
---|
332 | ARRAY(int,1) out_l=out_l_fromClient[rank] ; |
---|
333 | |
---|
334 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
335 | (*field)[(*out_i)[n]][(*out_j)[n]][(*out_l)[n]] = (*stored)[n] ; |
---|
336 | } |
---|
337 | |
---|
338 | void CGrid::outputField(int rank, const ARRAY(double, 1) stored, ARRAY(double, 2) field) |
---|
339 | { |
---|
340 | ARRAY(int,1) out_i=out_i_fromClient[rank] ; |
---|
341 | ARRAY(int,1) out_j=out_j_fromClient[rank] ; |
---|
342 | |
---|
343 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
344 | (*field)[(*out_i)[n]][(*out_j)[n]] = (*stored)[n] ; |
---|
345 | } |
---|
346 | |
---|
347 | //--------------------------------------------------------------- |
---|
348 | |
---|
349 | void CGrid::outputField(int rank,const ARRAY(double, 1) stored, ARRAY(double, 1) field) |
---|
350 | { |
---|
351 | ARRAY(int,1) out_i = out_i_fromClient[rank] ; |
---|
352 | for(StdSize n = 0; n < stored->num_elements(); n++) |
---|
353 | (*field)[(*out_i)[n]] = (*stored)[n] ; |
---|
354 | } |
---|
355 | |
---|
356 | //---------------------------------------------------------------- |
---|
357 | |
---|
358 | |
---|
359 | void CGrid::storeField_arr |
---|
360 | (const double * const data, ARRAY(double, 1) stored) const |
---|
361 | { |
---|
362 | const StdSize size = (this->storeIndex_client)->num_elements() ; |
---|
363 | |
---|
364 | stored->resize(boost::extents[size]) ; |
---|
365 | for(StdSize i = 0; i < size; i++) |
---|
366 | (*stored)[i] = data[(*storeIndex_client)[i]] ; |
---|
367 | } |
---|
368 | |
---|
369 | //--------------------------------------------------------------- |
---|
370 | |
---|
371 | void CGrid::toBinary (StdOStream & os) const |
---|
372 | { |
---|
373 | SuperClass::toBinary(os); |
---|
374 | |
---|
375 | os.write (reinterpret_cast<const char*>(&this->isChecked), sizeof(bool)); |
---|
376 | |
---|
377 | if (this->isChecked) |
---|
378 | { |
---|
379 | this->storeIndex [0]->toBinary(os); |
---|
380 | this->out_i_index[0]->toBinary(os); |
---|
381 | this->out_j_index[0]->toBinary(os); |
---|
382 | this->out_l_index[0]->toBinary(os); |
---|
383 | } |
---|
384 | } |
---|
385 | |
---|
386 | //--------------------------------------------------------------- |
---|
387 | |
---|
388 | void CGrid::fromBinary(StdIStream & is) |
---|
389 | { |
---|
390 | bool hasIndex = false; |
---|
391 | SuperClass::fromBinary(is); |
---|
392 | is.read (reinterpret_cast<char*>(&hasIndex), sizeof(bool)); |
---|
393 | |
---|
394 | if (hasIndex) |
---|
395 | { |
---|
396 | ARRAY_CREATE(storeIndex_ , int, 1, [0]); |
---|
397 | ARRAY_CREATE(out_l_index_, int, 1, [0]); |
---|
398 | ARRAY_CREATE(out_i_index_, int, 1, [0]); |
---|
399 | ARRAY_CREATE(out_j_index_, int, 1, [0]); |
---|
400 | |
---|
401 | storeIndex_ ->fromBinary(is); |
---|
402 | out_i_index_->fromBinary(is); |
---|
403 | out_j_index_->fromBinary(is); |
---|
404 | out_l_index_->fromBinary(is); |
---|
405 | |
---|
406 | this->storeIndex .push_back(storeIndex_); |
---|
407 | this->out_i_index.push_back(out_i_index_); |
---|
408 | this->out_j_index.push_back(out_j_index_); |
---|
409 | this->out_l_index.push_back(out_l_index_); |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | //--------------------------------------------------------------- |
---|
414 | void CGrid::sendIndex(void) |
---|
415 | { |
---|
416 | CContext* context = CContext::getCurrent() ; |
---|
417 | CContextClient* client=context->client ; |
---|
418 | |
---|
419 | CEventClient event(getType(),EVENT_ID_INDEX) ; |
---|
420 | int rank ; |
---|
421 | list<shared_ptr<CMessage> > list_msg ; |
---|
422 | list<ARRAY(int,1) > list_out_i,list_out_j,list_out_l ; |
---|
423 | |
---|
424 | for(int ns=0;ns<domain->connectedServer.size();ns++) |
---|
425 | { |
---|
426 | rank=domain->connectedServer[ns] ; |
---|
427 | int ib=domain->ib_srv[ns] ; |
---|
428 | int ie=domain->ie_srv[ns] ; |
---|
429 | int jb=domain->jb_srv[ns] ; |
---|
430 | int je=domain->je_srv[ns] ; |
---|
431 | |
---|
432 | int i,j ; |
---|
433 | int nb=0 ; |
---|
434 | for(int k=0;k<storeIndex_client->num_elements();k++) |
---|
435 | { |
---|
436 | i=(*out_i_client)[k] ; |
---|
437 | j=(*out_j_client)[k] ; |
---|
438 | if (i>=ib-1 && i<=ie-1 && j>=jb-1 && j<=je-1) nb++ ; |
---|
439 | } |
---|
440 | |
---|
441 | ARRAY_CREATE(storeIndex,int,1,[nb]) ; |
---|
442 | ARRAY_CREATE(out_i,int,1,[nb]) ; |
---|
443 | ARRAY_CREATE(out_j,int,1,[nb]) ; |
---|
444 | ARRAY_CREATE(out_l,int,1,[nb]) ; |
---|
445 | |
---|
446 | nb=0 ; |
---|
447 | for(int k=0;k<storeIndex_client->num_elements();k++) |
---|
448 | { |
---|
449 | i=(*out_i_client)[k] ; |
---|
450 | j=(*out_j_client)[k] ; |
---|
451 | if (i>=ib-1 && i<=ie-1 && j>=jb-1 && j<=je-1) |
---|
452 | { |
---|
453 | (*storeIndex)[nb]=k ; |
---|
454 | (*out_i)[nb]=(*out_i_client)[k] ; |
---|
455 | (*out_j)[nb]=(*out_j_client)[k] ; |
---|
456 | (*out_l)[nb]=(*out_l_client)[k] ; |
---|
457 | nb++ ; |
---|
458 | } |
---|
459 | } |
---|
460 | |
---|
461 | storeIndex_toSrv.insert(pair<int,ARRAY(int,1) >(rank,storeIndex)) ; |
---|
462 | nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; |
---|
463 | list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; |
---|
464 | list_out_i.push_back(out_i) ; |
---|
465 | list_out_j.push_back(out_j) ; |
---|
466 | list_out_l.push_back(out_l) ; |
---|
467 | |
---|
468 | *list_msg.back()<<getId()<<list_out_i.back()<<list_out_j.back()<<list_out_l.back() ; |
---|
469 | event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; |
---|
470 | } |
---|
471 | client->sendEvent(event) ; |
---|
472 | } |
---|
473 | |
---|
474 | void CGrid::recvIndex(CEventServer& event) |
---|
475 | { |
---|
476 | list<CEventServer::SSubEvent>::iterator it ; |
---|
477 | for (it=event.subEvents.begin();it!=event.subEvents.end();++it) |
---|
478 | { |
---|
479 | int rank=it->rank; |
---|
480 | CBufferIn* buffer=it->buffer; |
---|
481 | string domainId ; |
---|
482 | *buffer>>domainId ; |
---|
483 | get(domainId)->recvIndex(rank,*buffer) ; |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | void CGrid::recvIndex(int rank, CBufferIn& buffer) |
---|
488 | { |
---|
489 | ARRAY_CREATE(out_i,int,1,[0]) ; |
---|
490 | ARRAY_CREATE(out_j,int,1,[0]) ; |
---|
491 | ARRAY_CREATE(out_l,int,1,[0]) ; |
---|
492 | |
---|
493 | buffer>>out_i>>out_j>>out_l ; |
---|
494 | int offset ; |
---|
495 | |
---|
496 | offset=domain->zoom_ibegin_srv-1 ; |
---|
497 | for(int k=0;k<out_i->num_elements();k++) (*out_i)[k]=(*out_i)[k]-offset ; |
---|
498 | |
---|
499 | offset=domain->zoom_jbegin_srv-1 ; |
---|
500 | for(int k=0;k<out_i->num_elements();k++) (*out_j)[k]=(*out_j)[k]-offset ; |
---|
501 | |
---|
502 | out_i_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_i)) ; |
---|
503 | out_j_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_j)) ; |
---|
504 | out_l_fromClient.insert(pair< int,ARRAY(int,1) >(rank,out_l)) ; |
---|
505 | } |
---|
506 | |
---|
507 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
508 | { |
---|
509 | |
---|
510 | if (SuperClass::dispatchEvent(event)) return true ; |
---|
511 | else |
---|
512 | { |
---|
513 | switch(event.type) |
---|
514 | { |
---|
515 | case EVENT_ID_INDEX : |
---|
516 | recvIndex(event) ; |
---|
517 | return true ; |
---|
518 | break ; |
---|
519 | |
---|
520 | default : |
---|
521 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
522 | <<"Unknown Event") ; |
---|
523 | return false ; |
---|
524 | } |
---|
525 | } |
---|
526 | } |
---|
527 | |
---|
528 | |
---|
529 | /* |
---|
530 | void CGrid::computeIndexServer(void) |
---|
531 | { |
---|
532 | ARRAY(int, 2) local_mask = this->domain->getLocalMask(); |
---|
533 | |
---|
534 | const std::vector<int> & ibegin = this->domain->getIBeginSub(); |
---|
535 | const std::vector<int> & jbegin = this->domain->getJBeginSub(); |
---|
536 | const std::vector<int> & iend = this->domain->getIEndSub(); |
---|
537 | const std::vector<int> & jend = this->domain->getJEndSub(); |
---|
538 | const std::vector<int> & ibegin_zoom = this->domain->getIBeginZoomSub(); |
---|
539 | const std::vector<int> & jbegin_zoom = this->domain->getJBeginZoomSub(); |
---|
540 | const std::vector<int> & ni_zoom = this->domain->getNiZoomSub(); |
---|
541 | const std::vector<int> & nj_zoom = this->domain->getNjZoomSub(); |
---|
542 | |
---|
543 | const int ibegin_srv = this->domain->ibegin.getValue(); |
---|
544 | const int jbegin_srv = this->domain->jbegin.getValue(); |
---|
545 | const int iend_srv = this->domain->iend.getValue(); |
---|
546 | const int jend_srv = this->domain->jend.getValue(); |
---|
547 | const int zoom_ni_srv = this->domain->zoom_ni_loc.getValue(); |
---|
548 | const int zoom_nj_srv = this->domain->zoom_nj_loc.getValue(); |
---|
549 | |
---|
550 | const int ibegin_zoom_srv = this->domain->zoom_ibegin_loc.getValue(); |
---|
551 | const int jbegin_zoom_srv = this->domain->zoom_jbegin_loc.getValue(); |
---|
552 | const int iend_zoom_srv = ibegin_zoom_srv + zoom_ni_srv-1 ; |
---|
553 | const int jend_zoom_srv = jbegin_zoom_srv + zoom_nj_srv-1 ; |
---|
554 | |
---|
555 | StdSize dn = 0; |
---|
556 | for (StdSize j = 1; j < this->out_i_index.size(); j++) |
---|
557 | dn += this->out_i_index[j]->size(); |
---|
558 | |
---|
559 | ARRAY_CREATE(storeIndex_srv , int, 1, [dn]); |
---|
560 | ARRAY_CREATE(out_i_index_srv, int, 1, [dn]); |
---|
561 | ARRAY_CREATE(out_j_index_srv, int, 1, [dn]); |
---|
562 | ARRAY_CREATE(out_l_index_srv, int, 1, [dn]); |
---|
563 | |
---|
564 | for (StdSize i = 0, dn = 0; i < ibegin.size(); i++) |
---|
565 | { |
---|
566 | ARRAY(int, 1) storeIndex_cl = this->storeIndex [i + 1]; |
---|
567 | ARRAY(int, 1) out_i_index_cl = this->out_i_index[i + 1]; |
---|
568 | ARRAY(int, 1) out_j_index_cl = this->out_j_index[i + 1]; |
---|
569 | ARRAY(int, 1) out_l_index_cl = this->out_l_index[i + 1]; |
---|
570 | |
---|
571 | int ibegin_zoom_cl = ibegin[i]; //ibegin_zoom[i]; |
---|
572 | int jbegin_zoom_cl = jbegin[i]; //jbegin_zoom[i]; |
---|
573 | int iend_zoom_cl = iend[i]; //ibegin_zoom[i]; |
---|
574 | int jend_zoom_cl = jend[i]; //jbegin_zoom[i]; |
---|
575 | |
---|
576 | int ibegin_cl = ibegin[i]; //ibegin[i]; |
---|
577 | int jbegin_cl = jbegin[i]; //jbegin[i]; |
---|
578 | int iend_cl = iend[i]; //ibegin[i]; |
---|
579 | int jend_cl = jend[i]; //jbegin[i]; |
---|
580 | |
---|
581 | if (ibegin_zoom.size() != 0) |
---|
582 | { |
---|
583 | ibegin_zoom_cl = ibegin_zoom[i]; |
---|
584 | jbegin_zoom_cl = jbegin_zoom[i]; |
---|
585 | iend_zoom_cl = ibegin_zoom[i]+ni_zoom[i]-1; |
---|
586 | jend_zoom_cl = jbegin_zoom[i]+nj_zoom[i]-1; |
---|
587 | } |
---|
588 | |
---|
589 | |
---|
590 | if (comm::CMPIManager::IsClient()) |
---|
591 | { |
---|
592 | for (StdSize n = dn, m = 0; n < (dn + storeIndex_cl->size()); n++, m++) |
---|
593 | { |
---|
594 | (*storeIndex_srv)[n] = (*storeIndex_cl)[m]; // Faux mais inutile dans le cas serveur. |
---|
595 | |
---|
596 | (*out_i_index_srv)[n] = (*out_i_index_cl)[m] + ibegin_cl - 1 - (ibegin_srv + ibegin_zoom_srv - 1) + 1 ; |
---|
597 | (*out_j_index_srv)[n] = (*out_j_index_cl)[m] + jbegin_cl - 1 - (jbegin_srv + jbegin_zoom_srv - 1) + 1 ; |
---|
598 | (*out_l_index_srv)[n] = (*out_l_index_cl)[m]; |
---|
599 | } |
---|
600 | } |
---|
601 | else |
---|
602 | { |
---|
603 | for (StdSize n = dn, m = 0; n < (dn + storeIndex_cl->size()); n++, m++) |
---|
604 | { |
---|
605 | (*storeIndex_srv)[n] = (*storeIndex_cl)[m]; // Faux mais inutile dans le cas serveur. |
---|
606 | (*out_i_index_srv)[n] = (*out_i_index_cl)[m] |
---|
607 | + (ibegin_cl - 1) - (ibegin_srv - 1) + (ibegin_zoom_cl - 1) - (ibegin_zoom_srv - 1); |
---|
608 | (*out_j_index_srv)[n] = (*out_j_index_cl)[m] |
---|
609 | + (jbegin_cl - 1) - (jbegin_srv - 1) + (jbegin_zoom_cl - 1) - (jbegin_zoom_srv - 1); |
---|
610 | (*out_l_index_srv)[n] = (*out_l_index_cl)[m]; |
---|
611 | } |
---|
612 | |
---|
613 | } |
---|
614 | |
---|
615 | dn += storeIndex_cl->size(); |
---|
616 | } |
---|
617 | |
---|
618 | if (storeIndex_srv->size() != 0) |
---|
619 | { |
---|
620 | const int ibegin_t = |
---|
621 | *std::min_element(out_i_index_srv->begin(), out_i_index_srv->end()); |
---|
622 | const int iend_t = |
---|
623 | *std::max_element(out_i_index_srv->begin(), out_i_index_srv->end()); |
---|
624 | const int jbegin_t = |
---|
625 | *std::min_element(out_j_index_srv->begin(), out_j_index_srv->end()); |
---|
626 | const int jend_t = |
---|
627 | *std::max_element(out_j_index_srv->begin(), out_j_index_srv->end()); |
---|
628 | |
---|
629 | |
---|
630 | if ((ibegin_t < 0) || (jbegin_t < 0) || |
---|
631 | (iend_t >= zoom_ni_srv) || (jend_t >= zoom_nj_srv)) |
---|
632 | { |
---|
633 | ERROR("CGrid::computeIndexServer(void)", |
---|
634 | << "[ grille = " << this->getId() |
---|
635 | << ", ibegin_t = " << ibegin_t |
---|
636 | << ", jbegin_t = " << jbegin_t |
---|
637 | << ", iend_t = " << iend_t |
---|
638 | << ", jend_t = " << jend_t |
---|
639 | << ", zoom_ni_srv = " << zoom_ni_srv |
---|
640 | << ", zoom_nj_srv = " << zoom_nj_srv |
---|
641 | << ", nb subdomain = " << out_i_index.size()-1 |
---|
642 | <<" ] Erreur d'indexation de la grille au niveau du serveur") ; |
---|
643 | } |
---|
644 | } |
---|
645 | |
---|
646 | if (storeIndex_srv->size() != 0) |
---|
647 | for (StdSize u = 0; u < storeIndex_srv->size(); u++) |
---|
648 | (*local_mask)[(*out_i_index_srv)[u]][(*out_j_index_srv)[u]] = 1; |
---|
649 | |
---|
650 | // StdOFStream ofs(("log_server_"+this->getId()).c_str()); |
---|
651 | // for (StdSize h = 0; h < storeIndex_srv->size(); h++) |
---|
652 | // { |
---|
653 | // ofs << "(" << (*storeIndex_srv)[h] << ";" |
---|
654 | // << (*out_i_index_srv)[h] << "," |
---|
655 | // << (*out_j_index_srv)[h] << "," |
---|
656 | // << (*out_l_index_srv)[h] << ")" << std::endl; |
---|
657 | // } |
---|
658 | // ofs.close(); |
---|
659 | |
---|
660 | this->storeIndex [0] = storeIndex_srv ; |
---|
661 | this->out_i_index[0] = out_i_index_srv; |
---|
662 | this->out_j_index[0] = out_j_index_srv; |
---|
663 | this->out_l_index[0] = out_l_index_srv; |
---|
664 | } |
---|
665 | */ |
---|
666 | |
---|
667 | void CGrid::inputFieldServer |
---|
668 | (const std::deque<ARRAY(double, 1)> storedClient, |
---|
669 | ARRAY(double, 1) storedServer) const |
---|
670 | { |
---|
671 | if ((this->storeIndex.size()-1 ) != storedClient.size()) |
---|
672 | ERROR("CGrid::inputFieldServer(...)", |
---|
673 | << "[ Nombre de tableau attendu = " << (this->storeIndex.size()-1) << ", " |
---|
674 | << "[ Nombre de tableau reçu = " << storedClient.size() << "] " |
---|
675 | << "Les données d'un client sont manquantes !") ; |
---|
676 | if (storedServer.get() != NULL) |
---|
677 | storedServer->resize(boost::extents[this->storeIndex[0]->num_elements()]); |
---|
678 | else |
---|
679 | ARRAY_ASSIGN(storedServer, double, 1, [this->storeIndex[0]->num_elements()]); |
---|
680 | |
---|
681 | for (StdSize i = 0, n = 0; i < storedClient.size(); i++) |
---|
682 | for (StdSize j = 0; j < storedClient[i]->num_elements(); j++) |
---|
683 | (*storedServer)[n++] = (*storedClient[i])[j]; |
---|
684 | } |
---|
685 | |
---|
686 | void CGrid::outputFieldToServer(ARRAY(double, 1) fieldIn, int rank, ARRAY(double, 1) fieldOut) |
---|
687 | { |
---|
688 | ARRAY(int,1) index=storeIndex_toSrv[rank] ; |
---|
689 | int nb=index->num_elements() ; |
---|
690 | fieldOut->resize(extents[nb]) ; |
---|
691 | |
---|
692 | for(int k=0;k<nb;k++) (*fieldOut)[k]=(*fieldIn)[(*index)[k]] ; |
---|
693 | } |
---|
694 | ///--------------------------------------------------------------- |
---|
695 | |
---|
696 | } // namespace xios |
---|