libMesh
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Private Member Functions | Static Private Attributes | List of all members
FEOrientationTest< elem_type, order, family > Class Template Reference

The orientation tests on a cube of elem_type elements. More...

Inheritance diagram for FEOrientationTest< elem_type, order, family >:
[legend]

Public Member Functions

void build_mesh () override
 Builds the mesh the tests run on, before it is skewed.
 
void setUp ()
 
void tearDown ()
 
Entity node_entity (const Elem &elem, const unsigned int n)
 The entity of elem that owns the degrees of freedom sitting on node n.
 
unsigned int entity_orientation (const Elem &elem, const Entity &entity)
 The orientation index that the shape functions of entity follow.
 
void test_orientation_determines_shapes ()
 
void test_conformity_across_sides ()
 

Protected Attributes

std::unique_ptr< Mesh > _mesh
 
std::string libmesh_suite_name
 

Private Member Functions

unsigned int n_rounds () const
 Rounds of permutation, which vary the relative numbering of shared sides.
 
std::vector< Real > shapes (const FEType &fe_type, const Elem &elem, const unsigned int first, const unsigned int n_dofs, const std::vector< Point > &points)
 The values of shape functions first through first + n_dofs - 1 at points.
 
void record (std::map< unsigned int, std::vector< Real > > &seen, const unsigned int orientation, const std::vector< Real > &values, unsigned int &n_compared)
 Record values for orientation, or check them against those already recorded.
 

Static Private Attributes

static constexpr Real map_tolerance = TOLERANCE * TOLERANCE
 The tolerance for inverse_map()
 

Detailed Description

template<ElemType elem_type, Order order, FEFamily family>
class FEOrientationTest< elem_type, order, family >

The orientation tests on a cube of elem_type elements.

Definition at line 269 of file fe_orientation_test.C.

Member Function Documentation

◆ build_mesh()

template<ElemType elem_type, Order order, FEFamily family>
void FEOrientationTest< elem_type, order, family >::build_mesh ( )
inlineoverridevirtual

Builds the mesh the tests run on, before it is skewed.

Implements FEOrientationTestBase< order, family >.

Definition at line 272 of file fe_orientation_test.C.

273 {
274 const unsigned int dim = Elem::type_to_dim_map[elem_type];
275 MeshTools::Generation::build_cube(*this->_mesh, 2, 2, 2*(dim > 2),
276 0., 1., 0., 1., 0., 1., elem_type);
277 }
unsigned int dim
std::unique_ptr< Mesh > _mesh
static const unsigned int type_to_dim_map[INVALID_ELEM]
This array maps the integer representation of the ElemType enum to the geometric dimension of the ele...
Definition elem.h:649
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.

References FEOrientationTestBase< order, family >::_mesh, libMesh::MeshTools::Generation::build_cube(), dim, and libMesh::Elem::type_to_dim_map.

◆ entity_orientation()

template<Order order, FEFamily family>
unsigned int FEOrientationTestBase< order, family >::entity_orientation ( const Elem &  elem,
const Entity &  entity 
)
inlineinherited

The orientation index that the shape functions of entity follow.

Definition at line 76 of file fe_orientation_test.C.

77 {
78 switch (entity.first)
79 {
80 case EDGE:
81 return elem.positive_edge_orientation(entity.second);
82 case FACE:
83 return elem.face_orientation(entity.second);
84 default:
85 return 0;
86 }
87 }
bool positive_edge_orientation(const unsigned int i) const
Definition elem.C:4037
unsigned int face_orientation(const unsigned int i) const
Definition elem.C:4053

References EDGE, FACE, libMesh::Elem::face_orientation(), and libMesh::Elem::positive_edge_orientation().

Referenced by FEOrientationTestBase< order, family >::test_orientation_determines_shapes().

◆ n_rounds()

template<Order order, FEFamily family>
unsigned int FEOrientationTestBase< order, family >::n_rounds ( ) const
inlineprivateinherited

Rounds of permutation, which vary the relative numbering of shared sides.

Definition at line 221 of file fe_orientation_test.C.

222 {
223 unsigned int rounds = 0;
224 for (const auto * elem : _mesh->element_ptr_range())
225 rounds = std::max(rounds, elem->n_permutations());
226 _mesh->comm().max(rounds);
227 return rounds;
228 }

