libMesh
Public Member Functions | Private Attributes | List of all members
FETest< order, family, elem_type > Class Template Reference

#include <fe_test.h>

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

Public Member Functions

void setUp ()
 
void tearDown ()
 
void testU ()
 
void testGradU ()
 
void testGradUComp ()
 

Private Attributes

unsigned int _dim
 
unsigned int _nx
 
unsigned int _ny
 
unsigned int _nz
 
Elem_elem
 
std::vector< dof_id_type_dof_indices
 
FEBase_fe
 
Mesh_mesh
 
System_sys
 
EquationSystems_es
 

Detailed Description

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

Definition at line 120 of file fe_test.h.

Member Function Documentation

◆ setUp()

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

Definition at line 132 of file fe_test.h.

133  {
134  _mesh = new Mesh(*TestCommWorld);
135  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
136  _dim = test_elem->dim();
137  const unsigned int ny = _dim > 1;
138  const unsigned int nz = _dim > 2;
139 
140  unsigned char weight_index = 0;
141 
142  if (family == RATIONAL_BERNSTEIN)
143  {
144  // Make sure we can handle non-zero weight indices
145  _mesh->add_node_integer("buffer integer");
146  weight_index = cast_int<unsigned char>
147  (_mesh->add_node_datum<Real>("rational_weight"));
148  libmesh_assert_not_equal_to(weight_index, 0);
149 
150  // Set mapping data but not type, since here we're testing
151  // rational basis functions in the FE space but testing then
152  // with Lagrange bases for the mapping space.
153  _mesh->set_default_mapping_data(weight_index);
154  }
155 
157  1, ny, nz,
158  0., 1., 0., ny, 0., nz,
159  elem_type);
160 
161  // Set rational weights so we can exactly match our test solution
162  if (family == RATIONAL_BERNSTEIN)
163  {
164  for (auto elem : _mesh->active_element_ptr_range())
165  {
166  const unsigned int nv = elem->n_vertices();
167  const unsigned int nn = elem->n_nodes();
168  // We want interiors in lower dimensional elements treated
169  // like edges or faces as appropriate.
170  const unsigned int n_edges =
171  (elem->type() == EDGE3) ? 1 : elem->n_edges();
172  const unsigned int n_faces =
173  (elem->type() == QUAD9) ? 1 : elem->n_faces();
174  const unsigned int nve = std::min(nv + n_edges, nn);
175  const unsigned int nvef = std::min(nve + n_faces, nn);
176 
177  for (unsigned int i = 0; i != nv; ++i)
178  elem->node_ref(i).set_extra_datum<Real>(weight_index, 1.);
179  for (unsigned int i = nv; i != nve; ++i)
180  elem->node_ref(i).set_extra_datum<Real>(weight_index, rational_w);
181  const Real w2 = rational_w * rational_w;
182  for (unsigned int i = nve; i != nvef; ++i)
183  elem->node_ref(i).set_extra_datum<Real>(weight_index, w2);
184  const Real w3 = rational_w * w2;
185  for (unsigned int i = nvef; i != nn; ++i)
186  elem->node_ref(i).set_extra_datum<Real>(weight_index, w3);
187  }
188  }
189 
190  _es = new EquationSystems(*_mesh);
191  _sys = &(_es->add_system<System> ("SimpleSystem"));
192  _sys->add_variable("u", order, family);
193  _es->init();
194 
195  // Clough-Tocher elements still don't work multithreaded
196  if (family == CLOUGH && libMesh::n_threads() > 1)
197  return;
198 
199  if (family == RATIONAL_BERNSTEIN && order > 1)
200  {
202  }
203  else
204  {
206  }
207 
208  FEType fe_type = _sys->variable_type(0);
209  _fe = FEBase::build(_dim, fe_type).release();
210  _fe->get_phi();
211  _fe->get_dphi();
212  _fe->get_dphidx();
213 #if LIBMESH_DIM > 1
214  _fe->get_dphidy();
215 #endif
216 #if LIBMESH_DIM > 2
217  _fe->get_dphidz();
218 #endif
219 
221  _elem = rng.begin() == rng.end() ? nullptr : *(rng.begin());
222 
224 
225  _nx = 10;
226  _ny = (_dim > 1) ? _nx : 1;
227  _nz = (_dim > 2) ? _nx : 1;
228  }

