Back to index

salome-med  6.5.0
ParaMEDSPLITTERTest_medsplitter_para.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_medsplitter_para.cxx
00020 // Created   : Fri Jul 31 12:35:44 2009
00021 // Author    : Edward AGAPOV (eap)
00022 //
00023 
00024 #include "ParaMEDSPLITTERTest.hxx"
00025 #include "MEDSPLITTERTest_Utils.hxx"
00026 
00027 #include "MEDSPLITTER_ParaDomainSelector.hxx"
00028 #include "MEDSPLITTER_MESHCollection.hxx"
00029 #include "MEDSPLITTER_ParaDomainSelector.hxx"
00030 #include "MEDSPLITTER_Topology.hxx"
00031 //#include "MEDSPLITTER_API.hxx"
00032 
00033 #include <MEDMEM_Mesh.hxx>
00034 #include <MEDMEM_PointerOf.hxx>
00035 
00036 using namespace std;
00037 using namespace MEDSPLITTER;
00038 using namespace MED_EN;
00039 
00040 //================================================================================
00044 //================================================================================
00045 
00046 void ParaMEDSPLITTERTest::functional_validation()
00047 {
00048   //test_medsplitter_para( "/dn25/salome/eap/salome/misc/tmp/meshing_REsplit1.med", "meshing_1");
00049   test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("TimeStamps.med"), "dom");
00050   test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("square1.med"), "Mesh_2");
00051   test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("pointe.med"), "maa1");
00052 }
00053 
00054 //================================================================================
00059 //================================================================================
00060 
00061 void ParaMEDSPLITTERTest::test_medsplitter_para( const string& med_file, const string& meshname )
00062 {
00063   ParaDomainSelector dom_sel;
00064 
00065   string tmp_dir = MEDSPLITTERTest_Utils::getTmpDirectory();
00066   // if splitter is running on different hosts, assure tmp_dir to be accessible from all procs
00067   bool diff_hosts = dom_sel.isOnDifferentHosts();
00068   if ( diff_hosts )
00069     if ( getenv("HOME"))
00070       tmp_dir = getenv("HOME");
00071 
00072   string file_2 = tmp_dir + "/test_medsplitter_para_2" ;
00073   string file_3 = tmp_dir + "/test_medsplitter_para_3" ;
00074   string file_1 = tmp_dir + "/test_medsplitter_para_1" ;
00075   string file_3c= tmp_dir + "/test_medsplitter_para_3c" ;
00076   MEDMEM::STRING rm_cmd("rm "); rm_cmd << tmp_dir << "/test_medsplitter_para_*";
00077 
00078   MPI_Barrier( MPI_COMM_WORLD ); // avoid removing files being read
00079 
00080   // remove all old (master and med) files
00081   if ( dom_sel.rank() == 0 )
00082     system( rm_cmd );
00083 
00084   // découper en deux
00085   if ( dom_sel.rank() == 0 )
00086   {
00087     MESHCollection collection_1(med_file,meshname);
00088     auto_ptr<Topology> new_topo_2( collection_1.createPartition( 2, Graph::SCOTCH ));
00089 
00090     MESHCollection collection_2w( collection_1, new_topo_2.get());
00091     collection_2w.setDriverType(MEDSPLITTER::MedAscii);
00092     collection_2w.write( file_2 );
00093   }
00094   MPI_Barrier( MPI_COMM_WORLD ); // wait for master file_2
00095 
00096   // passer de deux à trois sous-domaines
00097   MESHCollection collection_2r(file_2,dom_sel);
00098   auto_ptr<Topology> new_topo_3( collection_2r.createPartition( 3, Graph::METIS ));
00099 
00100   MESHCollection collection_3w( collection_2r, new_topo_3.get());
00101   collection_3w.setDriverType(MEDSPLITTER::MedAscii);
00102   collection_3w.write( file_3 );
00103 
00104   // check global face numbers of collection_3w
00105   {
00106     int total_nb_faces = 0;
00107     for ( int idomain=0; idomain < collection_3w.getMesh().size(); ++idomain )
00108       total_nb_faces += collection_3w.getMesh()[idomain]->getNumberOfElements(collection_3w.getSubEntity(), MED_ALL_ELEMENTS );
00109 
00110     for ( int idomain=0; idomain < collection_3w.getMesh().size(); ++idomain )
00111     {
00112       int nb_dom_faces = new_topo_3->getFaceNumber(idomain);
00113       MEDMEM::PointerOf<int> glob_ids( nb_dom_faces );
00114       new_topo_3->getFaceList(idomain, glob_ids);
00115       for ( int i = 0; i < nb_dom_faces; ++i )
00116         if ( glob_ids[i] < 1 || glob_ids[i] > total_nb_faces )
00117           CPPUNIT_FAIL(MEDMEM::STRING("Invalid global face id: ")<< glob_ids[i]);
00118     }
00119   }
00120   
00121   MPI_Barrier( MPI_COMM_WORLD ); // wait for master file_3
00122 
00123   // revenir vers un sous-domaine
00124   MESHCollection collection_3r(file_3,dom_sel);
00125   auto_ptr<Topology> new_topo_1( collection_3r.createPartition( 1, Graph::METIS ));
00126 
00127   MESHCollection collection_1w( collection_3r, new_topo_1.get());
00128   collection_1w.setDriverType(MEDSPLITTER::MedAscii);
00129   collection_1w.write( file_1 );
00130 
00131   // compare initial and final mesh
00132 
00133   if ( dom_sel.getProccessorID(0) == dom_sel.rank() )
00134   {
00135     MEDMEM::MESH init_mesh( MEDMEM::MED_DRIVER, med_file, meshname);
00136     MEDMEM::MESH& res_mesh = * collection_1w.getMesh()[0];
00137 
00138     // nb nodes
00139     int i_nb_nodes = init_mesh.getNumberOfNodes();
00140     int r_nb_nodes = res_mesh.getNumberOfNodes();
00141     CPPUNIT_ASSERT_EQUAL( i_nb_nodes, r_nb_nodes );
00142 
00143     // coord
00144     string i_coo_sys = init_mesh.getCoordinatesSystem();
00145     string r_coo_sys = res_mesh.getCoordinatesSystem();
00146     CPPUNIT_ASSERT_EQUAL( i_coo_sys, r_coo_sys );
00147 
00148     // types and nb elements
00149     int i_nb_types = init_mesh.getNumberOfTypes(MED_CELL);
00150     int r_nb_types = res_mesh.getNumberOfTypes(MED_CELL);
00151     CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
00152     {
00153       const medGeometryElement* i_types = init_mesh.getTypes(MED_CELL);
00154       const medGeometryElement* r_types = res_mesh.getTypes(MED_CELL);
00155       for ( int i=0; i<i_nb_types; ++i )
00156         CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
00157       const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_CELL );
00158       const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_CELL );
00159       for ( int i=0; i<i_nb_types; ++i )
00160         CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
00161     }
00162     i_nb_types = init_mesh.getNumberOfTypes(MED_FACE);
00163     r_nb_types = res_mesh.getNumberOfTypes(MED_FACE);
00164     CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
00165     if ( i_nb_types )
00166     {
00167       const medGeometryElement* i_types = init_mesh.getTypes(MED_FACE);
00168       const medGeometryElement* r_types = res_mesh.getTypes(MED_FACE);
00169       for ( int i=0; i<i_nb_types; ++i )
00170         CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
00171       const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_FACE );
00172       const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_FACE );
00173       for ( int i=0; i<i_nb_types; ++i )
00174         CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
00175     }
00176     i_nb_types = init_mesh.getNumberOfTypes(MED_EDGE);
00177     r_nb_types = res_mesh.getNumberOfTypes(MED_EDGE);
00178     CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
00179     if ( i_nb_types )
00180     {
00181       const medGeometryElement* i_types = init_mesh.getTypes(MED_EDGE);
00182       const medGeometryElement* r_types = res_mesh.getTypes(MED_EDGE);
00183       for ( int i=0; i<i_nb_types; ++i )
00184         CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
00185       const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_EDGE );
00186       const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_EDGE );
00187       for ( int i=0; i<i_nb_types; ++i )
00188         CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
00189     }
00190   }
00191 
00192   // Check C API and create_boundary_faces
00193 //   medsplitter_para( file_2.c_str(),
00194 //                     file_3c.c_str(), 
00195 //                     /*nprocs                =*/ 3,
00196 //                     /*method                =*/ 0,
00197 //                     /*create_boundary_faces =*/ true,
00198 //                     /*family_splitting      =*/ false);
00199 
00200 //   CPPUNIT_ASSERT( access(file_3c.data(), F_OK) == 0);
00201 
00202   MPI_Barrier( MPI_COMM_WORLD ); // avoid removing files being read
00203 
00204   // remove all (master and med) files
00205   if ( dom_sel.rank() == 0 )
00206     system( rm_cmd );
00207 }