libMesh
equation_systems_test.C
Go to the documentation of this file.
1 // Ignore unused parameter warnings coming from cppunit headers
2 #include <libmesh/ignore_warnings.h>
3 #include <cppunit/extensions/HelperMacros.h>
4 #include <cppunit/TestCase.h>
5 #include <libmesh/restore_warnings.h>
6 
7 #include <libmesh/elem.h>
8 #include <libmesh/equation_systems.h>
9 #include <libmesh/mesh.h>
10 #include <libmesh/mesh_generation.h>
11 #include <libmesh/mesh_refinement.h>
12 #include <libmesh/remote_elem.h>
13 #include <libmesh/replicated_mesh.h>
14 
15 #include "test_comm.h"
16 
17 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
18 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
19 // warnings. These can be ignored in GCC as long as we wrap the
20 // offending code in appropriate pragmas. We can't get away with a
21 // single ignore_warnings.h inclusion at the beginning of this file,
22 // since the libmesh headers pull in a restore_warnings.h at some
23 // point. We also don't bother restoring warnings at the end of this
24 // file since it's not a header.
25 #include <libmesh/ignore_warnings.h>
26 
27 using namespace libMesh;
28 
29 class EquationSystemsTest : public CppUnit::TestCase {
30 public:
31  CPPUNIT_TEST_SUITE( EquationSystemsTest );
32 
33  CPPUNIT_TEST( testConstruction );
34  CPPUNIT_TEST( testAddSystem );
35  CPPUNIT_TEST( testInit );
36  CPPUNIT_TEST( testPostInitAddSystem );
37  CPPUNIT_TEST( testPostInitAddElem );
38  CPPUNIT_TEST( testRefineThenReinitPreserveFlags );
39 
40  CPPUNIT_TEST_SUITE_END();
41 
42 private:
43 
44 public:
45  void setUp()
46  {}
47 
48  void tearDown()
49  {}
50 
51 
52 
54  {
56  EquationSystems es(mesh);
57  }
58 
60  {
62  EquationSystems es(mesh);
63  /*System &sys = */es.add_system<System> ("SimpleSystem");
64  }
65 
66  void testInit()
67  {
69  EquationSystems es(mesh);
70  /*System &sys = */es.add_system<System> ("SimpleSystem");
72  es.init();
73  }
74 
76  {
79  EquationSystems es(mesh);
80  /*System &sys1 = */es.add_system<System> ("SimpleSystem");
81  es.init();
82  /*System &sys2 = */es.add_system<System> ("SecondSystem");
83  es.reinit();
84  }
85 
87  {
90  EquationSystems es(mesh);
91  System &sys1 = es.add_system<System> ("SimpleSystem");
92  sys1.add_variable("u1", FIRST);
93  es.init();
94  System &sys2 = es.add_system<System> ("SecondSystem");
95  sys2.add_variable("u2", FIRST);
96  es.reinit();
97  }
98 
100  {
102 
103  EquationSystems es(mesh);
104  System &sys = es.add_system<System> ("SimpleSystem");
105  sys.add_variable("u", FIRST);
106 
107  MeshTools::Generation::build_line (mesh, 10, 0., 1., EDGE2);
108  es.init();
109 
110  Elem* e = Elem::build(EDGE2).release();
111  e->set_id(mesh.max_elem_id());
112  e->processor_id() = 0;
113  e->set_node(0) = mesh.node_ptr(2);
114  e->set_node(1) = mesh.node_ptr(8);
115  mesh.add_elem(e);
116  mesh.prepare_for_use();
117 
118  es.reinit();
119  }
120 
122  {
123  // This test requires AMR support since it sets refinement flags.
124 #ifdef LIBMESH_ENABLE_AMR
126  mesh.allow_renumbering(false);
127  EquationSystems es(mesh);
128  System & sys = es.add_system<System> ("SimpleSystem");
129  sys.add_variable("u", FIRST);
131  es.init();
132 
133  Elem * to_refine = mesh.query_elem_ptr(0);
134  if (to_refine)
135  to_refine->set_refinement_flag(Elem::REFINE);
136 
137  MeshRefinement mr(mesh);
138  mr.refine_elements();
140  es.reinit();
141 
142  if (mesh.query_elem_ptr(1))
143  CPPUNIT_ASSERT( mesh.elem_ptr(1)->active() );
144 
145  const Elem * elem = mesh.query_elem_ptr(0);
146  if (elem)
147  {
148  CPPUNIT_ASSERT_EQUAL( Elem::INACTIVE,elem->refinement_flag() );
149 
150  for (unsigned int c=0; c<elem->n_children(); c++)
151  if (elem->child_ptr(c) != remote_elem)
152  CPPUNIT_ASSERT_EQUAL(Elem::JUST_REFINED,
153  elem->child_ptr(c)->refinement_flag());
154  }
155 #endif
156  }
157 
158 
159 
160 
161 
162 };
163 
virtual const Elem * elem_ptr(const dof_id_type i) const libmesh_override
virtual dof_id_type max_elem_id() const libmesh_override
This is the EquationSystems class.
virtual const Node * node_ptr(const dof_id_type i) const libmesh_override
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1941
void build_point(UnstructuredMesh &mesh, const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 0D meshes.
bool active() const
Definition: elem.h:2257
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:238
virtual Elem * add_elem(Elem *e) libmesh_override
Add elem e to the end of the element array.
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:749
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
ImplicitSystem & sys
bool refine_elements()
Only refines the user-requested elements.
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=libmesh_nullptr)
Adds the variable var to the list of variables for this system.
Definition: system.C:1101
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
MeshBase & mesh
void disable_refine_in_reinit()
Calls to reinit() will not try to coarsen or refine the mesh.
void set_refinement_flag(const RefinementState rflag)
Sets the value of the refinement flag for the element.
Definition: elem.h:2513
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.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type & set_id()
Definition: dof_object.h:641
This is the MeshRefinement class.
virtual const Elem * query_elem_ptr(const dof_id_type i) const libmesh_override
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
virtual void reinit()
Reinitialize all the systems.
const Elem * child_ptr(unsigned int i) const
Definition: elem.h:2445
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
void prepare_for_use(const bool skip_renumber_nodes_and_elements=false, const bool skip_find_neighbors=false)
Prepare a newly created (or read) mesh for use.
Definition: mesh_base.C:174
virtual unsigned int n_children() const =0
CPPUNIT_TEST_SUITE_REGISTRATION(EquationSystemsTest)
RefinementState refinement_flag() const
Definition: elem.h:2505
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.
virtual void init()
Initialize all the systems.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
processor_id_type processor_id() const
Definition: dof_object.h:694
const RemoteElem * remote_elem
Definition: remote_elem.C:57