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

Public Member Functions

 LIBMESH_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 14 of file mapped_subdomain_partitioner_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

MappedSubdomainPartitionerTest::CPPUNIT_TEST ( testMappedSubdomainPartitioner  )

◆ CPPUNIT_TEST_SUITE_END()

MappedSubdomainPartitionerTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

MappedSubdomainPartitionerTest::LIBMESH_CPPUNIT_TEST_SUITE ( MappedSubdomainPartitionerTest  )

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

◆ setUp()

void MappedSubdomainPartitionerTest::setUp ( )
inline

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

Definition at line 34 of file mapped_subdomain_partitioner_test.C.

34 {}

◆ tearDown()

void MappedSubdomainPartitionerTest::tearDown ( )
inline

Definition at line 36 of file mapped_subdomain_partitioner_test.C.

36 {}

◆ testMappedSubdomainPartitioner()

void MappedSubdomainPartitionerTest::testMappedSubdomainPartitioner ( )
inline

Definition at line 38 of file mapped_subdomain_partitioner_test.C.

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

39  {
40  LOG_UNIT_TEST;
41 
42  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/2);
43 
44  Real
45  xmin = 0., xmax = 1.,
46  ymin = 0., ymax = 10.;
47 
49  /*nx*/10,
50  /*ny*/100,
51  xmin, xmax,
52  ymin, ymax,
53  QUAD4);
54 
55  // The MappedSubdomainPartitioner partitions based on user-defined
56  // assignment of subdomains to processors.
57  mesh.partitioner() = std::make_unique<MappedSubdomainPartitioner>();
58 
59  // Get a pointer to the MappedSubdomainPartitioner so we can call its
60  // API specifically.
61  MappedSubdomainPartitioner * subdomain_partitioner =
62  dynamic_cast<MappedSubdomainPartitioner *>(mesh.partitioner().get());
63 
64  // Create 2x as many subdomains as processors, then assign them in
65  // the following way:
66  // subdomains(0,1) -> processor 0
67  // subdomains(2,3) -> processor 1
68  // subdomains(4,5) -> processor 2
69  // ...
70  // subdomains(n,n+1) -> processor n/2
71  subdomain_id_type n_subdomains = 2 * TestCommWorld->size();
72  for (subdomain_id_type sbd_id=0; sbd_id<n_subdomains; sbd_id+=2)
73  {
74  subdomain_partitioner->subdomain_to_proc[sbd_id] = sbd_id/2;
75  subdomain_partitioner->subdomain_to_proc[sbd_id+1] = sbd_id/2;
76  }
77 
78  // Assign subdomain ids to elements sequentially.
79  {
80  subdomain_id_type current_subdomain_id = 0;
81  for (auto & elem : mesh.element_ptr_range())
82  {
83  elem->subdomain_id() = current_subdomain_id++;
84 
85  // Wrap around
86  if (current_subdomain_id == n_subdomains)
87  current_subdomain_id = 0;
88  }
89  }
90 
91  // Partition again, now that we have set up the MappedSubdomainPartitioner.
92  mesh.partition();
93 
94  // Assert that the partitioning worked as expected.
95  for (auto & elem : mesh.element_ptr_range())
96  {
97  // Subdomain id n should map to processor id n/2.
98  CPPUNIT_ASSERT_EQUAL(static_cast<int>(elem->subdomain_id()/2),
99  static_cast<int>(elem->processor_id()));
100  }
101  }
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
The MappedSubdomainPartitioner partitions the elements based on their subdomain ids.
MeshBase & mesh
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each prepare_for_use()
Definition: mesh_base.h:154
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.
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:1503
processor_id_type size() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

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