source: XIOS/trunk/src/node/grid.cpp @ 314

Last change on this file since 314 was 314, checked in by ymipsl, 12 years ago

Removing obsolete files and some cleaning...

YM

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