libMesh
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
FECollocationTest< family, elem_type, order > Class Template Reference
Inheritance diagram for FECollocationTest< family, elem_type, order >:
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
std::unique_ptr< QBase > collocated_rule (const FEType &fe_type, const unsigned int dim)
 The quadrature rule collocated with the basis.
 
std::vector< unsigned int > collocation_points (const std::vector< std::vector< Real > > &phi)
 
void testShapesArePermutation ()
 
void testMassMatrixIsDiagonal ()
 

Static Public Attributes

static constexpr bool gll = (family == L2_LAGRANGE_GLL || family == LAGRANGE_GLL)
 Whether the family is one of the Gauss-Lobatto nodal families.
 
static constexpr Real tol = gll ? Real(0) : TOLERANCE*TOLERANCE
 The tolerance on shape function values at the collocation points.
 

Protected Attributes

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

Detailed Description

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

Definition at line 41 of file fe_collocation_test.C.

Member Function Documentation

◆ collocated_rule()

template<FEFamily family, ElemType elem_type, Order order>
std::unique_ptr< QBase > FECollocationTest< family, elem_type, order >::collocated_rule ( const FEType &  fe_type,
const unsigned int  dim 
)
inline

The quadrature rule collocated with the basis.

Definition at line 77 of file fe_collocation_test.C.

78 {
79 if (gll)
80 return fe_type.default_quadrature_rule(dim);
81
82 return std::make_unique<QNodal>(dim);
83 }
unsigned int dim
static constexpr bool gll
Whether the family is one of the Gauss-Lobatto nodal families.
std::unique_ptr< QBase > default_quadrature_rule(const unsigned int dim, const int extraorder=0) const
Definition fe_type.C:35

References libMesh::FEType::default_quadrature_rule(), dim, and FECollocationTest< family, elem_type, order >::gll.

Referenced by FECollocationTest< family, elem_type, order >::testMassMatrixIsDiagonal(), and FECollocationTest< family, elem_type, order >::testShapesArePermutation().

◆ collocation_points()

template<FEFamily family, ElemType elem_type, Order order>
std::vector< unsigned int > FECollocationTest< family, elem_type, order >::collocation_points ( const std::vector< std::vector< Real > > &  phi)
inline
Returns
Entry i is the index of the quadrature point at which shape function i is one, after checking that the shape function values at the quadrature points form a permutation matrix

Definition at line 97 of file fe_collocation_test.C.

98 {
99 std::vector<unsigned int> shape_qp(phi.size(), invalid_uint);
100
101 // Whether some shape function is already one at each quadrature point. A second shape
102 // function that is one at the same point would leave another point without one.
103 std::vector<bool> qp_claimed(phi.size(), false);
104
105 for (const auto i : index_range(phi))
106 {
107 // The collocated rule has one point per degree of freedom
108 CPPUNIT_ASSERT_EQUAL(phi.size(), phi[i].size());
109
110 for (const auto q : index_range(phi[i]))
111 if (std::abs(phi[i][q] - 1) <= tol)
112 {
113 CPPUNIT_ASSERT_EQUAL(invalid_uint, shape_qp[i]);
114 shape_qp[i] = q;
115 }
116 else
117 LIBMESH_ASSERT_FP_EQUAL(Real(0), phi[i][q], tol);
118
119 CPPUNIT_ASSERT(shape_qp[i] != invalid_uint);
120 CPPUNIT_ASSERT(!qp_claimed[shape_qp[i]]);
121 qp_claimed[shape_qp[i]] = true;
122 }
123
124 return shape_qp;
125 }
static constexpr Real tol
The tolerance on shape function values at the collocation points.
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
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::index_range(), libMesh::invalid_uint, libMesh::Real, and FECollocationTest< family, elem_type, order >::tol.

Referenced by FECollocationTest< family, elem_type, order >::testMassMatrixIsDiagonal(), and FECollocationTest< family, elem_type, order >::testShapesArePermutation().

◆ setUp()

template<FEFamily family, ElemType elem_type, Order order>
void FECollocationTest< family, elem_type, order >::setUp ( )
inline

Definition at line 48 of file fe_collocation_test.C.

49 {
50 _mesh = std::make_unique<Mesh>(*TestCommWorld);
51
52 const unsigned int dim = Elem::type_to_dim_map[elem_type];
53
54 if (dim == 1)
55 MeshTools::Generation::build_line(*_mesh, 2, 0., 1., elem_type);
56 else if (dim == 2)
57 MeshTools::Generation::build_square(*_mesh, 2, 2, 0., 1., 0., 1., elem_type);
58 else
59 MeshTools::Generation::build_cube(*_mesh, 2, 2, 2, 0., 1., 0., 1., 0., 1., elem_type);
60
61 // Shear the mesh so that the mapping to each element has off-diagonal Jacobian terms
62 for (auto * node : _mesh->node_ptr_range())
63 {
64 Node & p = *node;
65 const Real y = (LIBMESH_DIM > 1) ? p(1) : 0.;
66 const Real z = (LIBMESH_DIM > 2) ? p(2) : 0.;
67
68 p(0) += 0.3 * y + 0.17 * z;
69 if (LIBMESH_DIM > 1)
70 p(1) += 0.23 * z;
71 }
72 }
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
A Node is like a Point, but with more information.
Definition node.h:55
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
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 FECollocationTest< family, elem_type, order >::_mesh, libMesh::MeshTools::Generation::build_cube(), libMesh::MeshTools::Generation::build_line(), libMesh::MeshTools::Generation::build_square(), dim, libMesh::Real, TestCommWorld, and libMesh::Elem::type_to_dim_map.

◆ tearDown()

template<FEFamily family, ElemType elem_type, Order order>
void FECollocationTest< family, elem_type, order >::tearDown ( )
inline

Definition at line 74 of file fe_collocation_test.C.

74{ _mesh.reset(); }

References FECollocationTest< family, elem_type, order >::_mesh.

◆ testMassMatrixIsDiagonal()

template<FEFamily family, ElemType elem_type, Order order>
void FECollocationTest< family, elem_type, order >::testMassMatrixIsDiagonal ( )
inline

Definition at line 160 of file fe_collocation_test.C.

161 {
162 LOG_UNIT_TEST;
163
164 const FEType fe_type(order, family);
165 const unsigned int dim = Elem::type_to_dim_map[elem_type];
166
167 std::unique_ptr<FEBase> fe = FEBase::build(dim, fe_type);
168 std::unique_ptr<QBase> qrule = collocated_rule(fe_type, dim);
169 fe->attach_quadrature_rule(qrule.get());
170
171 const std::vector<std::vector<Real>> & phi = fe->get_phi();
172 const std::vector<Real> & JxW = fe->get_JxW();
173
174 for (const auto * elem : _mesh->active_local_element_ptr_range())
175 {
176 fe->reinit(elem);
177
178 const std::size_t n_dofs = phi.size();
179 const std::vector<unsigned int> shape_qp = collocation_points(phi);
180
181 for (const auto i : make_range(n_dofs))
182 for (const auto j : make_range(n_dofs))
183 {
184 Real m = 0.;
185 for (const auto q : index_range(JxW))
186 m += JxW[q] * phi[i][q] * phi[j][q];
187
188 if (i == j)
189 {
190 // Each diagonal entry equals JxW at its own point, which is positive on
191 // a valid element with positive quadrature weights
192 CPPUNIT_ASSERT(m > 0.);
193 LIBMESH_ASSERT_FP_EQUAL(JxW[shape_qp[i]], m, TOLERANCE*TOLERANCE);
194 }
195 else
196 LIBMESH_ASSERT_FP_EQUAL(Real(0), m, tol);
197 }
198 }
199 }
std::vector< unsigned int > collocation_points(const std::vector< std::vector< Real > > &phi)
std::unique_ptr< QBase > collocated_rule(const FEType &fe_type, const unsigned int dim)
The quadrature rule collocated with the basis.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition fe_type.h:197
static constexpr Real TOLERANCE
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 FECollocationTest< family, elem_type, order >::_mesh, libMesh::FEGenericBase< OutputType >::build(), FECollocationTest< family, elem_type, order >::collocated_rule(), FECollocationTest< family, elem_type, order >::collocation_points(), dim, libMesh::index_range(), libMesh::make_range(), libMesh::Real, FECollocationTest< family, elem_type, order >::tol, libMesh::TOLERANCE, and libMesh::Elem::type_to_dim_map.

◆ testShapesArePermutation()

template<FEFamily family, ElemType elem_type, Order order>
void FECollocationTest< family, elem_type, order >::testShapesArePermutation ( )
inline

Definition at line 127 of file fe_collocation_test.C.

128 {
129 LOG_UNIT_TEST;
130
131 const FEType fe_type(order, family);
132 const unsigned int dim = Elem::type_to_dim_map[elem_type];
133
134 std::unique_ptr<FEBase> fe = FEBase::build(dim, fe_type);
135 std::unique_ptr<QBase> qrule = collocated_rule(fe_type, dim);
136 fe->attach_quadrature_rule(qrule.get());
137
138 // Request phi before reinit so that reinit computes it
139 const std::vector<std::vector<Real>> & phi = fe->get_phi();
140
141 unsigned int n_elem = 0;
142
143 for (const auto * elem : _mesh->active_local_element_ptr_range())
144 {
145 fe->reinit(elem);
146
147 const std::vector<unsigned int> shape_qp = collocation_points(phi);
148
149 if (family == L2_LAGRANGE_GLL)
150 for (const auto i : index_range(shape_qp))
151 CPPUNIT_ASSERT_EQUAL(cast_int<unsigned int>(i), shape_qp[i]);
152
153 ++n_elem;
154 }
155
156 _mesh->comm().sum(n_elem);
157 CPPUNIT_ASSERT(n_elem > 0);
158 }
void ErrorVector unsigned int
Tnew cast_int(Told oldvar)
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).

References FECollocationTest< family, elem_type, order >::_mesh, libMesh::FEGenericBase< OutputType >::build(), FECollocationTest< family, elem_type, order >::collocated_rule(), FECollocationTest< family, elem_type, order >::collocation_points(), dim, libMesh::index_range(), libMesh::L2_LAGRANGE_GLL, and libMesh::Elem::type_to_dim_map.

Member Data Documentation

◆ _mesh

template<FEFamily family, ElemType elem_type, Order order>
std::unique_ptr<Mesh> FECollocationTest< family, elem_type, order >::_mesh
protected

◆ gll

template<FEFamily family, ElemType elem_type, Order order>
constexpr bool FECollocationTest< family, elem_type, order >::gll = (family == L2_LAGRANGE_GLL || family == LAGRANGE_GLL)
staticconstexpr

Whether the family is one of the Gauss-Lobatto nodal families.

Definition at line 86 of file fe_collocation_test.C.

Referenced by FECollocationTest< family, elem_type, order >::collocated_rule().

◆ libmesh_suite_name

template<FEFamily family, ElemType elem_type, Order order>
std::string FECollocationTest< family, elem_type, order >::libmesh_suite_name
protected

Definition at line 45 of file fe_collocation_test.C.

◆ tol

template<FEFamily family, ElemType elem_type, Order order>
constexpr Real FECollocationTest< family, elem_type, order >::tol = gll ? Real(0) : TOLERANCE*TOLERANCE
staticconstexpr

The tolerance on shape function values at the collocation points.

Definition at line 89 of file fe_collocation_test.C.

Referenced by FECollocationTest< family, elem_type, order >::collocation_points(), and FECollocationTest< family, elem_type, order >::testMassMatrixIsDiagonal().


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