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();
136 Point interior(0.5, -0.5, 0.0);
139 Point face(0.5, 0.0, 0.0);
142 std::set<const Elem *> int_cand;
143 (*_point_locator)(interior, int_cand,
nullptr);
144 CPPUNIT_ASSERT (int_cand.size() == 1);
145 for (std::set<const Elem *>::iterator it = int_cand.begin(); it != int_cand.end(); ++it)
146 CPPUNIT_ASSERT ((*it)->id() == 1);
149 std::set<const Elem *> face_cand;
150 (*_point_locator)(face, face_cand,
nullptr);
151 CPPUNIT_ASSERT (face_cand.size() == 2);
152 int array[2] = {0, 0};
153 for (std::set<const Elem *>::iterator it = face_cand.begin(); it != face_cand.end(); ++it)
156 CPPUNIT_ASSERT (array[(*it)->id()] == 0);
157 array[(*it)->id()] = 1;
159 CPPUNIT_ASSERT (array[0] == 1);
160 CPPUNIT_ASSERT (array[1] == 1);
167 Point top(0.5, 0.5, 0.0);
170 Point bottom(0.5, -0.5, 0.0);
173 Point face(0.5, 0.0, 0.0);
183 std::vector<unsigned int> variables;
185 std::unique_ptr<NumericVector<Number>> mesh_function_vector =
187 mesh_function_vector->init(sys.
n_dofs(),
false,
SERIAL);
188 sys.
solution->localize(*mesh_function_vector);
192 mesh_function.
init();
195 std::map<const Elem *, Number> top_val = mesh_function.discontinuous_value(top);
198 CPPUNIT_ASSERT (top_val.size() == 1);
201 for (std::map<const Elem *, Number>::const_iterator it = top_val.begin(); it != top_val.end(); ++it)
202 CPPUNIT_ASSERT (it->first->id() == 0 &&
std::abs(it->second) < 1.0e-10);
205 std::map<const Elem *, Number> bottom_val = mesh_function.discontinuous_value(bottom);
208 CPPUNIT_ASSERT (bottom_val.size() == 1);
211 for (std::map<const Elem *, Number>::const_iterator it = bottom_val.begin(); it != bottom_val.end(); ++it)
212 CPPUNIT_ASSERT (it->first->id() == 1 &&
std::abs(it->second - 1.0) < 1.0e-10);
215 std::map<const Elem *, Number> face_val = mesh_function.discontinuous_value(face);
218 CPPUNIT_ASSERT (face_val.size() == 2);
221 for (std::map<const Elem *, Number>::const_iterator it = face_val.begin(); it != face_val.end(); ++it)
222 if (it->first->id() == 0)
223 CPPUNIT_ASSERT (
std::abs(it->second) < 1.0e-10);
224 else if (it->first->id() == 1)
225 CPPUNIT_ASSERT (
std::abs(it->second - 1.0) < 1.0e-10);
227 CPPUNIT_ASSERT (
false);
235 Point top(0.5, 0.5, 0.0);
238 Point bottom(0.5, -0.5, 0.0);
241 Point face(0.5, 0.0, 0.0);
251 std::vector<unsigned int> variables;
253 std::unique_ptr<NumericVector<Number>> mesh_function_vector =
255 mesh_function_vector->init(sys.
n_dofs(),
false,
SERIAL);
256 sys.
solution->localize(*mesh_function_vector);
260 mesh_function.
init();
263 std::map<const Elem *, Gradient> top_val = mesh_function.discontinuous_gradient(top);
266 CPPUNIT_ASSERT (top_val.size() == 1);
269 for (std::map<const Elem *, Gradient>::const_iterator it = top_val.begin(); it != top_val.end(); ++it)
270 CPPUNIT_ASSERT (it->first->id() == 0 &&
std::abs(it->second(1) - 2.0) < 1.0e-10);
273 std::map<const Elem *, Gradient> bottom_val = mesh_function.discontinuous_gradient(bottom);
276 CPPUNIT_ASSERT (bottom_val.size() == 1);
279 for (std::map<const Elem *, Gradient>::const_iterator it = bottom_val.begin(); it != bottom_val.end(); ++it)
280 CPPUNIT_ASSERT (it->first->id() == 1 &&
std::abs(it->second(1) - 1.0) < 1.0e-10);
283 std::map<const Elem *, Gradient> face_val = mesh_function.discontinuous_gradient(face);
286 CPPUNIT_ASSERT (face_val.size() == 2);
289 for (std::map<const Elem *, Gradient>::const_iterator it = face_val.begin(); it != face_val.end(); ++it)
290 if (it->first->id() == 0)
291 CPPUNIT_ASSERT (
std::abs(it->second(1) - 2.0) < 1.0e-10);
292 else if (it->first->id() == 1)
293 CPPUNIT_ASSERT (
std::abs(it->second(1) - 1.0) < 1.0e-10);
295 CPPUNIT_ASSERT (
false);