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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (OverlappingFunctorTest)
 
 CPPUNIT_TEST (checkCouplingFunctorQuad)
 
 CPPUNIT_TEST (checkCouplingFunctorTri)
 
 CPPUNIT_TEST (checkOverlappingPartitioner)
 
 CPPUNIT_TEST (checkCouplingFunctorQuadUnifRef)
 
 CPPUNIT_TEST (checkCouplingFunctorTriUnifRef)
 
 CPPUNIT_TEST (checkOverlappingPartitionerUnifRef)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void checkCouplingFunctorQuad ()
 
void checkCouplingFunctorQuadUnifRef ()
 
void checkCouplingFunctorTri ()
 
void checkCouplingFunctorTriUnifRef ()
 
void checkOverlappingPartitioner ()
 
void checkOverlappingPartitionerUnifRef ()
 

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_coupling_functor_test (unsigned int n_refinements)
 
void run_partitioner_test (unsigned int n_refinements)
 

Detailed Description

Definition at line 365 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

◆ checkCouplingFunctorQuad()

void OverlappingFunctorTest::checkCouplingFunctorQuad ( )
inline

Definition at line 397 of file overlapping_coupling_test.C.

398  { this->run_coupling_functor_test(0); }
void run_coupling_functor_test(unsigned int n_refinements)

◆ checkCouplingFunctorQuadUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorQuadUnifRef ( )
inline

Definition at line 400 of file overlapping_coupling_test.C.

401  { this->run_coupling_functor_test(1); }
void run_coupling_functor_test(unsigned int n_refinements)

◆ checkCouplingFunctorTri()

void OverlappingFunctorTest::checkCouplingFunctorTri ( )
inline

Definition at line 403 of file overlapping_coupling_test.C.

References libMesh::MeshTools::Modification::all_tri().

404  {
406  _es->reinit();
407  this->run_coupling_functor_test(0);
408  }
void run_coupling_functor_test(unsigned int n_refinements)
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
void all_tri(MeshBase &mesh)
Subdivides any non-simplex elements in a Mesh to produce simplex (triangular in 2D, tetrahedral in 3D) elements.

◆ checkCouplingFunctorTriUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorTriUnifRef ( )
inline

Definition at line 410 of file overlapping_coupling_test.C.

References libMesh::MeshTools::Modification::all_tri().

411  {
413  _es->reinit();
414  this->run_coupling_functor_test(1);
415  }
void run_coupling_functor_test(unsigned int n_refinements)
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
void all_tri(MeshBase &mesh)
Subdivides any non-simplex elements in a Mesh to produce simplex (triangular in 2D, tetrahedral in 3D) elements.

◆ checkOverlappingPartitioner()

void OverlappingFunctorTest::checkOverlappingPartitioner ( )
inline

Definition at line 417 of file overlapping_coupling_test.C.

418  {
419  this->run_partitioner_test(0);
420  }
void run_partitioner_test(unsigned int n_refinements)

◆ checkOverlappingPartitionerUnifRef()

void OverlappingFunctorTest::checkOverlappingPartitionerUnifRef ( )
inline

Definition at line 422 of file overlapping_coupling_test.C.

423  {
424  this->run_partitioner_test(1);
425  }
void run_partitioner_test(unsigned int n_refinements)

◆ 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/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorQuad  )

◆ CPPUNIT_TEST() [2/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorTri  )

◆ CPPUNIT_TEST() [3/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkOverlappingPartitioner  )

◆ CPPUNIT_TEST() [4/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorQuadUnifRef  )

◆ CPPUNIT_TEST() [5/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorTriUnifRef  )

◆ CPPUNIT_TEST() [6/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkOverlappingPartitionerUnifRef  )

◆ CPPUNIT_TEST_SUITE_END()

OverlappingFunctorTest::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()

OverlappingFunctorTest::LIBMESH_CPPUNIT_TEST_SUITE ( OverlappingFunctorTest  )

◆ run_coupling_functor_test()

void OverlappingFunctorTest::run_coupling_functor_test ( unsigned int  n_refinements)
inlineprivate

Definition at line 433 of file overlapping_coupling_test.C.

References distance(), libMesh::DofObject::invalid_processor_id, and libMesh::MeshRefinement::uniformly_refine().

