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

Member Function Documentation

◆ CPPUNIT_TEST()

MappedSubdomainPartitionerTest::CPPUNIT_TEST ( testMappedSubdomainPartitioner  )

◆ CPPUNIT_TEST_SUITE()

MappedSubdomainPartitionerTest::CPPUNIT_TEST_SUITE ( MappedSubdomainPartitionerTest  )

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

◆ CPPUNIT_TEST_SUITE_END()

MappedSubdomainPartitionerTest::CPPUNIT_TEST_SUITE_END ( )

◆ 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.

39  {
40  ReplicatedMesh mesh(*TestCommWorld, /*dim=*/2);
41 
42  Real
43  xmin = 0., xmax = 1.,
44  ymin = 0., ymax = 10.;
45 
47  /*nx*/10,
48  /*ny*/100,
49  xmin, xmax,
50  ymin, ymax,
51  QUAD4);
52 
53  // The MappedSubdomainPartitioner partitions based on user-defined
54  // assignment of subdomains to processors.
55  mesh.partitioner() = libmesh_make_unique<MappedSubdomainPartitioner>();
56 
57  // Get a pointer to the MappedSubdomainPartitioner so we can call its
58  // API specifically.
59  MappedSubdomainPartitioner * subdomain_partitioner =
60  dynamic_cast<MappedSubdomainPartitioner *>(mesh.partitioner().get());
61 
62  // Create 2x as many subdomains as processors, then assign them in
63  // the following way:
64  // subdomains(0,1) -> processor 0
65  // subdomains(2,3) -> processor 1
66  // subdomains(4,5) -> processor 2
67  // ...
68  // subdomains(n,n+1) -> processor n/2
69  subdomain_id_type n_subdomains = 2 * TestCommWorld->size();
70  for (subdomain_id_type sbd_id=0; sbd_id<n_subdomains; sbd_id+=2)
71  {
72  subdomain_partitioner->subdomain_to_proc[sbd_id] = sbd_id/2;
73  subdomain_partitioner->subdomain_to_proc[sbd_id+1] = sbd_id/2;
74  }
75 
76  // Assign subdomain ids to elements sequentially.
77  {
78  subdomain_id_type current_subdomain_id = 0;
79  for (auto & elem : mesh.element_ptr_range())
80  {
81  elem->subdomain_id() = current_subdomain_id++;
82 
83  // Wrap around
84  if (current_subdomain_id == n_subdomains)
85  current_subdomain_id = 0;
86  }
87  }
88 
89  // Partition again, now that we have set up the MappedSubdomainPartitioner.
90  mesh.partition();
91 
92  // Assert that the partitioning worked as expected.
93  for (auto & elem : mesh.element_ptr_range())
94  {
95  // Subdomain id n should map to processor id n/2.
96  CPPUNIT_ASSERT_EQUAL(static_cast<int>(elem->subdomain_id()/2),
97  static_cast<int>(elem->processor_id()));
98  }
99  }

References libMesh::MeshTools::Generation::build_square(), libMesh::MeshBase::element_ptr_range(), mesh, libMesh::MeshBase::partition(), libMesh::MeshBase::partitioner(), libMesh::QUAD4, libMesh::Real, libMesh::MappedSubdomainPartitioner::subdomain_to_proc, and TestCommWorld.


The documentation for this class was generated from the following file:
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::MeshBase::element_ptr_range
virtual SimpleRange< element_iterator > element_ptr_range()=0
libMesh::MeshTools::Generation::build_square
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.
Definition: mesh_generation.C:1501
libMesh::QUAD4
Definition: enum_elem_type.h:41
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::MappedSubdomainPartitioner::subdomain_to_proc
std::map< subdomain_id_type, processor_id_type > subdomain_to_proc
Before calling partition() or partition_range(), the user must assign all the Mesh subdomains to cert...
Definition: mapped_subdomain_partitioner.h:79
libMesh::TestClass
Definition: id_types.h:33
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::MappedSubdomainPartitioner
The MappedSubdomainPartitioner partitions the elements based on their subdomain ids.
Definition: mapped_subdomain_partitioner.h:42
libMesh::MeshBase::partition
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:599
libMesh::MeshBase::partitioner
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each prepare_for_use()
Definition: mesh_base.h:127