Skip to content

Commit

Permalink
Add tests (libMesh#3385)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Sep 17, 2022
1 parent 2b95a30 commit 1cd708f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ unit_tests_sources = \
mesh/mesh_function_dfem.C \
mesh/mesh_generation_test.C \
mesh/mesh_input.C \
mesh/mesh_smoother.C \
mesh/mesh_stitch.C \
mesh/mesh_triangulation.C \
mesh/mixed_dim_mesh_test.C \
Expand Down Expand Up @@ -144,6 +145,12 @@ data = meshes/1_quad.bxt.gz \
meshes/good_32bit_elem_integers.e \
meshes/mesh_assign_test_mesh.xda \
meshes/shark_tooth_tri6.xda.gz \
meshes/smooth2d_in.e \
meshes/smooth2d_move.e \
meshes/smooth2d_nomove.e \
meshes/smooth3d_in.e \
meshes/smooth3d_move.e \
meshes/smooth3d_nomove.e \
meshes/tetgen_one_tet10.ele \
meshes/tetgen_one_tet10.node

Expand Down
70 changes: 70 additions & 0 deletions tests/mesh/mesh_smoother.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <libmesh/replicated_mesh.h>
#include <libmesh/distributed_mesh.h>
#include <libmesh/mesh_generation.h>
#include <libmesh/libmesh_config.h>
#include <libmesh/mesh_modification.h>
#include <libmesh/mesh_smoother_laplace.h>
#include <libmesh/mesh_communication.h>
#include <libmesh/exodusII_io.h>

#include "test_comm.h"
#include "libmesh_cppunit.h"

using namespace libMesh;

class SmoothMeshTest : public CppUnit::TestCase
{
public:
LIBMESH_CPPUNIT_TEST_SUITE(SmoothMeshTest);

CPPUNIT_TEST(laplace_smooth_2d_fixed_boundary_nodes);
CPPUNIT_TEST(laplace_smooth_2d_movable_boundary_nodes);
CPPUNIT_TEST(laplace_smooth_3d_fixed_boundary_nodes);
CPPUNIT_TEST(laplace_smooth_3d_movable_boundary_nodes);

CPPUNIT_TEST_SUITE_END();

private:
void test(const std::string in_file, const std::string gold_file, bool move_nodes)
{
// load input mesh
ReplicatedMesh in_mesh(*TestCommWorld);
ExodusII_IO exii(in_mesh);
if (in_mesh.processor_id() == 0)
exii.read(in_file);
MeshCommunication().broadcast(in_mesh);
in_mesh.prepare_for_use();

// load gold file
ReplicatedMesh gold_mesh(*TestCommWorld);
ExodusII_IO exii(gold_mesh);
if (gold_mesh.processor_id() == 0)
exii.read(gold_file);
MeshCommunication().broadcast(gold_mesh);
gold_mesh.prepare_for_use();

// run mesh smoother for 100 iterations
LaplaceMeshSmoother lms(static_cast<UnstructuredMesh &>(in_mesh), move_nodes);
lms.smooth(100);

// compare node positions
for (const auto & node : in_mesh.node_ref_range())
{
Point a = node;
Point b = gold_mesh.node_ref(node->id());
CPPUNIT_ASSERT((a-b).norm() < 1e-6);
}
}

public:
void setUp() {}

void tearDown() {}

void laplace_smooth_2d_fixed_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth2d_in.e", "smooth2d_nomove.e", false); }
void laplace_smooth_2d_movable_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth2d_in.e", "smooth2d_move.e", true); }
void laplace_smooth_3d_fixed_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth3d_in.e", "smooth3d_nomove.e", false); }
void laplace_smooth_3d_movable_boundary_nodes() { LOG_UNIT_TEST; test("meshes/smooth3d_in.e", "smooth3d_move.e", true); }
};

CPPUNIT_TEST_SUITE_REGISTRATION(CopyNodesAndElementsTest);
Binary file added tests/meshes/smooth2d_in.e
Binary file not shown.
Binary file added tests/meshes/smooth2d_move.e
Binary file not shown.
Binary file added tests/meshes/smooth2d_nomove.e
Binary file not shown.
Binary file added tests/meshes/smooth3d_in.e
Binary file not shown.
Binary file added tests/meshes/smooth3d_move.e
Binary file not shown.
Binary file added tests/meshes/smooth3d_nomove.e
Binary file not shown.

0 comments on commit 1cd708f

Please sign in to comment.