libMesh
Public Member Functions | Protected Attributes | Private Attributes | List of all members
RationalMapTest< elem_type > Class Template Reference
Inheritance diagram for RationalMapTest< elem_type >:
[legend]

Public Member Functions

void setUp ()
 
void tearDown ()
 
void testContainsPoint ()
 

Protected Attributes

std::string libmesh_suite_name
 

Private Attributes

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

Detailed Description

template<ElemType elem_type>
class RationalMapTest< elem_type >

Definition at line 22 of file fe_rational_map.C.

Member Function Documentation

◆ setUp()

template<ElemType elem_type>
void RationalMapTest< elem_type >::setUp ( )
inline

Definition at line 36 of file fe_rational_map.C.

References libMesh::System::add_variable(), libMesh::FEGenericBase< OutputType >::build(), libMesh::Elem::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::FIRST, libMesh::RATIONAL_BERNSTEIN_MAP, libMesh::Real, and libMesh::System::variable_type().

37  {
38  _mesh = std::make_unique<Mesh>(*TestCommWorld);
39  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
40  _dim = test_elem->dim();
41  const unsigned int ny = _dim > 1;
42  const unsigned int nz = _dim > 2;
43 
44  // Make sure we can handle non-zero weight indices
45  _mesh->add_node_integer("buffer integer1");
46  _mesh->add_node_integer("buffer integer2");
47 
48  // Default weight to 1.0 so we don't get NaN from contains_point
49  // checks with a default GhostPointNeighbors ghosting
50  const Real default_weight = 1.0;
51  unsigned char weight_index = cast_int<unsigned char>
52  (_mesh->add_node_datum<Real>("rational_weight", true,
53  &default_weight));
54 
55  libmesh_assert_not_equal_to(weight_index, 0);
56 
57  _mesh->set_default_mapping_type(RATIONAL_BERNSTEIN_MAP);
58  _mesh->set_default_mapping_data(weight_index);
59 
61  1, ny, nz,
62  0., 1., 0., ny, 0., nz,
63  elem_type);
64 
65  for (auto elem : _mesh->element_ptr_range())
66  {
67  CPPUNIT_ASSERT_EQUAL(elem->mapping_type(), RATIONAL_BERNSTEIN_MAP);
68  CPPUNIT_ASSERT_EQUAL(elem->mapping_data(), weight_index);
69  }
70 
71  // Transform the cube / square into a rotated quarter-annulus,
72  // with central axis at (-.5, 0) and radii ranging from .5 to 1.5
73 
74  for (auto node : _mesh->node_ptr_range())
75  {
76  Real & x = (*node)(0);
77  Real & y = (*node)(1);
78  node->set_extra_datum<Real>(weight_index, 1);
79  if (y > .6)
80  {
81  y = .5 + x;
82  x = -.5;
83  }
84  else if (y > .4)
85  {
86  y = .5 + x;
87  x = y - .5;
88  node->set_extra_datum<Real>(weight_index, sqrt(Real(2))/2);
89  }
90  }
91 
92  _es = std::make_unique<EquationSystems>(*_mesh);
93  System * sys = &(_es->add_system<System> ("SimpleSystem"));
94  sys->add_variable("u", FIRST);
95  _es->init();
96 
97  _fe = FEBase::build(_dim, sys->variable_type("u"));
98  _fe->get_xyz();
99  _fe->get_phi();
100  _fe->get_dphi();
101  _fe->get_dphidx();
102 #if LIBMESH_DIM > 1
103  _fe->get_dphidy();
104 #endif
105 #if LIBMESH_DIM > 2
106  _fe->get_dphidz();
107 #endif
108 
109  auto rng = _mesh->active_local_element_ptr_range();
110  _elem = rng.begin() == rng.end() ? nullptr : *(rng.begin());
111 
112  _nx = 10;
113  _ny = (_dim > 1) ? _nx : 0;
114  _nz = (_dim > 2) ? _nx : 0;
115  }
unsigned int _nz
unsigned int _dim
std::unique_ptr< FEBase > _fe
std::unique_ptr< EquationSystems > _es
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:96
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:1357
unsigned int _nx
const FEType & variable_type(const unsigned int i) const
Definition: system.h:2508
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::unique_ptr< Mesh > _mesh
unsigned int _ny
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.

◆ tearDown()

template<ElemType elem_type>
void RationalMapTest< elem_type >::tearDown ( )
inline

Definition at line 117 of file fe_rational_map.C.

117 {}

◆ testContainsPoint()

template<ElemType elem_type>
void RationalMapTest< elem_type >::testContainsPoint ( )
inline

Definition at line 119 of file fe_rational_map.C.

References libMesh::Elem::contains_point(), int, libMesh::pi, and libMesh::Real.

120  {
121  LOG_UNIT_TEST;
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 j=0; j != _ny+1; ++j)
134  for (unsigned int k=0; k != _nz+1; ++k)
135  {
136  for (int i=-1; i != int(_nx+2); ++i)
137  {
138  Real r = (Real(i)/_nx) + 0.5,
139  theta = (Real(j)/_nx)*pi/2,
140  z = (Real(k)/_nx);
141  Real x = -.5 + r * std::cos(theta),
142  y = r * std::sin(theta);
143  Point p(x,y,z);
144  // Test for false negatives
145  if (i >= 0 && i <= int(_nx))
146  CPPUNIT_ASSERT(_elem->contains_point(p));
147  // Also test for false positives
148  else
149  CPPUNIT_ASSERT(!_elem->contains_point(p));
150  }
151  }
152 #endif
153  }
unsigned int _nz
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2751
unsigned int _nx
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
unsigned int _ny
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
const Real pi
.
Definition: libmesh.h:299

Member Data Documentation

◆ _dim

template<ElemType elem_type>
unsigned int RationalMapTest< elem_type >::_dim
private

Definition at line 25 of file fe_rational_map.C.

◆ _dof_indices

template<ElemType elem_type>
std::vector<dof_id_type> RationalMapTest< elem_type >::_dof_indices
private

Definition at line 27 of file fe_rational_map.C.

◆ _elem

template<ElemType elem_type>
Elem* RationalMapTest< elem_type >::_elem
private

Definition at line 26 of file fe_rational_map.C.

◆ _es

template<ElemType elem_type>
std::unique_ptr<EquationSystems> RationalMapTest< elem_type >::_es
private

Definition at line 29 of file fe_rational_map.C.

◆ _fe

template<ElemType elem_type>
std::unique_ptr<FEBase> RationalMapTest< elem_type >::_fe
private

Definition at line 30 of file fe_rational_map.C.

◆ _mesh

template<ElemType elem_type>
std::unique_ptr<Mesh> RationalMapTest< elem_type >::_mesh
private

Definition at line 28 of file fe_rational_map.C.

◆ _nx

template<ElemType elem_type>
unsigned int RationalMapTest< elem_type >::_nx
private

Definition at line 25 of file fe_rational_map.C.

◆ _ny

template<ElemType elem_type>
unsigned int RationalMapTest< elem_type >::_ny
private

Definition at line 25 of file fe_rational_map.C.

◆ _nz

template<ElemType elem_type>
unsigned int RationalMapTest< elem_type >::_nz
private

Definition at line 25 of file fe_rational_map.C.

◆ libmesh_suite_name

template<ElemType elem_type>
std::string RationalMapTest< elem_type >::libmesh_suite_name
protected

Definition at line 33 of file fe_rational_map.C.


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