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

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (CheckpointIOTest)
 This test verifies that we can write files with the CheckpointIO object.
 
 CPPUNIT_TEST (testAsciiDistRepSplitter)
 
 CPPUNIT_TEST (testBinaryDistRepSplitter)
 
 CPPUNIT_TEST (testAsciiRepDistSplitter)
 
 CPPUNIT_TEST (testBinaryRepDistSplitter)
 
 CPPUNIT_TEST (testAsciiRepRepSplitter)
 
 CPPUNIT_TEST (testBinaryRepRepSplitter)
 
 CPPUNIT_TEST (testAsciiDistDistSplitter)
 
 CPPUNIT_TEST (testBinaryDistDistSplitter)
 
 CPPUNIT_TEST (testAsciiC0Polygon)
 
 CPPUNIT_TEST (testBinaryC0Polygon)
 
 CPPUNIT_TEST (testAsciiC0Polyhedron)
 
 CPPUNIT_TEST (testBinaryC0Polyhedron)
 
 CPPUNIT_TEST (testMissingSplitError)
 
 CPPUNIT_TEST (testAsciiDisjointNeighborPairs)
 
 CPPUNIT_TEST (testBinaryDisjointNeighborPairs)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
template<typename MeshA , typename MeshB >
void testSplitter (bool binary, bool using_distmesh, bool skip_partition=false)
 
void testC0PolygonCheckpoint (bool binary)
 
void testC0PolyhedronCheckpoint (bool binary)
 
void testMissingSplitError ()
 
void testAsciiDistRepSplitter ()
 
void testBinaryDistRepSplitter ()
 
void testAsciiRepDistSplitter ()
 
void testBinaryRepDistSplitter ()
 
void testAsciiRepRepSplitter ()
 
void testBinaryRepRepSplitter ()
 
void testAsciiDistDistSplitter ()
 
void testBinaryDistDistSplitter ()
 
void testDisjointNeighborPairsCheckpoint (bool binary)
 
void testAsciiDisjointNeighborPairs ()
 
void testBinaryDisjointNeighborPairs ()
 
void testAsciiC0Polygon ()
 
void testBinaryC0Polygon ()
 
void testAsciiC0Polyhedron ()
 
void testBinaryC0Polyhedron ()
 
void testAsciiDistDistSplitterCache ()
 

Detailed Description

Definition at line 25 of file checkpoint.C.

Member Function Documentation

◆ CPPUNIT_TEST() [1/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiC0Polygon  )

◆ CPPUNIT_TEST() [2/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiC0Polyhedron  )

◆ CPPUNIT_TEST() [3/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDisjointNeighborPairs  )

◆ CPPUNIT_TEST() [4/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistDistSplitter  )

◆ CPPUNIT_TEST() [5/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistRepSplitter  )

◆ CPPUNIT_TEST() [6/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepDistSplitter  )

◆ CPPUNIT_TEST() [7/15]

CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepRepSplitter  )

◆ CPPUNIT_TEST() [8/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryC0Polygon  )

◆ CPPUNIT_TEST() [9/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryC0Polyhedron  )

◆ CPPUNIT_TEST() [10/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryDisjointNeighborPairs  )

◆ CPPUNIT_TEST() [11/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistDistSplitter  )

◆ CPPUNIT_TEST() [12/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistRepSplitter  )

◆ CPPUNIT_TEST() [13/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepDistSplitter  )

◆ CPPUNIT_TEST() [14/15]

CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepRepSplitter  )

◆ CPPUNIT_TEST() [15/15]

CheckpointIOTest::CPPUNIT_TEST ( testMissingSplitError  )

◆ CPPUNIT_TEST_SUITE_END()

CheckpointIOTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

CheckpointIOTest::LIBMESH_CPPUNIT_TEST_SUITE ( CheckpointIOTest  )

This test verifies that we can write files with the CheckpointIO object.

◆ setUp()

void CheckpointIOTest::setUp ( )
inline

Definition at line 59 of file checkpoint.C.

60 {
61 }

◆ tearDown()

void CheckpointIOTest::tearDown ( )
inline

