1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ParaMEDMEMTest.hxx"
21 #include <cppunit/TestAssert.h>
23 #include "CommInterface.hxx"
24 #include "ProcessorGroup.hxx"
25 #include "MPIProcessorGroup.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"
43 using namespace MEDCoupling;
44 using namespace ICoCo;
46 void afficheGauthier1(const ParaFIELD& field, const double *vals, int lgth)
48 const DataArrayDouble *valsOfField(field.getField()->getArray());
49 CPPUNIT_ASSERT_EQUAL(lgth,(int)valsOfField->getNumberOfTuples());
50 for (int ele=0;ele<valsOfField->getNumberOfTuples();ele++)
51 CPPUNIT_ASSERT_DOUBLES_EQUAL(vals[ele],valsOfField->getIJ(ele,0),1e-12);
54 MEDCouplingUMesh *init_quadGauthier1(int is_master)
56 MCAuto<MEDCouplingUMesh> m(MEDCouplingUMesh::New("champ_quad",2));
57 MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
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};
62 std::copy(dataCoo,dataCoo+24,coo->getPointer());
63 const mcIdType conn[8]={0,1,3,2,4,5,7,6};
65 m->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn);
66 m->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn+4);
77 MEDCouplingUMesh *init_triangleGauthier1(int is_master)
79 MCAuto<MEDCouplingUMesh> m(MEDCouplingUMesh::New("champ_triangle",2));
80 MCAuto<DataArrayDouble> coo(DataArrayDouble::New());
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};
85 std::copy(dataCoo,dataCoo+24,coo->getPointer());
86 const mcIdType conn[12]={0,1,2,1,2,3,4,5,7,4,6,7};
89 m->insertNextCell(INTERP_KERNEL::NORM_TRI3,3,conn+3*i);
101 void ParaMEDMEMTest::testGauthier1()
105 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
106 MPI_Comm_size(MPI_COMM_WORLD,&size);
111 set<int> emetteur_ids;
112 set<int> recepteur_ids;
113 emetteur_ids.insert(0);
116 recepteur_ids.insert(1);
118 recepteur_ids.insert(2);
120 emetteur_ids.insert(3);
121 if ((rank==0)||(rank==1))
124 MPIProcessorGroup recepteur_group(comm,recepteur_ids);
125 MPIProcessorGroup emetteur_group(comm,emetteur_ids);
128 if (recepteur_group.containsMyRank())
131 //freopen("recpeteur.out","w",stdout);
132 //freopen("recepteur.err","w",stderr);
137 // freopen("emetteur.out","w",stdout);
138 //freopen("emetteur.err","w",stderr);
140 double expected[8][4]={
144 {40.,1.,1e200,1e200},
148 {20.5,1.,1e200,1e200}
150 int expectedLgth[8]={4,4,2,2,4,4,2,2};
152 for (int send=0;send<2;send++)
153 for (int rec=0;rec<2;rec++)
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);
162 mesh=init_quadGauthier1(is_master);
166 mesh=init_triangleGauthier1(is_master);
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);
175 mesh=init_triangleGauthier1(is_master);
179 mesh=init_quadGauthier1(is_master);
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);
187 champ_emetteur->getField()->getArray()->fillWithValue(1.);
191 MPI_Barrier(MPI_COMM_WORLD);
193 //clock_t clock0= clock ();
196 bool init=true; // first time step ??
198 //boucle sur les pas de quads
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++)
210 champ_emetteur->getField()->getArray()->setIJ(0,0,40);
212 //bool ok=false; // Is the time interval successfully solved ?
214 // Loop on the time interval tries
219 dec_emetteur.attachLocalField(champ_emetteur);
221 dec_emetteur.attachLocalField(champ_recepteur);
224 if(init) dec_emetteur.synchronize();
227 if (cas=="emetteur") {
228 // affiche(champ_emetteur);
229 dec_emetteur.sendData();
231 else if (cas=="recepteur")
233 dec_emetteur.recvData();
235 afficheGauthier1(*champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
239 MPI_Barrier(MPI_COMM_WORLD);
245 delete champ_emetteur;
246 delete champ_recepteur;
250 void ParaMEDMEMTest::testGauthier2()
252 std::cout << "testGauthier2\n";
253 double valuesExpected1[2]={0.,0.};
254 double valuesExpected2[2]={0.95,0.970625};
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 };
259 double *valuesExpected3[2]={valuesExpected30,valuesExpected31};
262 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
263 MPI_Comm_size(MPI_COMM_WORLD,&size);
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++)
274 MPIProcessorGroup entree_chaude_group(comm,entree_chaude_ids);
275 MPIProcessorGroup Genepi_group(comm,Genepi_ids);
277 MEDCoupling::ParaFIELD *vitesse(0);
278 InterpKernelDEC dec_vit_in_chaude(entree_chaude_group, Genepi_group);
280 if ( entree_chaude_group.containsMyRank())
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 mcIdType 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");
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 mcIdType 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());
323 dec_vit_in_chaude.attachLocalField(vitesse);
325 dec_vit_in_chaude.synchronize();
328 // Envois - receptions
329 if (entree_chaude_group.containsMyRank())
331 dec_vit_in_chaude.sendData();
335 dec_vit_in_chaude.recvData();
337 if ( !entree_chaude_group.containsMyRank() )
339 double pmin=1e38, pmax=-1e38;
340 const double *p(vitesse->getField()->getArray()->begin());
341 for(mcIdType i=0;i<vitesse->getField()->getArray()->getNbOfElems();i++,p++)
343 if (*p<pmin) pmin=*p;
344 if (*p>pmax) pmax=*p;
346 CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected1[type],pmin,1e-12);
347 CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected2[type],pmax,1e-12);
349 std::size_t nbCompo(vitesse->getField()->getNumberOfComponents());
350 p=vitesse->getField()->getArray()->begin();
351 for(int i=0;i<vitesse->getField()->getNumberOfTuples();i++)
352 for(std::size_t c=0;c<nbCompo;c++,p++)
353 CPPUNIT_ASSERT_DOUBLES_EQUAL(valuesExpected3[type][i*nbCompo+c],*p,1e-12);
359 void ParaMEDMEMTest::testGauthier3_1()
361 testGauthier3_GEN(true,4);
364 void ParaMEDMEMTest::testGauthier3_2()
366 testGauthier3_GEN(false,4);
369 void ParaMEDMEMTest::testGauthier3_3()
371 testGauthier3_GEN(true,5);
374 void ParaMEDMEMTest::testGauthier3_4()
377 MPI_Comm_size(MPI_COMM_WORLD,&size);
382 // Should throw since the two groups (source/target) do not form a partition of
384 CPPUNIT_ASSERT_THROW(testGauthier3_GEN(false,5), INTERP_KERNEL::Exception);
389 * Non regression test testing copy constructor of InterpKernelDEC.
391 void ParaMEDMEMTest::testGauthier3_GEN(bool withIDs, int nprocs)
395 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
396 MPI_Comm_size(MPI_COMM_WORLD,&size);
401 set<int> emetteur_ids;
402 set<int> recepteur_ids;
403 emetteur_ids.insert(0);
406 recepteur_ids.insert(1);
408 recepteur_ids.insert(size-2);
410 emetteur_ids.insert(size-1);
411 if ((rank==0)||(rank==1))
414 MPIProcessorGroup recepteur_group(comm,recepteur_ids);
415 MPIProcessorGroup emetteur_group(comm,emetteur_ids);
418 if (recepteur_group.containsMyRank())
421 //freopen("recpeteur.out","w",stdout);
422 //freopen("recepteur.err","w",stderr);
426 if (emetteur_group.containsMyRank())
430 // freopen("emetteur.out","w",stdout);
431 //freopen("emetteur.err","w",stderr);
434 double expected[8][4]={
438 {40.,1.,1e200,1e200},
442 {20.5,1.,1e200,1e200}
444 int expectedLgth[8]={4,4,2,2,4,4,2,2};
446 for (int send=0;send<2;send++)
447 for (int rec=0;rec<2;rec++)
449 std::vector<InterpKernelDEC> decu(1);
451 decu[0] = InterpKernelDEC(emetteur_ids,recepteur_ids);
453 decu[0] = InterpKernelDEC(emetteur_group,recepteur_group);
454 InterpKernelDEC& dec_emetteur=decu[0];
455 MEDCoupling::ParaFIELD *champ_emetteur(0),*champ_recepteur(0);
456 MEDCoupling::ParaMESH *paramesh(0);
457 MCAuto<MEDCouplingUMesh> mesh;
458 dec_emetteur.setOrientation(2);
461 mesh=init_quadGauthier1(is_master);
465 mesh=init_triangleGauthier1(is_master);
469 paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"emetteur mesh");
470 MEDCoupling::ComponentTopology comptopo;
471 champ_emetteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
472 champ_emetteur->getField()->setNature(IntensiveMaximum);
473 champ_emetteur->setOwnSupport(true);
476 mesh=init_triangleGauthier1(is_master);
480 mesh=init_quadGauthier1(is_master);
482 paramesh=new MEDCoupling::ParaMESH(mesh,recepteur_group.containsMyRank()?recepteur_group:emetteur_group,"recepteur mesh");
483 champ_recepteur=new MEDCoupling::ParaFIELD(ON_CELLS,ONE_TIME,paramesh,comptopo);
484 champ_recepteur->getField()->setNature(IntensiveMaximum);
485 champ_recepteur->setOwnSupport(true);
488 champ_emetteur->getField()->getArray()->fillWithValue(1.);
492 MPI_Barrier(MPI_COMM_WORLD);
494 //clock_t clock0= clock ();
497 bool init=true; // first time step ??
499 //boucle sur les pas de quads
503 //clock_t clocki= clock ();
504 //cout << compti << " CLOCK " << (clocki-clock0)*1.e-6 << endl;
505 for (int non_unif=0;non_unif<2;non_unif++)
511 champ_emetteur->getField()->getArray()->setIJ(0,0,40);
513 //bool ok=false; // Is the time interval successfully solved ?
515 // Loop on the time interval tries
520 dec_emetteur.attachLocalField(champ_emetteur);
522 dec_emetteur.attachLocalField(champ_recepteur);
525 if(init) dec_emetteur.synchronize();
528 if (cas=="emetteur") {
529 // affiche(champ_emetteur);
530 dec_emetteur.sendData();
532 else if (cas=="recepteur")
534 dec_emetteur.recvData();
536 afficheGauthier1(*champ_recepteur,expected[num_cas],expectedLgth[num_cas]);
540 MPI_Barrier(MPI_COMM_WORLD);
546 delete champ_emetteur;
547 delete champ_recepteur;
552 * This test is the parallel version of MEDCouplingBasicsTest.test3D1DOnP1P0_1 test.
554 void ParaMEDMEMTest::testGauthier4()
557 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};
558 const mcIdType 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};
559 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};
560 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.};
561 const mcIdType 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};
562 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.};
563 const mcIdType 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};
567 MPI_Comm_size(MPI_COMM_WORLD,&size);
568 MPI_Comm_rank(MPI_COMM_WORLD,&rank);
572 int nproc_source = 1;
574 set<int> procs_source;
575 set<int> procs_target;
577 for (int i=0; i<nproc_source; i++)
578 procs_source.insert(i);
579 for (int i=nproc_source; i<size; i++)
580 procs_target.insert(i);
581 self_procs.insert(rank);
583 MEDCoupling::MEDCouplingUMesh *mesh=0;
584 MEDCoupling::ParaMESH *paramesh=0;
585 MEDCoupling::ParaFIELD* parafield=0;
587 MEDCoupling::CommInterface interface;
589 ProcessorGroup* self_group = new MEDCoupling::MPIProcessorGroup(interface,self_procs);
590 ProcessorGroup* target_group = new MEDCoupling::MPIProcessorGroup(interface,procs_target);
591 ProcessorGroup* source_group = new MEDCoupling::MPIProcessorGroup(interface,procs_source);
593 MPI_Barrier(MPI_COMM_WORLD);
594 if(source_group->containsMyRank())
596 std::ostringstream stream; stream << "sourcemesh2D proc " << rank;
597 mesh=MEDCouplingUMesh::New(stream.str().c_str(),1);
598 mesh->allocateCells();
599 for(int i=0;i<18;i++)
600 mesh->insertNextCell(INTERP_KERNEL::NORM_SEG2,2,sourceConn+2*i);
601 mesh->finishInsertingCells();
602 DataArrayDouble *myCoords=DataArrayDouble::New();
603 myCoords->alloc(19,3);
604 std::copy(sourceCoords,sourceCoords+19*3,myCoords->getPointer());
605 mesh->setCoords(myCoords);
607 paramesh=new ParaMESH(mesh,*source_group,"source mesh");
608 MEDCoupling::ComponentTopology comptopo;
609 parafield = new ParaFIELD(ON_NODES,NO_TIME,paramesh,comptopo);
610 double *value=parafield->getField()->getArray()->getPointer();
611 std::copy(sourceVals,sourceVals+19,value);
617 std::ostringstream stream; stream << "targetmesh2D proc " << rank-nproc_source;
618 mesh=MEDCouplingUMesh::New(stream.str().c_str(),3);
619 mesh->allocateCells();
621 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,targetConn0+8*i);
622 mesh->finishInsertingCells();
623 DataArrayDouble *myCoords=DataArrayDouble::New();
624 myCoords->alloc(20,3);
625 std::copy(targetCoords0,targetCoords0+20*3,myCoords->getPointer());
626 mesh->setCoords(myCoords);
628 paramesh=new ParaMESH (mesh,*target_group,"target mesh");
629 MEDCoupling::ComponentTopology comptopo;
630 parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
634 std::ostringstream stream; stream << "targetmesh2D proc " << rank-nproc_source;
635 mesh=MEDCouplingUMesh::New(stream.str().c_str(),3);
636 mesh->allocateCells();
638 mesh->insertNextCell(INTERP_KERNEL::NORM_HEXA8,8,targetConn1+8*i);
639 mesh->finishInsertingCells();
640 DataArrayDouble *myCoords=DataArrayDouble::New();
641 myCoords->alloc(28,3);
642 std::copy(targetCoords1,targetCoords1+28*3,myCoords->getPointer());
643 mesh->setCoords(myCoords);
645 paramesh=new ParaMESH (mesh,*target_group,"target mesh");
646 MEDCoupling::ComponentTopology comptopo;
647 parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
650 //test 1 - primaire -> secondaire
651 MEDCoupling::InterpKernelDEC dec(*source_group,*target_group);
652 dec.setIntersectionType(INTERP_KERNEL::PointLocator);
653 parafield->getField()->setNature(IntensiveMaximum);//very important
654 if (source_group->containsMyRank())
657 dec.attachLocalField(parafield);
659 dec.setForcedRenormalization(false);
665 dec.attachLocalField(parafield);
667 dec.setForcedRenormalization(false);
669 const double *res(parafield->getField()->getArray()->getConstPointer());
672 const double expected0[4]={0.49,7.956666666666667,27.29,0.};
674 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected0[i],res[i],1e-13);
678 const double expected1[6]={59.95666666666667,94.09,0.,125.69,202.89,296.09};
680 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected1[i],res[i],1e-13);
683 MPI_Barrier(MPI_COMM_WORLD);
684 if (source_group->containsMyRank())
687 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.};
688 const double *res(parafield->getField()->getArray()->getConstPointer());
689 for(int i=0;i<19;i++)
690 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected2[i],res[i],1e-13);
703 MPI_Barrier(MPI_COMM_WORLD);