Back to index

salome-med  6.5.0
ParaMEDSPLITTERTest_MeshSendReceive.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 // File      : ParaMEDSPLITTERTest_MeshSendReceive.cxx
00020 // Created   : Mon Jul  6 14:14:29 2009
00021 // Author    : Edward AGAPOV (eap)
00022 
00023 #include "ParaMEDSPLITTERTest.hxx"
00024 #include "MEDSPLITTERTest_Utils.hxx"
00025 
00026 #include "MEDSPLITTER_MESHCollection.hxx"
00027 #include "MEDSPLITTER_MeshSendReceive.hxx"
00028 #include "MEDSPLITTER_Topology.hxx"
00029 
00030 #include "MEDMEM_MeshFuse.hxx"
00031 #include "MEDMEM_Mesh.hxx"
00032 #include "MEDMEM_MedMeshDriver.hxx"
00033 #include "MEDMEM_DriverFactory.hxx"
00034 
00035 using namespace std;
00036 using namespace MEDSPLITTER;
00037 using namespace MED_EN;
00038 
00039 //================================================================================
00043 //================================================================================
00044 
00045 void ParaMEDSPLITTERTest::testMeshSendReceive()
00046 {
00047   MEDMEM::STRING filename = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
00048   MEDMEM::MESH* meshSent = 0;
00049   MEDMEM::MESH* meshRecv = 0;
00050 
00051   int size, rank;
00052   MPI_Comm_size(MPI_COMM_WORLD, &size);
00053   MPI_Comm_rank(MPI_COMM_WORLD, &rank) ;
00054 
00055   MeshSendReceive sender, receiver;
00056   vector<int> nums_sent_1(3,7), nums_sent_2(4,8), nums_sent_3(5,9);
00057   vector<int> nums_recv_1, nums_recv_2, nums_recv_3;
00058 
00059   if ( rank == 0 )
00060   {
00061     meshSent = new MEDMEM::MESH;
00062     MEDMEM::MED_MESH_RDONLY_DRIVER drv(filename, meshSent );
00063     drv.setMeshName( "maa1" );
00064     drv.desactivateFacesComputation();
00065     drv.open();
00066     drv.read();
00067     drv.close();
00068     CPPUNIT_ASSERT_NO_THROW( sender.send( size-1, 1,meshSent,nums_sent_1,nums_sent_2,nums_sent_3));
00069   }
00070   if ( rank == size-1 )
00071   {
00072     CPPUNIT_ASSERT_NO_THROW( meshRecv = receiver.recv( 0, 1, nums_recv_1,nums_recv_2,nums_recv_3));
00073     CPPUNIT_ASSERT( meshRecv );
00074     // test by printing that minimally needed data is present
00075     MEDMEM::STRING out;
00076     CPPUNIT_ASSERT_NO_THROW( out << *meshRecv );
00077   }
00078   if ( size == 1 )
00079   {
00080     CPPUNIT_ASSERT( nums_recv_1 == nums_sent_1 );
00081     CPPUNIT_ASSERT( nums_recv_2 == nums_sent_2 );
00082     CPPUNIT_ASSERT( nums_recv_3 == nums_sent_3 );
00083 
00084     if ( ! meshSent->deepCompare( *meshRecv ) )
00085     {
00086 #ifdef _DEBUG_
00087       MEDMEM::STRING outfilename("/tmp/pointe");
00088       outfilename << (void*) meshRecv << ".med";
00089       int drv = meshRecv->addDriver(MEDMEM::MED_DRIVER, outfilename, meshRecv->getName() );
00090       meshRecv->write( drv );
00091       CPPUNIT_FAIL( MEDMEM::STRING("received mesh differs from the sent one ") << filename <<
00092                                    ", check the received mesh in " << outfilename);
00093 #else
00094       CPPUNIT_FAIL( "received mesh differs from the sent one ");
00095 #endif
00096     }
00097   }
00098 
00099   delete meshRecv;
00100   delete meshSent;
00101 }
00102 
00103 //================================================================================
00107 //================================================================================
00108 
00109 void ParaMEDSPLITTERTest::testMeshFuse()
00110 {
00111   string filename  = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
00112   string meshname  = "maa1";
00113 
00114   // Splitting
00115 
00116   MESHCollection collection(filename,meshname);
00117 
00118   vector<int> partition;
00119   partition.reserve( collection.getMesh()[0]->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS));
00120   for ( int i = 0; i < partition.capacity()/2; ++i )
00121     partition.push_back( 0 );
00122   while ( partition.size() < partition.capacity() )
00123     partition.push_back( 1 );
00124 
00125   Topology* new_topo = collection.createPartition( &partition[0] );
00126   MESHCollection new_collection(collection, new_topo);
00127 
00128   // test splits of the mesh by printing
00129   MEDMEM::STRING out;
00130   CPPUNIT_ASSERT_NO_THROW( out << *(new_collection.getMesh()[0]));
00131   CPPUNIT_ASSERT_NO_THROW( out << *(new_collection.getMesh()[1]));
00132 
00133   // global numbers
00134   vector<int> glob_nb_left ( new_topo->getNodeNumber(0) );
00135   vector<int> glob_nb_right( new_topo->getNodeNumber(1) );
00136   new_topo->getNodeList( 0, & glob_nb_left[0] );
00137   new_topo->getNodeList( 1, & glob_nb_right[0] );
00138 
00139   // Fusion
00140 
00141   // test that minimally needed data present by printing
00142   MEDMEM::MeshFuse fusion;
00143   fusion.concatenate(new_collection.getMesh()[0], glob_nb_left);
00144   CPPUNIT_ASSERT_NO_THROW( out << ( (const MEDMEM::MESH &) fusion ));
00145   fusion.concatenate(new_collection.getMesh()[1], glob_nb_right);
00146   CPPUNIT_ASSERT_NO_THROW( out << ( (const MEDMEM::MESH &) fusion ));
00147 
00148   // compare
00149   MEDMEM::MESH init_mesh( MEDMEM::MED_DRIVER, filename, meshname);
00150   if ( !init_mesh.deepCompare( fusion ))
00151   {
00152 //     fusion.addDriver( MEDMEM::MED_DRIVER, "/tmp/fusion.med", fusion.getName() );
00153 //     fusion.write();
00154 
00155 //     new_collection.getMesh()[0]->addDriver( MEDMEM::MED_DRIVER,"/tmp/split_1.med", "maa1");
00156 //     new_collection.getMesh()[1]->addDriver( MEDMEM::MED_DRIVER,"/tmp/split_2.med", "maa1");
00157 //     new_collection.getMesh()[0]->write();
00158 //     new_collection.getMesh()[1]->write();
00159 //     new_collection.write( "/tmp/split" );
00160     
00161     //CPPUNIT_ASSERT( init_mesh.getName() == fusion.getName() );
00162     CPPUNIT_ASSERT( init_mesh.getSpaceDimension() == fusion.getSpaceDimension() );
00163     CPPUNIT_ASSERT( init_mesh.getMeshDimension() == fusion.getMeshDimension() );
00164     CPPUNIT_ASSERT( init_mesh.getIsAGrid() == fusion.getIsAGrid() );
00165     CPPUNIT_ASSERT( init_mesh.getNumberOfNodes() == fusion.getNumberOfNodes() );
00166     //CPPUNIT_ASSERT( init_mesh.getCoordinatesSystem() == fusion.() );
00167     CPPUNIT_ASSERT( init_mesh.getNumberOfTypes(MED_CELL) == fusion.getNumberOfTypes(MED_CELL) );
00168     for ( int i = 0; i < init_mesh.getNumberOfTypes(MED_CELL); ++i )
00169       CPPUNIT_ASSERT( init_mesh.getTypes(MED_CELL)[i] == fusion.getTypes(MED_CELL)[i] );
00170     CPPUNIT_ASSERT( init_mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
00171                     == fusion.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) );
00172 
00173 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00174 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00175 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00176 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00177 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00178 //     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
00179   }
00180 
00181   delete new_topo;
00182 
00183 }