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 (checkCouplingFunctorQuadUnifRef)
 
 CPPUNIT_TEST (checkCouplingFunctorTri)
 
 CPPUNIT_TEST (checkCouplingFunctorTriUnifRef)
 
 CPPUNIT_TEST (checkOverlappingPartitioner)
 
 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 352 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 238 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().

239  {
240  // We are making assumptions in various places about the presence
241  // of the elements on the current processor so we're restricting to
242  // ReplicatedMesh for now.
243  _mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
244 
245  _mesh->set_mesh_dimension(2);
246 
247  _mesh->add_point( Point(0.0,0.0),0 );
248  _mesh->add_point( Point(1.0,0.0),1 );
249  _mesh->add_point( Point(1.0,1.0),2 );
250  _mesh->add_point( Point(0.0,1.0),3 );
251 
252  {
253  Elem * elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 0));
254  elem->subdomain_id() = 1;
255 
256  for (unsigned int n=0; n<4; n++)
257  elem->set_node(n) = _mesh->node_ptr(n);
258  }
259 
260  _mesh->add_point( Point(1.0,2.0),4 );
261  _mesh->add_point( Point(0.0,2.0),5 );
262 
263  {
264  Elem * elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 1));
265  elem->subdomain_id() = 1;
266 
267  elem->set_node(0) = _mesh->node_ptr(3);
268  elem->set_node(1) = _mesh->node_ptr(2);
269  elem->set_node(2) = _mesh->node_ptr(4);
270  elem->set_node(3) = _mesh->node_ptr(5);
271  }
272 
273  _mesh->add_point( Point(0.0,0.0),6 );
274  _mesh->add_point( Point(1.0,0.0),7 );
275  _mesh->add_point( Point(1.0,2.0),8 );
276  _mesh->add_point( Point(0.0,2.0),9 );
277 
278  {
279  Elem* elem = _mesh->add_elem(Elem::build_with_id(QUAD4, 2));
280  elem->subdomain_id() = 2;
281 
282  elem->set_node(0) = _mesh->node_ptr(6);
283  elem->set_node(1) = _mesh->node_ptr(7);
284  elem->set_node(2) = _mesh->node_ptr(8);
285  elem->set_node(3) = _mesh->node_ptr(9);
286  }
287 
288  _mesh->partitioner() = std::make_unique<OverlappingTestPartitioner>();
289 
290  _mesh->prepare_for_use();
291 
292 #ifdef LIBMESH_ENABLE_AMR
293  if (n_refinements > 0)
294  {
295  MeshRefinement refine(*_mesh);
296  refine.uniformly_refine(n_refinements);
297  }
298 #endif // LIBMESH_ENABLE_AMR
299  }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2381
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:2391
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39

◆ checkCouplingFunctorQuad()

void OverlappingFunctorTest::checkCouplingFunctorQuad ( )
inline

Definition at line 382 of file overlapping_coupling_test.C.

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

◆ checkCouplingFunctorQuadUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorQuadUnifRef ( )
inline

Definition at line 385 of file overlapping_coupling_test.C.

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

◆ checkCouplingFunctorTri()

void OverlappingFunctorTest::checkCouplingFunctorTri ( )
inline

Definition at line 388 of file overlapping_coupling_test.C.

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

389  {
391  _es->reinit();
392  this->run_coupling_functor_test(0);
393  }
void run_coupling_functor_test(unsigned int n_refinements)
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
void all_tri(MeshBase &mesh)
Converts the 2D quadrilateral elements of a Mesh into triangular elements.

◆ checkCouplingFunctorTriUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorTriUnifRef ( )
inline

Definition at line 395 of file overlapping_coupling_test.C.

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

396  {
398  _es->reinit();
399  this->run_coupling_functor_test(1);
400  }
void run_coupling_functor_test(unsigned int n_refinements)
std::unique_ptr< MeshBase > _mesh
std::unique_ptr< EquationSystems > _es
void all_tri(MeshBase &mesh)
Converts the 2D quadrilateral elements of a Mesh into triangular elements.

◆ checkOverlappingPartitioner()

void OverlappingFunctorTest::checkOverlappingPartitioner ( )
inline

Definition at line 402 of file overlapping_coupling_test.C.

403  {
404  this->run_partitioner_test(0);
405  }
void run_partitioner_test(unsigned int n_refinements)

◆ checkOverlappingPartitionerUnifRef()

void OverlappingFunctorTest::checkOverlappingPartitionerUnifRef ( )
inline

Definition at line 407 of file overlapping_coupling_test.C.

408  {
409  this->run_partitioner_test(1);
410  }
void run_partitioner_test(unsigned int n_refinements)

◆ clear()

void OverlappingTestBase::clear ( )
inlineprotectedinherited

Definition at line 321 of file overlapping_coupling_test.C.

322  {
323  _es.reset();
324  _mesh.reset();
325  }
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 ( checkCouplingFunctorQuadUnifRef  )

◆ CPPUNIT_TEST() [3/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorTri  )

◆ CPPUNIT_TEST() [4/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkCouplingFunctorTriUnifRef  )

◆ CPPUNIT_TEST() [5/6]

OverlappingFunctorTest::CPPUNIT_TEST ( checkOverlappingPartitioner  )

◆ 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 301 of file overlapping_coupling_test.C.

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

302  {
303  _es = std::make_unique<EquationSystems>(*_mesh);
304  LinearImplicitSystem & sys = _es->add_system<LinearImplicitSystem> ("SimpleSystem");
305 
306  std::set<subdomain_id_type> sub_one;
307  sub_one.insert(1);
308 
309  std::set<subdomain_id_type> sub_two;
310  sub_two.insert(2);
311 
312  sys.add_variable("U", FIRST, LAGRANGE, &sub_two);
313  sys.add_variable("L", FIRST, LAGRANGE, &sub_two);
314 
315  sys.add_variable("V", FIRST, LAGRANGE, &sub_one);
316  sys.add_variable("p", FIRST, LAGRANGE, &sub_one);
317 
318  _es->init();
319  }
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:1305

◆ 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 418 of file overlapping_coupling_test.C.

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

419  {
420 #if defined(LIBMESH_ENABLE_AMR) && defined(LIBMESH_HAVE_SOLVER)
421  if( n_refinements > 0 )
422  {
423  MeshRefinement refine(*_mesh);
424  refine.uniformly_refine(n_refinements);
425  _es->reinit();
426  }
427 #endif
428 
429  System & system = _es->get_system("SimpleSystem");
430 
431  OverlappingCouplingFunctor coupling_functor(system);
432 
433  GhostingFunctor::map_type subdomain_one_couplings;
434  GhostingFunctor::map_type subdomain_two_couplings;
435 
436  coupling_functor( _mesh->active_subdomain_elements_begin(1),
437  _mesh->active_subdomain_elements_end(1),
438  DofObject::invalid_processor_id,
439  subdomain_one_couplings );
440 
441  coupling_functor( _mesh->active_subdomain_elements_begin(2),
442  _mesh->active_subdomain_elements_end(2),
443  DofObject::invalid_processor_id,
444  subdomain_two_couplings );
445 
446  dof_id_type n_elems_subdomain_two = std::distance( _mesh->active_subdomain_elements_begin(2),
447  _mesh->active_subdomain_elements_end(2) );
448 
449  CPPUNIT_ASSERT_EQUAL(n_elems_subdomain_two, static_cast<dof_id_type>(subdomain_one_couplings.size()));
450  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(2*n_elems_subdomain_two), static_cast<dof_id_type>(subdomain_two_couplings.size()));
451  }
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:96
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 453 of file overlapping_coupling_test.C.

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

454  {
455 #ifdef LIBMESH_ENABLE_AMR
456  if( n_refinements > 0 )
457  {
458  MeshRefinement refine(*_mesh);
459  refine.uniformly_refine(n_refinements);
460  _es->reinit();
461  }
462 #endif // LIBMESH_ENABLE_AMR
463 
464  System & system = _es->get_system("SimpleSystem");
465 
466  std::set<processor_id_type> sub_one_proc_ids, sub_two_proc_ids;
467  for (auto & elem : _mesh->active_subdomain_elements_ptr_range(1))
468  sub_one_proc_ids.insert(elem->processor_id());
469 
470  for (auto & elem : _mesh->active_subdomain_elements_ptr_range(2))
471  sub_two_proc_ids.insert(elem->processor_id());
472 
473 
474  // Everyone should be on the same processor if only 1 processor
475  if( system.n_processors() == 1 )
476  {
477  CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(sub_one_proc_ids.size()));
478  CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(sub_two_proc_ids.size()));
479  CPPUNIT_ASSERT( sub_one_proc_ids == sub_two_proc_ids );
480  }
481  // Otherwise these sets should be disjoint
482  else
483  {
484  // Make sure no subdomain one ids in the subdomain two ids
485  for (auto & id : sub_one_proc_ids )
486  CPPUNIT_ASSERT( sub_two_proc_ids.find(id) == sub_two_proc_ids.end() );
487 
488  // Vice-versa
489  for (auto & id : sub_two_proc_ids )
490  CPPUNIT_ASSERT( sub_one_proc_ids.find(id) == sub_one_proc_ids.end() );
491  }
492  }
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:96

◆ setUp()

void OverlappingFunctorTest::setUp ( )
inline

Definition at line 373 of file overlapping_coupling_test.C.

References libMesh::TriangleWrapper::init().

374  {
375  this->build_quad_mesh();
376  this->init();
377  }
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 327 of file overlapping_coupling_test.C.

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

328  {
329  System & system = _es->get_system("SimpleSystem");
330 
331  coupling = std::make_unique<CouplingMatrix>(system.n_vars());
332 
333  const unsigned int u_var = system.variable_number("U");
334  const unsigned int l_var = system.variable_number("L");
335  const unsigned int v_var = system.variable_number("V");
336  const unsigned int p_var = system.variable_number("p");
337 
338  // Only adding the overlapping couplings since the primary ones should
339  // be there by default.
340  (*coupling)(u_var,v_var) = true;
341  (*coupling)(l_var,v_var) = true;
342  (*coupling)(l_var,p_var) = true;
343  (*coupling)(v_var,u_var) = true;
344  (*coupling)(v_var,l_var) = true;
345  }
unsigned int variable_number(std::string_view var) const
Definition: system.C:1557
std::unique_ptr< EquationSystems > _es
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
unsigned int n_vars() const
Definition: system.h:2349

◆ tearDown()

void OverlappingFunctorTest::tearDown ( )
inline

Definition at line 379 of file overlapping_coupling_test.C.

380  { this->clear(); }

Member Data Documentation

◆ _es

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

Definition at line 236 of file overlapping_coupling_test.C.

◆ _mesh

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

Definition at line 234 of file overlapping_coupling_test.C.


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