References FEOrientationTestBase< order, family >::_mesh.

Referenced by FEOrientationTestBase< order, family >::test_conformity_across_sides().

◆ node_entity()

template<Order order, FEFamily family>
Entity FEOrientationTestBase< order, family >::node_entity ( const Elem &  elem,
const unsigned int  n 
)
inlineinherited

The entity of elem that owns the degrees of freedom sitting on node n.

Definition at line 57 of file fe_orientation_test.C.

58 {
59 if (elem.is_vertex(n))
60 return {VERTEX, n};
61
62 if (elem.is_edge(n))
63 for (const auto e : make_range(elem.n_edges()))
64 if (elem.is_node_on_edge(n, e))
65 return {EDGE, e};
66
67 if (elem.is_face(n))
68 for (const auto f : make_range(elem.n_faces()))
69 if (elem.is_node_on_side(n, f))
70 return {FACE, f};
71
72 return {INTERIOR, 0};
73 }
virtual bool is_face(const unsigned int i) const =0
virtual bool is_edge(const unsigned int i) const =0
virtual bool is_vertex(const unsigned int i) const =0
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References EDGE, FACE, INTERIOR, libMesh::Elem::is_edge(), libMesh::Elem::is_face(), libMesh::Elem::is_node_on_edge(), libMesh::Elem::is_node_on_side(), libMesh::Elem::is_vertex(), libMesh::make_range(), libMesh::Elem::n_edges(), libMesh::Elem::n_faces(), and VERTEX.

Referenced by FEOrientationTestBase< order, family >::test_orientation_determines_shapes().

◆ record()

template<Order order, FEFamily family>
void FEOrientationTestBase< order, family >::record ( std::map< unsigned int, std::vector< Real > > &  seen,
const unsigned int  orientation,
const std::vector< Real > &  values,
unsigned int &  n_compared 
)
inlineprivateinherited

Record values for orientation, or check them against those already recorded.

Definition at line 247 of file fe_orientation_test.C.

251 {
252 const auto [entry, inserted] = seen.emplace(orientation, values);
253 if (inserted)
254 return;
255
256 CPPUNIT_ASSERT_EQUAL(entry->second.size(), values.size());
257 for (const auto k : index_range(values))
258 LIBMESH_ASSERT_FP_EQUAL(entry->second[k], values[k], TOLERANCE * TOLERANCE);
259
260 if (seen.size() > 1)
261 ++n_compared;
262 }
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
static constexpr Real TOLERANCE

References libMesh::index_range(), and libMesh::TOLERANCE.

Referenced by FEOrientationTestBase< order, family >::test_orientation_determines_shapes().

◆ setUp()

template<Order order, FEFamily family>
void FEOrientationTestBase< order, family >::setUp ( )
inlineinherited

Definition at line 39 of file fe_orientation_test.C.

40 {
41 _mesh = std::make_unique<Mesh>(*TestCommWorld);
42 build_mesh();
43
44 // An affine skew, so that no element symmetry masks a shape function following the wrong
45 // entity, and so that inverse_map() is exact
46 SkewFunc skew_func;
48 _mesh->complete_preparation();
49 }
virtual void build_mesh()=0
Builds the mesh the tests run on, before it is skewed.
void redistribute(MeshBase &mesh, const FunctionBase< Real > &mapfunc)
Deterministically perturb the nodal locations.

References FEOrientationTestBase< order, family >::_mesh, FEOrientationTestBase< order, family >::build_mesh(), libMesh::MeshTools::Modification::redistribute(), and TestCommWorld.

◆ shapes()

template<Order order, FEFamily family>
std::vector< Real > FEOrientationTestBase< order, family >::shapes ( const FEType &  fe_type,
const Elem &  elem,
const unsigned int  first,
const unsigned int  n_dofs,
const std::vector< Point > &  points 
)
inlineprivateinherited

The values of shape functions first through first + n_dofs - 1 at points.

Definition at line 231 of file fe_orientation_test.C.

236 {
237 std::vector<Real> values;
238
239 for (const auto & point : points)
240 for (const auto i : make_range(n_dofs))
241 values.push_back(FEInterface::shape(fe_type, &elem, first + i, point));
242
243 return values;
244 }
This class provides an encapsulated access to all static public member functions of finite element cl...

References libMesh::make_range(), and libMesh::FEInterface::shape().