Definition at line 63 of file checkpoint.C.

64 {
65 }

◆ testAsciiC0Polygon()

void CheckpointIOTest::testAsciiC0Polygon ( )
inline

Definition at line 536 of file checkpoint.C.

537 {
538 LOG_UNIT_TEST;
539
541 }
void testC0PolygonCheckpoint(bool binary)
Definition checkpoint.C:152

References testC0PolygonCheckpoint().

◆ testAsciiC0Polyhedron()

void CheckpointIOTest::testAsciiC0Polyhedron ( )
inline

Definition at line 551 of file checkpoint.C.

552 {
553 LOG_UNIT_TEST;
554
556 }
void testC0PolyhedronCheckpoint(bool binary)
Definition checkpoint.C:224

References testC0PolyhedronCheckpoint().

◆ testAsciiDisjointNeighborPairs()

void CheckpointIOTest::testAsciiDisjointNeighborPairs ( )
inline

Definition at line 521 of file checkpoint.C.

522 {
523 LOG_UNIT_TEST;
524
526 }
void testDisjointNeighborPairsCheckpoint(bool binary)
Definition checkpoint.C:442

References testDisjointNeighborPairsCheckpoint().

◆ testAsciiDistDistSplitter()

void CheckpointIOTest::testAsciiDistDistSplitter ( )
inline

Definition at line 425 of file checkpoint.C.

426 {
427 LOG_UNIT_TEST;
428
429 testSplitter<DistributedMesh, DistributedMesh>(false, true);
430 }

◆ testAsciiDistDistSplitterCache()

void CheckpointIOTest::testAsciiDistDistSplitterCache ( )
inline

Definition at line 566 of file checkpoint.C.

567 {
568 LOG_UNIT_TEST;
569
570 testSplitter<DistributedMesh, DistributedMesh>(false, true, true);
571 }

◆ testAsciiDistRepSplitter()

void CheckpointIOTest::testAsciiDistRepSplitter ( )
inline

Definition at line 383 of file checkpoint.C.

384 {
385 LOG_UNIT_TEST;
386
387 testSplitter<DistributedMesh, ReplicatedMesh>(false, true);
388 }

◆ testAsciiRepDistSplitter()

void CheckpointIOTest::testAsciiRepDistSplitter ( )
inline

Definition at line 397 of file checkpoint.C.

398 {
399 LOG_UNIT_TEST;
400
401 testSplitter<ReplicatedMesh, DistributedMesh>(false, true);
402 }

◆ testAsciiRepRepSplitter()

void CheckpointIOTest::testAsciiRepRepSplitter ( )
inline

Definition at line 411 of file checkpoint.C.

412 {
413 LOG_UNIT_TEST;
414
415 testSplitter<ReplicatedMesh, ReplicatedMesh>(false, false);
416 }

◆ testBinaryC0Polygon()

void CheckpointIOTest::testBinaryC0Polygon ( )
inline

Definition at line 543 of file checkpoint.C.

544 {
545 LOG_UNIT_TEST;
546
548 }

References testC0PolygonCheckpoint().

◆ testBinaryC0Polyhedron()

void CheckpointIOTest::testBinaryC0Polyhedron ( )
inline

Definition at line 558 of file checkpoint.C.

559 {
560 LOG_UNIT_TEST;
561
563 }

References testC0PolyhedronCheckpoint().

◆ testBinaryDisjointNeighborPairs()

void CheckpointIOTest::testBinaryDisjointNeighborPairs ( )
inline

Definition at line 528 of file checkpoint.C.

529 {
530 LOG_UNIT_TEST;
531
533 }

References testDisjointNeighborPairsCheckpoint().

◆ testBinaryDistDistSplitter()

void CheckpointIOTest::testBinaryDistDistSplitter ( )
inline

Definition at line 432 of file checkpoint.C.

433 {
434 LOG_UNIT_TEST;
435
436 testSplitter<DistributedMesh, DistributedMesh>(true, true);
437 }

◆ testBinaryDistRepSplitter()

void CheckpointIOTest::testBinaryDistRepSplitter ( )
inline

