libMesh
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
OverlappingAlgebraicGhostingTest Class Reference
Inheritance diagram for OverlappingAlgebraicGhostingTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (OverlappingAlgebraicGhostingTest)
 
 CPPUNIT_TEST (testGhostingCouplingMatrix)
 
 CPPUNIT_TEST (testGhostingNullCouplingMatrix)
 
 CPPUNIT_TEST (testGhostingNullCouplingMatrixUnifRef)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testGhostingCouplingMatrix ()
 
void testGhostingNullCouplingMatrix ()
 
void testGhostingNullCouplingMatrixUnifRef ()
 

Protected Member Functions

void build_quad_mesh (unsigned int n_refinements=0)
 
void init ()
 
void clear ()
 
void setup_coupling_matrix (std::unique_ptr< CouplingMatrix > &coupling)
 

Protected Attributes

std::unique_ptr< MeshBase_mesh
 
std::unique_ptr< EquationSystems_es
 

Private Member Functions

void run_ghosting_test (const unsigned int n_refinements, bool build_coupling_matrix)
 

Detailed Description

Definition at line 521 of file overlapping_coupling_test.C.

Member Function Documentation

◆ build_quad_mesh()

void OverlappingTestBase::build_quad_mesh ( unsigned int  n_refinements = 0)
inlineprotectedinherited

Definition at line 249 of file overlapping_coupling_test.C.

References libMesh::Elem::build_with_id(), libMesh::QUAD4, libMesh::Elem::set_node(), libMesh::Elem::subdomain_id(), and libMesh::MeshRefinement::uniformly_refine().

250  {
251  // We are making assumptions in various places about the presence
252  // of the elements on the current processor so we're restricting to
253  // ReplicatedMesh for now.
254  _mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
255 
256  _mesh->set_mesh_dimension(2);
257 
258  _mesh->add_point( Point(0.0,0.0),0 );
259  _mesh->add_point( Point(1.0,0.0),1 );
260  _mesh->add_point( Point(1.0,1.0),2 );
261  _mesh->add_point( Point(0.0,1.0),3 );
262 
263  {
264  Elem * elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 0));
265  elem->subdomain_id() = 1;
266 
267  for (unsigned int n=0; n<4; n++)
268  elem->set_node(n, _mesh->node_ptr(n));
269  }
270 
271  _mesh->add_point( Point(1.0,2.0),4 );
272  _mesh->add_point( Point(0.0,2.0),5 );
273 
274  {
275  Elem * elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 1));
276  elem->subdomain_id() = 1;
277 
278  elem->set_node(0, _mesh->node_ptr(3));
279  elem->set_node(1, _mesh->node_ptr(2));
280  elem->set_node(2, _mesh->node_ptr(4));
281  elem->set_node(3, _mesh->node_ptr(5));
282  }
283 
284  _mesh->add_point( Point(0.0,0.0),6 );
285  _mesh->add_point( Point(1.0,0.0),7 );
286  _mesh->add_point( Point(1.0,2.0),8 );
287  _mesh->add_point( Point(0.0,2.0),9 );
288 
289  {
290  Elem* elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 2));
291  elem->subdomain_id() = 2;
292 
293  elem->set_node(0, _mesh->node_ptr(6));
294  elem->set_node(1, _mesh->node_ptr(7));
295  elem->set_node(2, _mesh->node_ptr(8));
296  elem->set_node(3, _mesh->node_ptr(9));
297  }
298 
299  _mesh->partitioner() = std::make_unique<OverlappingTestPartitioner>();
300 
301  _mesh->prepare_for_use();
302 
303 #ifdef LIBMESH_ENABLE_AMR
304  if (n_refinements > 0)
305  {
306  MeshRefinement refine(*_mesh);
307  refine.uniformly_refine(n_refinements);
308  }
309 #else
310  CPPUNIT_ASSERT_EQUAL(n_refinements, 0u);
311 #endif // LIBMESH_ENABLE_AMR
312  }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2564
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
std::unique_ptr< MeshBase > _mesh
Implements (adaptive) mesh refinement algorithms for a MeshBase.
subdomain_id_type subdomain_id() const
Definition: elem.h:2588
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ clear()

void OverlappingTestBase::clear ( )
inlineprotectedinherited

Definition at line 334 of file overlapping_coupling_test.C.

335  {
336  _es.reset();
337  _mesh.reset();
338  }
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es

◆ CPPUNIT_TEST() [1/3]

OverlappingAlgebraicGhostingTest::CPPUNIT_TEST ( testGhostingCouplingMatrix  )

◆ CPPUNIT_TEST() [2/3]

OverlappingAlgebraicGhostingTest::CPPUNIT_TEST ( testGhostingNullCouplingMatrix  )

◆ CPPUNIT_TEST() [3/3]

OverlappingAlgebraicGhostingTest::CPPUNIT_TEST ( testGhostingNullCouplingMatrixUnifRef  )

◆ CPPUNIT_TEST_SUITE_END()

OverlappingAlgebraicGhostingTest::CPPUNIT_TEST_SUITE_END ( )

◆ init()

void OverlappingTestBase::init ( )
inlineprotectedinherited

Definition at line 314 of file overlapping_coupling_test.C.

References libMesh::System::add_variable(), libMesh::FIRST, and libMesh::LAGRANGE.

315  {
316  _es = std::make_unique<EquationSystems>(*_mesh);
317  LinearImplicitSystem & sys = _es->add_system<LinearImplicitSystem> ("SimpleSystem");
318 
319  std::set<subdomain_id_type> sub_one;
320  sub_one.insert(1);
321 
322  std::set<subdomain_id_type> sub_two;
323  sub_two.insert(2);
324 
325  sys.add_variable("U", FIRST, LAGRANGE, &sub_two);
326  sys.add_variable("L", FIRST, LAGRANGE, &sub_two);
327 
328  sys.add_variable("V", FIRST, LAGRANGE, &sub_one);
329  sys.add_variable("p", FIRST, LAGRANGE, &sub_one);
330 
331  _es->init();
332  }
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
std::unique_ptr< EquationSystems > _es
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

◆ LIBMESH_CPPUNIT_TEST_SUITE()

OverlappingAlgebraicGhostingTest::LIBMESH_CPPUNIT_TEST_SUITE ( OverlappingAlgebraicGhostingTest  )

◆ run_ghosting_test()

void OverlappingAlgebraicGhostingTest::run_ghosting_test ( const unsigned int  n_refinements,
bool  build_coupling_matrix 
)
inlineprivate

Definition at line 565 of file overlapping_coupling_test.C.

References libMesh::DofMap::add_algebraic_ghosting_functor(), libMesh::NumericVector< T >::build(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, libMesh::FEMContext::elem_fe_reinit(), libMesh::System::get_dof_map(), libMesh::FEMContext::get_element_fe(), libMesh::System::get_mesh(), libMesh::DofMap::get_send_list(), libMesh::GHOSTED, libMesh::TriangleWrapper::init(), libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::FEMContext::pre_fe_reinit(), libMesh::DofMap::reinit_send_list(), libMesh::System::solution, and libMesh::System::variable_number().

566  {
567  this->build_quad_mesh(n_refinements);
568  this->init();
569 
570  std::unique_ptr<CouplingMatrix> coupling_matrix;
571  if (build_coupling_matrix)
572  this->setup_coupling_matrix(coupling_matrix);
573 
574  LinearImplicitSystem & system = _es->get_system<LinearImplicitSystem>("SimpleSystem");
575 
576  // If we don't add this coupling functor and properly recompute the
577  // sparsity pattern, then PETSc will throw a malloc error when we
578  // try to assemble into the global matrix
579  OverlappingCouplingFunctor functor(system);
580  functor.set_coupling_matrix(coupling_matrix);
581 
582  DofMap & dof_map = system.get_dof_map();
583  dof_map.add_algebraic_ghosting_functor(functor);
584  dof_map.reinit_send_list(system.get_mesh());
585 
586  // Update current local solution
588 
589  system.current_local_solution->init(system.n_dofs(), system.n_local_dofs(),
590  dof_map.get_send_list(), false,
592 
593  system.solution->localize(*(system.current_local_solution),dof_map.get_send_list());
594 
595  std::unique_ptr<PointLocatorBase> point_locator = _mesh->sub_point_locator();
596 
597  const unsigned int u_var = system.variable_number("U");
598 
600 
601  FEMContext subdomain_one_context(system);
602  FEMContext subdomain_two_context(system);
603 
604  // The use case on which this test is based, we only add terms to the residual
605  // corresponding to the dofs in the second subdomain, but that have couplings
606  // to dofs in the first subdomain.
607  for (const auto & elem : _mesh->active_local_subdomain_elements_ptr_range(2))
608  {
609  // A little extra unit testing on the range iterator
610  CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(elem->subdomain_id()));
611 
612  subdomain_one_context.get_element_fe(u_var)->get_nothing(); // for this unit test
613  const std::vector<libMesh::Point> & qpoints = subdomain_two_context.get_element_fe(u_var)->get_xyz();
614 
615  // Setup the context for the current element
616  subdomain_two_context.pre_fe_reinit(system,elem);
617  subdomain_two_context.elem_fe_reinit();
618 
619  std::set<subdomain_id_type> allowed_subdomains;
620  allowed_subdomains.insert(1);
621 
622  // Now loop over the quadrature points and find the subdomain-one element that overlaps
623  // with the current subdomain-two element and then initialize the FEMContext for the
624  // subdomain-one element. If the algebraic ghosting has not been done properly,
625  // this will error.
626  for ( const auto & qp : qpoints )
627  {
628  const Elem * overlapping_elem = (*point_locator)( qp, &allowed_subdomains );
629  CPPUNIT_ASSERT(overlapping_elem);
630 
631  // Setup the context for the overlapping element
632  subdomain_one_context.pre_fe_reinit(system,overlapping_elem);
633  subdomain_one_context.elem_fe_reinit();
634  }
635  }
636  }
void setup_coupling_matrix(std::unique_ptr< CouplingMatrix > &coupling)
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
const Parallel::Communicator & comm() const
dof_id_type n_local_dofs() const
Definition: system.C:155
const MeshBase & get_mesh() const
Definition: system.h:2401
dof_id_type n_dofs() const
Definition: system.C:118
unsigned int variable_number(std::string_view var) const
Definition: system.C:1398
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:179
void build_quad_mesh(unsigned int n_refinements=0)
void reinit_send_list(MeshBase &mesh)
Clears the _send_list vector and then rebuilds it.
Definition: dof_map.C:1877
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1655
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1667
void add_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor, bool to_mesh=true)
Adds a functor which can specify algebraic ghosting requirements for use with distributed vectors...
Definition: dof_map.C:2062
const DofMap & get_dof_map() const
Definition: system.h:2417
const std::vector< dof_id_type > & get_send_list() const
Definition: dof_map.h:533

