Skip to content

Commit 1cd708f

Browse files
committed
Add tests (libMesh#3385)
1 parent 2b95a30 commit 1cd708f

8 files changed

+77
-0
lines changed

tests/Makefile.am

+7
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ unit_tests_sources = \
6868
mesh/mesh_function_dfem.C \
6969
mesh/mesh_generation_test.C \
7070
mesh/mesh_input.C \
71+
mesh/mesh_smoother.C \
7172
mesh/mesh_stitch.C \
7273
mesh/mesh_triangulation.C \
7374
mesh/mixed_dim_mesh_test.C \
@@ -144,6 +145,12 @@ data = meshes/1_quad.bxt.gz \
144145
meshes/good_32bit_elem_integers.e \
145146
meshes/mesh_assign_test_mesh.xda \
146147
meshes/shark_tooth_tri6.xda.gz \
148+
meshes/smooth2d_in.e \
149+
meshes/smooth2d_move.e \
150+
meshes/smooth2d_nomove.e \
151+
meshes/smooth3d_in.e \
152+
meshes/smooth3d_move.e \
153+
meshes/smooth3d_nomove.e \
147154
meshes/tetgen_one_tet10.ele \
148155
meshes/tetgen_one_tet10.node
149156

tests/mesh/mesh_smoother.C

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <libmesh/replicated_mesh.h>
2+
#include <libmesh/distributed_mesh.h>
3+
#include <libmesh/mesh_generation.h>
4+
#include <libmesh/libmesh_config.h>
5+
#include <libmesh/mesh_modification.h>
6+
#include <libmesh/mesh_smoother_laplace.h>
7+
#include <libmesh/mesh_communication.h>
8+
#include <libmesh/exodusII_io.h>
9+
10+
#include "test_comm.h"
11+
#include "libmesh_cppunit.h"
12+
13+
using namespace libMesh;
14+
15+
class SmoothMeshTest : public CppUnit::TestCase
16+
{
17+
public:
18+
LIBMESH_CPPUNIT_TEST_SUITE(SmoothMeshTest);
19+
20+
CPPUNIT_TEST(laplace_smooth_2d_fixed_boundary_nodes);
21+
CPPUNIT_TEST(laplace_smooth_2d_movable_boundary_nodes);
22+
CPPUNIT_TEST(laplace_smooth_3d_fixed_boundary_nodes);
23+
CPPUNIT_TEST(laplace_smooth_3d_movable_boundary_nodes);
24+
25+
CPPUNIT_TEST_SUITE_END();
26+
27+
private:
28+
void test(const std::string in_file, const std::string gold_file, bool move_nodes)
29+
{
30+
// load input mesh
31+
ReplicatedMesh in_mesh(*TestCommWorld);
32+
ExodusII_IO exii(in_mesh);
33+
if (in_mesh.processor_id() == 0)
34+
exii.read(in_file);
35+
MeshCommunication().broadcast(in_mesh);
36+
in_mesh.prepare_for_use();
37+
38+
// load gold file
39+
ReplicatedMesh gold_mesh(*TestCommWorld);
40+
ExodusII_IO exii(gold_mesh);
41+
if (gold_mesh.processor_id() == 0)
42+
exii.read(gold_file);
43+
MeshCommunication().broadcast(gold_mesh);
44+
gold_mesh.prepare_for_use();
45+
46+
// run mesh smoother for 100 iterations
47+
LaplaceMeshSmoother lms(static_cast<UnstructuredMesh &>(in_mesh), move_nodes);
48+
lms.smooth(100);
49+
50+
// compare node positions
51+
for (const auto & node : in_mesh.node_ref_range())
52+
{
53+
Point a = node;
54+
Point b = gold_mesh.node_ref(node->id());
55+
CPPUNIT_ASSERT((a-b).norm() < 1e-6);
56+
}
57+
}
58+
59+
public:
60+
void setUp() {}
61+
62+
void tearDown() {}
63+
64+
void laplace_smooth_2d_fixed_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth2d_in.e", "smooth2d_nomove.e", false); }
65+
void laplace_smooth_2d_movable_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth2d_in.e", "smooth2d_move.e", true); }
66+
void laplace_smooth_3d_fixed_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth3d_in.e", "smooth3d_nomove.e", false); }
67+
void laplace_smooth_3d_movable_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth3d_in.e", "smooth3d_move.e", true); }
68+
};
69+
70+
CPPUNIT_TEST_SUITE_REGISTRATION(CopyNodesAndElementsTest);

tests/meshes/smooth2d_in.e

7.38 KB
Binary file not shown.

tests/meshes/smooth2d_move.e

7.38 KB
Binary file not shown.

tests/meshes/smooth2d_nomove.e

7.38 KB
Binary file not shown.

tests/meshes/smooth3d_in.e

23 KB
Binary file not shown.

tests/meshes/smooth3d_move.e

23 KB
Binary file not shown.

tests/meshes/smooth3d_nomove.e

23 KB
Binary file not shown.

0 commit comments

Comments
 (0)