Referenced by FEOrientationTestBase< order, family >::test_orientation_determines_shapes().

◆ tearDown()

template<Order order, FEFamily family>
void FEOrientationTestBase< order, family >::tearDown ( )
inlineinherited

Definition at line 51 of file fe_orientation_test.C.

51{ _mesh.reset(); }

References FEOrientationTestBase< order, family >::_mesh.

◆ test_conformity_across_sides()

template<Order order, FEFamily family>
void FEOrientationTestBase< order, family >::test_conformity_across_sides ( )
inlineinherited

Definition at line 141 of file fe_orientation_test.C.

142 {
143 LOG_UNIT_TEST;
144
145 const FEType fe_type(order, family);
146
148 System & sys = es.add_system<System>("orientation");
149 sys.add_variable("u", fe_type);
150 es.init();
151 const DofMap & dof_map = sys.get_dof_map();
152
153 unsigned int n_compared = 0;
154
155 for (const auto round : make_range(n_rounds()))
156 {
157 // Permute by element id so that every processor agrees on the numbering of a ghosted
158 // element
159 for (auto * elem : _mesh->element_ptr_range())
160 elem->permute((round + elem->id()) % elem->n_permutations());
161
162 for (const auto * elem : _mesh->active_local_element_ptr_range())
163 {
164 std::vector<dof_id_type> dofs;
165 dof_map.dof_indices(elem, dofs);
166
167 for (const auto s : make_range(elem->n_sides()))
168 {
169 const Elem * neighbor = elem->neighbor_ptr(s);
170 if (!neighbor || neighbor == remote_elem)
171 continue;
172
173 std::vector<dof_id_type> neighbor_dofs;
174 dof_map.dof_indices(neighbor, neighbor_dofs);
175
176 std::unique_ptr<const Elem> side = elem->build_side_ptr(s);
177 QGauss side_rule(side->dim(), order);
178 side_rule.init(*side);
179
180 for (const auto & side_point : side_rule.get_points())
181 {
182 const Point physical = FEMap::map(side->dim(), side.get(), side_point);
183
184 // Map far tighter than the shape value tolerance, so mapping error cannot
185 // mask or cause a mismatch
186 const Point point =
187 FEMap::inverse_map(elem->dim(), elem, physical, map_tolerance);
188 const Point neighbor_point =
189 FEMap::inverse_map(neighbor->dim(), neighbor, physical, map_tolerance);
190
191 for (const auto i : index_range(dofs))
192 {
193 const auto it =
194 std::find(neighbor_dofs.begin(), neighbor_dofs.end(), dofs[i]);
195 if (it == neighbor_dofs.end())
196 continue;
197
198 const auto j = std::distance(neighbor_dofs.begin(), it);
199
200 LIBMESH_ASSERT_FP_EQUAL(
201 FEInterface::shape(fe_type, elem, i, point),
202 FEInterface::shape(fe_type, neighbor, j, neighbor_point),
203 TOLERANCE);
204 ++n_compared;
205 }
206 }
207 }
208 }
209 }
210
211 // Guard against a vacuous pass
212 _mesh->comm().sum(n_compared);
213 CPPUNIT_ASSERT(n_compared > 0);
214 }
static constexpr Real map_tolerance
The tolerance for inverse_map()
unsigned int n_rounds() const
Rounds of permutation, which vary the relative numbering of shared sides.
This class handles the numbering of degrees of freedom on a mesh.
Definition dof_map.h:181
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition dof_map.C:2203
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual unsigned short dim() const =0
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736
This is the EquationSystems class.
static Real shape(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int i, const Point &p)
static Point map(const unsigned int dim, const Elem *elem, const Point &reference_point)
Definition fe_map.C:1954
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
Definition fe_map.C:1512
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
This class implements specific orders of Gauss quadrature.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
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:1344
const DofMap & get_dof_map() const
Definition system.h:2417
const RemoteElem * remote_elem
Definition remote_elem.C:57

References FEOrientationTestBase< order, family >::_mesh, libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::Elem::dim(), libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::QBase::get_points(), libMesh::index_range(), libMesh::EquationSystems::init(), libMesh::QBase::init(), libMesh::FEMap::inverse_map(), libMesh::make_range(), libMesh::FEMap::map(), FEOrientationTestBase< order, family >::map_tolerance, FEOrientationTestBase< order, family >::n_rounds(), libMesh::Elem::neighbor_ptr(), libMesh::remote_elem, libMesh::FEInterface::shape(), and libMesh::TOLERANCE.

◆ test_orientation_determines_shapes()

template<Order order, FEFamily family>
void FEOrientationTestBase< order, family >::test_orientation_determines_shapes ( )
inlineinherited

Definition at line 89 of file fe_orientation_test.C.

90 {
91 LOG_UNIT_TEST;
92
93 const FEType fe_type(order, family);
94
95 // Number of comparisons between repeat visits to an entity orientation
96 unsigned int n_compared = 0;
97
98 for (auto * elem : _mesh->active_local_element_ptr_range())
99 {
100 QGauss qrule(elem->dim(), order);
101 qrule.init(*elem);
102 const std::vector<Point> & points = qrule.get_points();
103
104 // Shape function values seen, per entity and orientation index
105 std::map<Entity, std::map<unsigned int, std::vector<Real>>> seen;
106
107 // Permuting renumbers the vertices without moving them, cycling the entity orientations
108 for (const auto p : make_range(elem->n_permutations()))
109 {
110 elem->permute(p);
111
112 // Element degrees of freedom are numbered by node, then interior
113 unsigned int dof = 0;
114
115 for (const auto n : elem->node_index_range())
116 {
117 const unsigned int n_dofs = FEInterface::n_dofs_at_node(fe_type, elem, n);
118 if (!n_dofs)
119 continue;
120
121 record(seen[node_entity(*elem, n)],
122 entity_orientation(*elem, node_entity(*elem, n)),
123 shapes(fe_type, *elem, dof, n_dofs, points),
124 n_compared);
125
126 dof += n_dofs;
127 }
128
129 const unsigned int n_interior = FEInterface::n_dofs_per_elem(fe_type, elem);
130 if (n_interior)
131 record(seen[{INTERIOR, 0}], 0,
132 shapes(fe_type, *elem, dof, n_interior, points), n_compared);
133 }
134 }
135
136 // Guard against a vacuous pass
137 _mesh->comm().sum(n_compared);
138 CPPUNIT_ASSERT(n_compared > 0);
139 }
unsigned int entity_orientation(const Elem &elem, const Entity &entity)
The orientation index that the shape functions of entity follow.
Entity node_entity(const Elem &elem, const unsigned int n)
The entity of elem that owns the degrees of freedom sitting on node n.
std::vector< Real > shapes(const FEType &fe_type, const Elem &elem, const unsigned int first, const unsigned int n_dofs, const std::vector< Point > &points)
The values of shape functions first through first + n_dofs - 1 at points.
void record(std::map< unsigned int, std::vector< Real > > &seen, const unsigned int orientation, const std::vector< Real > &values, unsigned int &n_compared)
Record values for orientation, or check them against those already recorded.
static unsigned int n_dofs_at_node(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int n)
static unsigned int n_dofs_per_elem(const unsigned int dim, const FEType &fe_t, const ElemType t)

References FEOrientationTestBase< order, family >::_mesh, FEOrientationTestBase< order, family >::entity_orientation(), libMesh::QBase::get_points(), libMesh::QBase::init(), INTERIOR, libMesh::make_range(), libMesh::FEInterface::n_dofs_at_node(), libMesh::FEInterface::n_dofs_per_elem(), FEOrientationTestBase< order, family >::node_entity(), FEOrientationTestBase< order, family >::record(), and FEOrientationTestBase< order, family >::shapes().

Member Data Documentation

◆ _mesh

template<Order order, FEFamily family>
std::unique_ptr<Mesh> FEOrientationTestBase< order, family >::_mesh
protectedinherited

◆ libmesh_suite_name

template<Order order, FEFamily family>
std::string FEOrientationTestBase< order, family >::libmesh_suite_name
protectedinherited

Definition at line 36 of file fe_orientation_test.C.

◆ map_tolerance

template<Order order, FEFamily family>
constexpr Real FEOrientationTestBase< order, family >::map_tolerance = TOLERANCE * TOLERANCE
staticconstexprprivateinherited

The tolerance for inverse_map()

Definition at line 218 of file fe_orientation_test.C.

Referenced by FEOrientationTestBase< order, family >::test_conformity_across_sides().


The documentation for this class was generated from the following file: