Back to index

salome-med  6.5.0
Public Member Functions | Private Member Functions
ParaMEDSPLITTERTest Class Reference

#include <ParaMEDSPLITTERTest.hxx>

Inheritance diagram for ParaMEDSPLITTERTest:
Inheritance graph
[legend]
Collaboration diagram for ParaMEDSPLITTERTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void testMeshSendReceive ()
 Test intended to run on one proc.
void testMeshFuse ()
 Split pointe.med and fuse back.
void testParaDomainSelector_gatherGraph ()
 Test ParaDomainSelector::gatherGraph( graph )
void testParaDomainSelector_gatherNbOf ()
 test ParaDomainSelector::gatherNbOf( entity, domain_meshes )
void testParaDomainSelector_gatherEntityTypesInfo ()
 Test ParaDomainSelector::gatherEntityTypesInfo( domain_meshes, entity )
void testParaDomainSelector_gatherNbCellPairs ()
void testParaDomainSelector_exchangeJoint ()
 Test work of JointExchangeData and of ParaDomainSelector::exchangeJoint(joint)
void testParaDomainSelector_exchangeSubentityIds ()
 Test ParaDomainSelector::exchangeSubentityIds()
void functional_validation ()
 call test_medsplitter_para with 2 files: blade.med et pointe.med
void test_medsplitter_para (const std::string &med_file, const std::string &mesh)
 La validation consistera à prendre un maillage, à le découper en deux, à passer de deux à trois sous-domaines, puis à revenir vers un sous-domaine.

Private Member Functions

 CPPUNIT_TEST_SUITE (ParaMEDSPLITTERTest)
 CPPUNIT_TEST (testMeshSendReceive)
 CPPUNIT_TEST (testMeshFuse)
 CPPUNIT_TEST (testParaDomainSelector_gatherGraph)
 CPPUNIT_TEST (testParaDomainSelector_gatherNbOf)
 CPPUNIT_TEST (testParaDomainSelector_gatherEntityTypesInfo)
 CPPUNIT_TEST (testParaDomainSelector_gatherNbCellPairs)
 CPPUNIT_TEST (testParaDomainSelector_exchangeJoint)
 CPPUNIT_TEST (testParaDomainSelector_exchangeSubentityIds)
 CPPUNIT_TEST_SUITE_END ()

Detailed Description

Definition at line 37 of file ParaMEDSPLITTERTest.hxx.


Member Function Documentation

call test_medsplitter_para with 2 files: blade.med et pointe.med

Definition at line 46 of file ParaMEDSPLITTERTest_medsplitter_para.cxx.

{
  //test_medsplitter_para( "/dn25/salome/eap/salome/misc/tmp/meshing_REsplit1.med", "meshing_1");
  test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("TimeStamps.med"), "dom");
  test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("square1.med"), "Mesh_2");
  test_medsplitter_para( MEDSPLITTERTest_Utils::getResourceFile("pointe.med"), "maa1");
}

Here is the call graph for this function:

void ParaMEDSPLITTERTest::test_medsplitter_para ( const std::string &  med_file,
const std::string &  mesh 
)

La validation consistera à prendre un maillage, à le découper en deux, à passer de deux à trois sous-domaines, puis à revenir vers un sous-domaine.

Definition at line 61 of file ParaMEDSPLITTERTest_medsplitter_para.cxx.

