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

 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 (MeshBase &mesh)
 
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 355 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.

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 = libmesh_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( new Quad4 );
254  elem->set_id(0);
255  elem->subdomain_id() = 1;
256 
257  for (unsigned int n=0; n<4; n++)
258  elem->set_node(n) = _mesh->node_ptr(n);
259  }
260 
261  _mesh->add_point( Point(1.0,2.0),4 );
262  _mesh->add_point( Point(0.0,2.0),5 );
263 
264  {
265  Elem* elem = _mesh->add_elem( new Quad4 );
266  elem->set_id(1);
267  elem->subdomain_id() = 1;
268 
269  elem->set_node(0) = _mesh->node_ptr(3);
270  elem->set_node(1) = _mesh->node_ptr(2);
271  elem->set_node(2) = _mesh->node_ptr(4);
272  elem->set_node(3) = _mesh->node_ptr(5);
273  }
274 
275  _mesh->add_point( Point(0.0,0.0),6 );
276  _mesh->add_point( Point(1.0,0.0),7 );
277  _mesh->add_point( Point(1.0,2.0),8 );
278  _mesh->add_point( Point(0.0,2.0),9 );
279 
280  {
281  Elem* elem = _mesh->add_elem( new Quad4 );
282  elem->set_id(2);
283  elem->subdomain_id() = 2;
284 
285  elem->set_node(0) = _mesh->node_ptr(6);
286  elem->set_node(1) = _mesh->node_ptr(7);
287  elem->set_node(2) = _mesh->node_ptr(8);
288  elem->set_node(3) = _mesh->node_ptr(9);
289  }
290 
291  _mesh->partitioner() = libmesh_make_unique<OverlappingTestPartitioner>();
292 
293  _mesh->prepare_for_use();
294 
295 #ifdef LIBMESH_ENABLE_AMR
296  if (n_refinements > 0)
297  {
298  MeshRefinement refine(*_mesh);
299  refine.uniformly_refine(n_refinements);
300  }
301 #endif // LIBMESH_ENABLE_AMR
302  }

References libMesh::DofObject::set_id(), libMesh::Elem::set_node(), libMesh::Elem::subdomain_id(), TestCommWorld, and libMesh::MeshRefinement::uniformly_refine().

◆ checkCouplingFunctorQuad()

void OverlappingFunctorTest::checkCouplingFunctorQuad ( )
inline

Definition at line 385 of file overlapping_coupling_test.C.

386  { this->run_coupling_functor_test(0); }

◆ checkCouplingFunctorQuadUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorQuadUnifRef ( )
inline

Definition at line 388 of file overlapping_coupling_test.C.

389  { this->run_coupling_functor_test(1); }

◆ checkCouplingFunctorTri()

void OverlappingFunctorTest::checkCouplingFunctorTri ( )
inline

Definition at line 391 of file overlapping_coupling_test.C.

392  {
394  _es->reinit();
395  this->run_coupling_functor_test(0);
396  }

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

◆ checkCouplingFunctorTriUnifRef()

void OverlappingFunctorTest::checkCouplingFunctorTriUnifRef ( )
inline

Definition at line 398 of file overlapping_coupling_test.C.

399  {
401  _es->reinit();
402  this->run_coupling_functor_test(1);
403  }

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

◆ checkOverlappingPartitioner()

void OverlappingFunctorTest::checkOverlappingPartitioner ( )
inline

Definition at line 405 of file overlapping_coupling_test.C.

406  {
407  this->run_partitioner_test(0);
408  }

◆ checkOverlappingPartitionerUnifRef()

void OverlappingFunctorTest::checkOverlappingPartitionerUnifRef ( )
inline

Definition at line 410 of file overlapping_coupling_test.C.

411  {
412  this->run_partitioner_test(1);
413  }

◆ clear()

void OverlappingTestBase::clear ( )
inlineprotectedinherited

Definition at line 324 of file overlapping_coupling_test.C.

325  {
326  _es.reset();
327  _mesh.reset();
328  }

◆ 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()

OverlappingFunctorTest::CPPUNIT_TEST_SUITE ( OverlappingFunctorTest  )

◆ CPPUNIT_TEST_SUITE_END()

OverlappingFunctorTest::CPPUNIT_TEST_SUITE_END ( )

◆ init()

void OverlappingTestBase::init ( MeshBase mesh)
inlineprotectedinherited

Definition at line 304 of file overlapping_coupling_test.C.

305  {
306  _es = libmesh_make_unique<EquationSystems>(*_mesh);
307  LinearImplicitSystem & sys = _es->add_system<LinearImplicitSystem> ("SimpleSystem");
308 
309  std::set<subdomain_id_type> sub_one;
310  sub_one.insert(1);
311 
312  std::set<subdomain_id_type> sub_two;
313  sub_two.insert(2);
314 
315  sys.add_variable("U", FIRST, LAGRANGE, &sub_two);
316  sys.add_variable("L", FIRST, LAGRANGE, &sub_two);
317 
318  sys.add_variable("V", FIRST, LAGRANGE, &sub_one);
319  sys.add_variable("p", FIRST, LAGRANGE, &sub_one);
320 
321  _es->init();
322  }

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

◆ run_coupling_functor_test()

void OverlappingFunctorTest::run_coupling_functor_test ( unsigned int  n_refinements)
inlineprivate

Definition at line 421 of file overlapping_coupling_test.C.

422  {
423 #if defined(LIBMESH_ENABLE_AMR) && defined(LIBMESH_HAVE_SOLVER)
424  if( n_refinements > 0 )
425  {
426  MeshRefinement refine(*_mesh);
427  refine.uniformly_refine(n_refinements);
428  _es->reinit();
429  }
430 #endif
431 
432  System & system = _es->get_system("SimpleSystem");
433 
434  OverlappingCouplingFunctor coupling_functor(system);
435 
436  std::unordered_map<const Elem *,const CouplingMatrix*> subdomain_one_couplings;
437  std::unordered_map<const Elem *,const CouplingMatrix*> subdomain_two_couplings;
438 
439  coupling_functor( _mesh->active_subdomain_elements_begin(1),
440  _mesh->active_subdomain_elements_end(1),
441  DofObject::invalid_processor_id,
442  subdomain_one_couplings );
443 
444  coupling_functor( _mesh->active_subdomain_elements_begin(2),
445  _mesh->active_subdomain_elements_end(2),
446  DofObject::invalid_processor_id,
447  subdomain_two_couplings );
448 
449  dof_id_type n_elems_subdomain_two = std::distance( _mesh->active_subdomain_elements_begin(2),
450  _mesh->active_subdomain_elements_end(2) );
451 
452  CPPUNIT_ASSERT_EQUAL( n_elems_subdomain_two, (dof_id_type) subdomain_one_couplings.size() );
453  CPPUNIT_ASSERT_EQUAL( dof_id_type(2*n_elems_subdomain_two), (dof_id_type) subdomain_two_couplings.size() );
454  }

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

◆ run_partitioner_test()

void OverlappingFunctorTest::run_partitioner_test ( unsigned int  n_refinements)
inlineprivate

Definition at line 456 of file overlapping_coupling_test.C.

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

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

◆ setUp()

void OverlappingFunctorTest::setUp ( )
inline

Definition at line 376 of file overlapping_coupling_test.C.

377  {
378  this->build_quad_mesh();
379  this->init(*_mesh);
380  }

References libMesh::TriangleWrapper::init().

◆ setup_coupling_matrix()

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

Definition at line 330 of file overlapping_coupling_test.C.

331  {
332  System & system = _es->get_system("SimpleSystem");
333 
334  coupling = libmesh_make_unique<CouplingMatrix>(system.n_vars());
335 
336  const unsigned int u_var = system.variable_number("U");
337  const unsigned int l_var = system.variable_number("L");
338  const unsigned int v_var = system.variable_number("V");
339  const unsigned int p_var = system.variable_number("p");
340 
341  // Only adding the overlapping couplings since the primary ones should
342  // be there by default.
343  (*coupling)(u_var,v_var) = true;
344  (*coupling)(l_var,v_var) = true;
345  (*coupling)(l_var,p_var) = true;
346  (*coupling)(v_var,u_var) = true;
347  (*coupling)(v_var,l_var) = true;
348  }

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

◆ tearDown()

void OverlappingFunctorTest::tearDown ( )
inline

Definition at line 382 of file overlapping_coupling_test.C.

383  { 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:
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::dof_id_type
uint8_t dof_id_type
Definition: id_types.h:67
libMesh::System::n_vars
unsigned int n_vars() const
Definition: system.h:2155
libMesh::DofObject::set_id
dof_id_type & set_id()
Definition: dof_object.h:776
libMesh::MeshRefinement
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Definition: mesh_refinement.h:61
OverlappingCouplingFunctor
Definition: overlapping_coupling_test.C:37
libMesh::ParallelObject::n_processors
processor_id_type n_processors() const
Definition: parallel_object.h:100
OverlappingTestBase::_mesh
std::unique_ptr< MeshBase > _mesh
Definition: overlapping_coupling_test.C:234
libMesh::System::add_variable
unsigned int add_variable(const std::string &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:1069
OverlappingTestBase::_es
std::unique_ptr< EquationSystems > _es
Definition: overlapping_coupling_test.C:236
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
OverlappingFunctorTest::run_coupling_functor_test
void run_coupling_functor_test(unsigned int n_refinements)
Definition: overlapping_coupling_test.C:421
libMesh::Quad4
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:51
libMesh::Elem::set_node
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2059
distance
Real distance(const Point &p)
Definition: subdomains_ex3.C:50
libMesh::MeshTools::Modification::all_tri
void all_tri(MeshBase &mesh)
Converts the 2D quadrilateral elements of a Mesh into triangular elements.
Definition: mesh_modification.C:280
OverlappingTestBase::build_quad_mesh
void build_quad_mesh(unsigned int n_refinements=0)
Definition: overlapping_coupling_test.C:238
OverlappingTestBase::init
void init(MeshBase &mesh)
Definition: overlapping_coupling_test.C:304
libMesh::Elem::subdomain_id
subdomain_id_type subdomain_id() const
Definition: elem.h:2069
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::System::variable_number
unsigned short int variable_number(const std::string &var) const
Definition: system.C:1232
libMesh::LAGRANGE
Definition: enum_fe_family.h:36
OverlappingFunctorTest::run_partitioner_test
void run_partitioner_test(unsigned int n_refinements)
Definition: overlapping_coupling_test.C:456
libMesh::LinearImplicitSystem
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Definition: linear_implicit_system.h:55
OverlappingTestBase::clear
void clear()
Definition: overlapping_coupling_test.C:324
libMesh::FIRST
Definition: enum_order.h:42