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 61 of file fe_test.h.

Member Function Documentation

◆ setUp()

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

Definition at line 73 of file fe_test.h.

References libMesh::DistributedMesh::active_local_element_ptr_range(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::DofMap::dof_indices(), 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::EquationSystems::parameters, libMesh::System::project_solution(), TestCommWorld, and libMesh::System::variable_type().

74  {
75  _mesh = new Mesh(*TestCommWorld);
76  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
77  _dim = test_elem->dim();
78  const unsigned int ny = _dim > 1;
79  const unsigned int nz = _dim > 2;
80 
82  1, ny, nz,
83  0., 1., 0., ny, 0., nz,
84  elem_type);
85 
86  _es = new EquationSystems(*_mesh);
87  _sys = &(_es->add_system<System> ("SimpleSystem"));
88  _sys->add_variable("u", order, family);
89  _es->init();
91 
92  FEType fe_type = _sys->variable_type(0);
93  _fe = FEBase::build(_dim, fe_type).release();
94  _fe->get_phi();
95  _fe->get_dphi();
96  _fe->get_dphidx();
97 #if LIBMESH_DIM > 1
98  _fe->get_dphidy();
99 #endif
100 #if LIBMESH_DIM > 2
101  _fe->get_dphidz();
102 #endif
103 
105  _elem = rng.begin() == rng.end() ? nullptr : *(rng.begin());
106 
108 
109  _nx = 10;
110  _ny = _nx * (_dim > 1);
111  _nz = _nx * (_dim > 2);
112  }
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Definition: fe_type.h:179
EquationSystems * _es
Definition: fe_test.h:70
This is the EquationSystems class.
System * _sys
Definition: fe_test.h:69
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.
virtual void init()
Initialize all the systems.
unsigned int _dim
Definition: fe_test.h:64
libMesh::Parallel::Communicator * TestCommWorld
unsigned int _ny
Definition: fe_test.h:64
const std::vector< std::vector< OutputShape > > & get_dphidx() const
Definition: fe_base.h:239
std::vector< dof_id_type > _dof_indices
Definition: fe_test.h:66
unsigned int _nz
Definition: fe_test.h:64
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
const std::vector< std::vector< OutputGradient > > & get_dphi() const
Definition: fe_base.h:215
Number linear_test(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:32
This is the base class for classes which contain information related to any physical process that mig...
Definition: system.h:85
const std::vector< std::vector< OutputShape > > & get_dphidy() const
Definition: fe_base.h:247
Elem * _elem
Definition: fe_test.h:65
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2176
unsigned int _nx
Definition: fe_test.h:64
Parameters parameters
Data structure holding arbitrary parameters.
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.
virtual SimpleRange< element_iterator > active_local_element_ptr_range() override
FEBase * _fe
Definition: fe_test.h:67
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.
Gradient linear_test_grad(const Point &, const Parameters &, const std::string &, const std::string &)
Definition: fe_test.h:45
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:51
const DofMap & get_dof_map() const
Definition: system.h:2042
Mesh * _mesh
Definition: fe_test.h:68
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.
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:207
const std::vector< std::vector< OutputShape > > & get_dphidz() const
Definition: fe_base.h:255

◆ tearDown()

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

Definition at line 114 of file fe_test.h.

115  {
116  delete _fe;
117  delete _es;
118  delete _mesh;
119  }
EquationSystems * _es
Definition: fe_test.h:70
FEBase * _fe
Definition: fe_test.h:67
Mesh * _mesh
Definition: fe_test.h:68

◆ testGradU()

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

Definition at line 163 of file fe_test.h.

References libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::FEGenericBase< OutputType >::get_dphi(), libMesh::FEAbstract::get_fe_type(), libMesh::FEInterface::inverse_map(), libMesh::libmesh_real(), libMesh::Real, libMesh::FEAbstract::reinit(), and libMesh::TOLERANCE.

164  {
165  // Handle the "more processors than elements" case
166  if (!_elem)
167  return;
168 
169  // These tests require exceptions to be enabled because a
170  // TypeTensor::solve() call down in Elem::contains_point()
171  // actually throws a non-fatal exception for a certain Point which
172  // is not in the Elem. When exceptions are not enabled, this test
173  // simply aborts.
174 #ifdef LIBMESH_ENABLE_EXCEPTIONS
175  for (unsigned int i=0; i != _nx; ++i)
176  for (unsigned int j=0; j != _ny; ++j)
177  for (unsigned int k=0; k != _nz; ++k)
178  {
179  Point p(Real(i)/_nx);
180  if (j > 0)
181  p(1) = Real(j)/_ny;
182  if (k > 0)
183  p(2) = Real(k)/_ny;
184  if (!_elem->contains_point(p))
185  continue;
186 
187  std::vector<Point> master_points
188  (1, FEInterface::inverse_map(_dim, _fe->get_fe_type(), _elem, p));
189 
190  _fe->reinit(_elem, &master_points);
191 
192  Gradient grad_u = 0;
193  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
194  grad_u += _fe->get_dphi()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
195 
196  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u(0)), 1.0,
197  TOLERANCE*sqrt(TOLERANCE));
198  if (_dim > 1)
199  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u(1)), 0.25,
200  TOLERANCE*sqrt(TOLERANCE));
201  if (_dim > 2)
202  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u(2)), 0.0625,
203  TOLERANCE*sqrt(TOLERANCE));
204  }
205 #endif
206  }
T libmesh_real(T a)
System * _sys
Definition: fe_test.h:69
unsigned int _dim
Definition: fe_test.h:64
static const Real TOLERANCE
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
unsigned int _ny
Definition: fe_test.h:64
FEType get_fe_type() const
Definition: fe_abstract.h:429
std::vector< dof_id_type > _dof_indices
Definition: fe_test.h:66
unsigned int _nz
Definition: fe_test.h:64
const std::vector< std::vector< OutputGradient > > & get_dphi() const
Definition: fe_base.h:215
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.
Elem * _elem
Definition: fe_test.h:65
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _nx
Definition: fe_test.h:64
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:1528
FEBase * _fe
Definition: fe_test.h:67
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const

