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

Public Member Functions

 CPPUNIT_TEST_SUITE (SlitMeshRefinedSystemTest)
 The goal of this test is the same as the previous, but now we create a system and set dof values to make sure they are properly interpolated after refinement. More...
 
 CPPUNIT_TEST (testMesh)
 
 CPPUNIT_TEST (testSystem)
 
 CPPUNIT_TEST (testRestart)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testMesh ()
 
void testSystem ()
 
void testRestart ()
 
 CPPUNIT_TEST_SUITE (SlitMeshTest)
 The goal of this test is to ensure that a 2D mesh with nodes overlapping on opposite sides of an internal, "slit" edge is usable. More...
 

Protected Member Functions

void build_mesh ()
 

Protected Attributes

System_sys
 
EquationSystems_es
 
Mesh_mesh
 

Detailed Description

Definition at line 242 of file slit_mesh_test.C.

Member Function Documentation

void SlitMeshTest::build_mesh ( )
protectedinherited

Definition at line 91 of file slit_mesh_test.C.

References libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_point(), libMesh::MeshBase::allow_renumbering(), libMesh::DistributedMesh::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), and TestCommWorld.

92  {
93  _mesh = new Mesh(*TestCommWorld);
94 
95  // (0,1) (1,1) (2,1)
96  // x---------------x---------------x
97  // | | |
98  // | | |
99  // | | |
100  // | | |
101  // | | |
102  // x---------------x---------------x
103  // (0,0) (1,0) (2,0)
104  // | | |
105  // | | |
106  // | | |
107  // | | |
108  // x---------------x---------------x
109  // (0,-1) (1,-1) (2,-1)
110 
112 
113  _mesh->add_point( Point(0.0, 0.0), 0 );
114  _mesh->add_point( Point(1.0, 0.0), 1 );
115  _mesh->add_point( Point(1.0, 1.0), 2 );
116  _mesh->add_point( Point(0.0, 1.0), 3 );
117  _mesh->add_point( Point(0.0,-1.0), 4 );
118  _mesh->add_point( Point(1.0,-1.0), 5 );
119  _mesh->add_point( Point(1.0, 0.0), 6 );
120  _mesh->add_point( Point(2.0, 0.0), 7 );
121  _mesh->add_point( Point(2.0, 1.0), 8 );
122  _mesh->add_point( Point(2.0,-1.0), 9 );
123 
124  {
125  Elem* elem_top_left = new Quad4;
126  elem_top_left->set_node(0) = _mesh->node_ptr(0);
127  elem_top_left->set_node(1) = _mesh->node_ptr(1);
128  elem_top_left->set_node(2) = _mesh->node_ptr(2);
129  elem_top_left->set_node(3) = _mesh->node_ptr(3);
130  elem_top_left->set_id() = 0;
131  _mesh->add_elem(elem_top_left);
132 
133  Elem* elem_bottom_left = new Quad4;
134  elem_bottom_left->set_node(0) = _mesh->node_ptr(4);
135  elem_bottom_left->set_node(1) = _mesh->node_ptr(5);
136  elem_bottom_left->set_node(2) = _mesh->node_ptr(6);
137  elem_bottom_left->set_node(3) = _mesh->node_ptr(0);
138  elem_bottom_left->set_id() = 1;
139  _mesh->add_elem(elem_bottom_left);
140 
141  Elem* elem_top_right = new Quad4;
142  elem_top_right->set_node(0) = _mesh->node_ptr(1);
143  elem_top_right->set_node(1) = _mesh->node_ptr(7);
144  elem_top_right->set_node(2) = _mesh->node_ptr(8);
145  elem_top_right->set_node(3) = _mesh->node_ptr(2);
146  elem_top_right->set_id() = 2;
147  _mesh->add_elem(elem_top_right);
148 
149  Elem* elem_bottom_right = new Quad4;
150  elem_bottom_right->set_node(0) = _mesh->node_ptr(5);
151  elem_bottom_right->set_node(1) = _mesh->node_ptr(9);
152  elem_bottom_right->set_node(2) = _mesh->node_ptr(7);
153  elem_bottom_right->set_node(3) = _mesh->node_ptr(6);
154  elem_bottom_right->set_id() = 3;
155  _mesh->add_elem(elem_bottom_right);
156  }
157 
158  // libMesh shouldn't renumber, or our based-on-initial-id
159  // assertions later may fail.
160  _mesh->allow_renumbering(false);
161 
163  }
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1941
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:49
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
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
dof_id_type & set_id()
Definition: dof_object.h:641
virtual const Node * node_ptr(const dof_id_type i) const libmesh_override
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
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
Definition: mesh_base.h:199
virtual Elem * add_elem(Elem *e) libmesh_override
Add elem e to the end of the element array.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id) libmesh_override
functions for adding /deleting nodes elements.
SlitMeshRefinedSystemTest::CPPUNIT_TEST ( testMesh  )
SlitMeshRefinedSystemTest::CPPUNIT_TEST ( testSystem  )
SlitMeshRefinedSystemTest::CPPUNIT_TEST ( testRestart  )
SlitMeshTest::CPPUNIT_TEST_SUITE ( SlitMeshTest  )
inherited

