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);
46 CPPUNIT_TEST( test_subdomain_id_sets );
47 #ifdef LIBMESH_HAVE_PETSC 48 CPPUNIT_TEST( vectorMeshFunctionLagrange );
49 CPPUNIT_TEST( vectorMeshFunctionNedelec );
50 CPPUNIT_TEST( vectorMeshFunctionRaviartThomas );
51 CPPUNIT_TEST( mixedScalarAndVectorVariables );
52 #endif // LIBMESH_HAVE_PETSC 55 #ifdef LIBMESH_ENABLE_AMR 56 CPPUNIT_TEST( test_p_level );
60 CPPUNIT_TEST_SUITE_END();
83 for (
auto & elem :
mesh.active_element_ptr_range())
85 Point c = elem->vertex_average();
86 elem->subdomain_id() =
105 const std::set<subdomain_id_type> sbdids1 {0,2,11,13,20,22,31,33};
106 const std::set<subdomain_id_type> sbdids2 {1,3,10,12,21,23,30,32};
107 mesh_function.
init();
109 mesh_function.set_subdomain_ids(&sbdids1);
112 const std::string dummy;
116 for (
auto & elem :
mesh.active_local_element_ptr_range())
118 const Point c = elem->vertex_average();
119 const Real expected_value =
121 const std::vector<Point> offsets
122 {{0,-1/8.}, {1/8.,0}, {0,1/8.}, {-1/8.,0}};
123 for (
Point offset : offsets)
125 const Point p = c + offset;
126 mesh_function(p, 0, vec_values, &sbdids1);
127 const Number retval1 = vec_values.
empty() ? -12345 : vec_values(0);
128 mesh_function(p, 0, vec_values, &sbdids2);
129 const Number retval2 = vec_values.
empty() ? -12345 : vec_values(0);
130 mesh_function(c, 0, vec_values,
nullptr);
131 const Number retval3 = vec_values.
empty() ? -12345 : vec_values(0);
133 LIBMESH_ASSERT_NUMBERS_EQUAL
136 if (sbdids1.count(elem->subdomain_id()))
138 CPPUNIT_ASSERT(!sbdids2.count(elem->subdomain_id()));
139 LIBMESH_ASSERT_NUMBERS_EQUAL
142 mesh_function(c, 0, vec_values, &sbdids2);
143 CPPUNIT_ASSERT(vec_values.
empty());
147 LIBMESH_ASSERT_NUMBERS_EQUAL
150 mesh_function(c, 0, vec_values, &sbdids1);
151 CPPUNIT_ASSERT(vec_values.
empty());
159 #ifdef LIBMESH_ENABLE_AMR 178 for (
auto & elem :
mesh.active_element_ptr_range())
179 elem->set_p_level(1);
189 std::unique_ptr<NumericVector<Number>> mesh_function_vector
195 sys.
solution->localize(*mesh_function_vector,
201 std::vector<unsigned int> variables {u_var};
205 *mesh_function_vector,
209 mesh_function->init();
210 mesh_function->set_point_locator_tolerance(0.0001);
216 for (
const auto & node :
mesh.local_node_ptr_range())
218 (*mesh_function)(*node, 0., vec_values);
219 Number mesh_function_value =
225 LIBMESH_ASSERT_NUMBERS_EQUAL
229 #endif // LIBMESH_ENABLE_AMR 231 #ifdef LIBMESH_HAVE_PETSC 235 const std::string & solutions_name)
252 std::unique_ptr<NumericVector<Number>> mesh_function_vector =
254 mesh_function_vector->init(sys.
n_dofs(),
false,
SERIAL);
255 sys.
solution->localize(*mesh_function_vector);
258 std::vector<unsigned int> variables;
260 std::sort(variables.begin(),variables.end());
265 mesh_function.
init();
268 const std::set<subdomain_id_type> * subdomain_ids =
nullptr;
272 (mesh_function)(p, 0.0, output, subdomain_ids);
283 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/lagrange_vec_solution_mesh.xda",
"solutions/lagrange_vec_solution.xda");
301 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/nedelec_one_solution_mesh.xda",
"solutions/nedelec_one_solution.xda");
319 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/raviart_thomas_solution_mesh.xda",
"solutions/raviart_thomas_solution.xda");
341 DenseVector<Number> output = read_variable_info_from_output_data(
"solutions/raviart_thomas_solution_mesh.xda",
"solutions/raviart_thomas_solution.xda");
346 Number monomial_expected = -0.44265566716952;
347 Number scalar_expected = -2.86546e-18;
361 #endif // LIBMESH_HAVE_PETSC
void vectorMeshFunctionNedelec()
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
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)
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
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...
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
dof_id_type n_dofs() const
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
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 vectorMeshFunctionLagrange()
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void test_subdomain_id_sets()
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.
CPPUNIT_TEST_SUITE_REGISTRATION(MeshFunctionTest)
const DofMap & get_dof_map() 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()