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