libMesh
point_neighbor_coupling_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/numeric_vector.h>
11 #include <libmesh/dof_map.h>
12 #include <libmesh/elem.h>
13 #include <libmesh/default_coupling.h>
14 #include <libmesh/point_neighbor_coupling.h>
15 
16 #include "test_comm.h"
17 
18 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
19 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
20 // warnings. These can be ignored in GCC as long as we wrap the
21 // offending code in appropriate pragmas. We can't get away with a
22 // single ignore_warnings.h inclusion at the beginning of this file,
23 // since the libmesh headers pull in a restore_warnings.h at some
24 // point. We also don't bother restoring warnings at the end of this
25 // file since it's not a header.
26 #include <libmesh/ignore_warnings.h>
27 
28 using namespace libMesh;
29 
30 
31 
33  const Parameters&,
34  const std::string&,
35  const std::string&)
36 {
37  const Real & x = p(0);
38  const Real & y = p(1);
39  const Real & z = p(2);
40 
41  return x*(1-x)*(1-x) + x*x*(1-y) + x*(1-y)*(1-z) + y*(1-y)*z + z*(1-z)*(1-z);
42 }
43 
44 
45 
46 class PointNeighborCouplingTest : public CppUnit::TestCase {
47 public:
48  CPPUNIT_TEST_SUITE( PointNeighborCouplingTest );
49 
50  CPPUNIT_TEST( testCouplingOnEdge3 );
51  CPPUNIT_TEST( testCouplingOnQuad9 );
52  CPPUNIT_TEST( testCouplingOnTri6 );
53  CPPUNIT_TEST( testCouplingOnHex27 );
54 
55  CPPUNIT_TEST_SUITE_END();
56 
57 private:
58 
59 public:
60  void setUp()
61  {}
62 
63  void tearDown()
64  {}
65 
66  void testCoupling(const ElemType elem_type)
67  {
69 
70  EquationSystems es(mesh);
71  System &sys = es.add_system<System> ("SimpleSystem");
72  sys.add_variable("u", THIRD, HIERARCHIC);
73 
74  // Remove the default DoF ghosting functors
76  (sys.get_dof_map().default_coupling());
79 
80  // Create a replacement functor
81  PointNeighborCoupling point_neighbor_coupling;
82 
83  // This just re-sets the default; real users may want a real
84  // coupling matrix instead.
85  point_neighbor_coupling.set_dof_coupling(NULL);
86 
87  point_neighbor_coupling.set_n_levels(3);
88 
90  (point_neighbor_coupling);
91 
92  const unsigned n_elem_per_side = 5;
93  const UniquePtr<Elem> test_elem = Elem::build(elem_type);
94  const Real ymax = test_elem->dim() > 1;
95  const Real zmax = test_elem->dim() > 2;
96  const unsigned int ny = ymax * n_elem_per_side;
97  const unsigned int nz = zmax * n_elem_per_side;
98 
100  n_elem_per_side,
101  ny,
102  nz,
103  0., 1.,
104  0., ymax,
105  0., zmax,
106  elem_type);
107 
108  es.init();
110 
111  for (const auto & elem : mesh.active_local_element_ptr_range())
112  for (unsigned int s1=0; s1 != elem->n_neighbors(); ++s1)
113  {
114  const Elem * n1 = elem->neighbor_ptr(s1);
115  if (!n1)
116  continue;
117 
118  libmesh_assert(sys.get_dof_map().is_evaluable(*n1, 0));
119 
120  // Let's speed up this test by only checking the ghosted
121  // elements which are most likely to break.
122  if (n1->processor_id() == mesh.processor_id())
123  continue;
124 
125  for (unsigned int s2=0; s2 != elem->n_neighbors(); ++s2)
126  {
127  const Elem * n2 = elem->neighbor_ptr(s2);
128  if (!n2 ||
129  n2->processor_id() == mesh.processor_id())
130  continue;
131 
132  libmesh_assert(sys.get_dof_map().is_evaluable(*n2, 0));
133 
134  for (unsigned int s3=0; s3 != elem->n_neighbors(); ++s3)
135  {
136  const Elem * n3 = elem->neighbor_ptr(s3);
137  if (!n3 ||
138  n3->processor_id() == mesh.processor_id())
139  continue;
140 
141  libmesh_assert(sys.get_dof_map().is_evaluable(*n3, 0));
142 
143  Point p = n3->centroid();
144 
145  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(sys.point_value(0,p,n3)),
148  }
149  }
150  }
151  }
152 
153 
154 
155  void testCouplingOnEdge3() { testCoupling(EDGE3); }
156  void testCouplingOnQuad9() { testCoupling(QUAD9); }
157  void testCouplingOnTri6() { testCoupling(TRI6); }
158  void testCouplingOnHex27() { testCoupling(HEX27); }
159 
160 };
161 
T libmesh_real(T a)
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true) const
Definition: system.C:2011
This is the EquationSystems class.
DefaultCoupling & default_coupling()
Default coupling functor.
Definition: dof_map.h:287
static UniquePtr< Elem > build(const ElemType type, Elem *p=libmesh_nullptr)
Definition: elem.C:238
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:63
bool is_evaluable(const DofObjectSubclass &obj, unsigned int var_num=libMesh::invalid_uint) const
Definition: dof_map.C:2357
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
ImplicitSystem & sys
void set_n_levels(unsigned int n_levels)
ElemType
Defines an enum for geometric element types.
virtual SimpleRange< element_iterator > active_local_element_ptr_range() libmesh_override
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
DefaultCoupling & default_algebraic_ghosting()
Default algebraic ghosting functor.
Definition: dof_map.h:323
static const Real TOLERANCE
Number cubic_point_neighbor_coupling_test(const Point &p, const Parameters &, const std::string &, const std::string &)
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=libmesh_nullptr) const
Projects arbitrary functions onto the current solution.
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:1967
void add_algebraic_ghosting_functor(GhostingFunctor &ghosting_functor)
Adds a functor which can specify algebraic ghosting requirements for use with distributed vectors...
Definition: dof_map.C:1813
void testCoupling(const ElemType elem_type)
This class implements the default algebraic coupling in libMesh: elements couple to themselves...
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
void remove_algebraic_ghosting_functor(GhostingFunctor &ghosting_functor)
Removes a functor which was previously added to the set of algebraic ghosting functors.
Definition: dof_map.C:1822
void set_dof_coupling(const CouplingMatrix *dof_coupling)
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.
void remove_coupling_functor(GhostingFunctor &coupling_functor)
Removes a functor which was previously added to the set of coupling functors.
Definition: dof_map.C:1803
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Parameters parameters
Data structure holding arbitrary parameters.
virtual Point centroid() const
Definition: elem.C:446
virtual void init()
Initialize all the systems.
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
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.
processor_id_type processor_id() const
processor_id_type processor_id() const
Definition: dof_object.h:694
CPPUNIT_TEST_SUITE_REGISTRATION(PointNeighborCouplingTest)