libMesh
default_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 
15 #include "test_comm.h"
16 
17 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
18 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
19 // warnings. These can be ignored in GCC as long as we wrap the
20 // offending code in appropriate pragmas. We can't get away with a
21 // single ignore_warnings.h inclusion at the beginning of this file,
22 // since the libmesh headers pull in a restore_warnings.h at some
23 // point. We also don't bother restoring warnings at the end of this
24 // file since it's not a header.
25 #include <libmesh/ignore_warnings.h>
26 
27 using namespace libMesh;
28 
29 
30 
32  const Parameters&,
33  const std::string&,
34  const std::string&)
35 {
36  const Real & x = p(0);
37  const Real & y = p(1);
38  const Real & z = p(2);
39 
40  return x*(1-x)*(1-x) + x*x*(1-y) + x*(1-y)*(1-z) + y*(1-y)*z + z*(1-z)*(1-z);
41 }
42 
43 
44 
45 class DefaultCouplingTest : public CppUnit::TestCase {
46 public:
47  CPPUNIT_TEST_SUITE( DefaultCouplingTest );
48 
49  CPPUNIT_TEST( testCouplingOnEdge3 );
50  CPPUNIT_TEST( testCouplingOnQuad9 );
51  CPPUNIT_TEST( testCouplingOnTri6 );
52  CPPUNIT_TEST( testCouplingOnHex27 );
53 
54  CPPUNIT_TEST_SUITE_END();
55 
56 private:
57 
58 public:
59  void setUp()
60  {}
61 
62  void tearDown()
63  {}
64 
65  void testCoupling(const ElemType elem_type)
66  {
68 
69  EquationSystems es(mesh);
70  System &sys = es.add_system<System> ("SimpleSystem");
71  sys.add_variable("u", THIRD, HIERARCHIC);
73 
74  const unsigned n_elem_per_side = 5;
75  const UniquePtr<Elem> test_elem = Elem::build(elem_type);
76  const Real ymax = test_elem->dim() > 1;
77  const Real zmax = test_elem->dim() > 2;
78  const unsigned int ny = ymax * n_elem_per_side;
79  const unsigned int nz = zmax * n_elem_per_side;
80 
82  n_elem_per_side,
83  ny,
84  nz,
85  0., 1.,
86  0., ymax,
87  0., zmax,
88  elem_type);
89 
90  es.init();
92 
93  for (const auto & elem : mesh.active_local_element_ptr_range())
94  for (unsigned int s1=0; s1 != elem->n_neighbors(); ++s1)
95  {
96  const Elem * n1 = elem->neighbor_ptr(s1);
97  if (!n1)
98  continue;
99 
100  // Let's speed up this test by only checking the ghosted
101  // elements which are most likely to break.
102  if (n1->processor_id() == mesh.processor_id())
103  continue;
104 
105  for (unsigned int s2=0; s2 != elem->n_neighbors(); ++s2)
106  {
107  const Elem * n2 = elem->neighbor_ptr(s2);
108  if (!n2 ||
109  n2->processor_id() == mesh.processor_id())
110  continue;
111 
112  for (unsigned int s3=0; s3 != elem->n_neighbors(); ++s3)
113  {
114  const Elem * n3 = elem->neighbor_ptr(s3);
115  if (!n3 ||
116  n3->processor_id() == mesh.processor_id())
117  continue;
118 
119  Point p = n3->centroid();
120 
121  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(sys.point_value(0,p,n3)),
124  }
125  }
126  }
127  }
128 
129 
130 
131  void testCouplingOnEdge3() { testCoupling(EDGE3); }
132  void testCouplingOnQuad9() { testCoupling(QUAD9); }
133  void testCouplingOnTri6() { testCoupling(TRI6); }
134  void testCouplingOnHex27() { testCoupling(HEX27); }
135 
136 };
137 
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.
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
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
ImplicitSystem & sys
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
CPPUNIT_TEST_SUITE_REGISTRATION(DefaultCouplingTest)
static const Real TOLERANCE
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.
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
const Elem * neighbor_ptr(unsigned int i) const
Definition: elem.h:1967
PetscErrorCode Vec x
const DofMap & get_dof_map() const
Definition: system.h:2030
Number cubic_default_coupling_test(const Point &p, const Parameters &, const std::string &, const std::string &)
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:76
void testCoupling(const ElemType elem_type)
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 set_n_levels(unsigned int n_levels)
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