libMesh
fe_rational_map.C
Go to the documentation of this file.
1 #include "test_comm.h"
2 
3 #include <libmesh/dof_map.h>
4 #include <libmesh/elem.h>
5 #include <libmesh/equation_systems.h>
6 #include <libmesh/fe_base.h>
7 #include <libmesh/fe_interface.h>
8 #include <libmesh/mesh.h>
9 #include <libmesh/mesh_generation.h>
10 #include <libmesh/numeric_vector.h>
11 #include <libmesh/system.h>
12 
13 #include <vector>
14 
15 #include "libmesh_cppunit.h"
16 
17 
18 using namespace libMesh;
19 
20 
21 template <ElemType elem_type>
22 class RationalMapTest : public CppUnit::TestCase {
23 
24 private:
25  unsigned int _dim, _nx, _ny, _nz;
27  std::vector<dof_id_type> _dof_indices;
32 
33 public:
34  void setUp()
35  {
36  _mesh = new Mesh(*TestCommWorld);
37  const std::unique_ptr<Elem> test_elem = Elem::build(elem_type);
38  _dim = test_elem->dim();
39  const unsigned int ny = _dim > 1;
40  const unsigned int nz = _dim > 2;
41 
42  // Make sure we can handle non-zero weight indices
43  _mesh->add_node_integer("buffer integer1");
44  _mesh->add_node_integer("buffer integer2");
45  unsigned char weight_index = cast_int<unsigned char>
46  (_mesh->add_node_datum<Real>("rational_weight"));
47  libmesh_assert_not_equal_to(weight_index, 0);
48 
50  _mesh->set_default_mapping_data(weight_index);
51 
53  1, ny, nz,
54  0., 1., 0., ny, 0., nz,
55  elem_type);
56 
57  for (auto elem : _mesh->element_ptr_range())
58  {
59  CPPUNIT_ASSERT_EQUAL(elem->mapping_type(), RATIONAL_BERNSTEIN_MAP);
60  CPPUNIT_ASSERT_EQUAL(elem->mapping_data(), weight_index);
61  }
62 
63  // Transform the cube / square into a rotated quarter-annulus,
64  // with central axis at (-.5, 0) and radii ranging from .5 to 1.5
65 
66  for (auto node : _mesh->node_ptr_range())
67  {
68  Real & x = (*node)(0);
69  Real & y = (*node)(1);
70  node->set_extra_datum<Real>(weight_index, 1);
71  if (y > .6)
72  {
73  y = .5 + x;
74  x = -.5;
75  }
76  else if (y > .4)
77  {
78  y = .5 + x;
79  x = y - .5;
80  node->set_extra_datum<Real>(weight_index, sqrt(Real(2))/2);
81  }
82  }
83 
84  _es = new EquationSystems(*_mesh);
85  _sys = &(_es->add_system<System> ("SimpleSystem"));
86  _sys->add_variable("u", FIRST);
87  _es->init();
88 
89  _fe = FEBase::build(_dim, _sys->variable_type("u")).release();
90  _fe->get_xyz();
91  _fe->get_phi();
92  _fe->get_dphi();
93  _fe->get_dphidx();
94 #if LIBMESH_DIM > 1
95  _fe->get_dphidy();
96 #endif
97 #if LIBMESH_DIM > 2
98  _fe->get_dphidz();
99 #endif
100 
101  auto rng = _mesh->active_local_element_ptr_range();
102  _elem = rng.begin() == rng.end() ? nullptr : *(rng.begin());
103 
104  _nx = 10;
105  _ny = (_dim > 1) ? _nx : 0;
106  _nz = (_dim > 2) ? _nx : 0;
107  }
108 
109  void tearDown()
110  {
111  delete _fe;
112  delete _es;
113  delete _mesh;
114  }
115 
117  {
118  // Handle the "more processors than elements" case
119  if (!_elem)
120  return;
121 
122  // These tests require exceptions to be enabled because a
123  // TypeTensor::solve() call down in Elem::contains_point()
124  // actually throws a non-fatal exception for a certain Point which
125  // is not in the Elem. When exceptions are not enabled, this test
126  // simply aborts.
127 #ifdef LIBMESH_ENABLE_EXCEPTIONS
128  for (unsigned int j=0; j != _ny+1; ++j)
129  for (unsigned int k=0; k != _nz+1; ++k)
130  {
131  for (int i=-1; i != int(_nx+2); ++i)
132  {
133  Real r = (Real(i)/_nx) + 0.5,
134  theta = (Real(j)/_nx)*pi/2,
135  z = (Real(k)/_nx);
136  Real x = -.5 + r * std::cos(theta),
137  y = r * std::sin(theta);
138  Point p(x,y,z);
139  // Test for false negatives
140  if (i >= 0 && i <= int(_nx))
141  CPPUNIT_ASSERT(_elem->contains_point(p));
142  // Also test for false positives
143  else
144  CPPUNIT_ASSERT(!_elem->contains_point(p));
145  }
146  }
147 #endif
148  }
149 };
150 
151 
152 #define INSTANTIATE_RATIONALMAP_TEST(elemtype) \
153  class RationalMapTest_##elemtype : public RationalMapTest<elemtype> { \
154  public: \
155  CPPUNIT_TEST_SUITE( RationalMapTest_##elemtype ); \
156  CPPUNIT_TEST( testContainsPoint ); \
157  CPPUNIT_TEST_SUITE_END(); \
158  }; \
159  \
160  CPPUNIT_TEST_SUITE_REGISTRATION( RationalMapTest_##elemtype );
161 
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
RationalMapTest::_mesh
Mesh * _mesh
Definition: fe_rational_map.C:29
libMesh::HEX20
Definition: enum_elem_type.h:48
libMesh::pi
const Real pi
.
Definition: libmesh.h:237
libMesh::Mesh
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition: mesh.h:50
libMesh::FEAbstract::get_xyz
const std::vector< Point > & get_xyz() const
Definition: fe_abstract.h:237
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::Elem::contains_point
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
Definition: elem.C:2094
RationalMapTest::testContainsPoint
void testContainsPoint()
Definition: fe_rational_map.C:116
RationalMapTest::_es
EquationSystems * _es
Definition: fe_rational_map.C:31
libMesh::FEGenericBase::get_dphidx
const std::vector< std::vector< OutputShape > > & get_dphidx() const
Definition: fe_base.h:238
INSTANTIATE_RATIONALMAP_TEST
INSTANTIATE_RATIONALMAP_TEST(EDGE3)
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::FEGenericBase
This class forms the foundation from which generic finite elements may be derived.
Definition: exact_error_estimator.h:39
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::FEGenericBase::get_dphi
const std::vector< std::vector< OutputGradient > > & get_dphi() const
Definition: fe_base.h:214
libMesh::DistributedMesh::node_ptr_range
virtual SimpleRange< node_iterator > node_ptr_range() override
Definition: distributed_mesh.h:501
libMesh::RATIONAL_BERNSTEIN_MAP
Definition: enum_elem_type.h:84
RationalMapTest::_sys
System * _sys
Definition: fe_rational_map.C:30
RationalMapTest::_fe
FEBase * _fe
Definition: fe_rational_map.C:28
libMesh::HEX27
Definition: enum_elem_type.h:49
RationalMapTest::_dof_indices
std::vector< dof_id_type > _dof_indices
Definition: fe_rational_map.C:27
RationalMapTest::setUp
void setUp()
Definition: fe_rational_map.C:34
libMesh::FEGenericBase::build
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
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
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
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
RationalMapTest::_nz
unsigned int _nz
Definition: fe_rational_map.C:25
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
libMesh::FEGenericBase::get_dphidy
const std::vector< std::vector< OutputShape > > & get_dphidy() const
Definition: fe_base.h:246
libMesh::DistributedMesh::element_ptr_range
virtual SimpleRange< element_iterator > element_ptr_range() override
Definition: distributed_mesh.h:308
libmesh_cppunit.h
RationalMapTest::_elem
Elem * _elem
Definition: fe_rational_map.C:26
libMesh::MeshBase::set_default_mapping_type
void set_default_mapping_type(const ElemMappingType type)
Set the default master space to physical space mapping basis functions to be used on newly added elem...
Definition: mesh_base.h:716
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
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
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
RationalMapTest
Definition: fe_rational_map.C:22
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
test_comm.h
libMesh::Elem::build
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:246
RationalMapTest::tearDown
void tearDown()
Definition: fe_rational_map.C:109
libMesh::FIRST
Definition: enum_order.h:42
int
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
libMesh::QUAD8
Definition: enum_elem_type.h:42