libMesh
Loading...
Searching...
No Matches
Public Member Functions | List of all members
MeshAssignTest Class Reference
Inheritance diagram for MeshAssignTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (MeshAssignTest)
 This test verifies the operations of the move assignment operator for MeshBase and derived classes.
 
 CPPUNIT_TEST (testMeshMoveAssignFromMemory)
 
 CPPUNIT_TEST (testReplicatedMeshMoveAssignFromMemory)
 
 CPPUNIT_TEST (testDistributedMeshMoveAssignFromMemory)
 
 CPPUNIT_TEST (testMeshMoveAssignFromFile)
 
 CPPUNIT_TEST (testReplicatedMeshMoveAssignFromFile)
 
 CPPUNIT_TEST (testDistributedMeshMoveAssignFromFile)
 
 CPPUNIT_TEST (testReplicatedMeshConstructFromReplicated)
 
 CPPUNIT_TEST (testReplicatedMeshConstructFromDistributed)
 
 CPPUNIT_TEST (testDistributedMeshConstructFromReplicated)
 
 CPPUNIT_TEST (testDistributedMeshConstructFromDistributed)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testMeshMoveAssign (const std::string &mesh_type, const std::string &mesh_creation_type)
 
template<class SrcClass , class DestClass >
void testCopyConstruct ()
 
void testMeshMoveAssignFromMemory ()
 
void testReplicatedMeshMoveAssignFromMemory ()
 
void testDistributedMeshMoveAssignFromMemory ()
 
void testMeshMoveAssignFromFile ()
 
void testReplicatedMeshMoveAssignFromFile ()
 
void testDistributedMeshMoveAssignFromFile ()
 
void testReplicatedMeshConstructFromReplicated ()
 
void testReplicatedMeshConstructFromDistributed ()
 
void testDistributedMeshConstructFromReplicated ()
 
void testDistributedMeshConstructFromDistributed ()
 

Detailed Description

Definition at line 22 of file mesh_assign.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/10]

MeshAssignTest::CPPUNIT_TEST ( testDistributedMeshConstructFromDistributed  )

◆ CPPUNIT_TEST() [2/10]

MeshAssignTest::CPPUNIT_TEST ( testDistributedMeshConstructFromReplicated  )

◆ CPPUNIT_TEST() [3/10]

MeshAssignTest::CPPUNIT_TEST ( testDistributedMeshMoveAssignFromFile  )

◆ CPPUNIT_TEST() [4/10]

MeshAssignTest::CPPUNIT_TEST ( testDistributedMeshMoveAssignFromMemory  )

◆ CPPUNIT_TEST() [5/10]

MeshAssignTest::CPPUNIT_TEST ( testMeshMoveAssignFromFile  )

◆ CPPUNIT_TEST() [6/10]

MeshAssignTest::CPPUNIT_TEST ( testMeshMoveAssignFromMemory  )

◆ CPPUNIT_TEST() [7/10]

MeshAssignTest::CPPUNIT_TEST ( testReplicatedMeshConstructFromDistributed  )

◆ CPPUNIT_TEST() [8/10]

MeshAssignTest::CPPUNIT_TEST ( testReplicatedMeshConstructFromReplicated  )

◆ CPPUNIT_TEST() [9/10]

MeshAssignTest::CPPUNIT_TEST ( testReplicatedMeshMoveAssignFromFile  )

◆ CPPUNIT_TEST() [10/10]

MeshAssignTest::CPPUNIT_TEST ( testReplicatedMeshMoveAssignFromMemory  )

◆ CPPUNIT_TEST_SUITE_END()

MeshAssignTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

MeshAssignTest::LIBMESH_CPPUNIT_TEST_SUITE ( MeshAssignTest  )

This test verifies the operations of the move assignment operator for MeshBase and derived classes.

Future extensions can include copy assignment, move and copy constructors.

◆ setUp()

void MeshAssignTest::setUp ( )
inline

Definition at line 51 of file mesh_assign.C.

52 {
53 }

◆ tearDown()

void MeshAssignTest::tearDown ( )
inline

Definition at line 55 of file mesh_assign.C.

56 {
57 }

