1 // Copyright (C) 2007-2015 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 <cppunit/extensions/HelperMacros.h>
22 #include "MPI2Connector.hxx"
23 #include "ParaMESH.hxx"
24 #include "ParaFIELD.hxx"
25 #include "MEDCouplingUMesh.hxx"
26 #include "MEDCouplingFieldDouble.hxx"
27 #include "InterpKernelDEC.hxx"
28 #include "MPIProcessorGroup.hxx"
29 #include "CommInterface.hxx"
35 class MPI2ParaMEDMEMTest : public CppUnit::TestFixture
37 CPPUNIT_TEST_SUITE( MPI2ParaMEDMEMTest );
38 CPPUNIT_TEST( testBasicMPI2_1 );
39 CPPUNIT_TEST_SUITE_END();
41 void testBasicMPI2_1();
44 using namespace ParaMEDMEM;
46 void MPI2ParaMEDMEMTest::testBasicMPI2_1()
48 int lsize, lrank, gsize, grank;
50 std::string service = "SERVICE";
51 std::ostringstream meshfilename, meshname;
52 ParaMEDMEM::ParaMESH *paramesh=0;
53 ParaMEDMEM::MEDCouplingUMesh* mesh;
54 ParaMEDMEM::ParaFIELD *parafield=0;
55 ParaMEDMEM::CommInterface* interface;
56 ParaMEDMEM::MPIProcessorGroup* source, *target;
58 MPI_Comm_size( MPI_COMM_WORLD, &lsize );
59 MPI_Comm_rank( MPI_COMM_WORLD, &lrank );
62 CPPUNIT_ASSERT(false);
66 /* Connection to remote programm */
67 MPI2Connector *mpio = new MPI2Connector;
68 gcom = mpio->remoteMPI2Connect(service);
70 MPI_Comm_size( gcom, &gsize );
71 MPI_Comm_rank( gcom, &grank );
74 CPPUNIT_ASSERT(false);
78 interface = new ParaMEDMEM::CommInterface;
79 source = new ParaMEDMEM::MPIProcessorGroup(*interface,0,gsize-lsize-1,gcom);
80 target = new ParaMEDMEM::MPIProcessorGroup(*interface,gsize-lsize,gsize-1,gcom);
82 const double targetCoordsAll[3][16]={{0.7,1.45,0.7,1.65,0.9,1.65,0.9,1.45, 1.1,1.4,1.1,1.6,1.3,1.6,1.3,1.4},
83 {0.7,-0.6,0.7,0.7,0.9,0.7,0.9,-0.6, 1.1,-0.7,1.1,0.6,1.3,0.6,1.3,-0.7},
84 {0.7,-1.55,0.7,-1.35,0.9,-1.35,0.9,-1.55, 1.1,-1.65,1.1,-1.45,1.3,-1.45,1.3,-1.65}};
85 int conn4All[8]={0,1,2,3,4,5,6,7};
86 double targetResults[3][2]={{34.,34.},{38.333333333333336,42.666666666666664},{47.,47.}};
88 std::ostringstream stream; stream << "targetmesh2D proc " << grank-(gsize-lsize);
89 mesh=MEDCouplingUMesh::New(stream.str().c_str(),2);
90 mesh->allocateCells(2);
91 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn4All);
92 mesh->insertNextCell(INTERP_KERNEL::NORM_QUAD4,4,conn4All+4);
93 mesh->finishInsertingCells();
94 DataArrayDouble *myCoords=DataArrayDouble::New();
96 const double *targetCoords=targetCoordsAll[grank-(gsize-lsize)];
97 std::copy(targetCoords,targetCoords+16,myCoords->getPointer());
98 mesh->setCoords(myCoords);
100 paramesh=new ParaMESH (mesh,*target,"target mesh");
101 ParaMEDMEM::ComponentTopology comptopo;
102 parafield = new ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo);
104 ParaMEDMEM::InterpKernelDEC dec(*source,*target);
105 parafield->getField()->setNature(ConservativeVolumic);
108 dec.attachLocalField(parafield);
110 dec.setForcedRenormalization(false);
112 const double *res=parafield->getField()->getArray()->getConstPointer();
113 const double *expected=targetResults[grank-(gsize-lsize)];
114 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[0],res[0],1e-13);
115 CPPUNIT_ASSERT_DOUBLES_EQUAL(expected[1],res[1],1e-13);
116 /* Deconnection of remote programm */
117 mpio->remoteMPI2Disconnect(service);
128 CPPUNIT_TEST_SUITE_REGISTRATION( MPI2ParaMEDMEMTest );
130 #include "MPIMainTest.hxx"