References libMesh::DistributedMesh::active_element_ptr_range(), libMesh::DistributedMesh::active_local_element_ptr_range(), libMesh::MeshBase::add_node_datum(), libMesh::MeshBase::add_node_integer(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::CLOUGH, libMesh::DofMap::dof_indices(), libMesh::EDGE3, libMesh::System::get_dof_map(), libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::FEGenericBase< OutputType >::get_dphidx(), libMesh::FEGenericBase< OutputType >::get_dphidy(), libMesh::FEGenericBase< OutputType >::get_dphidz(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::EquationSystems::init(), linear_test(), linear_test_grad(), libMesh::n_threads(), libMesh::EquationSystems::parameters, libMesh::System::project_solution(), libMesh::QUAD9, libMesh::RATIONAL_BERNSTEIN, rational_test(), rational_test_grad(), rational_w, libMesh::Real, libMesh::MeshBase::set_default_mapping_data(), TestCommWorld, and libMesh::System::variable_type().

◆ tearDown()

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

Definition at line 230 of file fe_test.h.

231  {
232  delete _fe;
233  delete _es;
234  delete _mesh;
235  }

◆ testGradU()

template<Order order, FEFamily family, ElemType elem_type>
void FETest< order, family, elem_type >::testGradU ( )
inline

Definition at line 291 of file fe_test.h.

292  {
293  // Clough-Tocher elements still don't work multithreaded
294  if (family == CLOUGH && libMesh::n_threads() > 1)
295  return;
296 
297  // Handle the "more processors than elements" case
298  if (!_elem)
299  return;
300 
301  Parameters dummy;
302 
303  // These tests require exceptions to be enabled because a
304  // TypeTensor::solve() call down in Elem::contains_point()
305  // actually throws a non-fatal exception for a certain Point which
306  // is not in the Elem. When exceptions are not enabled, this test
307  // simply aborts.
308 #ifdef LIBMESH_ENABLE_EXCEPTIONS
309  for (unsigned int i=0; i != _nx; ++i)
310  for (unsigned int j=0; j != _ny; ++j)
311  for (unsigned int k=0; k != _nz; ++k)
312  {
313  Point p(Real(i)/_nx);
314  if (j > 0)
315  p(1) = Real(j)/_ny;
316  if (k > 0)
317  p(2) = Real(k)/_ny;
318  if (!_elem->contains_point(p))
319  continue;
320 
321  std::vector<Point> master_points
322  (1, FEMap::inverse_map(_dim, _elem, p));
323 
324  _fe->reinit(_elem, &master_points);
325 
326  Gradient grad_u = 0;
327  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
328  grad_u += _fe->get_dphi()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
329 
330  if (family == RATIONAL_BERNSTEIN && order > 1)
331  {
332  const Gradient rat_grad =
333  rational_test_grad(p, dummy, "", "");
334 
335  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(0)),
336  libmesh_real(rat_grad(0)),
338  if (_dim > 1)
339  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(1)),
340  libmesh_real(rat_grad(1)),
342  if (_dim > 2)
343  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(2)),
344  libmesh_real(rat_grad(2)),
346  }
347  else
348  {
349  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(0)), 1.0,
351  if (_dim > 1)
352  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(1)), 0.25,
354  if (_dim > 2)
355  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u(2)), 0.0625,
357  }
358  }
359 #endif
360  }

References libMesh::CLOUGH, libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::FEMap::inverse_map(), libMesh::libmesh_real(), libMesh::n_threads(), libMesh::RATIONAL_BERNSTEIN, rational_test_grad(), libMesh::Real, libMesh::FEAbstract::reinit(), std::sqrt(), and libMesh::TOLERANCE.

◆ testGradUComp()

template<Order order, FEFamily family, ElemType elem_type>
void FETest< order, family, elem_type >::testGradUComp ( )
inline

Definition at line 362 of file fe_test.h.

363  {
364  // Clough-Tocher elements still don't work multithreaded
365  if (family == CLOUGH && libMesh::n_threads() > 1)
366  return;
367 
368  // Handle the "more processors than elements" case
369  if (!_elem)
370  return;
371 
372  Parameters dummy;
373 
374  // These tests require exceptions to be enabled because a
375  // TypeTensor::solve() call down in Elem::contains_point()
376  // actually throws a non-fatal exception for a certain Point which
377  // is not in the Elem. When exceptions are not enabled, this test
378  // simply aborts.
379 #ifdef LIBMESH_ENABLE_EXCEPTIONS
380  for (unsigned int i=0; i != _nx; ++i)
381  for (unsigned int j=0; j != _ny; ++j)
382  for (unsigned int k=0; k != _nz; ++k)
383  {
384  Point p(Real(i)/_nx);
385  if (j > 0)
386  p(1) = Real(j)/_ny;
387  if (k > 0)
388  p(2) = Real(k)/_ny;
389  if (!_elem->contains_point(p))
390  continue;
391 
392  std::vector<Point> master_points
393  (1, FEMap::inverse_map(_dim, _elem, p));
394 
395  _fe->reinit(_elem, &master_points);
396 
397  Number grad_u_x = 0, grad_u_y = 0, grad_u_z = 0;
398  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
399  {
400  grad_u_x += _fe->get_dphidx()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
401 #if LIBMESH_DIM > 1
402  grad_u_y += _fe->get_dphidy()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
403 #endif
404 #if LIBMESH_DIM > 2
405  grad_u_z += _fe->get_dphidz()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
406 #endif
407  }
408 
409  if (family == RATIONAL_BERNSTEIN && order > 1)
410  {
411  const Gradient rat_grad =
412  rational_test_grad(p, dummy, "", "");
413 
414  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_x),
415  libmesh_real(rat_grad(0)),
417  if (_dim > 1)
418  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_y),
419  libmesh_real(rat_grad(1)),
421  if (_dim > 2)
422  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_z),
423  libmesh_real(rat_grad(2)),
425  }
426  else
427  {
428  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_x), 1.0,
430  if (_dim > 1)
431  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_y), 0.25,
433  if (_dim > 2)
434  LIBMESH_ASSERT_FP_EQUAL(libmesh_real(grad_u_z), 0.0625,
436  }
437  }
438 #endif
439  }

