Skip to content

Commit 3870415

Browse files
author
csdechant
committed
Adding 2D tests for Lagrange, Nedelec, and Raviart Thomas vector variable outputs for MeshFunction::operator() Closes libMesh#3714
1 parent 4b8ffda commit 3870415

9 files changed

+3113
-4
lines changed

tests/Makefile.am

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,13 @@ data = matrices/geom_1_extraction_op.m \
216216
meshes/non_manifold_junction2.exo \
217217
meshes/non_manifold_junction3.exo \
218218
meshes/Cluster_34.stl \
219-
meshes/engraving.stl
219+
meshes/engraving.stl \
220+
solutions/lagrange_vec_solution_mesh.xda \
221+
solutions/lagrange_vec_solution.xda \
222+
solutions/nedelec_one_solution_mesh.xda \
223+
solutions/nedelec_one_solution.xda \
224+
solutions/raviart_thomas_solution_mesh.xda \
225+
solutions/raviart_thomas_solution.xda
220226

221227

222228
unit_tests_data = $(data)
@@ -428,6 +434,7 @@ if LIBMESH_VPATH_BUILD
428434
BUILT_SOURCES = .linkstamp
429435

430436
.linkstamp:
437+
-rm -f solutions && $(LN_S) -f $(srcdir)/solutions .
431438
-rm -f meshes && $(LN_S) -f $(srcdir)/meshes .
432439
-rm -f matrices && $(LN_S) -f $(srcdir)/matrices .
433440
$(AM_V_GEN)touch .linkstamp

tests/Makefile.in

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,13 @@ data = matrices/geom_1_extraction_op.m \
23672367
meshes/non_manifold_junction2.exo \
23682368
meshes/non_manifold_junction3.exo \
23692369
meshes/Cluster_34.stl \
2370-
meshes/engraving.stl
2370+
meshes/engraving.stl \
2371+
solutions/lagrange_vec_solution_mesh.xda \
2372+
solutions/lagrange_vec_solution.xda \
2373+
solutions/nedelec_one_solution_mesh.xda \
2374+
solutions/nedelec_one_solution.xda \
2375+
solutions/raviart_thomas_solution_mesh.xda \
2376+
solutions/raviart_thomas_solution.xda
23712377

23722378
unit_tests_data = $(data)
23732379

@@ -14265,6 +14271,7 @@ $(top_builddir)/libmesh_oprof.la: FORCE
1426514271
(cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) libmesh_oprof.la)
1426614272

1426714273
14274+
@LIBMESH_VPATH_BUILD_TRUE@ -rm -f solutions && $(LN_S) -f $(srcdir)/solutions .
1426814275
@LIBMESH_VPATH_BUILD_TRUE@ -rm -f meshes && $(LN_S) -f $(srcdir)/meshes .
1426914276
@LIBMESH_VPATH_BUILD_TRUE@ -rm -f matrices && $(LN_S) -f $(srcdir)/matrices .
1427014277
@LIBMESH_VPATH_BUILD_TRUE@ $(AM_V_GEN)touch .linkstamp

tests/mesh/mesh_function.C

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "test_comm.h"
1111
#include "libmesh_cppunit.h"
12+
#include "libmesh/enum_xdr_mode.h"
1213

1314

1415
using namespace libMesh;
@@ -43,6 +44,9 @@ public:
4344

4445
#if LIBMESH_DIM > 1
4546
CPPUNIT_TEST( test_subdomain_id_sets );
47+
CPPUNIT_TEST( vectorMeshFuctionLagrange );
48+
CPPUNIT_TEST( vectorMeshFuctionNedelec );
49+
CPPUNIT_TEST( vectorMeshFuctionRaviartThomas );
4650
#endif
4751
#if LIBMESH_DIM > 2
4852
#ifdef LIBMESH_ENABLE_AMR
@@ -220,7 +224,141 @@ public:
220224
}
221225
}
222226
#endif // LIBMESH_ENABLE_AMR
223-
};
224227

