libMesh
Public Member Functions | List of all members
MappedSubdomainPartitionerTest Class Reference
Inheritance diagram for MappedSubdomainPartitionerTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (MappedSubdomainPartitionerTest)
 The goal of this test is to verify proper operation of the MappedSubdomainPartitioner on different numbers of processors. More...
 
 CPPUNIT_TEST (testMappedSubdomainPartitioner)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 Note: this second public is necessary, something in the macros above leaves us in a private region. More...
 
void tearDown ()
 
void testMappedSubdomainPartitioner ()
 

Detailed Description

Definition at line 28 of file mapped_subdomain_partitioner_test.C.

Member Function Documentation

MappedSubdomainPartitionerTest::CPPUNIT_TEST ( testMappedSubdomainPartitioner  )
MappedSubdomainPartitionerTest::CPPUNIT_TEST_SUITE ( MappedSubdomainPartitionerTest  )

The goal of this test is to verify proper operation of the MappedSubdomainPartitioner on different numbers of processors.

MappedSubdomainPartitionerTest::CPPUNIT_TEST_SUITE_END ( )
void MappedSubdomainPartitionerTest::setUp ( )

Note: this second public is necessary, something in the macros above leaves us in a private region.

Definition at line 46 of file mapped_subdomain_partitioner_test.C.

46 {}
void MappedSubdomainPartitionerTest::tearDown ( )

Definition at line 48 of file mapped_subdomain_partitioner_test.C.

48 {}
void MappedSubdomainPartitionerTest::testMappedSubdomainPartitioner ( )

Definition at line 50 of file mapped_subdomain_partitioner_test.C.

References libMesh::MeshTools::Generation::build_square(), CPPUNIT_TEST_SUITE_REGISTRATION(), libMesh::ReplicatedMesh::element_ptr_range(), mesh, libMesh::MeshBase::partition(), libMesh::MeshBase::partitioner(), libMesh::QUAD4, libMesh::Real, libMesh::Parallel::Communicator::size(), and TestCommWorld.

51  {
52  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/2);
53 
54  Real
55  xmin = 0., xmax = 1.,
56  ymin = 0., ymax = 10.;
57 
59  /*nx*/10,
60  /*ny*/100,
61  xmin, xmax,
62  ymin, ymax,
63  QUAD4);
64 
65  // The MappedSubdomainPartitioner partitions based on user-defined
66  // assignment of subdomains to processors.
68 
69  // Get a pointer to the MappedSubdomainPartitioner so we can call its
70  // API specifically.
71  MappedSubdomainPartitioner * subdomain_partitioner =
72  dynamic_cast<MappedSubdomainPartitioner *>(mesh.partitioner().get());
73 
74  // Create 2x as many subdomains as processors, then assign them in
75  // the following way:
76  // subdomains(0,1) -> processor 0
77  // subdomains(2,3) -> processor 1
78  // subdomains(4,5) -> processor 2
79  // ...
80  // subdomains(n,n+1) -> processor n/2
81  subdomain_id_type n_subdomains = 2 * TestCommWorld->size();
82  for (subdomain_id_type sbd_id=0; sbd_id<n_subdomains; sbd_id+=2)
83  {
84  subdomain_partitioner->subdomain_to_proc[sbd_id] = sbd_id/2;
85  subdomain_partitioner->subdomain_to_proc[sbd_id+1] = sbd_id/2;
86  }
87 
88  // Assign subdomain ids to elements sequentially.
89  {
90  subdomain_id_type current_subdomain_id = 0;
91  for (auto & elem : mesh.element_ptr_range())
92  {
93  elem->subdomain_id() = current_subdomain_id++;
94 
95  // Wrap around
96  if (current_subdomain_id == n_subdomains)
97  current_subdomain_id = 0;
98  }
99  }
100 
101  // Partition again, now that we have set up the MappedSubdomainPartitioner.
102  mesh.partition();
103 
104  // Assert that the partitioning worked as expected.
105  for (auto & elem : mesh.element_ptr_range())
106  {
107  // Subdomain id n should map to processor id n/2.
108  CPPUNIT_ASSERT_EQUAL(static_cast<int>(elem->subdomain_id()/2),
109  static_cast<int>(elem->processor_id()));
110  }
111  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
The MappedSubdomainPartitioner partitions the elements based on their subdomain ids.
MeshBase & mesh
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:462
virtual SimpleRange< element_iterator > element_ptr_range()=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual UniquePtr< Partitioner > & partitioner()
A partitioner to use at each prepare_for_use()
Definition: mesh_base.h:112

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