libMesh
Public Member Functions | List of all members
MeshFunctionTest Class Reference
Inheritance diagram for MeshFunctionTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (MeshFunctionTest)
 Tests for general MeshFunction capability. More...
 
 CPPUNIT_TEST (test_p_level)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void test_p_level ()
 

Detailed Description

Definition at line 27 of file mesh_function.C.

Member Function Documentation

◆ CPPUNIT_TEST()

MeshFunctionTest::CPPUNIT_TEST ( test_p_level  )

◆ CPPUNIT_TEST_SUITE()

MeshFunctionTest::CPPUNIT_TEST_SUITE ( MeshFunctionTest  )

Tests for general MeshFunction capability.

◆ CPPUNIT_TEST_SUITE_END()

MeshFunctionTest::CPPUNIT_TEST_SUITE_END ( )

◆ setUp()

void MeshFunctionTest::setUp ( )
inline

Definition at line 46 of file mesh_function.C.

46 {}

◆ tearDown()

void MeshFunctionTest::tearDown ( )
inline

Definition at line 48 of file mesh_function.C.

48 {}

◆ test_p_level()

void MeshFunctionTest::test_p_level ( )
inline

Definition at line 53 of file mesh_function.C.

54  {
56 
58  5, 5, 5,
59  0., 1.,
60  0., 1.,
61  0., 1.,
62  HEX20);
63 
64  // Bump the p-level for all elements. We will create a system with
65  // a FIRST, LAGRANGE variable and then use the additional p-level
66  // to solve with quadratic elements. Note: set_p_level(1) actually
67  // _increases_ the existing variable order by 1, it does not set
68  // it to 1.
69  for (auto & elem : mesh.active_element_ptr_range())
70  elem->set_p_level(1);
71 
73  System & sys = es.add_system<System> ("SimpleSystem");
74  unsigned int u_var = sys.add_variable("u", FIRST, LAGRANGE);
75 
76  es.init();
77  sys.project_solution(projection_function, nullptr, es.parameters);
78 
79 
80  std::unique_ptr<NumericVector<Number>> mesh_function_vector
82  mesh_function_vector->init(sys.n_dofs(), sys.n_local_dofs(),
83  sys.get_dof_map().get_send_list(), false,
84  GHOSTED);
85 
86  sys.solution->localize(*mesh_function_vector,
87  sys.get_dof_map().get_send_list());
88 
89  // So the MeshFunction knows which variables to compute values for.
90  std::vector<unsigned int> variables(1);
91  variables[0] = u_var;
92 
93  auto mesh_function =
94  libmesh_make_unique<MeshFunction>(sys.get_equation_systems(),
95  *mesh_function_vector,
96  sys.get_dof_map(),
97  variables);
98 
99  mesh_function->init();
100  mesh_function->set_point_locator_tolerance(0.0001);
101  DenseVector<Number> vec_values;
102  std::string dummy;
103 
104  // Make sure the MeshFunction's values interpolate the projected solution
105  // at the nodes
106  for (const auto & node : mesh.local_node_ptr_range())
107  {
108  (*mesh_function)(*node, /*time=*/ 0., vec_values);
109  Number mesh_function_value =
110  projection_function(*node,
111  es.parameters,
112  dummy,
113  dummy);
114 
115  LIBMESH_ASSERT_FP_EQUAL
116  (libmesh_real(vec_values(0)),
117  libmesh_real(mesh_function_value),
119  }
120  }

References libMesh::MeshBase::active_element_ptr_range(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::NumericVector< T >::build(), libMesh::MeshTools::Generation::build_cube(), libMesh::ParallelObject::comm(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::System::get_equation_systems(), libMesh::DofMap::get_send_list(), libMesh::GHOSTED, libMesh::HEX20, libMesh::EquationSystems::init(), libMesh::LAGRANGE, libMesh::libmesh_real(), libMesh::MeshBase::local_node_ptr_range(), mesh, libMesh::System::n_dofs(), libMesh::System::n_local_dofs(), libMesh::EquationSystems::parameters, libMesh::System::project_solution(), projection_function(), libMesh::System::solution, TestCommWorld, and libMesh::TOLERANCE.


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::HEX20
Definition: enum_elem_type.h:48
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::System::get_equation_systems
const EquationSystems & get_equation_systems() const
Definition: system.h:720
libMesh::libmesh_real
T libmesh_real(T a)
Definition: libmesh_common.h:166
libMesh::MeshBase::active_element_ptr_range
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
libMesh::NumericVector::init
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
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
libMesh::TOLERANCE
static const Real TOLERANCE
Definition: libmesh_common.h:128
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::GHOSTED
Definition: enum_parallel_type.h:37
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::ReplicatedMesh
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Definition: replicated_mesh.h:47
libMesh::NumericVector
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
Definition: vector_fe_ex5.C:43
libMesh::System::n_local_dofs
dof_id_type n_local_dofs() const
Definition: system.C:187
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::MeshBase::local_node_ptr_range
virtual SimpleRange< node_iterator > local_node_ptr_range()=0
TestCommWorld
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:111
projection_function
Number projection_function(const Point &p, const Parameters &, const std::string &, const std::string &)
Definition: mesh_function.C:16
libMesh::DofMap::get_send_list
const std::vector< dof_id_type > & get_send_list() const
Definition: dof_map.h:496
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::System::solution
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition: system.h:1539
libMesh::System::get_dof_map
const DofMap & get_dof_map() const
Definition: system.h:2099
libMesh::System::n_dofs
dof_id_type n_dofs() const
Definition: system.C:150
libMesh::LAGRANGE
Definition: enum_fe_family.h:36
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
libMesh::FIRST
Definition: enum_order.h:42
libMesh::DenseVector< Number >