libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
NonManifoldGhostingFunctorTest Class Reference
Inheritance diagram for NonManifoldGhostingFunctorTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (NonManifoldGhostingFunctorTest)
 
 CPPUNIT_TEST (verifySendListEntries0)
 
 CPPUNIT_TEST (verifySendListEntries1)
 
 CPPUNIT_TEST (verifySendListEntries2)
 
 CPPUNIT_TEST (verifySendListEntries3)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void verifySendListEntries0 ()
 
void verifySendListEntries1 ()
 
void verifySendListEntries2 ()
 
void verifySendListEntries3 ()
 
void verify_send_list_entries_helper (const std::string &mesh_filename)
 

Protected Member Functions

void read_mesh (const std::string &mesh_filename)
 
void init_es ()
 

Protected Attributes

std::unique_ptr< MeshBase > _mesh
 
std::unique_ptr< EquationSystems > _es
 

Detailed Description

Definition at line 169 of file nonmanifold_coupling_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/4]

NonManifoldGhostingFunctorTest::CPPUNIT_TEST ( verifySendListEntries0  )

◆ CPPUNIT_TEST() [2/4]

NonManifoldGhostingFunctorTest::CPPUNIT_TEST ( verifySendListEntries1  )

◆ CPPUNIT_TEST() [3/4]

NonManifoldGhostingFunctorTest::CPPUNIT_TEST ( verifySendListEntries2  )

◆ CPPUNIT_TEST() [4/4]

NonManifoldGhostingFunctorTest::CPPUNIT_TEST ( verifySendListEntries3  )

◆ CPPUNIT_TEST_SUITE_END()

NonManifoldGhostingFunctorTest::CPPUNIT_TEST_SUITE_END ( )

◆ init_es()

void NonManifoldCouplingTestBase::init_es ( )
inlineprotectedinherited

Definition at line 144 of file nonmanifold_coupling_test.C.

145 {
146 _es = std::make_unique<EquationSystems>(*_mesh);
147
148 // Add System with a single linear Lagrange variable on it.
149 LinearImplicitSystem & sys = _es->add_system<LinearImplicitSystem> ("SimpleSystem");
150 sys.add_variable("u", FIRST, LAGRANGE);
151
152 // Attach ghosting functor to the System. We use the std::shared_ptr interface
153 // so that the DofMap takes ownership of the object. Note: if you comment out
154 // this line, then the test _can_ fail when run in parallel, but it depends on
155 // the number of processors used. For small numbers of procs, sometimes we can
156 // get "lucky" and wind up with all the non-manifold neighbor DOFs either local
157 // to or ghosted on all procs where they are needed. In practice, this test should
158 // be run on 3 or more procs to make it fail when the NonManifoldGhostingFunctor
159 // is not used.
160 auto ghosting_functor = std::make_shared<NonManifoldGhostingFunctor>(*_mesh);
161 sys.get_dof_map().add_coupling_functor(ghosting_functor, /*to_mesh=*/true);
162
163 // Initialize the DofMap, etc. for all Systems
164 _es->init();
165 }
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Adds a functor which can specify coupling requirements for creation of sparse matrices.
Definition dof_map.C:2007
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
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
const DofMap & get_dof_map() const
Definition system.h:2417

References NonManifoldCouplingTestBase::_es, NonManifoldCouplingTestBase::_mesh, libMesh::DofMap::add_coupling_functor(), libMesh::System::add_variable(), libMesh::FIRST, libMesh::System::get_dof_map(), and libMesh::LAGRANGE.

Referenced by verify_send_list_entries_helper().

◆ LIBMESH_CPPUNIT_TEST_SUITE()

NonManifoldGhostingFunctorTest::LIBMESH_CPPUNIT_TEST_SUITE ( NonManifoldGhostingFunctorTest  )

◆ read_mesh()

void NonManifoldCouplingTestBase::read_mesh ( const std::string &  mesh_filename)
inlineprotectedinherited

Definition at line 125 of file nonmanifold_coupling_test.C.

126 {
127 // We are making assumptions in various places about the presence
128 // of the elements on the current processor so we're restricting to
129 // ReplicatedMesh for now.
130 _mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
131 _mesh->read(mesh_filename);
132
133 // Use our custom partitioner that assigns non-manifold edge
134 // neighbors to different processors.
135 _mesh->partitioner() = std::make_unique<NonManifoldTestPartitioner>();
136
137 _mesh->prepare_for_use();
138
139 // Debugging: print processor ids determined by partitioner
140 // for (const auto & elem : _mesh->element_ptr_range())
141 // libMesh::out << "Elem " << elem->id() << " is on processor " << elem->processor_id() << std::endl;
142 }

References NonManifoldCouplingTestBase::_mesh, and TestCommWorld.

Referenced by verify_send_list_entries_helper().

◆ setUp()

void NonManifoldGhostingFunctorTest::setUp ( )
inline

Definition at line 187 of file nonmanifold_coupling_test.C.

188 {
189 }

◆ tearDown()

void NonManifoldGhostingFunctorTest::tearDown ( )
inline

Definition at line 191 of file nonmanifold_coupling_test.C.

192 {
193 }

◆ verify_send_list_entries_helper()

void NonManifoldGhostingFunctorTest::verify_send_list_entries_helper ( const std::string &  mesh_filename)
inline

Definition at line 202 of file nonmanifold_coupling_test.C.

