1 #include <libmesh/equation_systems.h> 2 #include <libmesh/replicated_mesh.h> 3 #include <libmesh/mesh_generation.h> 4 #include <libmesh/dof_map.h> 5 #include <libmesh/system.h> 6 #include <libmesh/mesh_function.h> 7 #include <libmesh/numeric_vector.h> 8 #include <libmesh/elem.h> 12 #include "libmesh/enum_xdr_mode.h" 33 return 8*p(0) + 80*p(1) + 800*p(2);
42 return 8*p(0) + 80*p(1);
51 return 7.5*p(0)*p(0) + 75*p(1)*p(1) + 0.75*p(1)*p(0);
65 CPPUNIT_TEST( test_subdomain_id_sets );
66 CPPUNIT_TEST( test_bad_gradient_var_with_out_of_mesh_value );
67 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 68 CPPUNIT_TEST( test_bad_hessian_var_with_out_of_mesh_value );
70 #ifdef LIBMESH_HAVE_PETSC 71 CPPUNIT_TEST( vectorMeshFunctionLagrange );
72 CPPUNIT_TEST( vectorMeshFunctionNedelec );
73 CPPUNIT_TEST( vectorMeshFunctionRaviartThomas );
74 CPPUNIT_TEST( mixedScalarAndVectorVariables );
75 #endif // LIBMESH_HAVE_PETSC 78 #ifdef LIBMESH_ENABLE_AMR 79 CPPUNIT_TEST( test_p_level );
83 CPPUNIT_TEST_SUITE_END();
106 for (
auto & elem :
mesh.active_element_ptr_range())
108 Point c = elem->vertex_average();
109 elem->subdomain_id() =
128 const std::set<subdomain_id_type> sbdids1 {0,2,11,13,20,22,31,33};
129 const std::set<subdomain_id_type> sbdids2 {1,3,10,12,21,23,30,32};
130 mesh_function.
init();
132 mesh_function.set_subdomain_ids(&sbdids1);
135 const std::string dummy;
139 for (
auto & elem :
mesh.active_local_element_ptr_range())
141 const Point c = elem->vertex_average();
142 const Real expected_value =
144 const std::vector<Point> offsets
145 {{0,-1/8.}, {1/8.,0}, {0,1/8.}, {-1/8.,0}};
146 for (
Point offset : offsets)
148 const Point p = c + offset;
149 mesh_function(p, 0, vec_values, &sbdids1);
150 const Number retval1 = vec_values.
empty() ? -12345 : vec_values(0);
151 mesh_function(p, 0, vec_values, &sbdids2);
152 const Number retval2 = vec_values.
empty() ? -12345 : vec_values(0);
153 mesh_function(c, 0, vec_values,
nullptr);
154 const Number retval3 = vec_values.
empty() ? -12345 : vec_values(0);
156 LIBMESH_ASSERT_NUMBERS_EQUAL
159 if (sbdids1.count(elem->subdomain_id()))
161 CPPUNIT_ASSERT(!sbdids2.count(elem->subdomain_id()));
162 LIBMESH_ASSERT_NUMBERS_EQUAL
165 mesh_function(c, 0, vec_values, &sbdids2);
166 CPPUNIT_ASSERT(vec_values.
empty());
170 LIBMESH_ASSERT_NUMBERS_EQUAL
173 mesh_function(c, 0, vec_values, &sbdids1);
174 CPPUNIT_ASSERT(vec_values.
empty());
205 mesh_function.
init();
208 out_of_mesh_value(0) = -99.0;
209 out_of_mesh_value(1) = 5.25;
210 out_of_mesh_value(1) = 42;
211 mesh_function.enable_out_of_mesh_mode(out_of_mesh_value);
214 const Point good_p(0.375, 0.625, 0.0);
219 bool someone_found_elem = elem;
221 CPPUNIT_ASSERT(someone_found_elem);
223 std::vector<Gradient> gradients;
224 mesh_function.gradient(good_p, 0.0, gradients);
226 CPPUNIT_ASSERT_EQUAL(std::size_t(3), gradients.size());
238 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
241 LIBMESH_ASSERT_NUMBERS_EQUAL(out_of_mesh_value(2),
244 for (
unsigned int d = 1; d < LIBMESH_DIM; ++d)
245 LIBMESH_ASSERT_NUMBERS_EQUAL(0, gradients[2](d),
248 const Point bad_p(1.375, 0.625, 0.0);
249 mesh_function.gradient(bad_p, 0.0, gradients);
251 for (
unsigned int vn = 0; vn != 3; ++vn)
253 LIBMESH_ASSERT_NUMBERS_EQUAL(out_of_mesh_value(vn),
256 for (
unsigned int d = 1; d < LIBMESH_DIM; ++d)
257 LIBMESH_ASSERT_NUMBERS_EQUAL(0, gradients[vn](d),
262 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES 291 mesh_function.
init();
294 out_of_mesh_value(0) = -99.0;
295 out_of_mesh_value(1) = 5.25;
296 out_of_mesh_value(2) = 42;
297 mesh_function.enable_out_of_mesh_mode(out_of_mesh_value);
299 std::vector<Tensor> hessians;
300 const Point p(0.4, 0.6, 0.0);
305 bool someone_found_elem = elem;
307 CPPUNIT_ASSERT(someone_found_elem);
309 mesh_function.hessian(p, 0.0, hessians);
311 CPPUNIT_ASSERT_EQUAL(std::size_t(3), hessians.size());
317 LIBMESH_ASSERT_NUMBERS_EQUAL(15.0, hessians[0](0,0), tol);
318 LIBMESH_ASSERT_NUMBERS_EQUAL(0.75, hessians[0](0,1), tol);
319 LIBMESH_ASSERT_NUMBERS_EQUAL(0.75, hessians[0](1,0), tol);
320 LIBMESH_ASSERT_NUMBERS_EQUAL(150.0, hessians[0](1,1), tol);
323 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
324 for (
unsigned int d2 = 0; d2 < LIBMESH_DIM; ++d2)
326 LIBMESH_ASSERT_NUMBERS_EQUAL(0, hessians[0](d,d2),
330 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
331 for (
unsigned int d2 = 0; d2 < LIBMESH_DIM; ++d2)
332 LIBMESH_ASSERT_NUMBERS_EQUAL(0, hessians[1](d,d2), tol);
334 LIBMESH_ASSERT_NUMBERS_EQUAL(out_of_mesh_value(2),
337 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
338 for (
unsigned int d2 = 0; d2 < LIBMESH_DIM; ++d2)
340 LIBMESH_ASSERT_NUMBERS_EQUAL(0, hessians[2](d,d2),
343 const Point bad_p(1.375, 0.625, 0.0);
344 mesh_function.hessian(bad_p, 0.0, hessians);
346 for (
unsigned int vn = 0; vn != 2; ++vn)
348 LIBMESH_ASSERT_NUMBERS_EQUAL(out_of_mesh_value(vn),
349 hessians[vn](0,0), tol);
350 for (
unsigned int d = 0; d < LIBMESH_DIM; ++d)
351 for (
unsigned int d2 = 0; d2 < LIBMESH_DIM; ++d2)
353 LIBMESH_ASSERT_NUMBERS_EQUAL(0, hessians[vn](d,d2), tol);
356 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES 360 #ifdef LIBMESH_ENABLE_AMR 379 for (
auto & elem :
mesh.active_element_ptr_range())
380 elem->set_p_level(1);
390 std::unique_ptr<NumericVector<Number>> mesh_function_vector
396 sys.
solution->localize(*mesh_function_vector,
402 std::vector<unsigned int> variables {u_var};
406 *mesh_function_vector,
410 mesh_function->init();
411 mesh_function->set_point_locator_tolerance(0.0001);
417 for (
const auto & node :
mesh.local_node_ptr_range())
419 (*mesh_function)(*node, 0., vec_values);
420 Number mesh_function_value =
426 LIBMESH_ASSERT_NUMBERS_EQUAL
430 #endif // LIBMESH_ENABLE_AMR 432 #ifdef LIBMESH_HAVE_PETSC 436 const std::string & solutions_name)
453 std::unique_ptr<NumericVector<Number>> mesh_function_vector =
455 mesh_function_vector->init(sys.
n_dofs(),
false,
SERIAL);
456 sys.
solution->localize(*mesh_function_vector);
459 std::vector<unsigned int> variables;
461 std::sort(variables.begin(),variables.end());
466 mesh_function.
init();
469 const std::set<subdomain_id_type> * subdomain_ids =
nullptr;
473 (mesh_function)(p, 0.0, output, subdomain_ids);
484 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/lagrange_vec_solution_mesh.xda",
"solutions/lagrange_vec_solution.xda");
502 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/nedelec_one_solution_mesh.xda",
"solutions/nedelec_one_solution.xda");
520 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/raviart_thomas_solution_mesh.xda",
"solutions/raviart_thomas_solution.xda");
542 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/raviart_thomas_solution_mesh.xda",
"solutions/raviart_thomas_solution.xda");
547 Number monomial_expected = -0.44265566716952;
548 Number scalar_expected = -2.86546e-18;
562 #endif // LIBMESH_HAVE_PETSC
void vectorMeshFunctionNedelec()
Number biquadratic_function(const Point &p, const Parameters &, const std::string &, const std::string &)
This is the EquationSystems class.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
DenseVector< Number > read_variable_info_from_output_data(const std::string &mesh_name, const std::string &solutions_name)
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
std::unique_ptr< PointLocatorBase > sub_point_locator() const
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
This class provides the ability to map between arbitrary, user-defined strings and several data types...
Number trilinear_function(const Point &p, const Parameters &, const std::string &, const std::string &)
libMesh::Parallel::Communicator * TestCommWorld
static constexpr Real TOLERANCE
TestClass subdomain_id_type
Based on the 4-byte comment warning above, this probably doesn't work with exodusII at all...
Number projection_function(const Point &p, const Parameters &, const std::string &, const std::string &)
const EquationSystems & get_equation_systems() const
This is the base class from which all geometric element types are derived.
const Parallel::Communicator & comm() const
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
Fills all_variable_numbers with all the variable numbers for the variables that have been added to th...
Number bilinear_function(const Point &p, const Parameters &, const std::string &, const std::string &)
void test_bad_hessian_var_with_out_of_mesh_value()
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_local_dofs() const
const T_sys & get_system(std::string_view name) const
void test_bad_gradient_var_with_out_of_mesh_value()
dof_id_type n_dofs() const
void vectorMeshFunctionRaviartThomas()
Manages consistently variables, degrees of freedom, and coefficient vectors.
virtual bool empty() const override final
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
virtual void init() override
Override the FunctionBase::init() member function.
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
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.
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr, std::optional< ConstElemRange > active_local_range=std::nullopt, std::optional< std::vector< unsigned int >> variable_numbers=std::nullopt) const
Projects arbitrary functions onto the current solution.
void vectorMeshFunctionLagrange()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void test_subdomain_id_sets()
void max(const T &r, T &o, Request &req) const
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
Parameters parameters
Data structure holding arbitrary parameters.
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
virtual void init()
Initialize all the systems.
This class provides function-like objects for data distributed over a mesh.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
processor_id_type processor_id() const
CPPUNIT_TEST_SUITE_REGISTRATION(MeshFunctionTest)
const DofMap & get_dof_map() const
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
const std::vector< dof_id_type > & get_send_list() const
void update()
Updates local values for all the systems.
void mixedScalarAndVectorVariables()