1#include <libmesh/equation_systems.h>
2#include <libmesh/replicated_mesh.h>
3#include <libmesh/mesh_generation.h>
4#include <libmesh/edge_edge2.h>
5#include <libmesh/face_quad4.h>
6#include <libmesh/face_tri3.h>
7#include <libmesh/cell_hex8.h>
8#include <libmesh/dof_map.h>
9#include <libmesh/linear_implicit_system.h>
10#include <libmesh/mesh_refinement.h>
11#include <libmesh/mesh_function.h>
12#include <libmesh/numeric_vector.h>
37 return 2.0 * p(1) + 1.0;
62 std::unique_ptr<ReplicatedMesh>
_mesh;
85 _mesh->set_mesh_dimension(2);
108 _mesh->allow_renumbering(
true);
109 _mesh->prepare_for_use();
131 Point interior(0.5, -0.5, 0.0);
134 Point face(0.5, 0.0, 0.0);
137 std::set<const Elem *> int_cand;
138 (*_point_locator)(interior, int_cand,
nullptr);
139 CPPUNIT_ASSERT (int_cand.size() == 1);
140 for (std::set<const Elem *>::iterator it = int_cand.begin(); it != int_cand.end(); ++it)
141 CPPUNIT_ASSERT ((*it)->id() == 1);
144 std::set<const Elem *> face_cand;
145 (*_point_locator)(face, face_cand,
nullptr);
146 CPPUNIT_ASSERT (face_cand.size() == 2);
147 int array[2] = {0, 0};
148 for (std::set<const Elem *>::iterator it = face_cand.begin(); it != face_cand.end(); ++it)
151 CPPUNIT_ASSERT (array[(*it)->id()] == 0);
152 array[(*it)->id()] = 1;
154 CPPUNIT_ASSERT (array[0] == 1);
155 CPPUNIT_ASSERT (array[1] == 1);
164 Point top(0.5, 0.5, 0.0);
167 Point bottom(0.5, -0.5, 0.0);
170 Point face(0.5, 0.0, 0.0);
180 std::vector<unsigned int> variables;
182 std::unique_ptr<NumericVector<Number>> mesh_function_vector =
184 mesh_function_vector->init(sys.
n_dofs(),
false,
SERIAL);
185 sys.
solution->localize(*mesh_function_vector);
189 mesh_function.
init();
195 CPPUNIT_ASSERT (top_val.size() == 1);
198 for (std::map<const Elem *, Number>::const_iterator it = top_val.begin(); it != top_val.end(); ++it)
199 CPPUNIT_ASSERT (it->first->id() == 0 && std::abs(it->second) < 1.0e-10);
205 CPPUNIT_ASSERT (bottom_val.size() == 1);
208 for (std::map<const Elem *, Number>::const_iterator it = bottom_val.begin(); it != bottom_val.end(); ++it)
209 CPPUNIT_ASSERT (it->first->id() == 1 && std::abs(it->second - 1.0) < 1.0e-10);
215 CPPUNIT_ASSERT (face_val.size() == 2);
218 for (std::map<const Elem *, Number>::const_iterator it = face_val.begin(); it != face_val.end(); ++it)
219 if (it->first->id() == 0)
220 CPPUNIT_ASSERT (std::abs(it->second) < 1.0e-10);
221 else if (it->first->id() == 1)
222 CPPUNIT_ASSERT (std::abs(it->second - 1.0) < 1.0e-10);
224 CPPUNIT_ASSERT (
false);
234 Point top(0.5, 0.5, 0.0);
237 Point bottom(0.5, -0.5, 0.0);
240 Point face(0.5, 0.0, 0.0);
250 std::vector<unsigned int> variables;
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);
259 mesh_function.
init();
265 CPPUNIT_ASSERT (top_val.size() == 1);
268 for (std::map<const Elem *, Gradient>::const_iterator it = top_val.begin(); it != top_val.end(); ++it)
269 CPPUNIT_ASSERT (it->first->id() == 0 && std::abs(it->second(1) - 2.0) < 1.0e-10);
275 CPPUNIT_ASSERT (bottom_val.size() == 1);
278 for (std::map<const Elem *, Gradient>::const_iterator it = bottom_val.begin(); it != bottom_val.end(); ++it)
279 CPPUNIT_ASSERT (it->first->id() == 1 && std::abs(it->second(1) - 1.0) < 1.0e-10);
285 CPPUNIT_ASSERT (face_val.size() == 2);
288 for (std::map<const Elem *, Gradient>::const_iterator it = face_val.begin(); it != face_val.end(); ++it)
289 if (it->first->id() == 0)
290 CPPUNIT_ASSERT (std::abs(it->second(1) - 2.0) < 1.0e-10);
291 else if (it->first->id() == 1)
292 CPPUNIT_ASSERT (std::abs(it->second(1) - 1.0) < 1.0e-10);
294 CPPUNIT_ASSERT (
false);
void test_mesh_function_dfem_grad()
std::unique_ptr< ReplicatedMesh > _mesh
void test_mesh_function_dfem()
std::unique_ptr< PointLocatorBase > _point_locator
void test_point_locator_dfem()
CPPUNIT_TEST(test_mesh_function_dfem)
CPPUNIT_TEST(test_mesh_function_dfem_grad)
CPPUNIT_TEST(test_point_locator_dfem)
LIBMESH_CPPUNIT_TEST_SUITE(MeshfunctionDFEM)
The goal of this test is to verify proper operation of mesh function for discontinuous shape function...
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
This is the EquationSystems class.
Parameters parameters
Data structure holding arbitrary parameters.
virtual void init()
Initialize all the systems.
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.
This class provides function-like objects for data distributed over a mesh.
std::map< const Elem *, Number > discontinuous_value(const Point &p, const Real time=0.)
virtual void init() override
Override the FunctionBase::init() member function.
std::map< const Elem *, Gradient > discontinuous_gradient(const Point &p, const Real time=0.)
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...
const Parallel::Communicator & comm() const
This class provides the ability to map between arbitrary, user-defined strings and several data types...
A Point defines a location in LIBMESH_DIM dimensional Real space.
Manages consistently variables, degrees of freedom, and coefficient vectors.
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 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...
dof_id_type n_dofs() const
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.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
const DofMap & get_dof_map() const
Communicator * TestCommWorld
Number position_function2(const Point &p, const Parameters &, const std::string &, const std::string &)
Number position_function(const Point &p, const Parameters &, const std::string &, const std::string &)
CPPUNIT_TEST_SUITE_REGISTRATION(MeshfunctionDFEM)
The libMesh namespace provides an interface to certain functionality in the library.