Memosa-FVM  0.2
Field.cpp
Go to the documentation of this file.
1 // This file os part of FVM
2 // Copyright (c) 2012 FVM Authors
3 // See LICENSE file for terms.
4 
5 #ifdef FVM_PARALLEL
6 #include <mpi.h>
7 #endif
8 
9 #include "Field.h"
10 #include "ArrayBase.h"
11 #include "StorageSite.h"
12 #include "Array.h"
13 #include "OneToOneIndexMap.h"
14 #include <iostream>
15 
16 
17 #include <vector>
18 #include "Vector.h"
19 
20 using namespace std;
21 
22 Field::Field(const string& name):
23  IContainer(),
24  _name(name),
25  _arrays()
26 {
27  logCtor();
28 }
29 
31 {
32  logDtor();
33 }
34 
35 
36 bool
38 {
39  return ((_arrays.find(&s) != _arrays.end()) ||
40  (s.getParent() && (_arrays.find(s.getParent()) != _arrays.end())));
41 }
42 
43 const ArrayBase&
45 {
46  ArrayMap::const_iterator pos = _arrays.find(&s);
47  if (pos != _arrays.end())
48  return *pos->second;
49  return const_cast<Field&>(*this)._create(s);
50 }
51 
52 ArrayBase&
54 {
55  ArrayMap::iterator pos = _arrays.find(&s);
56  if (pos != _arrays.end())
57  return *pos->second;
58 
59  return _create(s);
60 }
61 
62 shared_ptr<ArrayBase>
64 {
65  if (_arrays.find(&s) == _arrays.end())
66  _create(s);
67 
68  return _arrays[&s];
69 }
70 
71 void
72 Field::addArray(const StorageSite& s, shared_ptr<ArrayBase> a)
73 {
74  removeArray(s);
75  _arrays[&s]=a;
76 }
77 
78 void
80 {
81  if (_childSitesMap.find(&s) != _childSitesMap.end())
82  {
83  vector<const StorageSite*>& childSites = *_childSitesMap[&s];
84  foreach (const StorageSite* site,childSites)
85  {
86  removeArray(*site);
87  }
88  delete &childSites;
89  _childSitesMap.erase(&s);
90 
91  }
92  _arrays.erase(&s);
93 }
94 
95 void
97 {
98  foreach(const StorageSite* s, sites)
99  {
100  removeArray(*s);
101  }
102 }
103 
104 void
106 {
107  _arrays.clear();
108  _childSitesMap.clear();
109  _ghostArrays.clear();
110  _ghostArraysLevel1.clear();
111 }
112 
113 ArrayBase&
115 {
116  const StorageSite* parentSite = s.getParent();
117  if (parentSite)
118  {
119  ArrayBase& parentArray = operator[](*parentSite);
120  shared_ptr<ArrayBase> anew = parentArray.createOffsetArray(s.getOffset(),
121  s.getCount());
122  _arrays[&s]=anew;
123 
124  if (_childSitesMap.find(parentSite) == _childSitesMap.end())
125  _childSitesMap[parentSite] = new vector<const StorageSite*>();
126 
127  vector<const StorageSite*>& childSites = *_childSitesMap[parentSite];
128  childSites.push_back(&s);
129  return *anew;
130  }
131  else
132  {
133  ostringstream e;
134  e << "Field::operator[] No array found and no creator defined for "
135  << &s << endl;
136  throw CException(e.str());
137  }
138 }
139 
140 shared_ptr<IContainer>
142 {
143  shared_ptr<Field> c(new Field(_name));
144 
145  foreach(const ArrayMap::value_type& pos, _arrays)
146  {
147  c->addArray(*(pos.first),
148  dynamic_pointer_cast<ArrayBase>(pos.second->newClone()));
149  }
150  return c;
151 }
152 
153 
154 shared_ptr<IContainer>
156 {
157  shared_ptr<Field> c(new Field(_name));
158  foreach(const ArrayMap::value_type& pos, _arrays)
159  {
160  c->addArray(*(pos.first),
161  dynamic_pointer_cast<ArrayBase>(pos.second->newCopy()));
162  }
163  return c;
164 }
165 
166 
167 void
169 {
170  foreach(ArrayMap::value_type& pos, _arrays)
171  {
172  pos.second->zero();
173  }
174 }
175 
176 Field&
177 Field::operator=(const Field& oField)
178 {
179  foreach(ArrayMap::value_type& pos, _arrays)
180  {
181  *pos.second = oField[*pos.first];
182  }
183  return *this;
184 }
185 
186 void
188 {
189  const Field& other = dynamic_cast<const Field&>(oc);
190  operator=(other);
191 }
192 
193 
194 void
196 {
197  ArrayBase& thisArray = operator[](site);
198 
199  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
200 
201  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
202  {
203  const StorageSite& oSite = *mpos.first;
204  EntryIndex e(&oSite, &site);
205  const Array<int>& toIndices = *(mpos.second);
206  if (_ghostArrays.find(e) == _ghostArrays.end())
207  {
208  _ghostArrays[e] = thisArray.newSizedClone(toIndices.getLength());
209  }
210  }
211 }
212 
213 void
215 {
216  ArrayBase& thisArray = operator[](site);
217 
218  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
219 
220  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
221  {
222  const StorageSite& oSite = *mpos.first;
223  EntryIndex e(&oSite, &site);
224  const Array<int>& toIndices = *(mpos.second);
225  if (_ghostArraysLevel1.find(e) == _ghostArraysLevel1.end())
226  {
227  _ghostArraysLevel1[e] = thisArray.newSizedClone(toIndices.getLength());
228  }
229  }
230 }
231 
232 
233 void
235 {
236  const ArrayBase& thisArray = operator[](site);
237 
238  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
239 
240  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap)
241  {
242  const StorageSite& oSite = *mpos.first;
243  EntryIndex e(&site, &oSite);
244  const Array<int>& fromIndices = *(mpos.second);
245  if (_ghostArrays.find(e) == _ghostArrays.end()){
246  _ghostArrays[e] = thisArray.newSizedClone( fromIndices.getLength() );
247  }
248 
249  ArrayBase& ghostArray = *_ghostArrays[e];
250  thisArray.scatter(ghostArray,fromIndices);
251 
252  }
253 }
254 
255 
256 void
258 {
259  const ArrayBase& thisArray = operator[](site);
260 
261  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
262 
263  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap)
264  {
265  const StorageSite& oSite = *mpos.first;
266  EntryIndex e(&site, &oSite);
267  const Array<int>& fromIndices = *(mpos.second);
268  if (_ghostArraysLevel1.find(e) == _ghostArraysLevel1.end()){
269  _ghostArraysLevel1[e] = thisArray.newSizedClone( fromIndices.getLength() );
270  }
271 
272  ArrayBase& ghostArray = *_ghostArraysLevel1[e];
273  thisArray.scatter(ghostArray,fromIndices);
274 
275  }
276 }
277 
278 
279 void
281 {
282  ArrayBase& thisArray = operator[](site);
283 
284  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
285 
286  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
287  {
288  const StorageSite& oSite = *mpos.first;
289  const Array<int>& toIndices = *(mpos.second);
290  EntryIndex e(&oSite, &site);
291 
292  if (_ghostArrays.find(e) == _ghostArrays.end())
293  {
294  ostringstream e;
295  e << "Field::syncScatter: ghost array not found for"
296  << &oSite << endl;
297  throw CException(e.str());
298  }
299 
300  const ArrayBase& ghostArray = *_ghostArrays[e];
301  thisArray.gather(ghostArray,toIndices);
302  }
303 }
304 
305 
306 void
308 {
309  ArrayBase& thisArray = operator[](site);
310 
311  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
312 
313  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
314  {
315  const StorageSite& oSite = *mpos.first;
316  const Array<int>& toIndices = *(mpos.second);
317  EntryIndex e(&oSite, &site);
318 
319  if (_ghostArraysLevel1.find(e) == _ghostArraysLevel1.end())
320  {
321  ostringstream e;
322  e << "Field::syncScatter: ghost array not found for"
323  << &oSite << endl;
324  throw CException(e.str());
325  }
326 
327  const ArrayBase& ghostArray = *_ghostArraysLevel1[e];
328  thisArray.gather(ghostArray,toIndices);
329  }
330 }
331 
332 
333 void
335 {
336  // scatter first (prepare ship packages)
337  foreach(ArrayMap::value_type& pos, _arrays)
338  syncScatter(*pos.first);
339 
340  foreach(ArrayMap::value_type& pos, _arrays)
341  createSyncGatherArrays(*pos.first);
342 
343 #ifdef FVM_PARALLEL
344  //SENDING
345  MPI::Request request_send[ get_request_size() ];
346  MPI::Request request_recv[ get_request_size() ];
347  int indxSend = 0;
348  int indxRecv = 0;
349  foreach(ArrayMap::value_type& pos, _arrays){
350  const StorageSite& site = *pos.first;
351  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
352  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
353  const StorageSite& oSite = *mpos.first;
354  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
355  EntryIndex e(&site,&oSite);
356  ArrayBase& sendArray = *_ghostArrays[e];
357  int to_where = oSite.getGatherProcID();
358  if ( to_where != -1 ){
359  int mpi_tag = oSite.getTag();
360  request_send[indxSend++] =
361  MPI::COMM_WORLD.Isend( sendArray.getData(), sendArray.getDataSize(), MPI::BYTE, to_where, mpi_tag );
362  }
363  }
364  //RECIEVING
365  //getting values from other meshes to fill g
366  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
367  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
368  const StorageSite& oSite = *mpos.first;
369  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
370  EntryIndex e(&oSite,&site);
371  ArrayBase& recvArray = *_ghostArrays[e];
372  int from_where = oSite.getGatherProcID();
373  if ( from_where != -1 ){
374  int mpi_tag = oSite.getTag();
375  request_recv[indxRecv++] =
376  MPI::COMM_WORLD.Irecv( recvArray.getData(), recvArray.getDataSize(), MPI::BYTE, from_where, mpi_tag );
377  }
378  }
379  }
380 
381  int count = get_request_size();
382  MPI::Request::Waitall( count, request_recv );
383  MPI::Request::Waitall( count, request_send );
384 #endif
385 
386  // gather
387  foreach(ArrayMap::value_type& pos, _arrays)
388  syncGather(*pos.first);
389 
390 
391  //sycnLocal1
392  syncLocalLevel1();
393 
394 }
395 
396 int
398 {
399  int indx = 0;
400  foreach(ArrayMap::value_type& pos, _arrays){
401  const StorageSite& site = *pos.first;
402  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
403  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
404  const StorageSite& oSite = *mpos.first;
405  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
406  if ( oSite.getGatherProcID() != -1 )
407  indx++;
408  }
409  }
410  return indx;
411 
412 }
413 
414 
415 
416 void
418 {
419 
420  // scatter first (prepare ship packages)
421  foreach(ArrayMap::value_type& pos, _arrays){
422  if ( pos.second->getLength() == pos.first->getCountLevel1() )
423  syncScatterLevel1(*pos.first);
424  }
425 
426  foreach(ArrayMap::value_type& pos, _arrays){
427  if ( pos.second->getLength() == pos.first->getCountLevel1() )
428  createSyncGatherArraysLevel1(*pos.first);
429  }
430 
431 #ifdef FVM_PARALLEL
432  //SENDING
433  int countScatter = get_request_size_scatter_level1();
434  int countGather = get_request_size_gather_level1();
435  MPI::Request request_send[ countScatter ];
436  MPI::Request request_recv[ countGather ];
437  int indxSend = 0;
438  int indxRecv = 0;
439  foreach(ArrayMap::value_type& pos, _arrays){
440  const StorageSite& site = *pos.first;
441  if ( pos.second->getLength() == pos.first->getCountLevel1() ){
442  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
443  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
444  const StorageSite& oSite = *mpos.first;
445  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
446  EntryIndex e(&site,&oSite);
447  ArrayBase& sendArray = *_ghostArraysLevel1[e];
448  int to_where = oSite.getGatherProcID();
449  if ( to_where != -1 ){
450  int mpi_tag = oSite.getTag();
451  request_send[indxSend++] =
452  MPI::COMM_WORLD.Isend( sendArray.getData(), sendArray.getDataSize(), MPI::BYTE, to_where, mpi_tag );
453  }
454  }
455  //RECIEVING
456  //getting values from other meshes to fill g
457  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
458  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
459  const StorageSite& oSite = *mpos.first;
460  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
461  EntryIndex e(&oSite,&site);
462  ArrayBase& recvArray = *_ghostArraysLevel1[e];
463  int from_where = oSite.getGatherProcID();
464  if ( from_where != -1 ){
465  int mpi_tag = oSite.getTag();
466  request_recv[indxRecv++] =
467  MPI::COMM_WORLD.Irecv( recvArray.getData(), recvArray.getDataSize(), MPI::BYTE, from_where, mpi_tag );
468  }
469  }
470 
471  }
472  }
473 
474  MPI::Request::Waitall( countGather, request_recv );
475  MPI::Request::Waitall( countScatter, request_send );
476 #endif
477 
478  // gather
479  foreach(ArrayMap::value_type& pos, _arrays){
480  if ( pos.second->getLength() == pos.first->getCountLevel1() )
481  syncGatherLevel1(*pos.first);
482  }
483 }
484 
485 int
487 {
488  int indx = 0;
489  foreach(ArrayMap::value_type& pos, _arrays){
490  const StorageSite& site = *pos.first;
491  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
492  if ( pos.second->getLength() == pos.first->getCountLevel1() ){
493  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
494  const StorageSite& oSite = *mpos.first;
495  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
496  if ( oSite.getGatherProcID() != -1 )
497  indx++;
498  }
499  }
500  }
501  return indx;
502 
503 }
504 
505 int
507 {
508  int indx = 0;
509  foreach(ArrayMap::value_type& pos, _arrays){
510  const StorageSite& site = *pos.first;
511  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
512  if ( pos.second->getLength() == pos.first->getCountLevel1() ){
513  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
514  const StorageSite& oSite = *mpos.first;
515  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
516  if ( oSite.getGatherProcID() != -1 )
517  indx++;
518  }
519  }
520  }
521  return indx;
522 
523 }
524 
525 
526 //only for one field need to be communicated
527 void
528 Field::createSyncGatherArraysVectorFields(const StorageSite& site, Field& field, const size_t numDir)
529 {
530  ArrayBase& thisArray = field[site];
531  GhostArrayMap& ghostArrays = field.getGhostArrayMap();
532 
533  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
534 
535  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
536  {
537  const StorageSite& oSite = *mpos.first;
538  EntryIndex e(&oSite, &site);
539  const Array<int>& toIndices = *(mpos.second);
540  if (ghostArrays.find(e) == ghostArrays.end())
541  {
542  ghostArrays[e] = thisArray.newSizedClone(toIndices.getLength() * numDir);
543  }
544  }
545 }
546 
547 void
548 Field::createSyncGatherArraysVectorFieldsLevel1(const StorageSite& site, Field& field, const size_t numDir)
549 {
550  ArrayBase& thisArray = field[site];
551  GhostArrayMap& ghostArrays = field.getGhostArrayMapLevel1();
552 
553  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
554 
555  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
556  {
557  const StorageSite& oSite = *mpos.first;
558  EntryIndex e(&oSite, &site);
559  const Array<int>& toIndices = *(mpos.second);
560  if (ghostArrays.find(e) == ghostArrays.end())
561  {
562  ghostArrays[e] = thisArray.newSizedClone(toIndices.getLength() * numDir);
563  }
564  }
565 }
566 
567 
568 void
569 Field::syncScatterVectorFields(const StorageSite& site, std::vector<Field*> & dsf)
570 {
571 
572  const size_t numDir = dsf.size();
573  Field& field0 = *dsf[0];
574  ArrayBase& thisArray0 = field0[site];
575  GhostArrayMap& ghostArrays = field0.getGhostArrayMap();
576 
577  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
578 
579  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap)
580  {
581  const StorageSite& oSite = *mpos.first;
582  EntryIndex e(&site, &oSite);
583  const Array<int>& fromIndices = *(mpos.second);
584  if (ghostArrays.find(e) == ghostArrays.end()){
585  ghostArrays[e] = thisArray0.newSizedClone( fromIndices.getLength() * numDir );
586  }
587 
588  const int chunkSize = fromIndices.getLength();
589  ArrayBase& ghostArray = *ghostArrays[e];
590  for (size_t dir=0; dir < numDir; dir++){
591  Field& field = *dsf[dir];
592  const ArrayBase& thisArray = field[site];
593  const int offset = chunkSize * dir;
594  thisArray.scatter(ghostArray,fromIndices, offset);
595  }
596  }
597 }
598 
599 void
600 Field::syncScatterVectorFieldsLevel1(const StorageSite& site, std::vector<Field*> & dsf)
601 {
602 
603  const size_t numDir = dsf.size();
604  Field& field0 = *dsf[0];
605  ArrayBase& thisArray0 = field0[site];
606  GhostArrayMap& ghostArrays = field0.getGhostArrayMapLevel1();
607 
608  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
609 
610  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap)
611  {
612  const StorageSite& oSite = *mpos.first;
613  EntryIndex e(&site, &oSite);
614  const Array<int>& fromIndices = *(mpos.second);
615  if (ghostArrays.find(e) == ghostArrays.end()){
616  ghostArrays[e] = thisArray0.newSizedClone( fromIndices.getLength() * numDir );
617  }
618 
619  const int chunkSize = fromIndices.getLength();
620  ArrayBase& ghostArray = *ghostArrays[e];
621  for (size_t dir=0; dir < numDir; dir++){
622  Field& field = *dsf[dir];
623  const ArrayBase& thisArray = field[site];
624  const int offset = chunkSize * dir;
625  thisArray.scatter(ghostArray,fromIndices, offset);
626  }
627  }
628 }
629 
630 
631 
632 void
633 Field::syncGatherVectorFields(const StorageSite& site, std::vector<Field*>& dsf)
634 {
635 
636  const size_t numDir = dsf.size();
637  Field& field0 = *dsf[0];
638  GhostArrayMap& ghostArrays = field0.getGhostArrayMap();
639 
640  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
641 
642  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
643  {
644  const StorageSite& oSite = *mpos.first;
645  const Array<int>& toIndices = *(mpos.second);
646  EntryIndex e(&oSite, &site);
647 
648  if (ghostArrays.find(e) == ghostArrays.end())
649  {
650  ostringstream e;
651  e << "Field::syncScatter: ghost array not found for"
652  << &oSite << endl;
653  throw CException(e.str());
654  }
655 
656  const ArrayBase& ghostArray = *ghostArrays[e];
657  const int chunkSize = toIndices.getLength();
658  for (size_t dir = 0; dir < numDir; dir++){
659  Field& field = *dsf[dir];
660  ArrayBase& thisArray = field[site];
661  const size_t offset = dir * chunkSize;
662  thisArray.gather(ghostArray,toIndices, offset);
663  }
664  }
665 }
666 
667 void
668 Field::syncGatherVectorFieldsLevel1(const StorageSite& site, std::vector<Field*>& dsf)
669 {
670 
671  const size_t numDir = dsf.size();
672  Field& field0 = *dsf[0];
673  GhostArrayMap& ghostArrays = field0.getGhostArrayMapLevel1();
674 
675  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
676 
677  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap)
678  {
679  const StorageSite& oSite = *mpos.first;
680  const Array<int>& toIndices = *(mpos.second);
681  EntryIndex e(&oSite, &site);
682 
683  if (ghostArrays.find(e) == ghostArrays.end())
684  {
685  ostringstream e;
686  e << "Field::syncScatter: ghost array not found for"
687  << &oSite << endl;
688  throw CException(e.str());
689  }
690 
691  const ArrayBase& ghostArray = *ghostArrays[e];
692  const int chunkSize = toIndices.getLength();
693  for (size_t dir = 0; dir < numDir; dir++){
694  Field& field = *dsf[dir];
695  ArrayBase& thisArray = field[site];
696  const size_t offset = dir * chunkSize;
697  thisArray.gather(ghostArray,toIndices, offset);
698  }
699  }
700 }
701 void
702 Field::syncLocalVectorFields(std::vector<Field*> & dsf)
703 {
704  // scatter first (prepare ship packages)
705  Field& field0 = *dsf[0];
706  ArrayMap& arrays = field0.getArrayMap();
707  foreach(ArrayMap::value_type& pos, arrays)
708  Field::syncScatterVectorFields(*pos.first, dsf);
709 
710  const size_t numDir = dsf.size();
711  foreach(ArrayMap::value_type& pos, arrays)
712  Field::createSyncGatherArraysVectorFields(*pos.first, field0, numDir );
713 
714  GhostArrayMap& ghostArrays = field0.getGhostArrayMap();
715 
716 #ifdef FVM_PARALLEL
717  //SENDING
718  MPI::Request request_send[ Field::get_request_size(field0) ];
719  MPI::Request request_recv[ Field::get_request_size(field0) ];
720  int indxSend = 0;
721  int indxRecv = 0;
722  foreach(ArrayMap::value_type& pos, arrays){
723  const StorageSite& site = *pos.first;
724  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
725  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
726  const StorageSite& oSite = *mpos.first;
727  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
728  EntryIndex e(&site,&oSite);
729  ArrayBase& sendArray = *ghostArrays[e];
730  int to_where = oSite.getGatherProcID();
731  if ( to_where != -1 ){
732  int mpi_tag = oSite.getTag();
733  request_send[indxSend++] =
734  MPI::COMM_WORLD.Isend( sendArray.getData(), sendArray.getDataSize(), MPI::BYTE, to_where, mpi_tag );
735  }
736  }
737  //RECIEVING
738  //getting values from other meshes to fill g
739  const StorageSite::GatherMap& gatherMap = site.getGatherMap();
740  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
741  const StorageSite& oSite = *mpos.first;
742  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
743  EntryIndex e(&oSite,&site);
744  ArrayBase& recvArray = *ghostArrays[e];
745  int from_where = oSite.getGatherProcID();
746  if ( from_where != -1 ){
747  int mpi_tag = oSite.getTag();
748  request_recv[indxRecv++] =
749  MPI::COMM_WORLD.Irecv( recvArray.getData(), recvArray.getDataSize(), MPI::BYTE, from_where, mpi_tag );
750  }
751  }
752  }
753 
754  int count = Field::get_request_size(field0);
755  MPI::Request::Waitall( count, request_recv );
756  MPI::Request::Waitall( count, request_send );
757 #endif
758 
759  // gather
760  foreach(ArrayMap::value_type& pos, arrays)
761  Field::syncGatherVectorFields(*pos.first, dsf);
762 
763 
764  //sycnLocal1
765 
767 }
768 
769 void
770 Field::syncLocalVectorFieldsLevel1(std::vector<Field*> & dsf)
771 {
772  // scatter first (prepare ship packages)
773  Field& field0 = *dsf[0];
774  ArrayMap& arrays = field0.getArrayMap();
775  foreach(ArrayMap::value_type& pos, arrays){
776  if ( pos.second->getLength() == pos.first->getCountLevel1() )
777  Field::syncScatterVectorFieldsLevel1(*pos.first, dsf);
778  }
779 
780  const size_t numDir = dsf.size();
781  foreach(ArrayMap::value_type& pos, arrays){
782  if ( pos.second->getLength() == pos.first->getCountLevel1() )
783  Field::createSyncGatherArraysVectorFieldsLevel1(*pos.first, field0, numDir );
784  }
785 
786  GhostArrayMap& ghostArrays = field0.getGhostArrayMapLevel1();
787 
788 #ifdef FVM_PARALLEL
789  //SENDING
790  MPI::Request request_send[ Field::get_request_size_level1(field0) ];
791  MPI::Request request_recv[ Field::get_request_size_level1(field0) ];
792  int indxSend = 0;
793  int indxRecv = 0;
794  foreach(ArrayMap::value_type& pos, arrays){
795  const StorageSite& site = *pos.first;
796  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
797  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
798  const StorageSite& oSite = *mpos.first;
799  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
800  EntryIndex e(&site,&oSite);
801  ArrayBase& sendArray = *ghostArrays[e];
802  int to_where = oSite.getGatherProcID();
803  if ( to_where != -1 ){
804  int mpi_tag = oSite.getTag();
805  request_send[indxSend++] =
806  MPI::COMM_WORLD.Isend( sendArray.getData(), sendArray.getDataSize(), MPI::BYTE, to_where, mpi_tag );
807  }
808  }
809  //RECIEVING
810  //getting values from other meshes to fill g
811  const StorageSite::GatherMap& gatherMap = site.getGatherMapLevel1();
812  foreach(const StorageSite::GatherMap::value_type& mpos, gatherMap){
813  const StorageSite& oSite = *mpos.first;
814  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
815  EntryIndex e(&oSite,&site);
816  ArrayBase& recvArray = *ghostArrays[e];
817  int from_where = oSite.getGatherProcID();
818  if ( from_where != -1 ){
819  int mpi_tag = oSite.getTag();
820  request_recv[indxRecv++] =
821  MPI::COMM_WORLD.Irecv( recvArray.getData(), recvArray.getDataSize(), MPI::BYTE, from_where, mpi_tag );
822  }
823  }
824  }
825 
826  int count = Field::get_request_size_level1(field0);
827  MPI::Request::Waitall( count, request_recv );
828  MPI::Request::Waitall( count, request_send );
829 #endif
830 
831  // gather
832  foreach(ArrayMap::value_type& pos, arrays){
833  if ( pos.second->getLength() == pos.first->getCountLevel1() )
834  Field::syncGatherVectorFieldsLevel1(*pos.first, dsf);
835  }
836 
837 
838 
839 }
840 
841 
842 int
844 {
845  ArrayMap& arrays = field.getArrayMap();
846  int indx = 0;
847  foreach(ArrayMap::value_type& pos, arrays){
848  const StorageSite& site = *pos.first;
849  const StorageSite::ScatterMap& scatterMap = site.getScatterMap();
850  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
851  const StorageSite& oSite = *mpos.first;
852  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
853  if ( oSite.getGatherProcID() != -1 )
854  indx++;
855  }
856  }
857  return indx;
858 
859 }
860 
861 
862 int
864 {
865  ArrayMap& arrays = field.getArrayMap();
866  int indx = 0;
867  foreach(ArrayMap::value_type& pos, arrays){
868  const StorageSite& site = *pos.first;
869  const StorageSite::ScatterMap& scatterMap = site.getScatterMapLevel1();
870  foreach(const StorageSite::ScatterMap::value_type& mpos, scatterMap){
871  const StorageSite& oSite = *mpos.first;
872  //checking if storage site is only site or ghost site, we only communicate ghost site ( oSite.getCount() == -1 )
873  if ( oSite.getGatherProcID() != -1 )
874  indx++;
875  }
876  }
877  return indx;
878 
879 }
880 
virtual int getDataSize() const =0
virtual shared_ptr< ArrayBase > createOffsetArray(const int offset, const int size)=0
Field & operator=(const Field &oField)
Definition: Field.cpp:177
Field(const string &name)
Definition: Field.cpp:22
static void syncScatterVectorFields(const StorageSite &site, std::vector< Field * > &dsf)
Definition: Field.cpp:569
const string _name
Definition: Field.h:90
static void syncGatherVectorFields(const StorageSite &site, std::vector< Field * > &dsf)
Definition: Field.cpp:633
bool hasArray(const StorageSite &s) const
Definition: Field.cpp:37
vector< const StorageSite * > StorageSiteList
Definition: StorageSite.h:114
ArrayMap _arrays
Definition: Field.h:91
virtual void scatter(ArrayBase &other_, const ArrayBase &indices, const int offset=0) const =0
ArrayMap & getArrayMap()
Definition: Field.h:48
ChildSitesMap _childSitesMap
Definition: Field.h:95
pair< const StorageSite *, const StorageSite * > EntryIndex
Definition: Field.h:19
Definition: Field.h:14
const GatherMap & getGatherMapLevel1() const
Definition: StorageSite.h:74
const ScatterMap & getScatterMapLevel1() const
Definition: StorageSite.h:73
virtual shared_ptr< IContainer > newClone() const
Definition: Field.cpp:141
static void createSyncGatherArraysVectorFields(const StorageSite &site, Field &field, const size_t numDir)
Definition: Field.cpp:528
map< EntryIndex, shared_ptr< ArrayBase > > GhostArrayMap
Definition: Field.h:20
void removeArray(const StorageSite &)
Definition: Field.cpp:79
void syncScatter(const StorageSite &site)
Definition: Field.cpp:234
#define logCtor()
Definition: RLogInterface.h:26
static void syncGatherVectorFieldsLevel1(const StorageSite &site, std::vector< Field * > &dsf)
Definition: Field.cpp:668
virtual void copyFrom(const IContainer &a)
Definition: Field.cpp:187
static void syncLocalVectorFieldsLevel1(std::vector< Field * > &dsf)
Definition: Field.cpp:770
int get_request_size()
Definition: Field.cpp:397
static void createSyncGatherArraysVectorFieldsLevel1(const StorageSite &site, Field &field, const size_t numDir)
Definition: Field.cpp:548
void clear()
Definition: Field.cpp:105
GhostArrayMap _ghostArraysLevel1
Definition: Field.h:93
int getTag() const
Definition: StorageSite.h:84
int getGatherProcID() const
Definition: StorageSite.h:83
void syncGather(const StorageSite &site)
Definition: Field.cpp:280
void createSyncGatherArrays(const StorageSite &site)
Definition: Field.cpp:195
const ArrayBase & operator[](const StorageSite &) const
Definition: Field.cpp:44
GhostArrayMap _ghostArrays
Definition: Field.h:92
#define logDtor()
Definition: RLogInterface.h:33
GhostArrayMap & getGhostArrayMapLevel1()
Definition: Field.h:51
const ScatterMap & getScatterMap() const
Definition: StorageSite.h:58
void addArray(const StorageSite &, shared_ptr< ArrayBase > a)
Definition: Field.cpp:72
map< const StorageSite *, shared_ptr< Array< int > > > ScatterMap
Definition: StorageSite.h:23
void syncScatterLevel1(const StorageSite &site)
Definition: Field.cpp:257
virtual shared_ptr< ArrayBase > newSizedClone(const int size) const =0
int get_request_size_scatter_level1()
Definition: Field.cpp:486
int getOffset() const
Definition: StorageSite.h:87
const StorageSite *const getParent() const
Definition: StorageSite.h:86
void syncGatherLevel1(const StorageSite &site)
Definition: Field.cpp:307
const GatherMap & getGatherMap() const
Definition: StorageSite.h:59
int get_request_size_gather_level1()
Definition: Field.cpp:506
static void syncLocalVectorFields(std::vector< Field * > &dsf)
Definition: Field.cpp:702
virtual void * getData() const =0
int getCount() const
Definition: StorageSite.h:39
virtual void gather(const ArrayBase &other_, const ArrayBase &indices, const int offset=0)=0
void createSyncGatherArraysLevel1(const StorageSite &site)
Definition: Field.cpp:214
GhostArrayMap & getGhostArrayMap()
Definition: Field.h:50
static void syncScatterVectorFieldsLevel1(const StorageSite &site, std::vector< Field * > &dsf)
Definition: Field.cpp:600
map< const StorageSite *, shared_ptr< Array< int > > > GatherMap
Definition: StorageSite.h:24
void syncLocalLevel1()
Definition: Field.cpp:417
ArrayBase & _create(const StorageSite &site)
Definition: Field.cpp:114
virtual ~Field()
Definition: Field.cpp:30
map< const StorageSite *, shared_ptr< ArrayBase > > ArrayMap
Definition: Field.h:17
shared_ptr< ArrayBase > getArrayPtr(const StorageSite &)
Definition: Field.cpp:63
virtual void zero()
Definition: Field.cpp:168
void syncLocal()
Definition: Field.cpp:334
static int get_request_size_level1(Field &field)
Definition: Field.cpp:863
virtual shared_ptr< IContainer > newCopy() const
Definition: Field.cpp:155
int getLength() const
Definition: Array.h:87
void removeArrays(const StorageSiteList &sites)
Definition: Field.cpp:96