The goal of this test is to ensure that a 2D mesh with nodes overlapping on opposite sides of an internal, "slit" edge is usable.

SlitMeshRefinedSystemTest::CPPUNIT_TEST_SUITE ( SlitMeshRefinedSystemTest  )

The goal of this test is the same as the previous, but now we create a system and set dof values to make sure they are properly interpolated after refinement.

SlitMeshRefinedSystemTest::CPPUNIT_TEST_SUITE_END ( )
void SlitMeshRefinedSystemTest::setUp ( )

Definition at line 268 of file slit_mesh_test.C.

References libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::FIRST, libMesh::EquationSystems::init(), libMesh::System::project_solution(), libMesh::EquationSystems::reinit(), and libMesh::MeshRefinement::uniformly_refine().

269  {
270  this->build_mesh();
271 
272  // libMesh *should* renumber now, or a DistributedMesh might not
273  // have contiguous ids, which is a requirement to write xda files.
274  _mesh->allow_renumbering(true);
275 
276  _es = new EquationSystems(*_mesh);
277  _sys = &_es->add_system<System> ("SimpleSystem");
278  _sys->add_variable("u", FIRST);
279 
280  _es->init();
281  SlitFunc slitfunc;
282  _sys->project_solution(&slitfunc);
283 
284 #ifdef LIBMESH_ENABLE_AMR
285  MeshRefinement(*_mesh).uniformly_refine(1);
286  _es->reinit();
287  MeshRefinement(*_mesh).uniformly_refine(1);
288  _es->reinit();
289 #endif
290  }
This is the EquationSystems class.
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
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
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr) const
Projects arbitrary functions onto the current solution.
This is the MeshRefinement class.
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.
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 build_mesh()
virtual void init()
Initialize all the systems.
void uniformly_refine(unsigned int n=1)
Uniformly refines the mesh n times.
void SlitMeshRefinedSystemTest::tearDown ( )

Definition at line 292 of file slit_mesh_test.C.

293  {
294  delete _es;
295  // _sys is owned by _es
296  delete _mesh;
297  }
void SlitMeshRefinedSystemTest::testMesh ( )

Definition at line 299 of file slit_mesh_test.C.

300  {
301 #ifdef LIBMESH_ENABLE_AMR
302  // We should have 84 total and 64 active elements.
303  CPPUNIT_ASSERT_EQUAL( (dof_id_type)(4+16+64), _mesh->n_elem() );
304  CPPUNIT_ASSERT_EQUAL( (dof_id_type)64, _mesh->n_active_elem() );
305 
306  // We should have 88 nodes
307  CPPUNIT_ASSERT_EQUAL( (dof_id_type)88, _mesh->n_nodes() );
308 #endif
309  }
virtual dof_id_type n_elem() const libmesh_override
virtual dof_id_type n_active_elem() const libmesh_override
virtual dof_id_type n_nodes() const libmesh_override
uint8_t dof_id_type
Definition: id_types.h:64
void SlitMeshRefinedSystemTest::testRestart ( )

Definition at line 351 of file slit_mesh_test.C.

References libMesh::DistributedMesh::active_local_element_ptr_range(), CPPUNIT_TEST_SUITE_REGISTRATION(), dim, libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::EquationSystems::get_system(), libMesh::FEAbstract::get_xyz(), libMesh::libmesh_real(), libMesh::System::n_vars(), libMesh::Elem::node_ref(), libMesh::UnstructuredMesh::read(), libMesh::EquationSystems::read(), libMesh::TypeVector< T >::size(), TestCommWorld, libMesh::TOLERANCE, libMesh::DofObject::unique_id(), libMesh::EquationSystems::write(), libMesh::EquationSystems::WRITE_DATA, and libMesh::EquationSystems::WRITE_SERIAL_FILES.

