libMesh
Loading...
Searching...
No Matches
distort.C
Go to the documentation of this file.
1#include <libmesh/libmesh.h>
2#include <libmesh/replicated_mesh.h>
3#include <libmesh/elem.h>
4#include <libmesh/mesh_generation.h>
5#include <libmesh/mesh_modification.h>
6#include <libmesh/mesh_tools.h>
7
8#include "test_comm.h"
9#include "libmesh_cppunit.h"
10
11// C++ includes
12#include <unordered_set>
13#include <unordered_map>
14
15
16using namespace libMesh;
17
18class DistortTest : public CppUnit::TestCase
19{
24public:
26
27 // 2D tests
28#if LIBMESH_DIM > 1
30#endif
31
32 // 3D tests
33#if LIBMESH_DIM > 2
35#endif
36
38
39protected:
40 // Helper function called by the test implementations, saves a few lines of code.
41 void test_helper_2D(ElemType elem_type)
42 {
44
46 /*nx=*/2, /*ny=*/2,
47 /*xmin=*/0., /*xmax=*/1.,
48 /*ymin=*/0., /*ymax=*/1.,
49 elem_type);
50
52 }
53
54 // Helper function called by the test implementations in 3D, saves a few lines of code.
55 void test_helper_3D(ElemType elem_type)
56 {
58
60 /*nx=*/2, /*ny=*/2, /*nz=*/2,
61 /*xmin=*/0., /*xmax=*/1.,
62 /*ymin=*/0., /*ymax=*/1.,
63 /*zmin=*/0., /*zmax=*/1.,
64 elem_type);
66 }
67
68 // Code to save node positions, perturb the mesh, and ensure the correct nodes moved.
70 {
71 // Record node positions ahead of time to make sure the correct
72 // ones are moved by distort.
73 std::unordered_map<dof_id_type, Point> pts_before;
74 for (const auto & node : mesh.node_ptr_range())
75 pts_before[node->id()] = *node;
76
77 std::unordered_set<dof_id_type> boundary_node_ids =
79
81 /*factor=*/0.1,
82 /*perturb_boundary=*/false);
83
84 // Make sure the boundary nodes are not perturbed, and the
85 // other nodes are.
86 for (const auto & node : mesh.node_ptr_range())
87 {
88 bool equal = node->absolute_fuzzy_equals(pts_before[node->id()]);
89 CPPUNIT_ASSERT(boundary_node_ids.count(node->id()) ? equal : !equal);
90 }
91 }
92
93public:
94 void setUp() {}
95 void tearDown() {}
96 void testDistortQuad() { LOG_UNIT_TEST; test_helper_2D(QUAD4); }
97 void testDistortHex() { LOG_UNIT_TEST; test_helper_3D(HEX8); }
98};
99
100
void test_helper_2D(ElemType elem_type)
Definition distort.C:41
void perturb_and_check(ReplicatedMesh &mesh)
Definition distort.C:69
LIBMESH_CPPUNIT_TEST_SUITE(DistortTest)
The goal of this test is to make sure that boundary nodes are not restricted during distortion.
void tearDown()
Definition distort.C:95
void testDistortHex()
Definition distort.C:97
void test_helper_3D(ElemType elem_type)
Definition distort.C:55
CPPUNIT_TEST_SUITE_END()
CPPUNIT_TEST(testDistortHex)
void setUp()
Definition distort.C:94
CPPUNIT_TEST(testDistortQuad)
void testDistortQuad()
Definition distort.C:96
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(DistortTest)
MeshBase & mesh
void build_square(UnstructuredMesh &mesh, const unsigned int nx, const unsigned int ny, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 2D meshes.
void build_cube(UnstructuredMesh &mesh, const unsigned int nx=0, const unsigned int ny=0, const unsigned int nz=0, const Real xmin=0., const Real xmax=1., const Real ymin=0., const Real ymax=1., const Real zmin=0., const Real zmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
Builds a (elements) cube.
void distort(MeshBase &mesh, const Real factor, const bool perturb_boundary=false)
Randomly perturb the nodal locations.
std::unordered_set< dof_id_type > find_boundary_nodes(const MeshBase &mesh)
Returns a std::set containing Node IDs for all of the boundary nodes.
Definition mesh_tools.C:524
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.