|
| 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); |
0 commit comments