libMesh
point_neighbor_coupling_test.C
Go to the documentation of this file.
1 #include <libmesh/equation_systems.h>
2 #include <libmesh/mesh.h>
3 #include <libmesh/mesh_generation.h>
4 #include <libmesh/numeric_vector.h>
5 #include <libmesh/dof_map.h>
6 #include <libmesh/elem.h>
7 #include <libmesh/default_coupling.h>
8 #include <libmesh/point_neighbor_coupling.h>
9 
10 #include "test_comm.h"
11 #include "libmesh_cppunit.h"
12 
13 
14 using namespace libMesh;
15 
16 
17 
19  const Parameters&,
20  const std::string&,
21  const std::string&)
22 {
23  const Real & x = p(0);
24  const Real & y = LIBMESH_DIM > 1 ? p(1) : 0;
25  const Real & z = LIBMESH_DIM > 2 ? p(2) : 0;
26 
27  return x*(1-x)*(1-x) + x*x*(1-y) + x*(1-y)*(1-z) + y*(1-y)*z + z*(1-z)*(1-z);
28 }
29 
30 
31 
32 class PointNeighborCouplingTest : public CppUnit::TestCase {
33 public:
34  LIBMESH_CPPUNIT_TEST_SUITE( PointNeighborCouplingTest );
35 
36  CPPUNIT_TEST( testCouplingOnEdge3 );
37 #if LIBMESH_DIM > 1
38  CPPUNIT_TEST( testCouplingOnQuad9 );
39  CPPUNIT_TEST( testCouplingOnTri6 );
40 #endif
41 #if LIBMESH_DIM > 2
42  CPPUNIT_TEST( testCouplingOnHex27 );
43 #endif
44 
45  CPPUNIT_TEST_SUITE_END();
46 
47 private:
48 
49 public:
50  void setUp()
51  {}
52 
53  void tearDown()
54  {}
55 
56  void testCoupling(const ElemType elem_type)
57  {
59 
61  System &sys = es.add_system<System> ("SimpleSystem");
62  sys.add_variable("u", THIRD, HIERARCHIC);
63 
64  // Remove the default DoF ghosting functors
66  (sys.get_dof_map().default_coupling());
69 
70  // Create a replacement functor
71  PointNeighborCoupling point_neighbor_coupling;
72 
73  // This just re-sets the default; real users may want a real
74  // coupling matrix instead.
75  point_neighbor_coupling.set_dof_coupling(nullptr);
76 
77  point_neighbor_coupling.set_n_levels(3);
78 
80  (point_neighbor_coupling);
81 
82  const unsigned int n_elem_per_side = 5;
83  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
84  const unsigned int ymax = test_elem->dim() > 1;
85  const unsigned int zmax = test_elem->dim() > 2;
86  const unsigned int ny = ymax * n_elem_per_side;
87  const unsigned int nz = zmax * n_elem_per_side;
88 
90  n_elem_per_side,
91  ny,
92  nz,
93  0., 1.,
94  0., ymax,
95  0., zmax,
96  elem_type);
97 
98  es.init();
100 
101  for (const auto & elem : mesh.active_local_element_ptr_range())
102  for (unsigned int s1=0; s1 != elem->n_neighbors(); ++s1)
103  {
104  const Elem * n1 = elem->neighbor_ptr(s1);
105  if (!n1)
106  continue;
107 
108  libmesh_assert(sys.get_dof_map().is_evaluable(*n1, 0));
109 
110  // Let's speed up this test by only checking the ghosted
111  // elements which are most likely to break.
112  if (n1->processor_id() == mesh.processor_id())
113  continue;
114 
115  for (unsigned int s2=0; s2 != elem->n_neighbors(); ++s2)
116  {
117  const Elem * n2 = elem->neighbor_ptr(s2);
118  if (!n2 ||
119  n2->processor_id() == mesh.processor_id())
120  continue;
121 
122  libmesh_assert(sys.get_dof_map().is_evaluable(*n2, 0));
123 
124  for (unsigned int s3=0; s3 != elem->n_neighbors(); ++s3)
125  {
126  const Elem * n3 = elem->neighbor_ptr(s3);
127  if (!n3 ||
128  n3->processor_id() == mesh.processor_id())
129  continue;
130 
131  libmesh_assert(sys.get_dof_map().is_evaluable(*n3, 0));
132 
133  Point p = n3->vertex_average();
134 
135  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(sys.point_value(0,p,n3)),
138  }
139  }
140  }
141  }
142 
143 
144 
145  void testCouplingOnEdge3() { LOG_UNIT_TEST; testCoupling(EDGE3); }
146  void testCouplingOnQuad9() { LOG_UNIT_TEST; testCoupling(QUAD9); }
147  void testCouplingOnTri6() { LOG_UNIT_TEST; testCoupling(TRI6); }
148  void testCouplingOnHex27() { LOG_UNIT_TEST; testCoupling(HEX27); }
149 
150 };
151 
T libmesh_real(T a)
ElemType
Defines an enum for geometric element types.
This is the EquationSystems class.
DefaultCoupling & default_coupling()
Default coupling functor.
Definition: dof_map.h:356
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:67
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:159
static constexpr Real TOLERANCE
void set_n_levels(unsigned int n_levels)
This is the base class from which all geometric element types are derived.
Definition: elem.h:94
MeshBase & mesh
DefaultCoupling & default_algebraic_ghosting()
Default algebraic ghosting functor.
Definition: dof_map.h:418
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2369
Number cubic_point_neighbor_coupling_test(const Point &p, const Parameters &, const std::string &, const std::string &)
The libMesh namespace provides an interface to certain functionality in the library.
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
void testCoupling(const ElemType elem_type)
This class implements the default algebraic coupling in libMesh: elements couple to themselves...
void set_dof_coupling(const CouplingMatrix *dof_coupling)
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:273
libmesh_assert(ctx)
unsigned int add_variable(std::string_view 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:1305
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2407
void remove_coupling_functor(GhostingFunctor &coupling_functor)
Removes a functor which was previously added to the set of coupling functors, from both this DofMap a...
Definition: dof_map.C:1873
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Parameters parameters
Data structure holding arbitrary parameters.
virtual void init()
Initialize all the systems.
void remove_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor)
Removes a functor which was previously added to the set of algebraic ghosting functors, from both this DofMap and from the underlying mesh.
Definition: dof_map.C:1898
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
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:1886
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
processor_id_type processor_id() const
const DofMap & get_dof_map() const
Definition: system.h:2293
processor_id_type processor_id() const
Definition: dof_object.h:898
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
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.
Point vertex_average() const
Definition: elem.C:498
bool is_evaluable(const DofObjectSubclass &obj, unsigned int var_num=libMesh::invalid_uint) const
Definition: dof_map.C:2609
CPPUNIT_TEST_SUITE_REGISTRATION(PointNeighborCouplingTest)