{
  ParaDomainSelector dom_sel;

  string tmp_dir = MEDSPLITTERTest_Utils::getTmpDirectory();
  // if splitter is running on different hosts, assure tmp_dir to be accessible from all procs
  bool diff_hosts = dom_sel.isOnDifferentHosts();
  if ( diff_hosts )
    if ( getenv("HOME"))
      tmp_dir = getenv("HOME");

  string file_2 = tmp_dir + "/test_medsplitter_para_2" ;
  string file_3 = tmp_dir + "/test_medsplitter_para_3" ;
  string file_1 = tmp_dir + "/test_medsplitter_para_1" ;
  string file_3c= tmp_dir + "/test_medsplitter_para_3c" ;
  MEDMEM::STRING rm_cmd("rm "); rm_cmd << tmp_dir << "/test_medsplitter_para_*";

  MPI_Barrier( MPI_COMM_WORLD ); // avoid removing files being read

  // remove all old (master and med) files
  if ( dom_sel.rank() == 0 )
    system( rm_cmd );

  // découper en deux
  if ( dom_sel.rank() == 0 )
  {
    MESHCollection collection_1(med_file,meshname);
    auto_ptr<Topology> new_topo_2( collection_1.createPartition( 2, Graph::SCOTCH ));

    MESHCollection collection_2w( collection_1, new_topo_2.get());
    collection_2w.setDriverType(MEDSPLITTER::MedAscii);
    collection_2w.write( file_2 );
  }
  MPI_Barrier( MPI_COMM_WORLD ); // wait for master file_2

  // passer de deux à trois sous-domaines
  MESHCollection collection_2r(file_2,dom_sel);
  auto_ptr<Topology> new_topo_3( collection_2r.createPartition( 3, Graph::METIS ));

  MESHCollection collection_3w( collection_2r, new_topo_3.get());
  collection_3w.setDriverType(MEDSPLITTER::MedAscii);
  collection_3w.write( file_3 );

  // check global face numbers of collection_3w
  {
    int total_nb_faces = 0;
    for ( int idomain=0; idomain < collection_3w.getMesh().size(); ++idomain )
      total_nb_faces += collection_3w.getMesh()[idomain]->getNumberOfElements(collection_3w.getSubEntity(), MED_ALL_ELEMENTS );

    for ( int idomain=0; idomain < collection_3w.getMesh().size(); ++idomain )
    {
      int nb_dom_faces = new_topo_3->getFaceNumber(idomain);
      MEDMEM::PointerOf<int> glob_ids( nb_dom_faces );
      new_topo_3->getFaceList(idomain, glob_ids);
      for ( int i = 0; i < nb_dom_faces; ++i )
        if ( glob_ids[i] < 1 || glob_ids[i] > total_nb_faces )
          CPPUNIT_FAIL(MEDMEM::STRING("Invalid global face id: ")<< glob_ids[i]);
    }
  }
  
  MPI_Barrier( MPI_COMM_WORLD ); // wait for master file_3

  // revenir vers un sous-domaine
  MESHCollection collection_3r(file_3,dom_sel);
  auto_ptr<Topology> new_topo_1( collection_3r.createPartition( 1, Graph::METIS ));

  MESHCollection collection_1w( collection_3r, new_topo_1.get());
  collection_1w.setDriverType(MEDSPLITTER::MedAscii);
  collection_1w.write( file_1 );

  // compare initial and final mesh

  if ( dom_sel.getProccessorID(0) == dom_sel.rank() )
  {
    MEDMEM::MESH init_mesh( MEDMEM::MED_DRIVER, med_file, meshname);
    MEDMEM::MESH& res_mesh = * collection_1w.getMesh()[0];

    // nb nodes
    int i_nb_nodes = init_mesh.getNumberOfNodes();
    int r_nb_nodes = res_mesh.getNumberOfNodes();
    CPPUNIT_ASSERT_EQUAL( i_nb_nodes, r_nb_nodes );

    // coord
    string i_coo_sys = init_mesh.getCoordinatesSystem();
    string r_coo_sys = res_mesh.getCoordinatesSystem();
    CPPUNIT_ASSERT_EQUAL( i_coo_sys, r_coo_sys );

    // types and nb elements
    int i_nb_types = init_mesh.getNumberOfTypes(MED_CELL);
    int r_nb_types = res_mesh.getNumberOfTypes(MED_CELL);
    CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
    {
      const medGeometryElement* i_types = init_mesh.getTypes(MED_CELL);
      const medGeometryElement* r_types = res_mesh.getTypes(MED_CELL);
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
      const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_CELL );
      const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_CELL );
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
    }
    i_nb_types = init_mesh.getNumberOfTypes(MED_FACE);
    r_nb_types = res_mesh.getNumberOfTypes(MED_FACE);
    CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
    if ( i_nb_types )
    {
      const medGeometryElement* i_types = init_mesh.getTypes(MED_FACE);
      const medGeometryElement* r_types = res_mesh.getTypes(MED_FACE);
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
      const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_FACE );
      const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_FACE );
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
    }
    i_nb_types = init_mesh.getNumberOfTypes(MED_EDGE);
    r_nb_types = res_mesh.getNumberOfTypes(MED_EDGE);
    CPPUNIT_ASSERT_EQUAL( i_nb_types, r_nb_types );
    if ( i_nb_types )
    {
      const medGeometryElement* i_types = init_mesh.getTypes(MED_EDGE);
      const medGeometryElement* r_types = res_mesh.getTypes(MED_EDGE);
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_types[i], r_types[i] );
      const int * i_nbs = init_mesh.getGlobalNumberingIndex( MED_EDGE );
      const int * r_nbs = res_mesh.getGlobalNumberingIndex( MED_EDGE );
      for ( int i=0; i<i_nb_types; ++i )
        CPPUNIT_ASSERT_EQUAL( i_nbs[i], r_nbs[i] );
    }
  }

  // Check C API and create_boundary_faces
//   medsplitter_para( file_2.c_str(),
//                     file_3c.c_str(), 
//                     /*nprocs                =*/ 3,
//                     /*method                =*/ 0,
//                     /*create_boundary_faces =*/ true,
//                     /*family_splitting      =*/ false);

//   CPPUNIT_ASSERT( access(file_3c.data(), F_OK) == 0);

  MPI_Barrier( MPI_COMM_WORLD ); // avoid removing files being read

  // remove all (master and med) files
  if ( dom_sel.rank() == 0 )
    system( rm_cmd );
}

Here is the call graph for this function:

Split pointe.med and fuse back.

Definition at line 109 of file ParaMEDSPLITTERTest_MeshSendReceive.cxx.

{
  string filename  = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
  string meshname  = "maa1";

  // Splitting

  MESHCollection collection(filename,meshname);

  vector<int> partition;
  partition.reserve( collection.getMesh()[0]->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS));
  for ( int i = 0; i < partition.capacity()/2; ++i )
    partition.push_back( 0 );
  while ( partition.size() < partition.capacity() )
    partition.push_back( 1 );

  Topology* new_topo = collection.createPartition( &partition[0] );
  MESHCollection new_collection(collection, new_topo);

  // test splits of the mesh by printing
  MEDMEM::STRING out;
  CPPUNIT_ASSERT_NO_THROW( out << *(new_collection.getMesh()[0]));
  CPPUNIT_ASSERT_NO_THROW( out << *(new_collection.getMesh()[1]));

  // global numbers
  vector<int> glob_nb_left ( new_topo->getNodeNumber(0) );
  vector<int> glob_nb_right( new_topo->getNodeNumber(1) );
  new_topo->getNodeList( 0, & glob_nb_left[0] );
  new_topo->getNodeList( 1, & glob_nb_right[0] );

  // Fusion

  // test that minimally needed data present by printing
  MEDMEM::MeshFuse fusion;
  fusion.concatenate(new_collection.getMesh()[0], glob_nb_left);
  CPPUNIT_ASSERT_NO_THROW( out << ( (const MEDMEM::MESH &) fusion ));
  fusion.concatenate(new_collection.getMesh()[1], glob_nb_right);
  CPPUNIT_ASSERT_NO_THROW( out << ( (const MEDMEM::MESH &) fusion ));

  // compare
  MEDMEM::MESH init_mesh( MEDMEM::MED_DRIVER, filename, meshname);
  if ( !init_mesh.deepCompare( fusion ))
  {
//     fusion.addDriver( MEDMEM::MED_DRIVER, "/tmp/fusion.med", fusion.getName() );
//     fusion.write();

//     new_collection.getMesh()[0]->addDriver( MEDMEM::MED_DRIVER,"/tmp/split_1.med", "maa1");
//     new_collection.getMesh()[1]->addDriver( MEDMEM::MED_DRIVER,"/tmp/split_2.med", "maa1");
//     new_collection.getMesh()[0]->write();
//     new_collection.getMesh()[1]->write();
//     new_collection.write( "/tmp/split" );
    
    //CPPUNIT_ASSERT( init_mesh.getName() == fusion.getName() );
    CPPUNIT_ASSERT( init_mesh.getSpaceDimension() == fusion.getSpaceDimension() );
    CPPUNIT_ASSERT( init_mesh.getMeshDimension() == fusion.getMeshDimension() );
    CPPUNIT_ASSERT( init_mesh.getIsAGrid() == fusion.getIsAGrid() );
    CPPUNIT_ASSERT( init_mesh.getNumberOfNodes() == fusion.getNumberOfNodes() );
    //CPPUNIT_ASSERT( init_mesh.getCoordinatesSystem() == fusion.() );
    CPPUNIT_ASSERT( init_mesh.getNumberOfTypes(MED_CELL) == fusion.getNumberOfTypes(MED_CELL) );
    for ( int i = 0; i < init_mesh.getNumberOfTypes(MED_CELL); ++i )
      CPPUNIT_ASSERT( init_mesh.getTypes(MED_CELL)[i] == fusion.getTypes(MED_CELL)[i] );
    CPPUNIT_ASSERT( init_mesh.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS)
                    == fusion.getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS) );

//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
//     CPPUNIT_ASSERT( init_mesh.() == fusion.() );
  }

  delete new_topo;

}

Here is the call graph for this function:

Test intended to run on one proc.

Definition at line 45 of file ParaMEDSPLITTERTest_MeshSendReceive.cxx.

