Loading [MathJax]/extensions/tex2jax.js
libMesh
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
default_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 
9 #include "test_comm.h"
10 #include "libmesh_cppunit.h"
11 
12 
13 using namespace libMesh;
14 
15 
16 
18  const Parameters&,
19  const std::string&,
20  const std::string&)
21 {
22  const Real & x = p(0);
23  const Real & y = LIBMESH_DIM > 1 ? p(1) : 0;
24  const Real & z = LIBMESH_DIM > 2 ? p(2) : 0;
25 
26  return x*(1-x)*(1-x) + x*x*(1-y) + x*(1-y)*(1-z) + y*(1-y)*z + z*(1-z)*(1-z);
27 }
28 
29 
30 
31 class DefaultCouplingTest : public CppUnit::TestCase {
32 public:
33  LIBMESH_CPPUNIT_TEST_SUITE( DefaultCouplingTest );
34 
35 #if LIBMESH_DIM > 1
36  CPPUNIT_TEST( testCouplingOnEdge3 );
37 #endif
38 #if LIBMESH_DIM > 2
39  CPPUNIT_TEST( testCouplingOnQuad9 );
40  CPPUNIT_TEST( testCouplingOnTri6 );
41  CPPUNIT_TEST( testCouplingOnHex27 );
42 #endif
43 
44  CPPUNIT_TEST_SUITE_END();
45 
46 private:
47 
48 public:
49  void setUp()
50  {}
51 
52  void tearDown()
53  {}
54 
55  void testCoupling(const ElemType elem_type)
56  {
57  LOG_UNIT_TEST;
58 
60 
62  System &sys = es.add_system<System> ("SimpleSystem");
63  sys.add_variable("u", THIRD, HIERARCHIC);
65 
66  const unsigned int n_elem_per_side = 5;
67  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
68  const unsigned int ymax = test_elem->dim() > 1;
69  const unsigned int zmax = test_elem->dim() > 2;
70  const unsigned int ny = ymax * n_elem_per_side;
71  const unsigned int nz = zmax * n_elem_per_side;
72 
74  n_elem_per_side,
75  ny,
76  nz,
77  0., 1.,
78  0., ymax,
79  0., zmax,
80  elem_type);
81 
82  es.init();
84 
85  std::set<dof_id_type> evaluable_elements;
86 
87  for (const auto & elem : mesh.active_local_element_ptr_range())
88  {
89  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*elem));
90  evaluable_elements.insert(elem->id());
91 
92  for (unsigned int s1=0; s1 != elem->n_neighbors(); ++s1)
93  {
94  const Elem * n1 = elem->neighbor_ptr(s1);
95  // Let's speed up this test by only checking the ghosted
96  // elements which are most likely to break.
97  if (!n1 ||
98  n1->processor_id() == mesh.processor_id())
99  continue;
100 
101  if (!evaluable_elements.count(n1->id()))
102  {
103  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n1));
104  evaluable_elements.insert(n1->id());
105  }
106 
107  for (unsigned int s2=0; s2 != elem->n_neighbors(); ++s2)
108  {
109  const Elem * n2 = n1->neighbor_ptr(s2);
110  if (!n2 ||
111  n2->processor_id() == mesh.processor_id())
112  continue;
113 
114  if (!evaluable_elements.count(n2->id()))
115  {
116  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n2));
117  evaluable_elements.insert(n2->id());
118  }
119 
120  for (unsigned int s3=0; s3 != elem->n_neighbors(); ++s3)
121  {
122  const Elem * n3 = n2->neighbor_ptr(s3);
123  if (!n3 ||
124  n3->processor_id() == mesh.processor_id() ||
125  evaluable_elements.count(n3->id()))
126  continue;
127 
128  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n3));
129  evaluable_elements.insert(n3->id());
130 
131  Point p = n3->vertex_average();
132 
133  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(sys.point_value(0,p,n3)),
136  }
137  }
138  }
139  }
140 
141  const std::size_t n_evaluable =
142  std::distance(mesh.evaluable_elements_begin(sys.get_dof_map()),
143  mesh.evaluable_elements_end(sys.get_dof_map()));
144 
145  CPPUNIT_ASSERT_EQUAL(evaluable_elements.size(), n_evaluable);
146  }
147 
148 
149 
150  void testCouplingOnEdge3() { LOG_UNIT_TEST; testCoupling(EDGE3); }
151  void testCouplingOnQuad9() { LOG_UNIT_TEST; testCoupling(QUAD9); }
152  void testCouplingOnTri6() { LOG_UNIT_TEST; testCoupling(TRI6); }
153  void testCouplingOnHex27() { LOG_UNIT_TEST; testCoupling(HEX27); }
154 
155 };
156 
T libmesh_real(T a)
ElemType
Defines an enum for geometric element types.
This is the EquationSystems class.
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:171
static constexpr Real TOLERANCE
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:432
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:2399
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultCouplingTest)
The libMesh namespace provides an interface to certain functionality in the library.
Real distance(const Point &p)
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Number cubic_default_coupling_test(const Point &p, const Parameters &, const std::string &, const std::string &)
dof_id_type id() const
Definition: dof_object.h:828
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:321
void testCoupling(const ElemType elem_type)
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:1335
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2520
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void set_n_levels(unsigned int n_levels)
Parameters parameters
Data structure holding arbitrary parameters.
virtual void init()
Initialize all the systems.
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.
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:2370
processor_id_type processor_id() const
Definition: dof_object.h:905
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:559
bool is_evaluable(const DofObjectSubclass &obj, unsigned int var_num=libMesh::invalid_uint) const
Definition: dof_map.C:2632