352  {
353  SlitFunc slitfunc;
354 
355  _mesh->write("slit_mesh.xda");
356  _es->write("slit_solution.xda",
357  EquationSystems::WRITE_DATA |
358  EquationSystems::WRITE_SERIAL_FILES);
359 
360  Mesh mesh2(*TestCommWorld);
361  mesh2.read("slit_mesh.xda");
362  EquationSystems es2(mesh2);
363  es2.read("slit_solution.xda");
364 
365  System & sys2 = es2.get_system<System> ("SimpleSystem");
366 
367  unsigned int dim = 2;
368 
369  CPPUNIT_ASSERT_EQUAL( sys2.n_vars(), 1u );
370 
371  FEMContext context(sys2);
372  FEBase * fe = NULL;
373  context.get_element_fe( 0, fe, dim );
374  const std::vector<Point> & xyz = fe->get_xyz();
375  fe->get_phi();
376 
377  // While we're in the middle of a unique id based test case, let's
378  // make sure our unique ids were all read in correctly too.
380 
381  if (!_mesh->is_serial())
382  locator->enable_out_of_mesh_mode();
383 
384  for (const auto & elem : mesh2.active_local_element_ptr_range())
385  {
386  const Elem * mesh1_elem = (*locator)(elem->centroid());
387  if (mesh1_elem)
388  {
389  CPPUNIT_ASSERT_EQUAL( elem->unique_id(),
390  mesh1_elem->unique_id() );
391 
392  for (unsigned int n=0; n != elem->n_nodes(); ++n)
393  {
394  const Node & node = elem->node_ref(n);
395  const Node & mesh1_node = mesh1_elem->node_ref(n);
396  CPPUNIT_ASSERT_EQUAL( node.unique_id(),
397  mesh1_node.unique_id() );
398  }
399  }
400 
401  context.pre_fe_reinit(sys2, elem);
402  context.elem_fe_reinit();
403 
404  const unsigned int n_qp = xyz.size();
405 
406  for (unsigned int qp=0; qp != n_qp; ++qp)
407  {
408  const Number exact_val = slitfunc(context, xyz[qp]);
409 
410  const Number discrete_val = context.interior_value(0, qp);
411 
412  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(exact_val),
413  libmesh_real(discrete_val),
415  }
416  }
417  }
T libmesh_real(T a)
This is the EquationSystems class.
A Node is like a Point, but with more information.
Definition: node.h:52
void write(const std::string &name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
unsigned int dim
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
static const Real TOLERANCE
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:208
virtual void write(const std::string &name) libmesh_override
Write the file specified by name.
const Node & node_ref(const unsigned int i) const
Definition: elem.h:1896
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
virtual bool is_serial() const libmesh_override
unsigned int n_vars() const
Definition: system.h:2086
Real size() const
Definition: type_vector.h:898
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
unique_id_type unique_id() const
Definition: dof_object.h:649
UniquePtr< PointLocatorBase > sub_point_locator() const
Definition: mesh_base.C:534
const std::vector< Point > & get_xyz() const
Definition: fe_abstract.h:230
This class forms the foundation from which generic finite elements may be derived.
void SlitMeshRefinedSystemTest::testSystem ( )

Definition at line 311 of file slit_mesh_test.C.

References dim, libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEAbstract::get_xyz(), libMesh::libmesh_real(), libMesh::System::n_vars(), and libMesh::TOLERANCE.

312  {
313  SlitFunc slitfunc;
314 
315  unsigned int dim = 2;
316 
317  CPPUNIT_ASSERT_EQUAL( _sys->n_vars(), 1u );
318 
319  FEMContext context(*_sys);
320  FEBase * fe = NULL;
321  context.get_element_fe( 0, fe, dim );
322  const std::vector<Point> & xyz = fe->get_xyz();
323  fe->get_phi();
324 
327  const MeshBase::const_element_iterator end_el =
329 
330  for (; el != end_el; ++el)
331  {
332  const Elem * elem = *el;
333  context.pre_fe_reinit(*_sys, elem);
334  context.elem_fe_reinit();
335 
336  const unsigned int n_qp = xyz.size();
337 
338  for (unsigned int qp=0; qp != n_qp; ++qp)
339  {
340  const Number exact_val = slitfunc(context, xyz[qp]);
341 
342  const Number discrete_val = context.interior_value(0, qp);
343 
344  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(exact_val),
345  libmesh_real(discrete_val),
347  }
348  }
349  }
T libmesh_real(T a)
virtual element_iterator active_local_elements_begin() libmesh_override
The definition of the const_element_iterator struct.
Definition: mesh_base.h:1494
unsigned int dim
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
virtual element_iterator active_local_elements_end() libmesh_override
static const Real TOLERANCE
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:208
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:61
unsigned int n_vars() const
Definition: system.h:2086
const std::vector< Point > & get_xyz() const
Definition: fe_abstract.h:230
This class forms the foundation from which generic finite elements may be derived.

Member Data Documentation

EquationSystems* SlitMeshRefinedSystemTest::_es
protected

Definition at line 264 of file slit_mesh_test.C.

Mesh* SlitMeshTest::_mesh
protectedinherited

Definition at line 89 of file slit_mesh_test.C.

System* SlitMeshRefinedSystemTest::_sys
protected

Definition at line 263 of file slit_mesh_test.C.


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