228+
// Tests the projection of Lagrange Vectors using MeshFunction
229+
void vectorMeshFuctionLagrange()
230+
{
231+
LOG_UNIT_TEST;
232+
233+
// Reading mesh and solution infromation from XDA files
234+
ReplicatedMesh mesh(*TestCommWorld);
235+
mesh.read("solutions/lagrange_vec_solution_mesh.xda");
236+
EquationSystems es(mesh);
237+
es.read("solutions/lagrange_vec_solution.xda", READ,
238+
EquationSystems::READ_HEADER |
239+
EquationSystems::READ_DATA |
240+
EquationSystems::READ_ADDITIONAL_DATA);
241+
es.update();
242+
243+
// Pulling the correct system and variable infromation from
244+
// the XDA files (the default system name is "nl0")
245+
System & sys = es.get_system<System>("nl0");
246+
std::unique_ptr<NumericVector<Number>> mesh_function_vector =
247+
NumericVector<Number>::build(es.comm());
248+
mesh_function_vector->init(sys.n_dofs(), false, SERIAL);
249+
sys.solution->localize(*mesh_function_vector);
250+
251+
// Setting up libMesh::MeshFuction
252+
MeshFunction mesh_function(es, *mesh_function_vector,
253+
sys.get_dof_map(), 0);
254+
mesh_function.init();
255+
256+
// Defining input parameters for MeshFunction::operator()
257+
DenseVector<Gradient> output;
258+
const std::set<subdomain_id_type> * subdomain_ids = nullptr;
259+
const Point & p = Point(0.5, 0.5);
260+
261+
// Suppling the Lagrange Vec value at center of mesh to output
262+
(mesh_function)(p, 0.0, output, subdomain_ids);
263+
264+
// Expected value at center mesh
265+
Gradient output_expected = Gradient(0.100977281077292,0.201954562154583);
266+
267+
LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0),
268+
TOLERANCE * TOLERANCE);
269+
LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1),
270+
TOLERANCE * TOLERANCE);
271+
}
272+
273+
// Tests the projection of Nedelec Vectors using MeshFunction
274+
void vectorMeshFuctionNedelec()
275+
{
276+
LOG_UNIT_TEST;
277+
278+
// Reading mesh and solution infromation from XDA files
279+
ReplicatedMesh mesh(*TestCommWorld);
280+
mesh.read("solutions/nedelec_one_solution_mesh.xda");
281+
EquationSystems es(mesh);
282+
es.read("solutions/nedelec_one_solution.xda", READ,
283+
EquationSystems::READ_HEADER |
284+
EquationSystems::READ_DATA |
285+
EquationSystems::READ_ADDITIONAL_DATA);
286+
es.update();
287+
288+
// Pulling the correct system and variable infromation from
289+
// the XDA files (the default system name is "nl0")
290+
System & sys = es.get_system<System>("nl0");
291+
std::unique_ptr<NumericVector<Number>> mesh_function_vector =
292+
NumericVector<Number>::build(es.comm());
293+
mesh_function_vector->init(sys.n_dofs(), false, SERIAL);
294+
sys.solution->localize(*mesh_function_vector);
295+
296+
// Setting up libMesh::MeshFuction
297+
MeshFunction mesh_function(es, *mesh_function_vector,
298+
sys.get_dof_map(), 0);
299+
mesh_function.init();
300+
301+
// Defining input parameters for MeshFunction::operator()
302+
DenseVector<Gradient> output;
303+
const std::set<subdomain_id_type> * subdomain_ids = nullptr;
304+
const Point & p = Point(0.5, 0.5);
305+
306+
// Suppling the Nedelec One value at center of mesh to output
307+
(mesh_function)(p, 0.0, output, subdomain_ids);
308+
309+
// Expected value at center mesh
310+
Gradient output_expected = Gradient(0.0949202883998996,-0.0949202883918033);
311+
312+
LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0),
313+
TOLERANCE * TOLERANCE);
314+
LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1),
315+
TOLERANCE * TOLERANCE);
316+
}
317+
318+
// Tests the projection of Raviart Thomas Vectors using MeshFunction
319+
void vectorMeshFuctionRaviartThomas()
320+
{
321+
LOG_UNIT_TEST;
322+
323+
// Reading mesh and solution infromation from XDA files
324+
ReplicatedMesh mesh(*TestCommWorld);
325+
mesh.read("solutions/raviart_thomas_solution_mesh.xda");
326+
EquationSystems es(mesh);
327+
es.read("solutions/raviart_thomas_solution.xda", READ,
328+
EquationSystems::READ_HEADER |
329+
EquationSystems::READ_DATA |
330+
EquationSystems::READ_ADDITIONAL_DATA);
331+
es.update();
332+
333+
// Pulling the correct system and variable infromation from
334+
// the XDA files (the default system name is "nl0")
335+
System & sys = es.get_system<System>("nl0");
336+
std::unique_ptr<NumericVector<Number>> mesh_function_vector =
337+
NumericVector<Number>::build(es.comm());
338+
mesh_function_vector->init(sys.n_dofs(), false, SERIAL);
339+
sys.solution->localize(*mesh_function_vector);
340+
341+
// Setting up libMesh::MeshFuction
342+
MeshFunction mesh_function(es, *mesh_function_vector,
343+
sys.get_dof_map(), 0);
344+
mesh_function.init();
345+
346+
// Defining input parameters for MeshFunction::operator()
347+
DenseVector<Gradient> output;
348+
const std::set<subdomain_id_type> * subdomain_ids = nullptr;
349+
const Point & p = Point(0.5, 0.5);
350+
351+
// Suppling the Raviart Thomas value at center of mesh to output
352+
(mesh_function)(p, 0.0, output, subdomain_ids);
353+
354+
// Expected value at center mesh
355+
Gradient output_expected = Gradient(0.0772539939808116,-0.0772537479511396);
356+
357+
LIBMESH_ASSERT_FP_EQUAL(output(0)(0), output_expected(0),
358+
TOLERANCE * TOLERANCE);
359+
LIBMESH_ASSERT_FP_EQUAL(output(0)(1), output_expected(1),
360+
TOLERANCE * TOLERANCE);
361+
}
362+
};
225363

226-
CPPUNIT_TEST_SUITE_REGISTRATION( MeshFunctionTest );
364+
CPPUNIT_TEST_SUITE_REGISTRATION(MeshFunctionTest);

0 commit comments

Comments
 (0)