libMesh
Loading...
Searching...
No Matches
mapped_subdomain_partitioner_test.C
Go to the documentation of this file.
1#include <libmesh/libmesh.h>
2#include <libmesh/replicated_mesh.h>
3#include <libmesh/elem.h>
4#include <libmesh/mesh_generation.h>
5#include <libmesh/mesh_modification.h>
6#include "libmesh/mapped_subdomain_partitioner.h"
7
8#include "test_comm.h"
9#include "libmesh_cppunit.h"
10
11
12using namespace libMesh;
13
14class MappedSubdomainPartitionerTest : public CppUnit::TestCase
15{
20public:
22
23#if LIBMESH_DIM > 1
25#endif
26
28
33public:
34 void setUp() {}
35
36 void tearDown() {}
37
39 {
40 LOG_UNIT_TEST;
41
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.
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 }
102};
103
104
void setUp()
Note: this second public is necessary, something in the macros above leaves us in a private region.
CPPUNIT_TEST(testMappedSubdomainPartitioner)
LIBMESH_CPPUNIT_TEST_SUITE(MappedSubdomainPartitionerTest)
The goal of this test is to verify proper operation of the MappedSubdomainPartitioner on different nu...
The MappedSubdomainPartitioner partitions the elements based on their subdomain ids.
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...
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each partitioning.
Definition mesh_base.h:165
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition mesh_base.C:1769
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(MappedSubdomainPartitionerTest)
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.
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real