libMesh
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  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  {
58 
60  System &sys = es.add_system<System> ("SimpleSystem");
61  sys.add_variable("u", THIRD, HIERARCHIC);
63 
64  const unsigned int n_elem_per_side = 5;
65  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
66  const unsigned int ymax = test_elem->dim() > 1;
67  const unsigned int zmax = test_elem->dim() > 2;
68  const unsigned int ny = ymax * n_elem_per_side;
69  const unsigned int nz = zmax * n_elem_per_side;
70 
72  n_elem_per_side,
73  ny,
74  nz,
75  0., 1.,
76  0., ymax,
77  0., zmax,
78  elem_type);
79 
80  es.init();
82 
83  std::set<dof_id_type> evaluable_elements;
84 
85  for (const auto & elem : mesh.active_local_element_ptr_range())
86  {
87  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*elem));
88  evaluable_elements.insert(elem->id());
89 
90  for (unsigned int s1=0; s1 != elem->n_neighbors(); ++s1)
91  {
92  const Elem * n1 = elem->neighbor_ptr(s1);
93  // Let's speed up this test by only checking the ghosted
94  // elements which are most likely to break.
95  if (!n1 ||
96  n1->processor_id() == mesh.processor_id())
97  continue;
98 
99  if (!evaluable_elements.count(n1->id()))
100  {
101  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n1));
102  evaluable_elements.insert(n1->id());
103  }
104 
105  for (unsigned int s2=0; s2 != elem->n_neighbors(); ++s2)
106  {
107  const Elem * n2 = n1->neighbor_ptr(s2);
108  if (!n2 ||
109  n2->processor_id() == mesh.processor_id())
110  continue;
111 
112  if (!evaluable_elements.count(n2->id()))
113  {
114  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n2));
115  evaluable_elements.insert(n2->id());
116  }
117 
118  for (unsigned int s3=0; s3 != elem->n_neighbors(); ++s3)
119  {
120  const Elem * n3 = n2->neighbor_ptr(s3);
121  if (!n3 ||
122  n3->processor_id() == mesh.processor_id() ||
123  evaluable_elements.count(n3->id()))
124  continue;
125 
126  CPPUNIT_ASSERT(sys.get_dof_map().is_evaluable(*n3));
127  evaluable_elements.insert(n3->id());
128 
129  Point p = n3->centroid();
130 
131  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(sys.point_value(0,p,n3)),
134  }
135  }
136  }
137  }
138 
139  const std::size_t n_evaluable =
142 
143  CPPUNIT_ASSERT_EQUAL(evaluable_elements.size(), n_evaluable);
144  }
145 
146 
147 
148  void testCouplingOnEdge3() { testCoupling(EDGE3); }
149  void testCouplingOnQuad9() { testCoupling(QUAD9); }
150  void testCouplingOnTri6() { testCoupling(TRI6); }
151  void testCouplingOnHex27() { testCoupling(HEX27); }
152 
153 };
154 
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::DofMap::is_evaluable
bool is_evaluable(const DofObjectSubclass &obj, unsigned int var_num=libMesh::invalid_uint) const
Definition: dof_map.C:2553
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::EquationSystems::add_system
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.
Definition: equation_systems.C:345
DefaultCouplingTest
Definition: default_coupling_test.C:31
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::MeshBase::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::MeshTools::Generation::build_cube
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.
Definition: mesh_generation.C:298
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::MeshBase::evaluable_elements_begin
virtual element_iterator evaluable_elements_begin(const DofMap &dof_map, unsigned int var_num=libMesh::invalid_uint)=0
Iterate over elements in the Mesh where the solution (as distributed by the given DofMap) can be eval...
libMesh::DofObject::processor_id
processor_id_type processor_id() const
Definition: dof_object.h:829
libMesh::Elem::centroid
virtual Point centroid() const
Definition: elem.C:345
libMesh::MeshBase::evaluable_elements_end
virtual element_iterator evaluable_elements_end(const DofMap &dof_map, unsigned int var_num=libMesh::invalid_uint)=0
DefaultCouplingTest::testCouplingOnQuad9
void testCouplingOnQuad9()
Definition: default_coupling_test.C:149
DefaultCouplingTest::setUp
void setUp()
Definition: default_coupling_test.C:49
cubic_default_coupling_test
Number cubic_default_coupling_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: default_coupling_test.C:17
libMesh::HEX27
Definition: enum_elem_type.h:49
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::System::add_variable
unsigned int add_variable(const std::string &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:1069
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
libMesh::EquationSystems::init
virtual void init()
Initialize all the systems.
Definition: equation_systems.C:96
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
CPPUNIT_TEST_SUITE_REGISTRATION
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultCouplingTest)
DefaultCouplingTest::testCoupling
void testCoupling(const ElemType elem_type)
Definition: default_coupling_test.C:55
libMesh::HIERARCHIC
Definition: enum_fe_family.h:37
DefaultCouplingTest::testCouplingOnHex27
void testCouplingOnHex27()
Definition: default_coupling_test.C:151
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
DefaultCouplingTest::tearDown
void tearDown()
Definition: default_coupling_test.C:52
libMesh::TRI6
Definition: enum_elem_type.h:40
distance
Real distance(const Point &p)
Definition: subdomains_ex3.C:50
libMesh::System::point_value
Number point_value(unsigned int var, const Point &p, const bool insist_on_success=true, const NumericVector< Number > *sol=nullptr) const
Definition: system.C:1971
libmesh_cppunit.h
libMesh::DofObject::id
dof_id_type id() const
Definition: dof_object.h:767
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
DefaultCouplingTest::testCouplingOnEdge3
void testCouplingOnEdge3()
Definition: default_coupling_test.C:148
libMesh::THIRD
Definition: enum_order.h:44
libMesh::DofMap::default_algebraic_ghosting
DefaultCoupling & default_algebraic_ghosting()
Default algebraic ghosting functor.
Definition: dof_map.h:403
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::Elem::neighbor_ptr
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:2085
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
test_comm.h
libMesh::System::project_solution
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Definition: system_projection.C:950
libMesh::Elem::build
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:246
DefaultCouplingTest::testCouplingOnTri6
void testCouplingOnTri6()
Definition: default_coupling_test.C:150
libMesh::Parameters
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:59
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33
libMesh::DefaultCoupling::set_n_levels
void set_n_levels(unsigned int n_levels)
Definition: default_coupling.h:65
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557