References libMesh::CLOUGH, libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::FEGenericBase< OutputType >::get_dphidx(), libMesh::FEGenericBase< OutputType >::get_dphidy(), libMesh::FEGenericBase< OutputType >::get_dphidz(), libMesh::FEMap::inverse_map(), libMesh::libmesh_real(), libMesh::n_threads(), libMesh::RATIONAL_BERNSTEIN, rational_test_grad(), libMesh::Real, libMesh::FEAbstract::reinit(), std::sqrt(), and libMesh::TOLERANCE.

◆ testU()

template<Order order, FEFamily family, ElemType elem_type>
void FETest< order, family, elem_type >::testU ( )
inline

Definition at line 237 of file fe_test.h.

238  {
239  // Clough-Tocher elements still don't work multithreaded
240  if (family == CLOUGH && libMesh::n_threads() > 1)
241  return;
242 
243  // Handle the "more processors than elements" case
244  if (!_elem)
245  return;
246 
247  Parameters dummy;
248 
249  // These tests require exceptions to be enabled because a
250  // TypeTensor::solve() call down in Elem::contains_point()
251  // actually throws a non-fatal exception for a certain Point which
252  // is not in the Elem. When exceptions are not enabled, this test
253  // simply aborts.
254 #ifdef LIBMESH_ENABLE_EXCEPTIONS
255  for (unsigned int i=0; i != _nx; ++i)
256  for (unsigned int j=0; j != _ny; ++j)
257  for (unsigned int k=0; k != _nz; ++k)
258  {
259  Real x = (Real(i)/_nx), y = 0, z = 0;
260  Point p = x;
261  if (j > 0)
262  p(1) = y = (Real(j)/_ny);
263  if (k > 0)
264  p(2) = z = (Real(k)/_nz);
265  if (!_elem->contains_point(p))
266  continue;
267 
268  std::vector<Point> master_points
269  (1, FEMap::inverse_map(_dim, _elem, p));
270 
271  _fe->reinit(_elem, &master_points);
272 
273  Number u = 0;
274  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
275  u += _fe->get_phi()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
276 
277  if (family == RATIONAL_BERNSTEIN && order > 1)
278  LIBMESH_ASSERT_FP_EQUAL
279  (libmesh_real(u),
280  libmesh_real(rational_test(p, dummy, "", "")),
282  else
283  LIBMESH_ASSERT_FP_EQUAL
284  (libmesh_real(u),
285  libmesh_real(x + 0.25*y + 0.0625*z),
287  }
288 #endif
289  }

References libMesh::CLOUGH, libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEMap::inverse_map(), libMesh::libmesh_real(), libMesh::n_threads(), libMesh::RATIONAL_BERNSTEIN, rational_test(), libMesh::Real, libMesh::FEAbstract::reinit(), and libMesh::TOLERANCE.

Member Data Documentation

◆ _dim

template<Order order, FEFamily family, ElemType elem_type>
unsigned int FETest< order, family, elem_type >::_dim
private

Definition at line 123 of file fe_test.h.

◆ _dof_indices

template<Order order, FEFamily family, ElemType elem_type>
std::vector<dof_id_type> FETest< order, family, elem_type >::_dof_indices
private

Definition at line 125 of file fe_test.h.

◆ _elem

template<Order order, FEFamily family, ElemType elem_type>
Elem* FETest< order, family, elem_type >::_elem
private

Definition at line 124 of file fe_test.h.

◆ _es

template<Order order, FEFamily family, ElemType elem_type>
EquationSystems* FETest< order, family, elem_type >::_es
private

Definition at line 129 of file fe_test.h.

◆ _fe

template<Order order, FEFamily family, ElemType elem_type>
FEBase* FETest< order, family, elem_type >::_fe
private

Definition at line 126 of file fe_test.h.

◆ _mesh

template<Order order, FEFamily family, ElemType elem_type>
Mesh* FETest< order, family, elem_type >::_mesh
private

Definition at line 127 of file fe_test.h.

◆ _nx

template<Order order, FEFamily family, ElemType elem_type>
unsigned int FETest< order, family, elem_type >::_nx
private

Definition at line 123 of file fe_test.h.

◆ _ny

template<Order order, FEFamily family, ElemType elem_type>
unsigned int FETest< order, family, elem_type >::_ny
private

Definition at line 123 of file fe_test.h.

◆ _nz

template<Order order, FEFamily family, ElemType elem_type>
unsigned int FETest< order, family, elem_type >::_nz
private

Definition at line 123 of file fe_test.h.

◆ _sys

template<Order order, FEFamily family, ElemType elem_type>
System* FETest< order, family, elem_type >::_sys
private

Definition at line 128 of file fe_test.h.


The documentation for this class was generated from the following file:
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::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
libMesh::DistributedMesh::active_local_element_ptr_range
virtual SimpleRange< element_iterator > active_local_element_ptr_range() override
Definition: distributed_mesh.h:372
libMesh::CLOUGH
Definition: enum_fe_family.h:53
libMesh::DofMap::dof_indices
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Fills the vector di with the global degree of freedom indices for the element.
Definition: dof_map.C:1967
libMesh::Elem::contains_point
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2094
libMesh::n_threads
unsigned int n_threads()
Definition: libmesh_base.h:96
FETest::_elem
Elem * _elem
Definition: fe_test.h:124
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::FEGenericBase::get_dphidx
const std::vector< std::vector< OutputShape > > & get_dphidx() const
Definition: fe_base.h:238
FETest::_es
EquationSystems * _es
Definition: fe_test.h:129
libMesh::DistributedMesh::active_element_ptr_range
virtual SimpleRange< element_iterator > active_element_ptr_range() override
Definition: distributed_mesh.h:315
libMesh::MeshBase::set_default_mapping_data
void set_default_mapping_data(const unsigned char data)
Set the default master space to physical space mapping basis functions to be used on newly added elem...
Definition: mesh_base.h:732
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
std::sqrt
MetaPhysicL::DualNumber< T, D > sqrt(const MetaPhysicL::DualNumber< T, D > &in)
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::FEGenericBase::get_dphi
const std::vector< std::vector< OutputGradient > > & get_dphi() const
Definition: fe_base.h:214
rational_test_grad
Gradient rational_test_grad(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:79
FETest::_fe
FEBase * _fe
Definition: fe_test.h:126
libMesh::VectorValue< Number >
rational_w
static const Real rational_w
Definition: fe_test.h:59
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
libMesh::System::current_local_solution
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition: system.h:1551
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
rational_test
Number rational_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:62
FETest::_nx
unsigned int _nx
Definition: fe_test.h:123
FETest::_ny
unsigned int _ny
Definition: fe_test.h:123
libMesh::MeshBase::add_node_integer
unsigned int add_node_integer(const std::string &name, bool allocate_data=true)
Register an integer datum (of type dof_id_type) to be added to each node in the mesh.
Definition: mesh_base.C:247
libMesh::RATIONAL_BERNSTEIN
Definition: enum_fe_family.h:64
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::System::variable_type
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2233
FETest::_dim
unsigned int _dim
Definition: fe_test.h:123
libMesh::FEType
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:178
libMesh::FEGenericBase::get_dphidy
const std::vector< std::vector< OutputShape > > & get_dphidy() const
Definition: fe_base.h:246
FETest::_mesh
Mesh * _mesh
Definition: fe_test.h:127
libMesh::EDGE3
Definition: enum_elem_type.h:36
libMesh::MeshBase::add_node_datum
unsigned int add_node_datum(const std::string &name, bool allocate_data=true)
Register a datum (of type T) to be added to each node in the mesh.
Definition: mesh_base.h:2011
linear_test_grad
Gradient linear_test_grad(const Point &, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:41
libMesh::FEGenericBase::get_dphidz
const std::vector< std::vector< OutputShape > > & get_dphidz() const
Definition: fe_base.h:254
libMesh::QUAD9
Definition: enum_elem_type.h:43
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::FEGenericBase::get_phi
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:206
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::FEAbstract::reinit
virtual void reinit(const Elem *elem, const std::vector< Point > *const pts=nullptr, const std::vector< Real > *const weights=nullptr)=0
This is at the core of this class.
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
FETest::_dof_indices
std::vector< dof_id_type > _dof_indices
Definition: fe_test.h:125
FETest::_sys
System * _sys
Definition: fe_test.h:128
FETest::_nz
unsigned int _nz
Definition: fe_test.h:123
linear_test
Number linear_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:28
libMesh::Parameters
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Definition: parameters.h:59
libMesh::EquationSystems::parameters
Parameters parameters
Data structure holding arbitrary parameters.
Definition: equation_systems.h:557