{
  MEDMEM::STRING filename = MEDSPLITTERTest_Utils::getResourceFile("pointe.med");
  MEDMEM::MESH* meshSent = 0;
  MEDMEM::MESH* meshRecv = 0;

  int size, rank;
  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank) ;

  MeshSendReceive sender, receiver;
  vector<int> nums_sent_1(3,7), nums_sent_2(4,8), nums_sent_3(5,9);
  vector<int> nums_recv_1, nums_recv_2, nums_recv_3;

  if ( rank == 0 )
  {
    meshSent = new MEDMEM::MESH;
    MEDMEM::MED_MESH_RDONLY_DRIVER drv(filename, meshSent );
    drv.setMeshName( "maa1" );
    drv.desactivateFacesComputation();
    drv.open();
    drv.read();
    drv.close();
    CPPUNIT_ASSERT_NO_THROW( sender.send( size-1, 1,meshSent,nums_sent_1,nums_sent_2,nums_sent_3));
  }
  if ( rank == size-1 )
  {
    CPPUNIT_ASSERT_NO_THROW( meshRecv = receiver.recv( 0, 1, nums_recv_1,nums_recv_2,nums_recv_3));
    CPPUNIT_ASSERT( meshRecv );
    // test by printing that minimally needed data is present
    MEDMEM::STRING out;
    CPPUNIT_ASSERT_NO_THROW( out << *meshRecv );
  }
  if ( size == 1 )
  {
    CPPUNIT_ASSERT( nums_recv_1 == nums_sent_1 );
    CPPUNIT_ASSERT( nums_recv_2 == nums_sent_2 );
    CPPUNIT_ASSERT( nums_recv_3 == nums_sent_3 );

    if ( ! meshSent->deepCompare( *meshRecv ) )
    {
#ifdef _DEBUG_
      MEDMEM::STRING outfilename("/tmp/pointe");
      outfilename << (void*) meshRecv << ".med";
      int drv = meshRecv->addDriver(MEDMEM::MED_DRIVER, outfilename, meshRecv->getName() );
      meshRecv->write( drv );
      CPPUNIT_FAIL( MEDMEM::STRING("received mesh differs from the sent one ") << filename <<
                                   ", check the received mesh in " << outfilename);
#else
      CPPUNIT_FAIL( "received mesh differs from the sent one ");
#endif
    }
  }

  delete meshRecv;
  delete meshSent;
}

Here is the call graph for this function:

Test work of JointExchangeData and of ParaDomainSelector::exchangeJoint(joint)