◆ testCopyConstruct()

template<class SrcClass , class DestClass >
void MeshAssignTest::testCopyConstruct ( )
inline

Definition at line 221 of file mesh_assign.C.

222 {
223 SrcClass src_mesh(*TestCommWorld);
224
226
227 DestClass dest_mesh(src_mesh);
228
229 // Check for consistency
230 CPPUNIT_ASSERT(TestCommWorld->verify(dest_mesh.n_elem()));
231 CPPUNIT_ASSERT(TestCommWorld->verify(dest_mesh.n_nodes()));
232 dof_id_type n_dest_elem = dest_mesh.n_local_elem();
233 TestCommWorld->sum(n_dest_elem);
234 dof_id_type n_dest_nodes = dest_mesh.n_local_nodes();
235 TestCommWorld->sum(n_dest_nodes);
236 CPPUNIT_ASSERT_EQUAL(n_dest_elem, dest_mesh.n_elem());
237 CPPUNIT_ASSERT_EQUAL(n_dest_nodes, dest_mesh.n_nodes());
238 CPPUNIT_ASSERT_EQUAL(src_mesh.n_elem(), dest_mesh.n_elem());
239 CPPUNIT_ASSERT_EQUAL(src_mesh.n_nodes(), dest_mesh.n_nodes());
240 }
Communicator * TestCommWorld
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.
uint8_t dof_id_type
Definition id_types.h:67

References libMesh::MeshTools::Generation::build_square(), and TestCommWorld.

◆ testDistributedMeshConstructFromDistributed()

void MeshAssignTest::testDistributedMeshConstructFromDistributed ( )
inline

Definition at line 269 of file mesh_assign.C.

270 { LOG_UNIT_TEST; testCopyConstruct<DistributedMesh, DistributedMesh>(); }

◆ testDistributedMeshConstructFromReplicated()

void MeshAssignTest::testDistributedMeshConstructFromReplicated ( )
inline

Definition at line 266 of file mesh_assign.C.

267 { LOG_UNIT_TEST; testCopyConstruct<ReplicatedMesh, DistributedMesh>(); }

◆ testDistributedMeshMoveAssignFromFile()

void MeshAssignTest::testDistributedMeshMoveAssignFromFile ( )
inline

Definition at line 257 of file mesh_assign.C.

258 { LOG_UNIT_TEST; testMeshMoveAssign("distributed", "from_file"); }
void testMeshMoveAssign(const std::string &mesh_type, const std::string &mesh_creation_type)
Definition mesh_assign.C:59

References testMeshMoveAssign().

◆ testDistributedMeshMoveAssignFromMemory()

void MeshAssignTest::testDistributedMeshMoveAssignFromMemory ( )
inline

Definition at line 248 of file mesh_assign.C.

249 { LOG_UNIT_TEST; testMeshMoveAssign("distributed", "from_memory"); }

References testMeshMoveAssign().

◆ testMeshMoveAssign()

void MeshAssignTest::testMeshMoveAssign ( const std::string &  mesh_type,
const std::string &  mesh_creation_type 
)
inline

Build a 2d 2x2 square mesh (mesh_one) covering [0.0, 1.0] x [0.0, 1.0] with linear Quad elements. A new mesh will later be moved to this same object using MeshBase::operator = (&&).

Create an ES based on the mesh, with a single variable. We will set non-homogenous bc u = 1.0 on the bottom and right sides of the mesh. After moving a new mesh into mesh_one, we will verify that u is projected properly onto the new mesh_one topology.

Build another 2d 2x2 square mesh (mesh_two) covering [0.0, 1.0] x [0.0, 1.0] with linear Quad elements. We will later refine this mesh and replace mesh_one with it.

Definition at line 59 of file mesh_assign.C.

