libMesh
Public Member Functions | List of all members
EquationSystemsTest Class Reference
Inheritance diagram for EquationSystemsTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (EquationSystemsTest)
 
 CPPUNIT_TEST (testConstruction)
 
 CPPUNIT_TEST (testAddSystem)
 
 CPPUNIT_TEST (testInit)
 
 CPPUNIT_TEST (testPostInitAddSystem)
 
 CPPUNIT_TEST (testPostInitAddElem)
 
 CPPUNIT_TEST (testReinitWithNodeElem)
 
 CPPUNIT_TEST (testRefineThenReinitPreserveFlags)
 
 CPPUNIT_TEST (testRepartitionThenReinit)
 
 CPPUNIT_TEST (testDisableDefaultGhosting)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testConstruction ()
 
void testAddSystem ()
 
void testInit ()
 
void testPostInitAddSystem ()
 
void testPostInitAddRealSystem ()
 
void testPostInitAddElem ()
 
void testReinitWithNodeElem ()
 
void testRefineThenReinitPreserveFlags ()
 
void testRepartitionThenReinit ()
 
void testDisableDefaultGhosting ()
 

Detailed Description

Definition at line 34 of file equation_systems_test.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/9]

EquationSystemsTest::CPPUNIT_TEST ( testAddSystem  )

◆ CPPUNIT_TEST() [2/9]

EquationSystemsTest::CPPUNIT_TEST ( testConstruction  )

◆ CPPUNIT_TEST() [3/9]

EquationSystemsTest::CPPUNIT_TEST ( testDisableDefaultGhosting  )

◆ CPPUNIT_TEST() [4/9]

EquationSystemsTest::CPPUNIT_TEST ( testInit  )

◆ CPPUNIT_TEST() [5/9]

EquationSystemsTest::CPPUNIT_TEST ( testPostInitAddElem  )

◆ CPPUNIT_TEST() [6/9]

EquationSystemsTest::CPPUNIT_TEST ( testPostInitAddSystem  )

◆ CPPUNIT_TEST() [7/9]

EquationSystemsTest::CPPUNIT_TEST ( testRefineThenReinitPreserveFlags  )

◆ CPPUNIT_TEST() [8/9]

EquationSystemsTest::CPPUNIT_TEST ( testReinitWithNodeElem  )

◆ CPPUNIT_TEST() [9/9]

EquationSystemsTest::CPPUNIT_TEST ( testRepartitionThenReinit  )

◆ CPPUNIT_TEST_SUITE()

EquationSystemsTest::CPPUNIT_TEST_SUITE ( EquationSystemsTest  )

◆ CPPUNIT_TEST_SUITE_END()

EquationSystemsTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void EquationSystemsTest::setUp ( )
inline

Definition at line 57 of file equation_systems_test.C.

58  {}

◆ tearDown()

void EquationSystemsTest::tearDown ( )
inline

Definition at line 60 of file equation_systems_test.C.

61  {}

◆ testAddSystem()

void EquationSystemsTest::testAddSystem ( )
inline

Definition at line 71 of file equation_systems_test.C.

72  {
75  /*System &sys = */es.add_system<System> ("SimpleSystem");
76  }

References libMesh::EquationSystems::add_system(), mesh, and TestCommWorld.

◆ testConstruction()

void EquationSystemsTest::testConstruction ( )
inline

Definition at line 65 of file equation_systems_test.C.

66  {
69  }

References mesh, and TestCommWorld.

◆ testDisableDefaultGhosting()

void EquationSystemsTest::testDisableDefaultGhosting ( )
inline

Definition at line 217 of file equation_systems_test.C.

218  {
220  EquationSystems es(mesh);
221 
222  auto n_ghosts = [&mesh]() {
225  };
226 
227  auto n_evaluables = [](System &sys) {
228  return int(std::distance(sys.get_dof_map().algebraic_ghosting_functors_begin(),
229  sys.get_dof_map().algebraic_ghosting_functors_end()));
230  };
231 
232  auto n_couplings = [](System &sys) {
233  return int(std::distance(sys.get_dof_map().coupling_functors_begin(),
234  sys.get_dof_map().coupling_functors_end()));
235  };
236 
237  // One default ghosting functor on the mesh
238  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
239 
240  // Add another functor, making two
241  auto gpn = std::make_shared<GhostPointNeighbors>(mesh);
243  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 2);
244 
245  // Remove the default, leaving just the user functor
246  es.enable_default_ghosting(false);
247  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
248 
249  // Which can be removed too
251  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 0);
252 
253  // Adding a new system shouldn't add any default ghosting if the
254  // EquationSystems disabled it
255  System & sys1 = es.add_system<System>("System1");
256  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 0);
257  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 0);
258  CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 0);
259 
260  // But if we reenable it then now we should have three functors,
261  // with the default algebraic and coupling functors from sys1.
262  //
263  // We currently iterate over coupling functors manually even when
264  // using them for evaluability... this test will need to change
265  // eventually, when that does.
266  es.enable_default_ghosting(true);
267  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 3);
268  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 1);
269  CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
270 
271  // Adding a second system with default ghosting reenabled should
272  // give us 2 more functors.
273  System & sys2 = es.add_system<System>("System2");
274  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 5);
275  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys2), 1);
276  CPPUNIT_ASSERT_EQUAL(n_couplings(sys2), 1);
277 
278  // Adding a user functor to evaluables and couplings should add it
279  // to the mesh
282  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 6);
283  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 2);
284  CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
285 
286  // Unless we say not to.
287  auto gpn3 = std::make_shared<GhostPointNeighbors>(mesh);
288  sys1.get_dof_map().add_coupling_functor(gpn3, /*to_mesh=*/false);
289  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 6);
290  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 2);
291  CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 2);
292 
293  // Turning off default coupling again should get rid of everything
294  // except the user functors.
295  es.enable_default_ghosting(false);
296  CPPUNIT_ASSERT_EQUAL(n_ghosts(), 1);
297  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys1), 1);
298  CPPUNIT_ASSERT_EQUAL(n_couplings(sys1), 1);
299  CPPUNIT_ASSERT_EQUAL(n_evaluables(sys2), 0);
300  CPPUNIT_ASSERT_EQUAL(n_couplings(sys2), 0);
301  }

References libMesh::DofMap::add_algebraic_ghosting_functor(), libMesh::DofMap::add_coupling_functor(), libMesh::MeshBase::add_ghosting_functor(), libMesh::EquationSystems::add_system(), distance(), libMesh::EquationSystems::enable_default_ghosting(), libMesh::System::get_dof_map(), libMesh::MeshBase::ghosting_functors_begin(), libMesh::MeshBase::ghosting_functors_end(), int, mesh, libMesh::MeshBase::remove_ghosting_functor(), and TestCommWorld.

◆ testInit()

void EquationSystemsTest::testInit ( )
inline

Definition at line 78 of file equation_systems_test.C.

79  {
82  /*System &sys = */es.add_system<System> ("SimpleSystem");
84  es.init();
85  }

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_point(), libMesh::EquationSystems::init(), mesh, and TestCommWorld.

◆ testPostInitAddElem()

void EquationSystemsTest::testPostInitAddElem ( )
inline

◆ testPostInitAddRealSystem()

void EquationSystemsTest::testPostInitAddRealSystem ( )
inline

Definition at line 98 of file equation_systems_test.C.

99  {
102  EquationSystems es(mesh);
103  System &sys1 = es.add_system<System> ("SimpleSystem");
104  sys1.add_variable("u1", FIRST);
105  es.init();
106  System &sys2 = es.add_system<System> ("SecondSystem");
107  sys2.add_variable("u2", FIRST);
108  es.reinit();
109  }

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_point(), libMesh::FIRST, libMesh::EquationSystems::init(), mesh, libMesh::EquationSystems::reinit(), and TestCommWorld.

◆ testPostInitAddSystem()

void EquationSystemsTest::testPostInitAddSystem ( )
inline

Definition at line 87 of file equation_systems_test.C.

88  {
92  /*System &sys1 = */es.add_system<System> ("SimpleSystem");
93  es.init();
94  /*System &sys2 = */es.add_system<System> ("SecondSystem");
95  es.reinit();
96  }

References libMesh::EquationSystems::add_system(), libMesh::MeshTools::Generation::build_point(), libMesh::EquationSystems::init(), mesh, libMesh::EquationSystems::reinit(), and TestCommWorld.

◆ testRefineThenReinitPreserveFlags()

void EquationSystemsTest::testRefineThenReinitPreserveFlags ( )
inline

Definition at line 149 of file equation_systems_test.C.

150  {
151  // This test requires AMR support since it sets refinement flags.
152 #ifdef LIBMESH_ENABLE_AMR
154  mesh.allow_renumbering(false);
155  EquationSystems es(mesh);
156  System & sys = es.add_system<System> ("SimpleSystem");
157  sys.add_variable("u", FIRST);
159  es.init();
160 
161  Elem * to_refine = mesh.query_elem_ptr(0);
162  if (to_refine)
163  to_refine->set_refinement_flag(Elem::REFINE);
164 
165  MeshRefinement mr(mesh);
166  mr.refine_elements();
167  es.disable_refine_in_reinit();
168  es.reinit();
169 
170  if (mesh.query_elem_ptr(1))
171  CPPUNIT_ASSERT( mesh.elem_ptr(1)->active() );
172 
173  const Elem * elem = mesh.query_elem_ptr(0);
174  if (elem)
175  {
176  CPPUNIT_ASSERT_EQUAL( Elem::INACTIVE,elem->refinement_flag() );
177 
178  for (unsigned int c=0; c<elem->n_children(); c++)
179  if (elem->child_ptr(c) != remote_elem)
180  CPPUNIT_ASSERT_EQUAL(Elem::JUST_REFINED,
181  elem->child_ptr(c)->refinement_flag());
182  }
183 #endif
184  }

References libMesh::Elem::active(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshTools::Generation::build_square(), libMesh::Elem::child_ptr(), libMesh::EquationSystems::disable_refine_in_reinit(), libMesh::MeshBase::elem_ptr(), libMesh::FIRST, libMesh::Elem::INACTIVE, libMesh::EquationSystems::init(), libMesh::Elem::JUST_REFINED, mesh, libMesh::Elem::n_children(), libMesh::MeshBase::query_elem_ptr(), libMesh::Elem::REFINE, libMesh::MeshRefinement::refine_elements(), libMesh::Elem::refinement_flag(), libMesh::EquationSystems::reinit(), libMesh::remote_elem, libMesh::Elem::set_refinement_flag(), and TestCommWorld.

◆ testReinitWithNodeElem()

void EquationSystemsTest::testReinitWithNodeElem ( )
inline

◆ testRepartitionThenReinit()

void EquationSystemsTest::testRepartitionThenReinit ( )
inline

Definition at line 188 of file equation_systems_test.C.

189  {
191  mesh.allow_renumbering(false);
192  EquationSystems es(mesh);
193  System & sys = es.add_system<System> ("SimpleSystem");
194  sys.add_variable("u", FIRST);
196  es.init();
197  sys.project_solution(bilinear_test, NULL, es.parameters);
198 
199  // Force (in parallel) a different partitioning - we'll simply put
200  // everything on rank 0, which hopefully is not what our default
201  // partitioner did!
202  mesh.partition(1);
203 
204  // Make sure the solution is still intact after reinit
205  es.reinit();
206 
207  for (Real x = 0.1; x < 1; x += 0.2)
208  for (Real y = 0.1; y < 1; y += 0.2)
209  {
210  Point p(x,y);
211  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(sys.point_value(0,p)),
212  libmesh_real(bilinear_test(p,es.parameters,"","")),
214  }
215  }

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::allow_renumbering(), libMesh::MeshTools::Generation::build_square(), libMesh::FIRST, libMesh::EquationSystems::init(), libMesh::libmesh_real(), mesh, libMesh::EquationSystems::parameters, libMesh::MeshBase::partition(), libMesh::System::point_value(), libMesh::System::project_solution(), libMesh::Real, libMesh::EquationSystems::reinit(), TestCommWorld, and libMesh::TOLERANCE.


The documentation for this class was generated from the following file:
libMesh::DofMap::add_algebraic_ghosting_functor
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:1862
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::MeshBase::ghosting_functors_begin
std::set< GhostingFunctor * >::const_iterator ghosting_functors_begin() const
Beginning of range of ghosting functors.
Definition: mesh_base.h:1113
libMesh::Elem::child_ptr
const Elem * child_ptr(unsigned int i) const
Definition: elem.h:2567
libMesh::MeshBase::ghosting_functors_end
std::set< GhostingFunctor * >::const_iterator ghosting_functors_end() const
End of range of ghosting functors.
Definition: mesh_base.h:1119
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::System::reinit
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
Definition: system.C:390
libMesh::System::init
void init()
Initializes degrees of freedom on the current mesh.
Definition: system.C:237
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::DofObject::set_id
dof_id_type & set_id()
Definition: dof_object.h:776
libMesh::MeshBase::max_elem_id
virtual dof_id_type max_elem_id() const =0
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::GhostPointNeighbors
This class implements the default geometry ghosting in libMesh: point neighbors and interior_parent e...
Definition: ghost_point_neighbors.h:36
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::node_ptr
virtual const Node * node_ptr(const dof_id_type i) const =0
libMesh::DofObject::processor_id
processor_id_type processor_id() const
Definition: dof_object.h:829
libMesh::MeshBase::elem_ptr
virtual const Elem * elem_ptr(const dof_id_type i) const =0
libMesh::Elem::active
bool active() const
Definition: elem.h:2345
libMesh::MeshBase::query_elem_ptr
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::MeshRefinement
Implements (adaptive) mesh refinement algorithms for a MeshBase.
Definition: mesh_refinement.h:61
libMesh::MeshTools::Generation::build_square
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
Definition: mesh_generation.C:1501
libMesh::MeshBase::remove_ghosting_functor
void remove_ghosting_functor(GhostingFunctor &ghosting_functor)
Removes a functor which was previously added to the set of ghosting functors.
Definition: mesh_base.C:450
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
libMesh::MeshTools::Generation::build_line
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
Definition: mesh_generation.C:1480
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
libMesh::NodeElem
The NodeElem is a point element, generally used as a side of a 1D element.
Definition: node_elem.h:37
libMesh::CONSTANT
Definition: enum_order.h:41
libMesh::MONOMIAL
Definition: enum_fe_family.h:39
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::Elem::set_node
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:2059
libMesh::MeshBase::add_ghosting_functor
void add_ghosting_functor(GhostingFunctor &ghosting_functor)
Adds a functor which can specify ghosting requirements for use on distributed meshes.
Definition: mesh_base.h:1089
libMesh::Elem::refinement_flag
RefinementState refinement_flag() const
Definition: elem.h:2614
distance
Real distance(const Point &p)
Definition: subdomains_ex3.C:50
libMesh::System::point_value
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:1971
libMesh::Elem::n_children
virtual unsigned int n_children() const =0
libMesh::MeshBase::add_elem
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::Elem::set_refinement_flag
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2622
libMesh::MeshBase::allow_renumbering
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
Definition: mesh_base.h:1025
libMesh::MeshTools::Generation::build_point
void build_point(UnstructuredMesh &mesh, const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 0D meshes.
Definition: mesh_generation.C:1462
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::MeshBase::prepare_for_use
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly ecreated (or read) mesh for use.
Definition: mesh_base.C:318
libMesh::System::project_solution
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Definition: system_projection.C:950
libMesh::FIRST
Definition: enum_order.h:42
libMesh::remote_elem
const RemoteElem * remote_elem
Definition: remote_elem.C:57
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::EDGE2
Definition: enum_elem_type.h:35
libMesh::MeshBase::partition
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:599
libMesh::DofMap::add_coupling_functor
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:1838