Definition at line 354 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  ParaDomainSelector dom_sel;

  // Exchange a joint between two grids with following global ids
  //    5     6      6     9
  //   *-----*      *-----*
  //   |     |      |     |
  //   |  2  |      |  4  |
  //   |3    |4     |4    |8
  //   *-----*      *-----*
  //   |     |      |     |
  //   |  1  |      |  3  |
  //   |1    |2     |2    |7
  //   *-----*      *-----*
  
  // make grids; actually we make one grid as their connectivities are same and
  // coordinates doesn't matter here
  const MEDMEM::MESH* grid = 0;
  {
    const int dim = 2;
    vector<vector<double> > xyz_array(dim);
    vector<string>          coord_name(dim,"coo");
    vector<string>          unit(dim,"m");

    xyz_array[0].resize(2, 0.);
    xyz_array[1].resize(3, 0.);
    MEDMEM::GRID tmpGrid( xyz_array, coord_name, unit );
    grid = tmpGrid.convertInMESH();
  }

  // global ids
  int cells1[] = { 1, 2 };
  int cells2[] = { 3, 4 };
  int nodes1[] = { 1, 2, 3, 4, 5, 6 };
  int nodes2[] = { 2, 7, 4, 8, 6, 9 };
  int* cells_here = dom_sel.rank() ? cells2 : cells1;
  int* cells_dist = dom_sel.rank() ? cells2 : cells1;
  int* nodes_here = dom_sel.rank() ? nodes2 : nodes1;
  //int* nodes_dist = dom_sel.rank() ? nodes2 : nodes1;

  int dom_here = dom_sel.isMyDomain( 0 ) ? 0 : 1;
  int dom_dist = 1 - dom_here;

  // store cell/cell correspondencies
  JointExchangeData joint;
  joint.addCellCorrespondence( grid, dom_dist, dom_here, cells_dist[0], cells_here[0], 1 );
  joint.addCellCorrespondence( grid, dom_dist, dom_here, cells_dist[1], cells_here[1], 2 );
  CPPUNIT_ASSERT_EQUAL( 2, joint.nbCellPairs());

  // prepare to exchangeJoint()
  joint.setMeshes( dom_dist, grid, dom_here, grid );
  CPPUNIT_ASSERT_EQUAL( dom_dist, joint.distantDomain() );
  CPPUNIT_ASSERT_EQUAL( dom_here, joint.localDomain() );

  joint.setConnectivity( nodes_here );
  // in general case we woul need to call dom_sel.gatherEntityTypesInfo() but grid
  // knows nb of elements without connectivity initialization
  CPPUNIT_ASSERT_THROW( dom_sel.exchangeJoint( & joint ), MED_EXCEPTION);
  dom_sel.setNbDomains( 2 );
  dom_sel.setNbCellPairs( 2, dom_dist, dom_here );
  dom_sel.gatherNbCellPairs();
  CPPUNIT_ASSERT_NO_THROW( dom_sel.exchangeJoint( & joint ));

  // get CONNECTZONE
  const int joint_edge_glob_id = 100;
  joint.setFisrtGlobalIdOfSubentity( joint_edge_glob_id );
  TGeom2FacesByDomian face_map(2);
  auto_ptr<MEDMEM::CONNECTZONE> cz( joint.makeConnectZone(face_map));
  CPPUNIT_ASSERT( cz.get() );

  // ---------
  // check cz
  // ---------

  CPPUNIT_ASSERT_EQUAL( dom_dist, cz->getDistantDomainNumber() );
  CPPUNIT_ASSERT_EQUAL( dom_here, cz->getLocalDomainNumber() );

  CPPUNIT_ASSERT_EQUAL( long(grid), long(cz->getLocalMesh()) );
  CPPUNIT_ASSERT_EQUAL( long(grid), long(cz->getDistantMesh()) );

  CPPUNIT_ASSERT( cz->isEntityCorrespPresent(MED_CELL, MED_CELL) );
  CPPUNIT_ASSERT( !cz->isEntityCorrespPresent(MED_NODE, MED_NODE) );
  CPPUNIT_ASSERT( !cz->isEntityCorrespPresent(MED_EDGE, MED_EDGE) );
  CPPUNIT_ASSERT( !cz->isEntityCorrespPresent(MED_FACE, MED_FACE) );

  CPPUNIT_ASSERT_EQUAL( 3, cz->getNodeNumber() );
  CPPUNIT_ASSERT_EQUAL( 2, cz->getEntityCorrespNumber(MED_CELL,MED_CELL));

  const int * node_index = cz->getNodeCorrespIndex();
  CPPUNIT_ASSERT(node_index);
  for ( int i = 0; i < 4; ++i )
    CPPUNIT_ASSERT_EQUAL( i + 1, node_index[ i ]);

  const int * node_value = cz->getNodeCorrespValue();
  CPPUNIT_ASSERT(node_value);
  int val[2][6] = {{ 2, 1, 4, 3, 6, 5 },
                   { 1, 2, 3, 4, 5, 6 }}; // local ids of neighbouring domain
  for ( int i = 0; i < 6; ++i )
    CPPUNIT_ASSERT_EQUAL( val[ dom_sel.rank()][ i ], node_value[ i ]);

  const int * cell_index = cz->getEntityCorrespIndex(MED_CELL, MED_CELL);
  CPPUNIT_ASSERT(cell_index);
  for ( int i = 0; i < 3; ++i )
    CPPUNIT_ASSERT_EQUAL( i + 1, cell_index[ i ]);

  const int * cell_value = cz->getEntityCorrespValue(MED_CELL, MED_CELL);
  CPPUNIT_ASSERT(cell_value);
  CPPUNIT_ASSERT_EQUAL( 1, cell_value[ 0 ]);
  CPPUNIT_ASSERT_EQUAL( 2, cell_value[ 1 ]);

  CPPUNIT_ASSERT_EQUAL( 1, int( face_map[ dom_sel.rank() ].size() ));
  CPPUNIT_ASSERT_EQUAL( 0, int( face_map[ 1 - dom_sel.rank() ].size() ));
  CPPUNIT_ASSERT_EQUAL( MED_SEG2, face_map[ dom_sel.rank() ].begin()->first );

  vector< MEDSPLITTER_FaceModel* >& faces = face_map[ dom_sel.rank() ][ MED_SEG2 ];
  CPPUNIT_ASSERT_EQUAL( 2, int( faces.size() ));
  CPPUNIT_ASSERT_EQUAL( MED_SEG2, faces[0]->getType());
  CPPUNIT_ASSERT_EQUAL( joint_edge_glob_id+0, faces[0]->getGlobal());
  CPPUNIT_ASSERT_EQUAL( joint_edge_glob_id+1, faces[1]->getGlobal());
  // edge connectivity
  CPPUNIT_ASSERT_EQUAL( dom_sel.rank() ? 1 : 4, (*faces[0])[0]);
  CPPUNIT_ASSERT_EQUAL( dom_sel.rank() ? 3 : 2, (*faces[0])[1]);
  CPPUNIT_ASSERT_EQUAL( dom_sel.rank() ? 3 : 6, (*faces[1])[0]);
  CPPUNIT_ASSERT_EQUAL( dom_sel.rank() ? 5 : 4, (*faces[1])[1]);

  grid->removeReference();
}

Here is the call graph for this function:

Test ParaDomainSelector::exchangeSubentityIds()

Definition at line 495 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  ParaDomainSelector dom_sel;
  vector<int> loc_ids_here(3, -373);
  int* got_ids;
  CPPUNIT_ASSERT_THROW
    ( dom_sel.exchangeSubentityIds( dom_sel.rank(), 1-dom_sel.rank(), loc_ids_here),MED_EXCEPTION);
  dom_sel.setNbDomains( 2 );
  CPPUNIT_ASSERT_NO_THROW
    ( got_ids = dom_sel.exchangeSubentityIds( dom_sel.rank(), 1-dom_sel.rank(), loc_ids_here));
  CPPUNIT_ASSERT_EQUAL( loc_ids_here[0], got_ids[0] );
  CPPUNIT_ASSERT_EQUAL( loc_ids_here[1], got_ids[1] );
  CPPUNIT_ASSERT_EQUAL( loc_ids_here[2], got_ids[2] );
  delete [] got_ids;
}

Here is the call graph for this function:

Test ParaDomainSelector::gatherEntityTypesInfo( domain_meshes, entity )

Definition at line 186 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  string filename = MEDSPLITTERTest_Utils::getResourceFile("square1_split1.med");
  string meshname  = "Mesh_2_1";

  ParaDomainSelector dom_sel;

  MEDMEM::MESH mesh_full( MEDMEM::MED_DRIVER, filename, meshname);
  MEDMEM::MESH mesh_empty;

  vector<MEDMEM::MESH*> meshes(2);
  meshes[0] = & mesh_full;
  meshes[1] = & mesh_empty;
  if ( dom_sel.rank() > 0 )
    swap( meshes[0], meshes[1] );

  // ---------------
  // test for cells
  // ---------------

  const medGeometryElement * init_cell_types = mesh_full.getTypes               (MED_CELL);
  const int * init_cell_nb_index             = mesh_full.getGlobalNumberingIndex(MED_CELL);
  int nb_init_cell_types                     = mesh_full.getNumberOfTypes       (MED_CELL);

  // pass info on cell types from mesh_full on other proc to mesh_empty on this proc
  CPPUNIT_ASSERT_NO_THROW( dom_sel.gatherEntityTypesInfo( meshes, MED_CELL ));

  const medGeometryElement * got_cell_types = mesh_empty.getTypes               (MED_CELL);
  const int * got_cell_nb_index             = mesh_empty.getGlobalNumberingIndex(MED_CELL);
  int nb_got_cell_types                     = mesh_empty.getNumberOfTypes       (MED_CELL);

  // check that we got the same info
  CPPUNIT_ASSERT_EQUAL( nb_init_cell_types, nb_got_cell_types);
  CPPUNIT_ASSERT_EQUAL( nb_init_cell_types, mesh_full.getNumberOfTypes(MED_CELL));
  CPPUNIT_ASSERT_EQUAL( init_cell_types,    mesh_full.getTypes (MED_CELL));
  for ( int i = 0; i < nb_got_cell_types; ++i )
  {
    CPPUNIT_ASSERT_EQUAL( init_cell_types[i], got_cell_types[i] );
    CPPUNIT_ASSERT_EQUAL( mesh_full.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS ),
                          mesh_empty.getNumberOfElements(MED_CELL, MED_ALL_ELEMENTS ));
    CPPUNIT_ASSERT_EQUAL( init_cell_nb_index[ i+1 ], got_cell_nb_index[ i+1 ]);
  }

  // test for faces - there are no faces
  CPPUNIT_ASSERT_THROW( dom_sel.gatherEntityTypesInfo( meshes, MED_FACE ), MED_EXCEPTION);

  // ---------------
  // test for edges
  // ---------------

  const medGeometryElement * init_edge_types = mesh_full.getTypes               (MED_EDGE);
  const int * init_edge_nb_index             = mesh_full.getGlobalNumberingIndex(MED_EDGE);
  int nb_init_edge_types                     = mesh_full.getNumberOfTypes       (MED_EDGE);

  // pass info on edge types from mesh_full on other proc to mesh_empty on this proc
  CPPUNIT_ASSERT_NO_THROW( dom_sel.gatherEntityTypesInfo( meshes, MED_EDGE ));

  const medGeometryElement * got_edge_types = mesh_empty.getTypes               (MED_EDGE);
  const int * got_edge_nb_index             = mesh_empty.getGlobalNumberingIndex(MED_EDGE);
  int nb_got_edge_types                     = mesh_empty.getNumberOfTypes       (MED_EDGE);

  // check that we got the same info
  CPPUNIT_ASSERT_EQUAL( nb_init_edge_types, nb_got_edge_types);
  CPPUNIT_ASSERT_EQUAL( nb_init_edge_types, mesh_full.getNumberOfTypes(MED_EDGE));
  CPPUNIT_ASSERT_EQUAL( init_edge_types,    mesh_full.getTypes (MED_EDGE));
  for ( int i = 0; i < nb_got_edge_types; ++i )
  {
    CPPUNIT_ASSERT_EQUAL( init_edge_types[i], got_edge_types[i] );
    CPPUNIT_ASSERT_EQUAL( mesh_full.getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS ),
                          mesh_empty.getNumberOfElements(MED_EDGE, MED_ALL_ELEMENTS ));
    CPPUNIT_ASSERT_EQUAL( init_edge_nb_index[ i+1 ], got_edge_nb_index[ i+1 ]);
  }
}

Here is the call graph for this function:

Test ParaDomainSelector::gatherGraph( graph )

Definition at line 48 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  // Combine two equal graphs:
  // index: [ 1, 3, 6 ]
  // value: [ 1, 2, 1, 2, 3]
  // partition: [ 0, 1 ]
  //
  // Expect to get:
  // index: [ 1, 3, 6, 8, 11 ]
  // value: [ 1, 2, 1, 2, 3, 1, 2, 1, 2, 3]
  // partition: [ 0, 1, 0, 1 ]

  ParaDomainSelector dom_sel;
  CPPUNIT_ASSERT_NO_THROW( dom_sel.isOnDifferentHosts() );
#ifdef _DEBUG_
  cout << "On different hosts = " << dom_sel.isOnDifferentHosts() << endl;
#endif

  // Let ParaDomainSelector know domain sizes

  MEDMEM::MESHING meshing;
  int nb_elems[] = { 2 }; medGeometryElement type = MED_POINT1;
  meshing.setNumberOfTypes   ( 1, MED_CELL );
  meshing.setTypes           ( &type, MED_CELL );
  meshing.setNumberOfElements( nb_elems, MED_CELL );

  vector<MEDMEM::MESH*> domain_meshes(2, (MEDMEM::MESH*)0);
  domain_meshes[ dom_sel.rank() ] = &meshing;
  dom_sel.gatherNbOf( MED_CELL, domain_meshes );

  // Make the graph

  int index[] = { 1, 3, 6 };
  int value[] = { 1, 2, 1, 2, 3 };
  int* partition = new int[2];
  partition[0]=0; partition[1] = 1;
  MEDMEM::MEDSKYLINEARRAY* array = new MEDMEM::MEDSKYLINEARRAY( 2, 5, index, value);
  auto_ptr<Graph> graph( new UserGraph( array, partition, 2 ));

  // Gather graphs

  auto_ptr<Graph> glob_graph( dom_sel.gatherGraph( graph.get() ));

  const int* ind = glob_graph->getGraph()->getIndex();
  const int* val = glob_graph->getGraph()->getValue();
  const int* part= glob_graph->getPart();

  CPPUNIT_ASSERT_EQUAL( 4, glob_graph->getGraph()->getNumberOf() );
  CPPUNIT_ASSERT_EQUAL( index[0], ind[0] );
  CPPUNIT_ASSERT_EQUAL( index[1], ind[1] );
  CPPUNIT_ASSERT_EQUAL( index[2], ind[2] );
  CPPUNIT_ASSERT_EQUAL( index[2]+ind[1]-ind[0], ind[3] );
  CPPUNIT_ASSERT_EQUAL( index[2]+ind[2]-ind[0], ind[4] );

  CPPUNIT_ASSERT_EQUAL( 10, glob_graph->getGraph()->getLength() );
  CPPUNIT_ASSERT_EQUAL( value[0], val[0] );
  CPPUNIT_ASSERT_EQUAL( value[1], val[1] );
  CPPUNIT_ASSERT_EQUAL( value[2], val[2] );
  CPPUNIT_ASSERT_EQUAL( value[3], val[3] );
  CPPUNIT_ASSERT_EQUAL( value[4], val[4] );
  CPPUNIT_ASSERT_EQUAL( value[0], val[5] );
  CPPUNIT_ASSERT_EQUAL( value[1], val[6] );
  CPPUNIT_ASSERT_EQUAL( value[2], val[7] );
  CPPUNIT_ASSERT_EQUAL( value[3], val[8] );
  CPPUNIT_ASSERT_EQUAL( value[4], val[9] );

  CPPUNIT_ASSERT_EQUAL( partition[0], part[0] );
  CPPUNIT_ASSERT_EQUAL( partition[1], part[1] );
  CPPUNIT_ASSERT_EQUAL( partition[0], part[2] );
  CPPUNIT_ASSERT_EQUAL( partition[1], part[3] );
}

Here is the call graph for this function:

Definition at line 266 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  ParaDomainSelector dom_sel;
  CPPUNIT_ASSERT_EQUAL( 2, dom_sel.nbProcs() );

  // imagine we have 5 domains
  const int nb_domains = 5;
  dom_sel.setNbDomains(nb_domains);

  // ----------------------------------------
  // test isMyDomain() and getProccessorID()
  // ----------------------------------------
  set<int> doms_here;
  for ( int idomain = 0; idomain < nb_domains; ++idomain )
    if ( dom_sel.isMyDomain( idomain ))
    {
      doms_here.insert( idomain );
      CPPUNIT_ASSERT_EQUAL( dom_sel.getProccessorID( idomain ), dom_sel.rank() );
    }
  CPPUNIT_ASSERT( doms_here.size() == 2 || doms_here.size() == 3 );

  // ---------------
  // test jointId()
  // ---------------
  set<int> joint_ids;
  set< pair< int, int> > dom_pairs;
  for ( int idom1 = 0; idom1 < nb_domains; ++idom1 )
    for ( int idom2 = 0; idom2 < nb_domains; ++idom2 )
      if ( idom1 != idom2 )
      {
        joint_ids.insert( dom_sel.jointId( idom1, idom2 ));
        dom_pairs.insert( idom1 < idom2 ? make_pair( idom1, idom2 ) : make_pair( idom2, idom1 ));
      }
  CPPUNIT_ASSERT_EQUAL( dom_pairs.size(), joint_ids.size() );

  // -------------------------
  // test gatherNbCellPairs()
  // -------------------------
  joint_ids.clear();
  int nb_interproc_pairs = 0, nb_local_pairs = 0, total_joint_size = 0;
  for ( int idom1 = 0; idom1 < nb_domains; ++idom1 )
    for ( int idom2 = idom1+1; idom2 < nb_domains; ++idom2 )
    {
      // gather data for further checks
      int nb_doms_here   = doms_here.count( idom1 ) + doms_here.count( idom2 );
      bool is_inter_proc = ( nb_doms_here == 1 );
      bool is_local      = ( nb_doms_here%2 == 0 );
      int nb_pairs       = dom_sel.jointId( idom1, idom2 );
      total_joint_size += nb_pairs;
      if ( is_inter_proc ) nb_interproc_pairs += nb_pairs;
      if ( is_local      ) nb_local_pairs     += nb_pairs;
      if ( nb_doms_here == 0 || idom1 == idom2 ) continue;
      // set data to ParaDomainSelector
      if ( is_inter_proc && doms_here.count( idom1 ) ||
           is_local      && nb_doms_here == 2 )
      {
        dom_sel.setNbCellPairs( nb_pairs, idom1, idom2 );
      }
    }
  dom_sel.gatherNbCellPairs();
  //CPPUNIT_ASSERT_EQUAL( nb_local_pairs, dom_sel.getNbSubentitiesWithoutProcJoints() );

  for ( int idom1 = 0; idom1 < nb_domains; ++idom1 )
    for ( int idom2 = 0; idom2 < nb_domains; ++idom2 )
    {
      //int nb_doms_here = doms_here.count( idom1 ) + doms_here.count( idom2 );
      int nb_pairs_expect = dom_sel.jointId( idom1, idom2 );
      if ( int nb_pairs = dom_sel.getNbCellPairs( idom1, idom2 ))
      {
        CPPUNIT_ASSERT_EQUAL( nb_pairs_expect, nb_pairs );
        int fisrt_id = dom_sel.getFisrtGlobalIdOfSubentity( idom1, idom2 );
        CPPUNIT_ASSERT(0 < fisrt_id && fisrt_id <= total_joint_size);
      }
    }
}

Here is the call graph for this function:

test ParaDomainSelector::gatherNbOf( entity, domain_meshes )

Definition at line 132 of file ParaMEDSPLITTERTest_ParaDomainSelector.cxx.

{
  int world_size;
  MPI_Comm_size(MPI_COMM_WORLD,&world_size);

  if ( world_size != 2 )
    return;

  string filename = MEDSPLITTERTest_Utils::getResourceFile("square1_split1.med");
  string meshname  = "Mesh_2_1";

  ParaDomainSelector dom_sel;

  MEDMEM::MESH mesh_full( MEDMEM::MED_DRIVER, filename, meshname);
  MEDMEM::MESH mesh_empty;

  vector<MEDMEM::MESH*> meshes(2);
  meshes[0] = & mesh_full;
  meshes[1] = & mesh_empty;
  if ( dom_sel.rank() > 0 )
    swap( meshes[0], meshes[1] );

  // test gatherNbOf( MED_CELL )
  int nb_cells, init_nb_cells = mesh_full.getNumberOfElements( MED_CELL, MED_ALL_ELEMENTS );
  CPPUNIT_ASSERT_NO_THROW( nb_cells = dom_sel.gatherNbOf( MED_CELL, meshes ));
  CPPUNIT_ASSERT_EQUAL( 2 * init_nb_cells, nb_cells );

  // test gatherNbOf( MED_EDGE )
  int nb_edges, init_nb_edges = mesh_full.getNumberOfElements( MED_EDGE, MED_ALL_ELEMENTS );
  CPPUNIT_ASSERT_NO_THROW( nb_edges = dom_sel.gatherNbOf( MED_EDGE, meshes ));
  CPPUNIT_ASSERT_EQUAL( 2 * init_nb_edges, nb_edges );

  // test getNbVertOfProcs()
  int* nb_cell_by_proc;
  CPPUNIT_ASSERT_NO_THROW( nb_cell_by_proc = dom_sel.getNbVertOfProcs() );
  CPPUNIT_ASSERT_EQUAL( init_nb_cells, nb_cell_by_proc[1]-nb_cell_by_proc[0] );
  CPPUNIT_ASSERT_EQUAL( init_nb_cells, nb_cell_by_proc[2]-nb_cell_by_proc[1] );

  // test getProcShift()
  if ( dom_sel.rank() == 0 )
    CPPUNIT_ASSERT_EQUAL( 0, dom_sel.getProcShift() );
  else
    CPPUNIT_ASSERT_EQUAL( init_nb_cells, dom_sel.getProcShift() );

  CPPUNIT_ASSERT_EQUAL( 0, dom_sel.getDomainShift(0) );
  CPPUNIT_ASSERT_EQUAL( init_nb_cells, dom_sel.getDomainShift(1) );
}

Here is the call graph for this function:


The documentation for this class was generated from the following files: