libMesh
dof_map_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/equation_systems.h>
8 #include <libmesh/mesh.h>
9 #include <libmesh/mesh_generation.h>
10 #include <libmesh/elem.h>
11 #include <libmesh/dof_map.h>
12 
13 #include "test_comm.h"
14 
15 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
16 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
17 // warnings. These can be ignored in GCC as long as we wrap the
18 // offending code in appropriate pragmas. We can't get away with a
19 // single ignore_warnings.h inclusion at the beginning of this file,
20 // since the libmesh headers pull in a restore_warnings.h at some
21 // point. We also don't bother restoring warnings at the end of this
22 // file since it's not a header.
23 #include <libmesh/ignore_warnings.h>
24 
25 using namespace libMesh;
26 
27 
28 
29 class DofMapTest : public CppUnit::TestCase {
30 public:
31  CPPUNIT_TEST_SUITE( DofMapTest );
32 
33  CPPUNIT_TEST( testDofOwnerOnEdge3 );
34  CPPUNIT_TEST( testDofOwnerOnQuad9 );
35  CPPUNIT_TEST( testDofOwnerOnTri6 );
36  CPPUNIT_TEST( testDofOwnerOnHex27 );
37 
38  CPPUNIT_TEST_SUITE_END();
39 
40 private:
41 
42 public:
43  void setUp()
44  {}
45 
46  void tearDown()
47  {}
48 
49  void testDofOwner(const ElemType elem_type)
50  {
52 
53  EquationSystems es(mesh);
54  System &sys = es.add_system<System> ("SimpleSystem");
55  sys.add_variable("u", THIRD, HIERARCHIC);
56 
57  const unsigned n_elem_per_side = 3;
58  const UniquePtr<Elem> test_elem = Elem::build(elem_type);
59  const Real ymax = test_elem->dim() > 1;
60  const Real zmax = test_elem->dim() > 2;
61  const unsigned int ny = ymax * n_elem_per_side;
62  const unsigned int nz = zmax * n_elem_per_side;
63 
65  n_elem_per_side,
66  ny,
67  nz,
68  0., 1.,
69  0., ymax,
70  0., zmax,
71  elem_type);
72 
73  es.init();
74 
75  DofMap & dof_map = sys.get_dof_map();
76  for (dof_id_type id = 0; id != dof_map.n_dofs(); ++id)
77  {
78  const processor_id_type pid = dof_map.dof_owner(id);
79  CPPUNIT_ASSERT(dof_map.first_dof(pid) <= id);
80  CPPUNIT_ASSERT(id < dof_map.end_dof(pid));
81  }
82  }
83 
84 
85 
86  void testDofOwnerOnEdge3() { testDofOwner(EDGE3); }
87  void testDofOwnerOnQuad9() { testDofOwner(QUAD9); }
88  void testDofOwnerOnTri6() { testDofOwner(TRI6); }
89  void testDofOwnerOnHex27() { testDofOwner(HEX27); }
90 
91 };
92 
This is the EquationSystems class.
void testDofOwnerOnQuad9()
Definition: dof_map_test.C:87
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:238
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
ImplicitSystem & sys
ElemType
Defines an enum for geometric element types.
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
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
processor_id_type dof_owner(const dof_id_type dof) const
Definition: dof_map.h:586
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_dofs() const
Definition: dof_map.h:510
void testDofOwnerOnEdge3()
Definition: dof_map_test.C:86
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void testDofOwner(const ElemType elem_type)
Definition: dof_map_test.C:49
This class handles the numbering of degrees of freedom on a mesh.
Definition: dof_map.h:167
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:535
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:577
void testDofOwnerOnTri6()
Definition: dof_map_test.C:88
const DofMap & get_dof_map() const
Definition: system.h:2030
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void tearDown()
Definition: dof_map_test.C:46
virtual void init()
Initialize all the systems.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
void testDofOwnerOnHex27()
Definition: dof_map_test.C:89
void setUp()
Definition: dof_map_test.C:43
CPPUNIT_TEST_SUITE_REGISTRATION(DofMapTest)
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
uint8_t dof_id_type
Definition: id_types.h:64