◆ setUp()

void OverlappingAlgebraicGhostingTest::setUp ( )
inline

Definition at line 537 of file overlapping_coupling_test.C.

538  {}

◆ setup_coupling_matrix()

void OverlappingTestBase::setup_coupling_matrix ( std::unique_ptr< CouplingMatrix > &  coupling)
inlineprotectedinherited

Definition at line 340 of file overlapping_coupling_test.C.

References libMesh::System::n_vars(), and libMesh::System::variable_number().

341  {
342  System & system = _es->get_system("SimpleSystem");
343 
344  coupling = std::make_unique<CouplingMatrix>(system.n_vars());
345 
346  const unsigned int u_var = system.variable_number("U");
347  const unsigned int l_var = system.variable_number("L");
348  const unsigned int v_var = system.variable_number("V");
349  const unsigned int p_var = system.variable_number("p");
350 
351  // Only adding the overlapping couplings since the primary ones should
352  // be there by default.
353  (*coupling)(u_var,v_var) = true;
354  (*coupling)(l_var,v_var) = true;
355  (*coupling)(l_var,p_var) = true;
356  (*coupling)(v_var,u_var) = true;
357  (*coupling)(v_var,l_var) = true;
358  }
unsigned int variable_number(std::string_view var) const
Definition: system.C:1398
std::unique_ptr< EquationSystems > _es
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
unsigned int n_vars() const
Definition: system.C:2674

◆ tearDown()

void OverlappingAlgebraicGhostingTest::tearDown ( )
inline

Definition at line 540 of file overlapping_coupling_test.C.

541  { this->clear(); }

◆ testGhostingCouplingMatrix()

void OverlappingAlgebraicGhostingTest::testGhostingCouplingMatrix ( )
inline

Definition at line 543 of file overlapping_coupling_test.C.

544  {
545  LOG_UNIT_TEST;
546  this->run_ghosting_test(0, true);
547  }
void run_ghosting_test(const unsigned int n_refinements, bool build_coupling_matrix)

◆ testGhostingNullCouplingMatrix()

void OverlappingAlgebraicGhostingTest::testGhostingNullCouplingMatrix ( )
inline

Definition at line 549 of file overlapping_coupling_test.C.

550  {
551  LOG_UNIT_TEST;
552  this->run_ghosting_test(0, false);
553  }
void run_ghosting_test(const unsigned int n_refinements, bool build_coupling_matrix)

◆ testGhostingNullCouplingMatrixUnifRef()

void OverlappingAlgebraicGhostingTest::testGhostingNullCouplingMatrixUnifRef ( )
inline

Definition at line 555 of file overlapping_coupling_test.C.

556  {
557  LOG_UNIT_TEST;
558  std::unique_ptr<CouplingMatrix> coupling_matrix;
559 
560  this->run_ghosting_test(2, false);
561  }
void run_ghosting_test(const unsigned int n_refinements, bool build_coupling_matrix)

Member Data Documentation

◆ _es

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

Definition at line 247 of file overlapping_coupling_test.C.

◆ _mesh

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

Definition at line 245 of file overlapping_coupling_test.C.


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