61 {
62 // Create two mesh ptrs.
63 std::shared_ptr<UnstructuredMesh> mesh_one;
64 std::shared_ptr<UnstructuredMesh> mesh_two;
65
72 if (mesh_type.compare("Mesh") == 0)
73 {
74 mesh_one = std::make_shared<Mesh>(*TestCommWorld);
75 }
76 else if (mesh_type.compare("replicated") == 0)
77 {
78 mesh_one = std::make_shared<ReplicatedMesh>(*TestCommWorld);
79 }
80 else if (mesh_type.compare("distributed") == 0)
81 {
82 mesh_one = std::make_shared<DistributedMesh>(*TestCommWorld);
83 }
84 else
85 {
86 libmesh_error_msg("Error: specified mesh_type not understood");
87 }
88
90 2, 2,
91 0., 1.,
92 0., 1.,
93 QUAD9);
94
95 // build_square adds boundary_ids 0,1,2,3 for the bottom, right,
96 // top, and left sides, respectively.
97
103 EquationSystems es(*mesh_one);
104 System & system = es.add_system<System> ("SimpleSystem");
105 system.add_variable("u", FIRST);
106
107 // Now set the Dirichlet bcs: u = 1.0, when boundary id = 0 and 1.
108 // The function describing the boundary value
109 ConstFunction<Number> one(1.0);
110
111 // The boundary ids of the boundaries where the value is to be set.
112 const boundary_id_type all_bdry_ids[4] = {0, 1, 2, 3};
113 const std::set<boundary_id_type> bottom_right_bdry_ids(all_bdry_ids, all_bdry_ids + 1);
114
115 // The variables for which we are defining the bc.
116 std::vector<unsigned int> variables = {0};
117 variables.push_back(0);
118
119 DirichletBoundary dirichlet_bc(bottom_right_bdry_ids, variables, &one);
120
121 system.get_dof_map().add_dirichlet_boundary(dirichlet_bc);
122
123 es.init();
124
125 if (mesh_type.compare("Mesh") == 0)
126 {
127 mesh_two = std::make_shared<Mesh>(*TestCommWorld);
128 }
129 else if (mesh_type.compare("replicated") == 0)
130 {
131 mesh_two = std::make_shared<ReplicatedMesh>(*TestCommWorld);
132 }
133 else if (mesh_type.compare("distributed") == 0)
134 {
135 mesh_two = std::make_shared<DistributedMesh>(*TestCommWorld);
136 }
137 else
138 {
139 libmesh_error_msg("Error: specified mesh_type not understood");
140 }
141
142#ifdef LIBMESH_ENABLE_AMR // We refine or read refined meshes for this test
143 if(mesh_creation_type.compare("from_memory") == 0)
144 {
152 2, 2,
153 0., 1.,
154 0., 1.,
155 QUAD4);
156
157 // Uniformly refine mesh_two
158 std::unique_ptr<MeshRefinement> mesh_refinement(std::make_unique<MeshRefinement>(*mesh_two));
159
160 mesh_refinement->uniformly_refine(1);
161
162 std::unique_ptr<MeshBase> mesh_two_clone =
163 mesh_two->clone();
164
165 // Move mesh_two into mesh_one
166 system.get_mesh().clear();
167 system.get_mesh().assign(std::move(*mesh_two));
168 mesh_two->clear();
169
170 // Assert that the moved into mesh has the right number of elements.
171 CPPUNIT_ASSERT_EQUAL(system.get_mesh().n_elem(), static_cast<dof_id_type>(20));
172
173 CPPUNIT_ASSERT(system.get_mesh() == *mesh_two_clone);
174
175 // Reinit the dofs and other system related data structures
176 // based on its mesh
178
179 // Reinit
180 system.get_equation_systems().reinit();
181
182 // Write out the mesh xda, this currently fails with DistributedMesh,
183 // running on more than 8 processors, when the mesh to be moved in is
184 // read from a file.
185 system.get_mesh().write("mesh.out.memory.moved.xda");
186
187 system.get_mesh().clear();
188 }
189 else if (mesh_creation_type.compare("from_file") == 0)
190 {
191 mesh_two->read("meshes/mesh_assign_test_mesh.xda");
192
193 std::unique_ptr<MeshBase> mesh_two_clone =
194 mesh_two->clone();
195
196 system.get_mesh().clear();
197 system.get_mesh().assign(std::move(*mesh_two));
198
199 mesh_two->clear();
200
201 // Assert that the moved into mesh has the right number of elements.
202 CPPUNIT_ASSERT_EQUAL(system.get_mesh().n_elem(), static_cast<dof_id_type>(42));
203
204 CPPUNIT_ASSERT(system.get_mesh() == *mesh_two_clone);
205
207 system.get_equation_systems().reinit();
208
209 system.get_mesh().write("mesh.out.file.moved.xda");
210
211 system.get_mesh().clear();
212 }
213 else
214 {
215 libmesh_error_msg("Error: invalid mesh two case type.");
216 }
217#endif // LIBMESH_ENABLE_AMR
218 }
Function that returns a single value that never changes.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
This is the EquationSystems class.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
virtual void reinit_mesh()
Handle the association of a completely new mesh with the EquationSystem and all the Systems assigned ...
virtual dof_id_type n_elem() const =0
virtual void write(const std::string &name) const =0
virtual void clear()
Deletes all the element and node data that is currently stored.
Definition mesh_base.C:1036
virtual MeshBase & assign(MeshBase &&other_mesh)=0
Shim to allow operator = (&&) to behave like a virtual function without having to be one.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
Definition system.C:1344
const DofMap & get_dof_map() const
Definition system.h:2417
const EquationSystems & get_equation_systems() const
Definition system.h:767
const MeshBase & get_mesh() const
Definition system.h:2401
int8_t boundary_id_type
Definition id_types.h:51

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshBase::assign(), libMesh::MeshTools::Generation::build_square(), libMesh::MeshBase::clear(), libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::System::get_equation_systems(), libMesh::System::get_mesh(), libMesh::EquationSystems::init(), libMesh::MeshBase::n_elem(), libMesh::QUAD4, libMesh::QUAD9, libMesh::EquationSystems::reinit(), libMesh::EquationSystems::reinit_mesh(), TestCommWorld, and libMesh::MeshBase::write().

Referenced by testDistributedMeshMoveAssignFromFile(), testDistributedMeshMoveAssignFromMemory(), testMeshMoveAssignFromFile(), testMeshMoveAssignFromMemory(), testReplicatedMeshMoveAssignFromFile(), and testReplicatedMeshMoveAssignFromMemory().

◆ testMeshMoveAssignFromFile()

void MeshAssignTest::testMeshMoveAssignFromFile ( )
inline

Definition at line 251 of file mesh_assign.C.

252 { LOG_UNIT_TEST; testMeshMoveAssign("Mesh", "from_file"); }

References testMeshMoveAssign().

◆ testMeshMoveAssignFromMemory()

void MeshAssignTest::testMeshMoveAssignFromMemory ( )
inline

Definition at line 242 of file mesh_assign.C.

243 { LOG_UNIT_TEST; testMeshMoveAssign("Mesh", "from_memory"); }

References testMeshMoveAssign().

◆ testReplicatedMeshConstructFromDistributed()

void MeshAssignTest::testReplicatedMeshConstructFromDistributed ( )
inline

Definition at line 263 of file mesh_assign.C.

264 { LOG_UNIT_TEST; testCopyConstruct<DistributedMesh, ReplicatedMesh>(); }

◆ testReplicatedMeshConstructFromReplicated()

void MeshAssignTest::testReplicatedMeshConstructFromReplicated ( )
inline

Definition at line 260 of file mesh_assign.C.

261 { LOG_UNIT_TEST; testCopyConstruct<ReplicatedMesh, ReplicatedMesh>(); }

◆ testReplicatedMeshMoveAssignFromFile()

void MeshAssignTest::testReplicatedMeshMoveAssignFromFile ( )
inline

Definition at line 254 of file mesh_assign.C.

255 { LOG_UNIT_TEST; testMeshMoveAssign("replicated", "from_file"); }

References testMeshMoveAssign().

◆ testReplicatedMeshMoveAssignFromMemory()

void MeshAssignTest::testReplicatedMeshMoveAssignFromMemory ( )
inline

Definition at line 245 of file mesh_assign.C.

246 { LOG_UNIT_TEST; testMeshMoveAssign("replicated", "from_memory"); }

References testMeshMoveAssign().


The documentation for this class was generated from the following file: