libMesh
Loading...
Searching...
No Matches
multi_evaluable_pred_test.C
Go to the documentation of this file.
1#include <libmesh/partitioner.h>
2#include <libmesh/mesh.h>
3#include <libmesh/mesh_generation.h>
4#include <libmesh/equation_systems.h>
5#include <libmesh/elem.h>
6#include <libmesh/system.h>
7#include <libmesh/dof_map.h>
9
10#include "test_comm.h"
11#include "libmesh_cppunit.h"
12
13#include <memory>
14
15using namespace libMesh;
16
18{
19public:
25 virtual ~ContrivedPartitioner() = default;
26
27 std::unique_ptr<Partitioner> clone() const override
28 {
29 return std::make_unique<ContrivedPartitioner>(*this);
30 }
31
32 virtual bool partitions_from_scratch () const override { return true; }
33
34protected:
35 void _do_partition(MeshBase & mesh, const unsigned int n) override
36 {
37 libmesh_assert(n > 1);
38
39 unsigned int n_interior_elems = 0;
40 for (Elem * const elem : as_range(mesh.elements_begin(), mesh.elements_end()))
41 {
42 bool internal_elem = true;
43 for (const Elem * const neighbor : elem->neighbor_ptr_range())
44 if (!neighbor)
45 {
46 internal_elem = false;
47 break;
48 }
49
50 // The interior element will go on processor 1. Other elements will go on processor 0. For a
51 // system/DofMap that has all nodal variables all elements on processor 0 will appear
52 // evaluable. However, for a system/DofMap that has any elemental variables the interior
53 // element will not appear evaluable on processor 0
54 n_interior_elems += internal_elem;
55 elem->processor_id() = internal_elem;
56 }
57
58 // This test is hand-crafted for one interior element
59 CPPUNIT_ASSERT_EQUAL(n_interior_elems, 1u);
60 }
61};
62
63class MultiEvaluablePredTest : public CppUnit::TestCase
64{
65public:
67
69
71
72public:
73 void setUp() {}
74
75 void tearDown() {}
76
77 void test()
78 {
79 LOG_UNIT_TEST;
80 const auto rank = TestCommWorld->rank();
82 mesh.partitioner() = std::make_unique<ContrivedPartitioner>();
84
86 auto & nodal_system = es.add_system<System>("nodal_system");
87 nodal_system.add_variable("nodal", FIRST, LAGRANGE);
88 auto & nodal_dof_map = nodal_system.get_dof_map();
89 nodal_dof_map.remove_default_ghosting();
90 auto & elem_system = es.add_system<System>("elem_system");
91 elem_system.add_variable("elem", CONSTANT, MONOMIAL);
92 auto & elem_dof_map = elem_system.get_dof_map();
93 elem_dof_map.remove_default_ghosting();
94
95 es.init();
96
97 {
98 auto n_evaluable = std::distance(mesh.evaluable_elements_begin(nodal_dof_map),
99 mesh.evaluable_elements_end(nodal_dof_map));
100 typedef decltype(n_evaluable) comp_type;
101 switch (rank)
102 {
103 case 0:
104 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(9));
105 break;
106
107 case 1:
108 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(1));
109 break;
110
111 default:
112 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(0));
113 break;
114 }
115 }
116
117 {
118 auto n_evaluable = std::distance(mesh.evaluable_elements_begin(elem_dof_map),
119 mesh.evaluable_elements_end(elem_dof_map));
120 typedef decltype(n_evaluable) comp_type;
121 switch (rank)
122 {
123 case 0:
124 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(TestCommWorld->size() == 1 ? 9 : 8));
125 break;
126
127 case 1:
128 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(1));
129 break;
130
131 default:
132 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(0));
133 break;
134 }
135 }
136
137 {
138 std::vector<const DofMap *> dof_maps = {&nodal_dof_map, &elem_dof_map};
139 auto n_evaluable = std::distance(mesh.multi_evaluable_elements_begin(dof_maps),
140 mesh.multi_evaluable_elements_end(dof_maps));
141 typedef decltype(n_evaluable) comp_type;
142 switch (rank)
143 {
144 case 0:
145 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(TestCommWorld->size() == 1 ? 9 : 8));
146 break;
147
148 case 1:
149 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(1));
150 break;
151
152 default:
153 CPPUNIT_ASSERT_EQUAL(n_evaluable, comp_type(0));
154 break;
155 }
156 }
157 }
158};
159
void _do_partition(MeshBase &mesh, const unsigned int n) override
This is the actual partitioning method which must be overridden in derived classes.
ContrivedPartitioner & operator=(ContrivedPartitioner &&)=default
ContrivedPartitioner()=default
ContrivedPartitioner & operator=(const ContrivedPartitioner &)=default
ContrivedPartitioner(ContrivedPartitioner &&)=default
std::unique_ptr< Partitioner > clone() const override
ContrivedPartitioner(const ContrivedPartitioner &)=default
virtual bool partitions_from_scratch() const override
virtual ~ContrivedPartitioner()=default
LIBMESH_CPPUNIT_TEST_SUITE(MultiEvaluablePredTest)
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This is the EquationSystems class.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
This is the MeshBase class.
Definition mesh_base.h:81
virtual std::unique_ptr< Partitioner > & partitioner()
A partitioner to use at each partitioning.
Definition mesh_base.h:165
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
The Partitioner class provides a uniform interface for partitioning algorithms.
Definition partitioner.h:52
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition system.C:1344
Communicator * TestCommWorld
MeshBase & mesh
CPPUNIT_TEST_SUITE_REGISTRATION(MultiEvaluablePredTest)
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.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
libmesh_assert(ctx)