203 {
204 // Call base class implementations
205 this->read_mesh(mesh_filename);
206 this->init_es();
207
208 // Get reference to the System, corresponding DofMap, and send_list for this processor
209 System & system = _es->get_system("SimpleSystem");
210 DofMap & dof_map = system.get_dof_map();
211 const std::vector<dof_id_type> & send_list = dof_map.get_send_list();
212
214
215 // Use the SidesToElemMap to get a range of Elem pointers attached
216 // to the non-manifold edge that we intentionally partitioned onto
217 // different processors.
219 auto side_neighbors_found = [&]() -> bool
220 {
221 for (const auto & elem : _mesh->element_ptr_range())
222 for (auto s : elem->side_index_range())
223 {
224 auto range = stem.get_connected_elems(elem, s);
225 if (std::distance(range.first, range.second) == 5)
226 {
227 beg = range.first;
228 end = range.second;
229 return true;
230 }
231 }
232
233 // If we made it here, then we didn't find a Side shared by
234 // 5 elements and we'll throw an error later
235 return false;
236 }();
237
238 // Require that neighbors were found
239 CPPUNIT_ASSERT(side_neighbors_found);
240
241 // For every pair of elements (e,f) on this edge owned by processors (proc_e, proc_f) respectively, check that:
242 // 1.) The DOFs of e are either local to, or in the send-list of, proc_f
243 // 2.) The DOFs of f are either local to, or in the send-list of, proc_e
244 for (auto it_e = beg; it_e != end; ++it_e)
245 for (auto it_f = std::next(it_e); it_f != end; ++it_f)
246 {
247 // Lambda to be used for error checking
248 auto check_dofs = [&](const Elem * elem)
249 {
250 std::vector<dof_id_type> dof_indices;
251 dof_map.dof_indices(elem, dof_indices);
252
253 for (const auto & dof : dof_indices)
254 {
255 bool is_local = (dof >= dof_map.first_dof()) && (dof < dof_map.end_dof());
256 bool is_in_send_list = (Utility::binary_find(send_list.begin(), send_list.end(), dof) != send_list.end());
257 CPPUNIT_ASSERT(is_local || is_in_send_list);
258 }
259 };
260
261 const Elem * elem_e = *it_e;
262 const Elem * elem_f = *it_f;
263
264 if (_mesh->comm().rank() == elem_e->processor_id())
265 check_dofs(elem_f);
266
267 if (_mesh->comm().rank() == elem_f->processor_id())
268 check_dofs(elem_e);
269 }
270 }
void read_mesh(const std::string &mesh_filename)
dof_id_type first_dof(const processor_id_type proc) const
dof_id_type end_dof(const processor_id_type proc) const
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
const std::vector< dof_id_type > & get_send_list() const
Definition dof_map.h:540
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition dof_map.C:2203
processor_id_type processor_id() const
Definition dof_object.h:895
This is the base class from which all geometric element types are derived.
Definition elem.h:96
This class implements a generalization of the MeshTools::build_nodes_to_elem_map() function,...
static SidesToElemMap build(const MeshBase &mesh)
Static build function.
std::vector< constElem * >::const_iterator ElemIter
Typedef for the iterator type returned by the SidesToeElemMap::get_connected_elems() function.
std::pair< ElemIter, ElemIter > get_connected_elems(const Elem *elem, unsigned int side) const
Return an iterator pair defining the range of Elems connected to "side" of "elem".
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
ForwardIterator binary_find(ForwardIterator first, ForwardIterator last, const T &value)
The STL provides std::binary_search() which returns true or false depending on whether the searched-f...
Definition utility.h:233

References NonManifoldCouplingTestBase::_es, NonManifoldCouplingTestBase::_mesh, libMesh::Utility::binary_find(), libMesh::MeshTools::SidesToElemMap::build(), libMesh::DofMap::dof_indices(), libMesh::DofMapBase::end_dof(), libMesh::DofMapBase::first_dof(), libMesh::MeshTools::SidesToElemMap::get_connected_elems(), libMesh::System::get_dof_map(), libMesh::DofMap::get_send_list(), NonManifoldCouplingTestBase::init_es(), libMesh::DofObject::processor_id(), and NonManifoldCouplingTestBase::read_mesh().

Referenced by verifySendListEntries0(), verifySendListEntries1(), verifySendListEntries2(), and verifySendListEntries3().

◆ verifySendListEntries0()

void NonManifoldGhostingFunctorTest::verifySendListEntries0 ( )
inline

Definition at line 195 of file nonmanifold_coupling_test.C.

195{ this->verify_send_list_entries_helper("meshes/non_manifold_junction0.exo"); }
void verify_send_list_entries_helper(const std::string &mesh_filename)

References verify_send_list_entries_helper().

◆ verifySendListEntries1()

void NonManifoldGhostingFunctorTest::verifySendListEntries1 ( )
inline

Definition at line 196 of file nonmanifold_coupling_test.C.

196{ this->verify_send_list_entries_helper("meshes/non_manifold_junction1.exo"); }

References verify_send_list_entries_helper().

◆ verifySendListEntries2()

void NonManifoldGhostingFunctorTest::verifySendListEntries2 ( )
inline

Definition at line 197 of file nonmanifold_coupling_test.C.

197{ this->verify_send_list_entries_helper("meshes/non_manifold_junction2.exo"); }

References verify_send_list_entries_helper().

◆ verifySendListEntries3()

void NonManifoldGhostingFunctorTest::verifySendListEntries3 ( )
inline

Definition at line 198 of file nonmanifold_coupling_test.C.

198{ this->verify_send_list_entries_helper("meshes/non_manifold_junction3.exo"); }

References verify_send_list_entries_helper().

Member Data Documentation

◆ _es

std::unique_ptr<EquationSystems> NonManifoldCouplingTestBase::_es
protectedinherited

◆ _mesh

std::unique_ptr<MeshBase> NonManifoldCouplingTestBase::_mesh
protectedinherited

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