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;
52 CPPUNIT_TEST( test_point_locator_dfem );
54 CPPUNIT_TEST( test_mesh_function_dfem );
56 CPPUNIT_TEST( test_mesh_function_dfem_grad );
59 CPPUNIT_TEST_SUITE_END();
62 std::unique_ptr<ReplicatedMesh>
_mesh;
67 _mesh = std::make_unique<ReplicatedMesh>(*TestCommWorld);
85 _mesh->set_mesh_dimension(2);
87 _mesh->add_point(
Point(0.0,-1.0), 4 );
88 _mesh->add_point(
Point(1.0,-1.0), 5 );
89 _mesh->add_point(
Point(1.0, 0.0), 1 );
90 _mesh->add_point(
Point(1.0, 1.0), 2 );
91 _mesh->add_point(
Point(0.0, 1.0), 3 );
92 _mesh->add_point(
Point(0.0, 0.0), 0 );
96 elem_top->
set_node(0, _mesh->node_ptr(0));
97 elem_top->
set_node(1, _mesh->node_ptr(1));
98 elem_top->
set_node(2, _mesh->node_ptr(2));
99 elem_top->
set_node(3, _mesh->node_ptr(3));
102 elem_bottom->
set_node(0, _mesh->node_ptr(4));
103 elem_bottom->
set_node(1, _mesh->node_ptr(5));
104 elem_bottom->
set_node(2, _mesh->node_ptr(1));
105 elem_bottom->
set_node(3, _mesh->node_ptr(0));
108 _mesh->allow_renumbering(
true);
109 _mesh->prepare_for_use();
112 _point_locator = _mesh->sub_point_locator();
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();
192 std::map<const Elem *, Number> top_val = mesh_function.discontinuous_value(top);
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);
202 std::map<const Elem *, Number> bottom_val = mesh_function.discontinuous_value(bottom);
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);
212 std::map<const Elem *, Number> face_val = mesh_function.discontinuous_value(face);
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();
262 std::map<const Elem *, Gradient> top_val = mesh_function.discontinuous_gradient(top);
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);
272 std::map<const Elem *, Gradient> bottom_val = mesh_function.discontinuous_gradient(bottom);
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);
282 std::map<const Elem *, Gradient> face_val = mesh_function.discontinuous_gradient(face);
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);
Number position_function2(const Point &p, const Parameters &, const std::string &, const std::string &)
This is the EquationSystems class.
virtual Node *& set_node(const unsigned int i)
This class provides the ability to map between arbitrary, user-defined strings and several data types...
std::unique_ptr< PointLocatorBase > _point_locator
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...
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_dofs() const
void test_mesh_function_dfem_grad()
void project_solution(FunctionBase< Number > *f, FunctionBase< Gradient > *g=nullptr) const
Projects arbitrary functions onto the current solution.
Manages consistently variables, degrees of freedom, and coefficient vectors.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
virtual void init() override
Override the FunctionBase::init() member function.
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.
Number position_function(const Point &p, const Parameters &, const std::string &, const std::string &)
void test_mesh_function_dfem()
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.
CPPUNIT_TEST_SUITE_REGISTRATION(MeshfunctionDFEM)
void test_point_locator_dfem()
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.
const DofMap & get_dof_map() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
std::unique_ptr< ReplicatedMesh > _mesh