◆ testGradUComp()

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

Definition at line 208 of file fe_test.h.

References 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::FEAbstract::get_fe_type(), libMesh::FEInterface::inverse_map(), libMesh::libmesh_real(), libMesh::Real, libMesh::FEAbstract::reinit(), and libMesh::TOLERANCE.

209  {
210  // Handle the "more processors than elements" case
211  if (!_elem)
212  return;
213 
214  // These tests require exceptions to be enabled because a
215  // TypeTensor::solve() call down in Elem::contains_point()
216  // actually throws a non-fatal exception for a certain Point which
217  // is not in the Elem. When exceptions are not enabled, this test
218  // simply aborts.
219 #ifdef LIBMESH_ENABLE_EXCEPTIONS
220  for (unsigned int i=0; i != _nx; ++i)
221  for (unsigned int j=0; j != _ny; ++j)
222  for (unsigned int k=0; k != _nz; ++k)
223  {
224  Point p(Real(i)/_nx);
225  if (j > 0)
226  p(1) = Real(j)/_ny;
227  if (k > 0)
228  p(2) = Real(k)/_ny;
229  if (!_elem->contains_point(p))
230  continue;
231 
232  std::vector<Point> master_points
233  (1, FEInterface::inverse_map(_dim, _fe->get_fe_type(), _elem, p));
234 
235  _fe->reinit(_elem, &master_points);
236 
237  Number grad_u_x = 0, grad_u_y = 0, grad_u_z = 0;
238  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
239  {
240  grad_u_x += _fe->get_dphidx()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
241 #if LIBMESH_DIM > 1
242  grad_u_y += _fe->get_dphidy()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
243 #endif
244 #if LIBMESH_DIM > 2
245  grad_u_z += _fe->get_dphidz()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
246 #endif
247  }
248 
249  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u_x), 1.0,
250  TOLERANCE*sqrt(TOLERANCE));
251  if (_dim > 1)
252  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u_y), 0.25,
253  TOLERANCE*sqrt(TOLERANCE));
254  if (_dim > 2)
255  CPPUNIT_ASSERT_DOUBLES_EQUAL(libmesh_real(grad_u_z), 0.0625,
256  TOLERANCE*sqrt(TOLERANCE));
257  }
258 #endif
259  }
T libmesh_real(T a)
System * _sys
Definition: fe_test.h:69
unsigned int _dim
Definition: fe_test.h:64
static const Real TOLERANCE
unsigned int _ny
Definition: fe_test.h:64
const std::vector< std::vector< OutputShape > > & get_dphidx() const
Definition: fe_base.h:239
FEType get_fe_type() const
Definition: fe_abstract.h:429
std::vector< dof_id_type > _dof_indices
Definition: fe_test.h:66
unsigned int _nz
Definition: fe_test.h:64
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.
const std::vector< std::vector< OutputShape > > & get_dphidy() const
Definition: fe_base.h:247
Elem * _elem
Definition: fe_test.h:65
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _nx
Definition: fe_test.h:64
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:1528
FEBase * _fe
Definition: fe_test.h:67
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
const std::vector< std::vector< OutputShape > > & get_dphidz() const
Definition: fe_base.h:255

◆ testU()

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

Definition at line 121 of file fe_test.h.

References libMesh::Elem::contains_point(), libMesh::System::current_local_solution, libMesh::FEAbstract::get_fe_type(), libMesh::FEGenericBase< OutputType >::get_phi(), libMesh::FEInterface::inverse_map(), libMesh::libmesh_real(), libMesh::Real, libMesh::FEAbstract::reinit(), and libMesh::TOLERANCE.

122  {
123  // Handle the "more processors than elements" case
124  if (!_elem)
125  return;
126 
127  // These tests require exceptions to be enabled because a
128  // TypeTensor::solve() call down in Elem::contains_point()
129  // actually throws a non-fatal exception for a certain Point which
130  // is not in the Elem. When exceptions are not enabled, this test
131  // simply aborts.
132 #ifdef LIBMESH_ENABLE_EXCEPTIONS
133  for (unsigned int i=0; i != _nx; ++i)
134  for (unsigned int j=0; j != _ny; ++j)
135  for (unsigned int k=0; k != _nz; ++k)
136  {
137  Real x = (Real(i)/_nx), y = 0, z = 0;
138  Point p = x;
139  if (j > 0)
140  p(1) = y = (Real(j)/_ny);
141  if (k > 0)
142  p(2) = z = (Real(k)/_nz);
143  if (!_elem->contains_point(p))
144  continue;
145 
146  std::vector<Point> master_points
147  (1, FEInterface::inverse_map(_dim, _fe->get_fe_type(), _elem, p));
148 
149  _fe->reinit(_elem, &master_points);
150 
151  Number u = 0;
152  for (std::size_t d = 0; d != _dof_indices.size(); ++d)
153  u += _fe->get_phi()[d][0] * (*_sys->current_local_solution)(_dof_indices[d]);
154 
155  CPPUNIT_ASSERT_DOUBLES_EQUAL
156  (libmesh_real(u),
157  libmesh_real(x + 0.25*y + 0.0625*z),
159  }
160 #endif
161  }
T libmesh_real(T a)
System * _sys
Definition: fe_test.h:69
unsigned int _dim
Definition: fe_test.h:64
static const Real TOLERANCE
unsigned int _ny
Definition: fe_test.h:64
FEType get_fe_type() const
Definition: fe_abstract.h:429
std::vector< dof_id_type > _dof_indices
Definition: fe_test.h:66
unsigned int _nz
Definition: fe_test.h:64
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.
Elem * _elem
Definition: fe_test.h:65
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _nx
Definition: fe_test.h:64
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:1528
FEBase * _fe
Definition: fe_test.h:67
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
const std::vector< std::vector< OutputShape > > & get_phi() const
Definition: fe_base.h:207

Member Data Documentation

◆ _dim

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

Definition at line 64 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 66 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 65 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 70 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 67 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 68 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 64 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 64 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 64 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 69 of file fe_test.h.


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