434  {
435 #if defined(LIBMESH_ENABLE_AMR) && defined(LIBMESH_HAVE_SOLVER)
436  if( n_refinements > 0 )
437  {
438  MeshRefinement refine(*_mesh);
439  refine.uniformly_refine(n_refinements);
440  _es->reinit();
441  }
442 #else
443  CPPUNIT_ASSERT_EQUAL(n_refinements, 0u);
444 #endif
445 
446  System & system = _es->get_system("SimpleSystem");
447 
448  OverlappingCouplingFunctor coupling_functor(system);
449 
450  GhostingFunctor::map_type subdomain_one_couplings;
451  GhostingFunctor::map_type subdomain_two_couplings;
452 
453  coupling_functor( _mesh->active_subdomain_elements_begin(1),
454  _mesh->active_subdomain_elements_end(1),
455  DofObject::invalid_processor_id,
456  subdomain_one_couplings );
457 
458  coupling_functor( _mesh->active_subdomain_elements_begin(2),
459  _mesh->active_subdomain_elements_end(2),
460  DofObject::invalid_processor_id,
461  subdomain_two_couplings );
462 
463  dof_id_type n_elems_subdomain_two = std::distance( _mesh->active_subdomain_elements_begin(2),
464  _mesh->active_subdomain_elements_end(2) );
465 
466  CPPUNIT_ASSERT_EQUAL(n_elems_subdomain_two, static_cast<dof_id_type>(subdomain_one_couplings.size()));
467  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(2*n_elems_subdomain_two), static_cast<dof_id_type>(subdomain_two_couplings.size()));
468  }
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
What elements do we care about and what variables do we care about on each element?
Real distance(const Point &p)
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98
uint8_t dof_id_type
Definition: id_types.h:67

◆ run_partitioner_test()

void OverlappingFunctorTest::run_partitioner_test ( unsigned int  n_refinements)
inlineprivate

Definition at line 470 of file overlapping_coupling_test.C.

References libMesh::ParallelObject::n_processors(), and libMesh::MeshRefinement::uniformly_refine().

471  {
472 #ifdef LIBMESH_ENABLE_AMR
473  if( n_refinements > 0 )
474  {
475  MeshRefinement refine(*_mesh);
476  refine.uniformly_refine(n_refinements);
477  _es->reinit();
478  }
479 #else
480  CPPUNIT_ASSERT_EQUAL(n_refinements, 0u);
481 #endif // LIBMESH_ENABLE_AMR
482 
483  System & system = _es->get_system("SimpleSystem");
484 
485  std::set<processor_id_type> sub_one_proc_ids, sub_two_proc_ids;
486  for (auto & elem : _mesh->active_subdomain_elements_ptr_range(1))
487  sub_one_proc_ids.insert(elem->processor_id());
488 
489  for (auto & elem : _mesh->active_subdomain_elements_ptr_range(2))
490  sub_two_proc_ids.insert(elem->processor_id());
491 
492 
493  // Everyone should be on the same processor if only 1 processor
494  if( system.n_processors() == 1 )
495  {
496  CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(sub_one_proc_ids.size()));
497  CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(sub_two_proc_ids.size()));
498  CPPUNIT_ASSERT( sub_one_proc_ids == sub_two_proc_ids );
499  }
500  // Otherwise these sets should be disjoint
501  else
502  {
503  // Make sure no subdomain one ids in the subdomain two ids
504  for (auto & id : sub_one_proc_ids )
505  CPPUNIT_ASSERT( sub_two_proc_ids.find(id) == sub_two_proc_ids.end() );
506 
507  // Vice-versa
508  for (auto & id : sub_two_proc_ids )
509  CPPUNIT_ASSERT( sub_one_proc_ids.find(id) == sub_one_proc_ids.end() );
510  }
511  }
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
processor_id_type n_processors() const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:98

◆ setUp()

void OverlappingFunctorTest::setUp ( )
inline

Definition at line 388 of file overlapping_coupling_test.C.

References libMesh::TriangleWrapper::init().

389  {
390  this->build_quad_mesh();
391  this->init();
392  }
void build_quad_mesh(unsigned int n_refinements=0)

◆ 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 OverlappingFunctorTest::tearDown ( )
inline

Definition at line 394 of file overlapping_coupling_test.C.

395  { this->clear(); }

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: