Salome HOME
Get relevant changes from V7_dev branch (copyright update, adm files etc)
[tools/medcoupling.git] / src / ParaMEDMEMTest / ParaMEDMEMTest_Gauthier1.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "ParaMEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
22
23 #include "CommInterface.hxx"
24 #include "ProcessorGroup.hxx"
25 #include "MPIProcessorGroup.hxx"
26 #include "DEC.hxx"
27 #include "InterpKernelDEC.hxx"
28 #include "MEDCouplingUMesh.hxx"
29 #include "MEDCouplingFieldDouble.hxx"
30 #include "ParaMESH.hxx"
31 #include "ParaFIELD.hxx"
32 #include "ComponentTopology.hxx"
33 #include "BlockTopology.hxx"
34
35 #include <set>
36 #include <time.h>
37 #include <iostream>
38 #include <assert.h>
39 #include <string>
40 #include <math.h>
41
42 using namespace std;
43 using namespace MEDCoupling;
44 using namespace ICoCo;
45
46 void afficheGauthier1(const ParaFIELD& field, const double *vals, int lgth)
47 {
48   const DataArrayDouble *valsOfField(field.getField()->getArray());
49   CPPUNIT_ASSERT_EQUAL(lgth,valsOfField->getNumberOfTuples());
50   for (int ele=0;ele<valsOfField->getNumberOfTuples();ele++)
51     CPPUNIT_ASSERT_DOUBLES_EQUAL(vals[ele],valsOfField->getIJ(ele,0),1e-12);
52 }
53
54 MEDCouplingUMesh *init_quadGauthier1(int is_master)
55 {
56   MCAuto<MEDCouplingUMesh> m(MEDCouplingUMesh::New("champ_quad",2));
57   MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
58   if(is_master)
59     {
60       const double dataCoo[24]={0,0,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,1,1,1,1};
61       coo->alloc(8,3);
62       std::copy(dataCoo,dataCoo+24,coo->getPointer());
63       const int conn[8]={0,1,3,2,4,5,7,6};
64       m->allocateCells(2);
65       m->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
66       m->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+4);
67     }
68   else
69     {
70       coo->alloc(0,3);
71       m->allocateCells(0);
72     }
73   m->setCoords(coo);
74   return m.retn();
75 }
76
77 MEDCouplingUMesh *init_triangleGauthier1(int is_master)
78 {
79   MCAuto<MEDCouplingUMesh> m(MEDCouplingUMesh::New("champ_triangle",2));
80   MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
81   if(is_master)
82     {
83       const double dataCoo[24]={0,0,0,1,0,0,0,0,1,1,0,1,0,1,0,1,1,0,0,1,1,1,1,1};
84       coo->alloc(8,3);
85       std::copy(dataCoo,dataCoo+24,coo->getPointer());
86       const int conn[12]={0,1,2,1,2,3,4,5,7,4,6,7};
87       m->allocateCells(2);
88       for(int i=0;i<4;i++)
89         m->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3*i);
90     }
91   else
92     {
93       coo->alloc(0,3);
94       m->allocateCells(0);
95     }
96   m->setCoords(coo);
97   return m.retn();
98 }
99
100
101 void ParaMEDMEMTest::testGauthier1()
102 {
103   int num_cas=0;
104   int rank, size;
105   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
106   MPI_Comm_size(MPI_COMM_WORLD,&size);
107   
108   int is_master=0;
109
110   CommInterface comm;
111   set<int> emetteur_ids;
112   set<int> recepteur_ids;
113   emetteur_ids.insert(0);
114   if(size!=4)
115     return;
116   recepteur_ids.insert(1);
117   if (size >2) 
118     recepteur_ids.insert(2);
119   if (size >2) 
120     emetteur_ids.insert(3);
121   if ((rank==0)||(rank==1)) 
122     is_master=1;
123   
124   MPIProcessorGroup recepteur_group(comm,recepteur_ids);
125   MPIProcessorGroup emetteur_group(comm,emetteur_ids);
126
127   string cas;
128   if (recepteur_group.containsMyRank())
129     {
130       cas="recepteur";
131       //freopen("recpeteur.out","w",stdout);
132       //freopen("recepteur.err","w",stderr);
133     }
134   else
135     {
136       cas="emetteur";
137       // freopen("emetteur.out","w",stdout);
138       //freopen("emetteur.err","w",stderr);
139     }
140   double expected[8][4]={
141     {1.,1.,1.,1.},
142     {40., 40., 1., 1.},
143     {1.,1.,1e200,1e200},
144     {40.,1.,1e200,1e200},
145     {1.,1.,1.,1.},
146     {40.,1.,1.,1.},
147     {1.,1.,1e200,1e200},
148     {20.5,1.,1e200,1e200}
149   };
150   int expectedLgth[8]={4,4,2,2,4,4,2,2};
151   
152   for (int send=0;send<2;send++)
153     for (int rec=0;rec<2;rec++)
154       {
155         InterpKernelDEC dec_emetteur(emetteur_group, recepteur_group);
156         MEDCoupling::ParaFIELD *champ_emetteur(0),*champ_recepteur(0);
157         MEDCoupling::ParaMESH *paramesh(0);
158         MCAuto<MEDCouplingUMesh> mesh;
159         dec_emetteur.setOrientation(2);
160         if (send==0)
161           {
162             mesh=init_quadGauthier1(is_master);
163           }
164         else
165           {
166             mesh=init_triangleGauthier1(is_master);
167           }
168         paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"emetteur mesh");
169         MEDCoupling::ComponentTopology comptopo;
170         champ_emetteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
171         champ_emetteur->getField()->setNature(IntensiveMaximum);
172         champ_emetteur->setOwnSupport(true);
173         if (rec==0)
174           {
175             mesh=init_triangleGauthier1(is_master);
176           }
177         else
178           {
179             mesh=init_quadGauthier1(is_master);
180           }
181         paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"recepteur mesh");
182         champ_recepteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
183         champ_recepteur->getField()->setNature(IntensiveMaximum);
184         champ_recepteur->setOwnSupport(true);
185         if (cas=="emetteur") 
186           {
187             champ_emetteur->getField()->getArray()->fillWithValue(1.);
188           }
189   
190   
191         MPI_Barrier(MPI_COMM_WORLD);
192
193         //clock_t clock0= clock ();
194         int compti=0;
195
196         bool init=true; // first time step ??
197         bool stop=false;
198         //boucle sur les pas de quads
199         while (!stop) {
200   
201           compti++;
202           //clock_t clocki= clock ();
203           //cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl; 
204           for (int non_unif=0;non_unif<2;non_unif++)
205             {
206               if (cas=="emetteur") 
207                 {
208                   if (non_unif)
209                     if(rank!=3)
210                       champ_emetteur->getField()->getArray()->setIJ(0,0,40);
211                 }
212               //bool ok=false; // Is the time interval successfully solved ?
213     
214               // Loop on the time interval tries
215               if(1) {
216       
217
218                 if (cas=="emetteur")
219                   dec_emetteur.attachLocalField(champ_emetteur);
220                 else
221                   dec_emetteur.attachLocalField(champ_recepteur);
222
223
224                 if(init) dec_emetteur.synchronize();
225                 init=false;
226
227                 if (cas=="emetteur") {
228                   //    affiche(champ_emetteur);
229                   dec_emetteur.sendData();
230                 }
231                 else if (cas=="recepteur")
232                   {
233                     dec_emetteur.recvData();
234                     if (is_master)
235                       afficheGauthier1(*champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
236                   }
237                 else
238                   throw 0;
239                 MPI_Barrier(MPI_COMM_WORLD);
240               }
241               stop=true;
242               num_cas++;
243             }
244         }
245         delete champ_emetteur;
246         delete champ_recepteur;
247       }
248 }
249
250 void ParaMEDMEMTest::testGauthier2()
251 {
252   std::cout << "testGauthier2\n";
253   double valuesExpected1[2]={0.,0.};
254   double valuesExpected2[2]={0.95,0.970625};
255   
256   double valuesExpected30[]={0., 0., 0.05, 0., 0., 0.15, 0., 0., 0.25, 0., 0., 0.35, 0., 0., 0.45, 0., 0., 0.55, 0., 0., 0.65, 0., 0., 0.75, 0., 0., 0.85, 0., 0., 0.95};
257   double valuesExpected31[]={0.,  0.,  0.029375,  0.,  0.,  0.029375,  0.,  0.,  0.1,  0.,  0.,  0.1,  0.,  0.,  0.2,  0.,  0.,  0.2,  0.,  0.,  0.3,  0.,  0.,  0.3,  0.,  0.,  0.4,  0.,  0.,  0.4,  0.,  0.,  0.5,  0.,  0.,  0.5,  0.,  0.,  0.6,  0.,  0.,  0.6,  0.,  0.,  0.7,  0.,  0.,  0.7,  0.,  0.,  0.8,  0.,  0.,  0.8,  0.,  0.,  0.9,  0.,  0.,  0.9,  0.,  0.,  0.970625,  0.,  0.,  0.970625 };
258
259   double *valuesExpected3[2]={valuesExpected30,valuesExpected31};
260
261   int rank, size;
262   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
263   MPI_Comm_size(MPI_COMM_WORLD,&size);
264   if (size <2)
265     return ;
266   CommInterface comm;
267   set<int> Genepi_ids;
268   set<int> entree_chaude_ids;
269   Genepi_ids.insert(0);
270   for (int i=1;i<size;i++)
271     entree_chaude_ids.insert(i);
272   for (int type=0;type<2;type++)
273     {
274       MPIProcessorGroup entree_chaude_group(comm,entree_chaude_ids);
275       MPIProcessorGroup Genepi_group(comm,Genepi_ids);
276
277       MEDCoupling::ParaFIELD *vitesse(0);
278       InterpKernelDEC dec_vit_in_chaude(entree_chaude_group, Genepi_group);
279
280       if ( entree_chaude_group.containsMyRank())
281         {
282           MCAuto<MEDCouplingUMesh> mesh(MEDCouplingUMesh::New("mesh",2));
283           MCAuto<DataArrayDouble> arr(DataArrayDouble::New()); arr->alloc(63,3);
284           const double cooData[189]={0.,0.,0.,0.5,0.,0.,0.5,0.05,0.,0.,0.1,0.,0.5,0.1,0.,0.5,0.15,0.,0.,0.2,0.,0.5,0.2,0.,0.5,0.25,0.,0.,0.3,0.,0.5,0.3,0.,0.5,0.35,0.,0.,0.4,0.,0.5,0.4,0.,0.5,0.45,0.,0.,0.5,0.,0.5,0.5,0.,0.5,0.55,0.,0.,0.6,0.,0.5,0.6,0.,0.5,0.65,0.,0.,0.7,0.,0.5,0.7,0.,0.5,0.75,0.,0.,0.8,0.,0.5,0.8,0.,0.5,0.85,0.,0.,0.9,0.,0.5,0.9,0.,0.5,0.95,0.,1.,0.,0.,1.,0.1,0.,1.,0.2,0.,1.,0.3,0.,1.,0.4,0.,1.,0.5,0.,1.,0.6,0.,1.,0.7,0.,1.,0.8,0.,1.,0.9,0.,1.,0.05,0.,1.,0.15,0.,1.,0.25,0.,1.,0.35,0.,1.,0.45,0.,1.,0.55,0.,1.,0.65,0.,1.,0.75,0.,1.,0.85,0.,1.,0.95,0.,1.,1.,0.,0.,1.,0.,0.5,1.,0.,0.,0.05,0.,0.,0.15,0.,0.,0.25,0.,0.,0.35,0.,0.,0.45,0.,0.,0.55,0.,0.,0.65,0.,0.,0.75,0.,0.,0.85,0.,0.,0.95,0.};
285           std::copy(cooData,cooData+189,arr->getPointer());
286           mesh->setCoords(arr);
287           mesh->allocateCells(80);
288           const int conn[240]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,2,1,31,5,4,32,8,7,33,11,10,34,14,13,35,17,16,36,20,19,37,23,22,38,26,25,39,29,28,30,40,2,31,41,5,32,42,8,33,43,11,34,44,14,35,45,17,36,46,20,37,47,23,38,48,26,39,49,29,31,2,40,32,5,41,33,8,42,34,11,43,35,14,44,36,17,45,37,20,46,38,23,47,39,26,48,50,29,49,3,2,4,6,5,7,9,8,10,12,11,13,15,14,16,18,17,19,21,20,22,24,23,25,27,26,28,51,29,52,31,4,2,32,7,5,33,10,8,34,13,11,35,16,14,36,19,17,37,22,20,38,25,23,39,28,26,50,52,29,0,2,53,3,5,54,6,8,55,9,11,56,12,14,57,15,17,58,18,20,59,21,23,60,24,26,61,27,29,62,3,53,2,6,54,5,9,55,8,12,56,11,15,57,14,18,58,17,21,59,20,24,60,23,27,61,26,51,62,29};
289           for(int i=0;i<80;i++)
290             mesh->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3*i);
291           MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(ON_NODES,ONE_TIME));
292           const double valsOfField[189]={0.,0.,0.,0.,0.,0.,0.,0.,0.05,0.,0.,0.1,0.,0.,0.1,0.,0.,0.15,0.,0.,0.2,0.,0.,0.2,0.,0.,0.25,0.,0.,0.3,0.,0.,0.3,0.,0.,0.35,0.,0.,0.4,0.,0.,0.4,0.,0.,0.45,0.,0.,0.5,0.,0.,0.5,0.,0.,0.55,0.,0.,0.6,0.,0.,0.6,0.,0.,0.65,0.,0.,0.7,0.,0.,0.7,0.,0.,0.75,0.,0.,0.8,0.,0.,0.8,0.,0.,0.85,0.,0.,0.9,0.,0.,0.9,0.,0.,0.95,0.,0.,0.,0.,0.,0.1,0.,0.,0.2,0.,0.,0.3,0.,0.,0.4,0.,0.,0.5,0.,0.,0.6,0.,0.,0.7,0.,0.,0.8,0.,0.,0.9,0.,0.,0.05,0.,0.,0.15,0.,0.,0.25,0.,0.,0.35,0.,0.,0.45,0.,0.,0.55,0.,0.,0.65,0.,0.,0.75,0.,0.,0.85,0.,0.,0.95,0.,0.,1.,0.,0.,1.,0.,0.,1.,0.,0.,0.05,0.,0.,0.15,0.,0.,0.25,0.,0.,0.35,0.,0.,0.45,0.,0.,0.55,0.,0.,0.65,0.,0.,0.75,0.,0.,0.85,0.,0.,0.95};
293           f->setMesh(mesh); f->setName("VITESSE_P1_OUT");
294           arr=DataArrayDouble::New(); arr->alloc(63,3);
295           std::copy(valsOfField,valsOfField+189,arr->getPointer());
296           f->setArray(arr); f->setNature(IntensiveMaximum);
297           MEDCoupling::ParaMESH *paramesh(new MEDCoupling::ParaMESH(mesh,entree_chaude_group,"emetteur mesh"));
298           vitesse=new MEDCoupling::ParaFIELD(f,paramesh,entree_chaude_group);
299           vitesse->setOwnSupport(true);
300           dec_vit_in_chaude.setMethod("P1");
301         }
302       else
303         {
304           MCAuto<MEDCouplingUMesh> mesh(MEDCouplingUMesh::New("mesh",2));
305           MCAuto<DataArrayDouble> arr(DataArrayDouble::New()); arr->alloc(22,3);
306           const double cooData[66]={0,0,0,1,0,0,0,0.1,0,1,0.1,0,0,0.2,0,1,0.2,0,0,0.3,0,1,0.3,0,0,0.4,0,1,0.4,0,0,0.5,0,1,0.5,0,0,0.6,0,1,0.6,0,0,0.7,0,1,0.7,0,0,0.8,0,1,0.8,0,0,0.9,0,1,0.9,0,0,1,0,1,1,0};
307           std::copy(cooData,cooData+66,arr->getPointer());
308           mesh->setCoords(arr);
309           mesh->allocateCells(10);
310           const int conn[40]={0,1,3,2,2,3,5,4,4,5,7,6,6,7,9,8,8,9,11,10,10,11,13,12,12,13,15,14,14,15,17,16,16,17,19,18,18,19,21,20};
311           for(int i=0;i<10;i++)
312             mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+4*i);
313           MCAuto<MEDCouplingFieldDouble> f(MEDCouplingFieldDouble::New(type==0?ON_CELLS:ON_NODES,ONE_TIME));
314           f->setMesh(mesh); f->setName("vitesse_in_chaude");
315           arr=DataArrayDouble::New(); arr->alloc(f->getNumberOfTuplesExpected()*3); arr->fillWithZero(); arr->rearrange(3);
316           f->setArray(arr); f->setNature(IntensiveMaximum);
317           MEDCoupling::ParaMESH *paramesh(new MEDCoupling::ParaMESH(mesh,Genepi_group,"recepteur mesh"));
318           vitesse=new MEDCoupling::ParaFIELD(f,paramesh,Genepi_group);
319           vitesse->setOwnSupport(true);
320           dec_vit_in_chaude.setMethod(f->getDiscretization()->getRepr());
321         }
322
323       dec_vit_in_chaude.attachLocalField(vitesse);
324       
325       dec_vit_in_chaude.synchronize();
326   
327   
328       // Envois - receptions
329       if (entree_chaude_group.containsMyRank())
330         {
331           dec_vit_in_chaude.sendData();
332         }
333       else
334         {
335           dec_vit_in_chaude.recvData(); 
336         }
337       if ( !entree_chaude_group.containsMyRank() )
338         {
339           double pmin=1e38, pmax=-1e38;
340           const double *p(vitesse->getField()->getArray()->begin());
341           for(std::size_t i=0;i<vitesse->getField()->getArray()->getNbOfElems();i++,p++)
342             {
343               if (*p<pmin) pmin=*p;
344               if (*p>pmax) pmax=*p;
345             }
346           CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected1[type],pmin,1e-12);
347           CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[type],pmax,1e-12);
348       
349           int nbCompo(vitesse->getField()->getNumberOfComponents());
350           p=vitesse->getField()->getArray()->begin();
351           for(int i=0;i<vitesse->getField()->getNumberOfTuples();i++)
352             for(int c=0;c<nbCompo;c++,p++)
353               CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[type][i*nbCompo+c],*p,1e-12);
354         }
355       delete vitesse;
356     }
357 }
358
359 /*!
360  * Non regression test testing copy constructor of InterpKernelDEC. 
361  */
362 void ParaMEDMEMTest::testGauthier3()
363 {
364   int num_cas=0;
365   int rank, size;
366   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
367   MPI_Comm_size(MPI_COMM_WORLD,&size);
368   
369   int is_master=0;
370
371   CommInterface comm;
372   set<int> emetteur_ids;
373   set<int> recepteur_ids;
374   emetteur_ids.insert(0);
375   if(size!=4)
376     return;
377   recepteur_ids.insert(1);
378   if (size >2) 
379     recepteur_ids.insert(2);
380   if (size >2) 
381     emetteur_ids.insert(3);
382   if ((rank==0)||(rank==1)) 
383     is_master=1;
384   
385   MPIProcessorGroup recepteur_group(comm,recepteur_ids);
386   MPIProcessorGroup emetteur_group(comm,emetteur_ids);
387
388   string cas;
389   if (recepteur_group.containsMyRank())
390     {
391       cas="recepteur";
392       //freopen("recpeteur.out","w",stdout);
393       //freopen("recepteur.err","w",stderr);
394     }
395   else
396     {
397       cas="emetteur";
398       // freopen("emetteur.out","w",stdout);
399       //freopen("emetteur.err","w",stderr);
400     }
401   double expected[8][4]={
402     {1.,1.,1.,1.},
403     {40., 40., 1., 1.},
404     {1.,1.,1e200,1e200},
405     {40.,1.,1e200,1e200},
406     {1.,1.,1.,1.},
407     {40.,1.,1.,1.},
408     {1.,1.,1e200,1e200},
409     {20.5,1.,1e200,1e200}
410   };
411   int expectedLgth[8]={4,4,2,2,4,4,2,2};
412   
413   for (int send=0;send<2;send++)
414     for (int rec=0;rec<2;rec++)
415       {
416         std::vector<InterpKernelDEC> decu(1);
417         decu[0]=InterpKernelDEC(emetteur_group,recepteur_group);
418         InterpKernelDEC& dec_emetteur=decu[0];
419         MEDCoupling::ParaFIELD *champ_emetteur(0),*champ_recepteur(0);
420         MEDCoupling::ParaMESH *paramesh(0);
421         MCAuto<MEDCouplingUMesh> mesh;
422         dec_emetteur.setOrientation(2);
423         if (send==0)
424           {
425             mesh=init_quadGauthier1(is_master);
426           }
427         else
428           {
429             mesh=init_triangleGauthier1(is_master);
430           }
431         paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"emetteur mesh");
432         MEDCoupling::ComponentTopology comptopo;
433         champ_emetteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
434         champ_emetteur->getField()->setNature(IntensiveMaximum);
435         champ_emetteur->setOwnSupport(true);
436         if (rec==0)
437           {
438             mesh=init_triangleGauthier1(is_master);
439           }
440         else
441           {
442             mesh=init_quadGauthier1(is_master);
443           }
444         paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"recepteur mesh");
445         champ_recepteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
446         champ_recepteur->getField()->setNature(IntensiveMaximum);
447         champ_recepteur->setOwnSupport(true);
448         if (cas=="emetteur") 
449           {
450             champ_emetteur->getField()->getArray()->fillWithValue(1.);
451           }
452   
453   
454         MPI_Barrier(MPI_COMM_WORLD);
455
456         //clock_t clock0= clock ();
457         int compti=0;
458
459         bool init=true; // first time step ??
460         bool stop=false;
461         //boucle sur les pas de quads
462         while (!stop) {
463   
464           compti++;
465           //clock_t clocki= clock ();
466           //cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl; 
467           for (int non_unif=0;non_unif<2;non_unif++)
468             {
469               if (cas=="emetteur") 
470                 {
471                   if (non_unif)
472                     if(rank!=3)
473                       champ_emetteur->getField()->getArray()->setIJ(0,0,40);
474                 }
475               //bool ok=false; // Is the time interval successfully solved ?
476     
477               // Loop on the time interval tries
478               if(1) {
479       
480
481                 if (cas=="emetteur")
482                   dec_emetteur.attachLocalField(champ_emetteur);
483                 else
484                   dec_emetteur.attachLocalField(champ_recepteur);
485
486
487                 if(init) dec_emetteur.synchronize();
488                 init=false;
489
490                 if (cas=="emetteur") {
491                   //    affiche(champ_emetteur);
492                   dec_emetteur.sendData();
493                 }
494                 else if (cas=="recepteur")
495                   {
496                     dec_emetteur.recvData();
497                     if (is_master)
498                       afficheGauthier1(*champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
499                   }
500                 else
501                   throw 0;
502                 MPI_Barrier(MPI_COMM_WORLD);
503               }
504               stop=true;
505               num_cas++;
506             }
507         }
508         delete champ_emetteur;
509         delete champ_recepteur;
510       }
511 }
512
513 /*!
514  * This test is the parallel version of MEDCouplingBasicsTest.test3D1DOnP1P0_1 test.
515  */
516 void ParaMEDMEMTest::testGauthier4()
517 {
518   //
519   const double sourceCoords[19*3]={0.5,0.5,0.1,0.5,0.5,1.2,0.5,0.5,1.6,0.5,0.5,1.8,0.5,0.5,2.43,0.5,0.5,2.55,0.5,0.5,4.1,0.5,0.5,4.4,0.5,0.5,4.9,0.5,0.5,5.1,0.5,0.5,7.6,0.5,0.5,7.7,0.5,0.5,8.2,0.5,0.5,8.4,0.5,0.5,8.6,0.5,0.5,8.8,0.5,0.5,9.2,0.5,0.5,9.6,0.5,0.5,11.5};
520   const int sourceConn[18*2]={0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18};
521   const double sourceVals[19]={0.49,2.8899999999999997,7.29,13.69,22.09,32.49,44.89,59.29,75.69,94.09, 114.49,136.89,161.29,187.69,216.09,246.49,278.89,313.29,349.69};
522   const double targetCoords0[20*3]={0.,0.,0.,1.,0.,0.,0.,1.,0.,1.,1.,0.,0.,0.,1.,1.,0.,1.,0.,1.,1.,1.,1.,1.,0.,0.,2.,1.,0.,2.,0.,1.,2.,1.,1.,2.,0.,0.,3.,1.,0.,3.,0.,1.,3.,1.,1.,3.,0.,0.,4.,1.,0.,4.,0.,1.,4.,1.,1.,4.};
523   const int targetConn0[8*4]={1,0,2,3,5,4,6,7,5,4,6,7,9,8,10,11,9,8,10,11,13,12,14,15,13,12,14,15,17,16,18,19};
524   const double targetCoords1[28*3]={0.,0.,4.,1.,0.,4.,0.,1.,4.,1.,1.,4.,0.,0.,5.,1.,0.,5.,0.,1.,5.,1.,1.,5.,0.,0.,6.,1.,0.,6.,0.,1.,6.,1.,1.,6.,0.,0.,7.,1.,0.,7.,0.,1.,7.,1.,1.,7.,0.,0.,8.,1.,0.,8.,0.,1.,8.,1.,1.,8.,0.,0.,9.,1.,0.,9.,0.,1.,9.,1.,1.,9.,0.,0.,10.,1.,0.,10.,0.,1.,10.,1.,1.,10.};
525   const int targetConn1[8*6]={1,0,2,3,5,4,6,7,5,4,6,7,9,8,10,11,9,8,10,11,13,12,14,15,13,12,14,15,17,16,18,19,17,16,18,19,21,20,22,23,21,20,22,23,25,24,26,27};
526   //
527   int size;
528   int rank;
529   MPI_Comm_size(MPI_COMM_WORLD,&size);
530   MPI_Comm_rank(MPI_COMM_WORLD,&rank);
531   //
532   if(size!=3)
533     return ;
534   int nproc_source = 1;
535   set<int> self_procs;
536   set<int> procs_source;
537   set<int> procs_target;
538   
539   for (int i=0; i<nproc_source; i++)
540     procs_source.insert(i);
541   for (int i=nproc_source; i<size; i++)
542     procs_target.insert(i);
543   self_procs.insert(rank);
544   //
545   MEDCoupling::MEDCouplingUMesh *mesh=0;
546   MEDCoupling::ParaMESH *paramesh=0;
547   MEDCoupling::ParaFIELD* parafield=0;
548   //
549   MEDCoupling::CommInterface interface;
550   //
551   ProcessorGroup* self_group = new MEDCoupling::MPIProcessorGroup(interface,self_procs);
552   ProcessorGroup* target_group = new MEDCoupling::MPIProcessorGroup(interface,procs_target);
553   ProcessorGroup* source_group = new MEDCoupling::MPIProcessorGroup(interface,procs_source);
554   //
555   MPI_Barrier(MPI_COMM_WORLD);
556   if(source_group->containsMyRank())
557     {
558       std::ostringstream stream; stream << "sourcemesh2D proc " << rank;
559       mesh=MEDCouplingUMesh::New(stream.str().c_str(),1);
560       mesh->allocateCells();
561       for(int i=0;i<18;i++)
562         mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,sourceConn+2*i);
563       mesh->finishInsertingCells();
564       DataArrayDouble *myCoords=DataArrayDouble::New();
565       myCoords->alloc(19,3);
566       std::copy(sourceCoords,sourceCoords+19*3,myCoords->getPointer());
567       mesh->setCoords(myCoords);
568       myCoords->decrRef();
569       paramesh=new ParaMESH(mesh,*source_group,"source mesh");
570       MEDCoupling::ComponentTopology comptopo;
571       parafield = new ParaFIELD(ON_NODES,NO_TIME,paramesh,comptopo);
572       double *value=parafield->getField()->getArray()->getPointer();
573       std::copy(sourceVals,sourceVals+19,value);
574     }
575   else
576     {
577       if(rank==1)
578         {
579           std::ostringstream stream; stream << "targetmesh2D proc " << rank-nproc_source;
580           mesh=MEDCouplingUMesh::New(stream.str().c_str(),3);
581           mesh->allocateCells();
582           for(int i=0;i<4;i++)
583             mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,targetConn0+8*i);
584           mesh->finishInsertingCells();
585           DataArrayDouble *myCoords=DataArrayDouble::New();
586           myCoords->alloc(20,3);
587           std::copy(targetCoords0,targetCoords0+20*3,myCoords->getPointer());
588           mesh->setCoords(myCoords);
589           myCoords->decrRef();
590           paramesh=new ParaMESH (mesh,*target_group,"target mesh");
591           MEDCoupling::ComponentTopology comptopo;
592           parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
593         }
594       else if(rank==2)
595         {
596           std::ostringstream stream; stream << "targetmesh2D proc " << rank-nproc_source;
597           mesh=MEDCouplingUMesh::New(stream.str().c_str(),3);
598           mesh->allocateCells();
599           for(int i=0;i<6;i++)
600             mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,targetConn1+8*i);
601           mesh->finishInsertingCells();
602           DataArrayDouble *myCoords=DataArrayDouble::New();
603           myCoords->alloc(28,3);
604           std::copy(targetCoords1,targetCoords1+28*3,myCoords->getPointer());
605           mesh->setCoords(myCoords);
606           myCoords->decrRef();
607           paramesh=new ParaMESH (mesh,*target_group,"target mesh");
608           MEDCoupling::ComponentTopology comptopo;
609           parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
610         }
611     }
612   //test 1 - primaire -> secondaire
613   MEDCoupling::InterpKernelDEC dec(*source_group,*target_group);
614   dec.setIntersectionType(INTERP_KERNEL::PointLocator);
615   parafield->getField()->setNature(IntensiveMaximum);//very important
616   if (source_group->containsMyRank())
617     { 
618       dec.setMethod("P1");
619       dec.attachLocalField(parafield);
620       dec.synchronize();
621       dec.setForcedRenormalization(false);
622       dec.sendData();
623     }
624   else
625     {
626       dec.setMethod("P0");
627       dec.attachLocalField(parafield);
628       dec.synchronize();
629       dec.setForcedRenormalization(false);
630       dec.recvData();
631       const double *res(parafield->getField()->getArray()->getConstPointer());
632       if(rank==1)
633         {
634           const double expected0[4]={0.49,7.956666666666667,27.29,0.};
635           for(int i=0;i<4;i++)
636             CPPUNIT_ASSERT_DOUBLES_EQUAL(expected0[i],res[i],1e-13);
637         }
638       else
639         {
640           const double expected1[6]={59.95666666666667,94.09,0.,125.69,202.89,296.09};
641           for(int i=0;i<6;i++)
642             CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],res[i],1e-13);
643         }
644     }
645   MPI_Barrier(MPI_COMM_WORLD);
646   if (source_group->containsMyRank())
647     {
648       dec.recvData();
649       const double expected2[19]={0.49,7.956666666666667,7.956666666666667,7.956666666666667,27.29,27.29,59.95666666666667,59.95666666666667,59.95666666666667,94.09,125.69,125.69,202.89,202.89,202.89,202.89,296.09,296.09,0.};
650       const double *res(parafield->getField()->getArray()->getConstPointer());
651       for(int i=0;i<19;i++)
652         CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],res[i],1e-13);
653     }
654   else
655     {
656       dec.sendData();
657     }
658   delete parafield;
659   mesh->decrRef();
660   delete paramesh;
661   delete self_group;
662   delete target_group;
663   delete source_group;
664   //
665   MPI_Barrier(MPI_COMM_WORLD);
666 }