Definition at line 390 of file checkpoint.C.

391 {
392 LOG_UNIT_TEST;
393
394 testSplitter<DistributedMesh, ReplicatedMesh>(true, true);
395 }

◆ testBinaryRepDistSplitter()

void CheckpointIOTest::testBinaryRepDistSplitter ( )
inline

Definition at line 404 of file checkpoint.C.

405 {
406 LOG_UNIT_TEST;
407
408 testSplitter<ReplicatedMesh, DistributedMesh>(true, true);
409 }

◆ testBinaryRepRepSplitter()

void CheckpointIOTest::testBinaryRepRepSplitter ( )
inline

Definition at line 418 of file checkpoint.C.

419 {
420 LOG_UNIT_TEST;
421
422 testSplitter<ReplicatedMesh, ReplicatedMesh>(true, false);
423 }

◆ testC0PolygonCheckpoint()

void CheckpointIOTest::testC0PolygonCheckpoint ( bool  binary)
inline

Definition at line 152 of file checkpoint.C.

153 {
154#ifdef LIBMESH_HAVE_XDR
155 // Parallel element packing does not yet support runtime topology,
156 // so exercise serial CheckpointIO independently on rank 0.
157 if (TestCommWorld->rank() != 0)
158 return;
159
160 Parallel::Communicator comm_self;
161 const std::string filename =
162 std::string("checkpoint_c0polygon.cp") + (binary ? "r" : "a");
163 const std::vector<Point> points =
164 {{0., 0.}, {1., 0.}, {1.5, 0.5}, {1., 1.}, {0., 1.}};
165
166 {
167 Mesh mesh(comm_self, 2);
168 mesh.allow_renumbering(false);
169
170 auto polygon =
171 std::make_unique<C0Polygon>(cast_int<unsigned int>(points.size()));
172 polygon->set_id() = 0;
173 for (auto n : index_range(points))
174 polygon->set_node(n, mesh.add_point(points[n], n));
175
176 mesh.add_elem(std::move(polygon));
178
179 CheckpointIO checkpoint(mesh, binary);
180 checkpoint.write(filename);
181 }
182
183 {
184 Mesh mesh(comm_self);
185 CheckpointIO checkpoint(mesh, binary);
186 checkpoint.read(filename);
187
188 CPPUNIT_ASSERT_EQUAL(dof_id_type(1), mesh.n_elem());
189 CPPUNIT_ASSERT_EQUAL(dof_id_type(5), mesh.n_nodes());
190 CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned int>(mesh.mesh_dimension()));
191
192 const Elem * elem = mesh.query_elem_ptr(0);
193 bool found_elem = elem;
194 mesh.comm().max(found_elem);
195 CPPUNIT_ASSERT(found_elem);
196
197 if (elem)
198 {
199 CPPUNIT_ASSERT_EQUAL(C0POLYGON, elem->type());
200 CPPUNIT_ASSERT_EQUAL(5u, elem->n_nodes());
201 CPPUNIT_ASSERT_EQUAL(5u, elem->n_vertices());
202 CPPUNIT_ASSERT_EQUAL(5u, elem->n_sides());
203 CPPUNIT_ASSERT_EQUAL(5u, elem->n_edges());
204
205 for (auto n : index_range(points))
206 {
207 CPPUNIT_ASSERT_EQUAL(cast_int<dof_id_type>(n), elem->node_id(n));
208 CPPUNIT_ASSERT_EQUAL(points[n], elem->point(n));
209
210 const auto side_nodes = elem->nodes_on_side(n);
211 CPPUNIT_ASSERT_EQUAL(std::size_t(2), side_nodes.size());
212 CPPUNIT_ASSERT_EQUAL(cast_int<unsigned int>(n), side_nodes[0]);
213 CPPUNIT_ASSERT_EQUAL
214 (cast_int<unsigned int>((n + 1) % points.size()), side_nodes[1]);
215 }
216 }
217 }
218
219 CheckpointIO::cleanup(filename, 1);
220#endif // LIBMESH_HAVE_XDR
221 }
void max(const T &r, T &o, Request &req) const
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
static void cleanup(const std::string &input_name, processor_id_type n_procs)
Used to remove a checkpoint directory and its corresponding files.
This is the base class from which all geometric element types are derived.
Definition elem.h:96
virtual unsigned int n_vertices() const =0
const Point & point(const unsigned int i) const
Definition elem.h:2583
virtual unsigned int n_nodes() const =0
virtual std::vector< unsigned int > nodes_on_side(const unsigned int) const =0
virtual ElemType type() const =0
virtual unsigned int n_edges() const =0
virtual unsigned int n_sides() const =0
dof_id_type node_id(const unsigned int i) const
Definition elem.h:2605
unsigned int mesh_dimension() const
Definition mesh_base.C:435
virtual dof_id_type n_elem() const =0
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
Definition mesh_base.h:1359
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
Definition mesh_base.C:824
virtual dof_id_type n_nodes() const =0
virtual const Elem * query_elem_ptr(const dof_id_type i) const =0
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
const Parallel::Communicator & comm() const
Communicator * TestCommWorld
MeshBase & mesh
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
uint8_t dof_id_type
Definition id_types.h:67

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::MeshBase::allow_renumbering(), libMesh::C0POLYGON, libMesh::CheckpointIO::cleanup(), libMesh::ParallelObject::comm(), libMesh::index_range(), libMesh::Parallel::Communicator::max(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::Elem::n_edges(), libMesh::MeshBase::n_elem(), libMesh::Elem::n_nodes(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_sides(), libMesh::Elem::n_vertices(), libMesh::Elem::node_id(), libMesh::Elem::nodes_on_side(), libMesh::Elem::point(), libMesh::MeshBase::prepare_for_use(), libMesh::MeshBase::query_elem_ptr(), libMesh::CheckpointIO::read(), TestCommWorld, libMesh::Elem::type(), and libMesh::CheckpointIO::write().

Referenced by testAsciiC0Polygon(), and testBinaryC0Polygon().

◆ testC0PolyhedronCheckpoint()

void CheckpointIOTest::testC0PolyhedronCheckpoint ( bool  binary)
inline

Definition at line 224 of file checkpoint.C.

225 {
226#ifdef LIBMESH_HAVE_XDR
227 // Parallel element packing does not yet support runtime topology,
228 // so exercise serial CheckpointIO independently on rank 0.
229 if (TestCommWorld->rank() != 0)
230 return;
231
232 Parallel::Communicator comm_self;
233 const std::string filename =
234 std::string("checkpoint_c0polyhedron.cp") + (binary ? "r" : "a");
235 const std::vector<Point> points =
236 {{0., -2., 0.}, {-1., -1., 0.}, {-1., 1., 0.},
237 {0., 2., 0.}, {1., 1., 0.}, {1., -1., 0.},
238 {0., -2., 1.}, {-1., -1., 1.}, {-1., 1., 1.},
239 {0., 2., 1.}, {1., 1., 1.}, {1., -1., 1.}};
240 const std::vector<std::vector<unsigned int>> nodes_on_sides =
241 {{0, 1, 2, 3, 4, 5},
242 {0, 1, 7, 6},
243 {1, 2, 8, 7},
244 {2, 3, 9, 8},
245 {3, 4, 10, 9},
246 {4, 5, 11, 10},
247 {5, 0, 6, 11},
248 {6, 7, 8, 9, 10, 11}};
249
250 {
251 Mesh mesh(comm_self, 3);
252 mesh.allow_renumbering(false);
253 for (auto n : index_range(points))
254 mesh.add_point(points[n], n);
255
256 std::vector<std::shared_ptr<Polygon>> sides(nodes_on_sides.size());
257 for (auto s : index_range(nodes_on_sides))
258 {
259 const auto & side_nodes = nodes_on_sides[s];
260 auto side =
261 std::make_shared<C0Polygon>
262 (cast_int<unsigned int>(side_nodes.size()));
263 for (auto n : index_range(side_nodes))
264 side->set_node(n, mesh.node_ptr(side_nodes[n]));
265 sides[s] = std::move(side);
266 }
267
268 std::unique_ptr<Node> mid_elem_node;
269 auto polyhedron =
270 std::make_unique<C0Polyhedron>(sides, mid_elem_node);
271 CPPUNIT_ASSERT(mid_elem_node);
272
273 // Explicit id so DistributedMesh matches ReplicatedMesh
274 mid_elem_node->set_id(points.size());
275
276 mesh.add_node(std::move(mid_elem_node));
277 polyhedron->set_id() = 0;
278 mesh.add_elem(std::move(polyhedron));
280
281 CheckpointIO checkpoint(mesh, binary);
282 checkpoint.write(filename);
283 }
284
285 {
286 Mesh mesh(comm_self);
287 CheckpointIO checkpoint(mesh, binary);
288 checkpoint.read(filename);
289
290 CPPUNIT_ASSERT_EQUAL(dof_id_type(1), mesh.n_elem());
291 CPPUNIT_ASSERT_EQUAL(dof_id_type(13), mesh.n_nodes());
292 CPPUNIT_ASSERT_EQUAL(3u, static_cast<unsigned int>(mesh.mesh_dimension()));
293
294 const Elem * elem = mesh.query_elem_ptr(0);
295 bool found_elem = elem;
296 mesh.comm().max(found_elem);
297 CPPUNIT_ASSERT(found_elem);
298
299 if (elem)
300 {
301 CPPUNIT_ASSERT_EQUAL(C0POLYHEDRON, elem->type());
302 CPPUNIT_ASSERT_EQUAL(12u, elem->n_vertices());
303 CPPUNIT_ASSERT_EQUAL(13u, elem->n_nodes());
304 CPPUNIT_ASSERT_EQUAL(8u, elem->n_sides());
305 CPPUNIT_ASSERT_EQUAL(18u, elem->n_edges());
306 CPPUNIT_ASSERT_EQUAL(dof_id_type(12),
307 elem->node_id(elem->n_vertices()));
308
309 for (auto s : index_range(nodes_on_sides))
310 {
311 const auto side_nodes = elem->nodes_on_side(s);
312 CPPUNIT_ASSERT_EQUAL(nodes_on_sides[s].size(), side_nodes.size());
313 for (auto n : index_range(side_nodes))
314 CPPUNIT_ASSERT_EQUAL
315 (cast_int<dof_id_type>(nodes_on_sides[s][n]),
316 elem->node_id(side_nodes[n]));
317 }
318 }
319 }
320
321 CheckpointIO::cleanup(filename, 1);
322#endif // LIBMESH_HAVE_XDR
323 }
dof_id_type & set_id()
Definition dof_object.h:841
virtual Node * add_node(Node *n)=0
Add Node n to the end of the vertex array.
Tnew cast_int(Told oldvar)

References libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_node(), libMesh::MeshBase::add_point(), libMesh::MeshBase::allow_renumbering(), libMesh::C0POLYHEDRON, libMesh::CheckpointIO::cleanup(), libMesh::ParallelObject::comm(), libMesh::index_range(), libMesh::Parallel::Communicator::max(), mesh, libMesh::MeshBase::mesh_dimension(), libMesh::Elem::n_edges(), libMesh::MeshBase::n_elem(), libMesh::Elem::n_nodes(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_sides(), libMesh::Elem::n_vertices(), libMesh::Elem::node_id(), libMesh::MeshBase::node_ptr(), libMesh::Elem::nodes_on_side(), libMesh::MeshBase::prepare_for_use(), libMesh::MeshBase::query_elem_ptr(), libMesh::CheckpointIO::read(), libMesh::DofObject::set_id(), TestCommWorld, libMesh::Elem::type(), and libMesh::CheckpointIO::write().

Referenced by testAsciiC0Polyhedron(), and testBinaryC0Polyhedron().

◆ testDisjointNeighborPairsCheckpoint()

void CheckpointIOTest::testDisjointNeighborPairsCheckpoint ( bool  binary)
inline

Definition at line 442 of file checkpoint.C.

443 {
444#ifdef LIBMESH_HAVE_XDR
445 const std::string filename =
446 std::string("checkpoint_disjoint_pairs.cp") + (binary ? "r" : "a");
447 const boundary_id_type left_id = 5, right_id = 6;
448 const RealVectorValue translation(0.25, 0.);
449 processor_id_type n_splits = 1;
450
451 {
452 // Two unit quads whose facing sides share coordinates but not
453 // nodes; only the disjoint pair makes them neighbors.
454 Mesh mesh(*TestCommWorld, 2);
455 mesh.allow_renumbering(false);
456
457 for (auto i : make_range(2))
458 {
459 const Real x0 = 1.25 * i;
460 const dof_id_type n0 = 4 * i;
461 mesh.add_point(Point(x0, 0.), n0);
462 mesh.add_point(Point(x0 + 1, 0.), n0 + 1);
463 mesh.add_point(Point(x0 + 1, 1.), n0 + 2);
464 mesh.add_point(Point(x0, 1.), n0 + 3);
465
467 for (auto n : make_range(4))
468 elem->set_node(n, mesh.node_ptr(n0 + n));
469 }
470
471 BoundaryInfo & boundary_info = mesh.get_boundary_info();
472 boundary_info.add_side(mesh.elem_ptr(0), 1, left_id);
473 boundary_info.add_side(mesh.elem_ptr(1), 3, right_id);
476
477 n_splits = mesh.is_serial() ? 1 : mesh.n_processors();
478 CheckpointIO checkpoint(mesh, binary);
479 checkpoint.write(filename);
480 }
481
482 {
483 Mesh mesh(*TestCommWorld);
484 mesh.allow_renumbering(false);
485
486 // A stale pair on the mesh being read into must not survive
487 const boundary_id_type stale_id = 7;
489
490 CheckpointIO checkpoint(mesh, binary);
491 checkpoint.read(filename);
493
495 CPPUNIT_ASSERT(db);
496 CPPUNIT_ASSERT_EQUAL(std::size_t(2), db->size());
497 CPPUNIT_ASSERT_EQUAL(right_id, libmesh_map_find(*db, left_id)->pairedboundary);
498 CPPUNIT_ASSERT_EQUAL(left_id, libmesh_map_find(*db, right_id)->pairedboundary);
499 LIBMESH_ASSERT_FP_EQUAL
500 (0., (libmesh_map_find(*db, left_id)->get_corresponding_pos(Point(0)) -
501 translation).norm(), TOLERANCE*TOLERANCE);
502
503 if (const Elem * elem = mesh.query_elem_ptr(0))
504 {
505 CPPUNIT_ASSERT(elem->neighbor_ptr(1));
506 CPPUNIT_ASSERT_EQUAL(dof_id_type(1), elem->neighbor_ptr(1)->id());
507 }
508 if (const Elem * elem = mesh.query_elem_ptr(1))
509 {
510 CPPUNIT_ASSERT(elem->neighbor_ptr(3));
511 CPPUNIT_ASSERT_EQUAL(dof_id_type(0), elem->neighbor_ptr(3)->id());
512 }
513 }
514
515 TestCommWorld->barrier();
516 if (TestCommWorld->rank() == 0)
517 CheckpointIO::cleanup(filename, n_splits);
518#endif // LIBMESH_HAVE_XDR
519 }
The BoundaryInfo class contains information relevant to boundary conditions including storing faces,...
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
Add side side of element number elem with boundary id id to the boundary information data structure.
dof_id_type id() const
Definition dof_object.h:833
static std::unique_ptr< Elem > build_with_id(const ElemType type, dof_id_type id)
Calls the build() method above with a nullptr parent, and additionally sets the newly-created Elem's ...
Definition elem.C:496
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736
virtual bool is_serial() const
Definition mesh_base.h:357
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
Definition mesh_base.h:170
PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs()
Definition mesh_base.C:2311
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
virtual const Elem * elem_ptr(const dof_id_type i) const =0
void add_disjoint_neighbor_boundary_pairs(const boundary_id_type b1, const boundary_id_type b2, const RealVectorValue &translation)
Register a pair of boundaries as disjoint neighbor boundary pairs.
Definition mesh_base.C:2287
processor_id_type n_processors() const
We're using a class instead of a typedef to allow forward declarations and future flexibility.
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition point.h:41
static const boundary_id_type left_id
static const boundary_id_type right_id
LIBMESH_DEVICE_INLINE auto norm(const T &a)
int8_t boundary_id_type
Definition id_types.h:51
VectorValue< Real > RealVectorValue
Useful typedefs to allow transparent switching between Real and Complex data types.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::MeshBase::add_disjoint_neighbor_boundary_pairs(), libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::BoundaryInfo::add_side(), libMesh::MeshBase::allow_renumbering(), libMesh::Elem::build_with_id(), libMesh::CheckpointIO::cleanup(), libMesh::MeshBase::elem_ptr(), libMesh::MeshBase::get_boundary_info(), libMesh::MeshBase::get_disjoint_neighbor_boundary_pairs(), libMesh::MeshBase::is_serial(), left_id, libMesh::make_range(), mesh, libMesh::ParallelObject::n_processors(), libMesh::MeshBase::node_ptr(), libMesh::MeshBase::prepare_for_use(), libMesh::QUAD4, libMesh::MeshBase::query_elem_ptr(), libMesh::CheckpointIO::read(), libMesh::Real, right_id, libMesh::Elem::set_node(), TestCommWorld, libMesh::TOLERANCE, and libMesh::CheckpointIO::write().

Referenced by testAsciiDisjointNeighborPairs(), and testBinaryDisjointNeighborPairs().

◆ testMissingSplitError()

void CheckpointIOTest::testMissingSplitError ( )
inline

Definition at line 328 of file checkpoint.C.

329 {
330 LOG_UNIT_TEST;
331
332#ifdef LIBMESH_HAVE_XDR
333#ifdef LIBMESH_ENABLE_EXCEPTIONS
334 // The error message we're checking only depends on the checkpoint
335 // directory's contents, so there's no need to exercise this on more
336 // than one rank.
337 if (TestCommWorld->rank() != 0)
338 return;
339
340 Parallel::Communicator comm_self;
341 const std::string filename = "checkpoint_missing_split.cpa";
342 const processor_id_type n_procs = 2;
343
344 {
345 ReplicatedMesh mesh(comm_self);
346 MeshTools::Generation::build_square(mesh, 2, 2, 0., 1., 0., 1., QUAD4);
347 mesh.partition(n_procs);
348
349 CheckpointIO cpr(mesh);
350 cpr.current_processor_ids().clear();
351 for (processor_id_type pid = 0; pid < n_procs; pid++)
352 cpr.current_processor_ids().push_back(pid);
353 cpr.current_n_processors() = n_procs;
354 cpr.parallel() = true;
355 cpr.write(filename);
356 }
357
358 {
359 // Ask for a split count for which neither that split nor the
360 // serial fallback exists; only the split for n_procs does.
361 ReplicatedMesh mesh(comm_self);
362 CheckpointIO cpr(mesh);
363 cpr.current_n_processors() = n_procs + 1;
364
365 bool threw_desired_exception = false;
366 try {
367 cpr.read(filename);
368 }
369 catch (libMesh::LogicError & e) {
370 std::regex msg_regex("Splits that do exist in '" + filename + "': " +
371 std::to_string(n_procs) + "\\.");
372 CPPUNIT_ASSERT(std::regex_search(e.what(), msg_regex));
373 threw_desired_exception = true;
374 }
375 CPPUNIT_ASSERT(threw_desired_exception);
376 }
377
378 CheckpointIO::cleanup(filename, n_procs);
379#endif
380#endif
381 }
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition mesh_base.C:1784
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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.

References libMesh::MeshTools::Generation::build_square(), libMesh::CheckpointIO::cleanup(), libMesh::CheckpointIO::current_n_processors(), libMesh::CheckpointIO::current_processor_ids(), mesh, libMesh::CheckpointIO::parallel(), libMesh::MeshBase::partition(), libMesh::QUAD4, libMesh::CheckpointIO::read(), TestCommWorld, and libMesh::CheckpointIO::write().

◆ testSplitter()

template<typename MeshA , typename MeshB >
void CheckpointIOTest::testSplitter ( bool  binary,
bool  using_distmesh,
bool  skip_partition = false 
)
inline

Definition at line 69 of file checkpoint.C.

70 {
71 // The CheckpointIO-based splitter requires XDR.
72#ifdef LIBMESH_HAVE_XDR
73
74 // In this test, we partition the mesh into n_procs parts. Don't
75 // try to partition a DistributedMesh into more parts than we have
76 // processors, though.
77 const unsigned int n_procs = using_distmesh ?
78 std::min(static_cast<processor_id_type>(2), TestCommWorld->size()) :
79 2;
80
81 // The number of elements in the original mesh. For verification
82 // later.
83 dof_id_type original_n_elem = 0;
84
85 const std::string filename =
86 std::string("checkpoint_splitter.cp") + (binary ? "r" : "a");
87
88 {
89 MeshA mesh(*TestCommWorld);
90
92 4, 4,
93 0., 1.,
94 0., 1.,
95 QUAD4);
96
97 // Store the number of elements that were in the original mesh.
98 original_n_elem = mesh.n_elem();
99
100 // Partition the mesh into n_procs pieces
101 mesh.partition(n_procs);
102
103 // Write out checkpoint files for each piece. Since on a
104 // ReplicatedMesh we might have more pieces than we do
105 // processors, some processors may have to write out more than
106 // one piece.
107 CheckpointIO cpr(mesh);
108 cpr.current_processor_ids().clear();
109 for (processor_id_type pid = mesh.processor_id(); pid < n_procs; pid += mesh.n_processors())
110 cpr.current_processor_ids().push_back(pid);
111 cpr.current_n_processors() = n_procs;
112 cpr.binary() = binary;
113 cpr.parallel() = true;
114 cpr.write(filename);
115 }
116
117 TestCommWorld->barrier();
118
119 // Test that we can read in the files we wrote and sum up to the
120 // same total number of elements.
121 {
122 MeshB mesh(*TestCommWorld);
123 if (skip_partition)
125
126 CheckpointIO cpr(mesh);
127 cpr.current_n_processors() = n_procs;
128 cpr.binary() = binary;
129 cpr.read(filename);
130
131 // If we decided to skip partitioning, then we shouldn't be
132 // waiting for a partition() call to get our n_partitions()
133 // cache in order
134 if (skip_partition)
135 CPPUNIT_ASSERT_EQUAL(mesh.n_partitions(), n_procs);
136
137 std::size_t read_in_elements = 0;
138
139 for (unsigned pid=mesh.processor_id(); pid<n_procs; pid += mesh.n_processors())
140 {
141 read_in_elements += std::distance(mesh.pid_elements_begin(pid),
142 mesh.pid_elements_end(pid));
143 }
144 mesh.comm().sum(read_in_elements);
145
146 // Verify that we read in exactly as many elements as we started with.
147 CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(read_in_elements), original_n_elem);
148 }
149#endif // LIBMESH_HAVE_XDR
150 }
unsigned int n_partitions() const
Definition mesh_base.h:1530
void skip_partitioning(bool skip)
If true is passed in then nothing on this mesh will be (re)partitioned.
Definition mesh_base.h:1433
processor_id_type processor_id() const

References libMesh::CheckpointIO::binary(), libMesh::MeshTools::Generation::build_square(), libMesh::ParallelObject::comm(), libMesh::CheckpointIO::current_n_processors(), libMesh::CheckpointIO::current_processor_ids(), mesh, libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_partitions(), libMesh::ParallelObject::n_processors(), libMesh::CheckpointIO::parallel(), libMesh::MeshBase::partition(), libMesh::ParallelObject::processor_id(), libMesh::QUAD4, libMesh::CheckpointIO::read(), libMesh::MeshBase::skip_partitioning(), libMesh::Parallel::Communicator::sum(), TestCommWorld, and libMesh::CheckpointIO::write().


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