1#include "libmesh/boundary_info.h"
2#include "libmesh/cell_c0polyhedron.h"
3#include "libmesh/checkpoint_io.h"
4#include "libmesh/distributed_mesh.h"
5#include "libmesh/face_c0polygon.h"
6#include "libmesh/int_range.h"
7#include "libmesh/mesh.h"
8#include "libmesh/mesh_generation.h"
9#include "libmesh/node.h"
10#include "libmesh/parallel.h"
11#include "libmesh/partitioner.h"
12#include "libmesh/periodic_boundaries.h"
13#include "libmesh/periodic_boundary_base.h"
14#include "libmesh/replicated_mesh.h"
15#include "libmesh/utility.h"
48#ifdef LIBMESH_ENABLE_PERIODIC
68 template <
typename MeshA,
typename MeshB>
69 void testSplitter(
bool binary,
bool using_distmesh,
bool skip_partition =
false)
72#ifdef LIBMESH_HAVE_XDR
77 const unsigned int n_procs = using_distmesh ?
85 const std::string filename =
86 std::string(
"checkpoint_splitter.cp") + (binary ?
"r" :
"a");
137 std::size_t read_in_elements = 0;
141 read_in_elements += std::distance(
mesh.pid_elements_begin(pid),
142 mesh.pid_elements_end(pid));
147 CPPUNIT_ASSERT_EQUAL(
static_cast<dof_id_type>(read_in_elements), original_n_elem);
154#ifdef LIBMESH_HAVE_XDR
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.}};
171 std::make_unique<C0Polygon>(cast_int<unsigned int>(points.size()));
172 polygon->set_id() = 0;
180 checkpoint.
write(filename);
186 checkpoint.
read(filename);
193 bool found_elem = elem;
195 CPPUNIT_ASSERT(found_elem);
200 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_nodes());
202 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_sides());
203 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_edges());
207 CPPUNIT_ASSERT_EQUAL(cast_int<dof_id_type>(n), elem->
node_id(n));
208 CPPUNIT_ASSERT_EQUAL(points[n], elem->
point(n));
211 CPPUNIT_ASSERT_EQUAL(std::size_t(2), side_nodes.size());
212 CPPUNIT_ASSERT_EQUAL(cast_int<unsigned int>(n), side_nodes[0]);
214 (cast_int<unsigned int>((n + 1) % points.size()), side_nodes[1]);
226#ifdef LIBMESH_HAVE_XDR
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 =
248 {6, 7, 8, 9, 10, 11}};
256 std::vector<std::shared_ptr<Polygon>> sides(nodes_on_sides.size());
259 const auto & side_nodes = nodes_on_sides[s];
261 std::make_shared<C0Polygon>
262 (cast_int<unsigned int>(side_nodes.size()));
265 sides[s] = std::move(side);
268 std::unique_ptr<Node> mid_elem_node;
270 std::make_unique<C0Polyhedron>(sides, mid_elem_node);
271 CPPUNIT_ASSERT(mid_elem_node);
274 mid_elem_node->set_id(points.size());
282 checkpoint.
write(filename);
288 checkpoint.
read(filename);
295 bool found_elem = elem;
297 CPPUNIT_ASSERT(found_elem);
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());
312 CPPUNIT_ASSERT_EQUAL(nodes_on_sides[s].size(), side_nodes.size());
315 (cast_int<dof_id_type>(nodes_on_sides[s][n]),
332#ifdef LIBMESH_HAVE_XDR
333#ifdef LIBMESH_ENABLE_EXCEPTIONS
341 const std::string filename =
"checkpoint_missing_split.cpa";
365 bool threw_desired_exception =
false;
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;
375 CPPUNIT_ASSERT(threw_desired_exception);
387 testSplitter<DistributedMesh, ReplicatedMesh>(
false,
true);
394 testSplitter<DistributedMesh, ReplicatedMesh>(
true,
true);
401 testSplitter<ReplicatedMesh, DistributedMesh>(
false,
true);
408 testSplitter<ReplicatedMesh, DistributedMesh>(
true,
true);
415 testSplitter<ReplicatedMesh, ReplicatedMesh>(
false,
false);
422 testSplitter<ReplicatedMesh, ReplicatedMesh>(
true,
false);
429 testSplitter<DistributedMesh, DistributedMesh>(
false,
true);
436 testSplitter<DistributedMesh, DistributedMesh>(
true,
true);
439#ifdef LIBMESH_ENABLE_PERIODIC
444#ifdef LIBMESH_HAVE_XDR
445 const std::string filename =
446 std::string(
"checkpoint_disjoint_pairs.cp") + (binary ?
"r" :
"a");
459 const Real x0 = 1.25 * i;
479 checkpoint.
write(filename);
491 checkpoint.
read(filename);
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)) -
505 CPPUNIT_ASSERT(elem->neighbor_ptr(1));
506 CPPUNIT_ASSERT_EQUAL(
dof_id_type(1), elem->neighbor_ptr(1)->id());
510 CPPUNIT_ASSERT(elem->neighbor_ptr(3));
511 CPPUNIT_ASSERT_EQUAL(
dof_id_type(0), elem->neighbor_ptr(3)->id());
570 testSplitter<DistributedMesh, DistributedMesh>(
false,
true,
true);
CPPUNIT_TEST_SUITE_REGISTRATION(CheckpointIOTest)
void testBinaryDistDistSplitter()
CPPUNIT_TEST(testBinaryC0Polygon)
CPPUNIT_TEST(testAsciiRepRepSplitter)
void testSplitter(bool binary, bool using_distmesh, bool skip_partition=false)
void testBinaryDisjointNeighborPairs()
CPPUNIT_TEST(testAsciiDisjointNeighborPairs)
void testBinaryRepDistSplitter()
void testAsciiDisjointNeighborPairs()
void testC0PolyhedronCheckpoint(bool binary)
void testAsciiRepDistSplitter()
void testBinaryC0Polygon()
CPPUNIT_TEST(testAsciiDistRepSplitter)
CPPUNIT_TEST(testBinaryDistRepSplitter)
LIBMESH_CPPUNIT_TEST_SUITE(CheckpointIOTest)
This test verifies that we can write files with the CheckpointIO object.
CPPUNIT_TEST(testMissingSplitError)
void testAsciiDistDistSplitter()
void testBinaryRepRepSplitter()
void testC0PolygonCheckpoint(bool binary)
CPPUNIT_TEST(testBinaryDisjointNeighborPairs)
void testAsciiC0Polygon()
void testAsciiRepRepSplitter()
void testAsciiC0Polyhedron()
CPPUNIT_TEST(testBinaryRepDistSplitter)
void testAsciiDistRepSplitter()
CPPUNIT_TEST(testAsciiC0Polygon)
CPPUNIT_TEST(testBinaryC0Polyhedron)
CPPUNIT_TEST(testBinaryRepRepSplitter)
void testMissingSplitError()
void testDisjointNeighborPairsCheckpoint(bool binary)
void testBinaryC0Polyhedron()
void testBinaryDistRepSplitter()
CPPUNIT_TEST(testAsciiDistDistSplitter)
CPPUNIT_TEST(testBinaryDistDistSplitter)
CPPUNIT_TEST(testAsciiC0Polyhedron)
CPPUNIT_TEST(testAsciiRepDistSplitter)
void testAsciiDistDistSplitterCache()
void max(const T &r, T &o, Request &req) const
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.
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
const std::vector< processor_id_type > & current_processor_ids() const
Get/Set the processor id or processor ids to use.
virtual void read(const std::string &input_name) override
This method implements reading a mesh from a specified file.
bool binary() const
Get/Set the flag indicating if we should read/write binary.
const processor_id_type & current_n_processors() const
Get/Set the n_processors to use.
static void cleanup(const std::string &input_name, processor_id_type n_procs)
Used to remove a checkpoint directory and its corresponding files.
virtual void write(const std::string &name) override
This method implements writing a mesh to a specified file.
bool parallel() const
Get/Set the flag indicating if we should read/write binary.
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
virtual unsigned int n_vertices() const =0
const Point & point(const unsigned int i) const
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 ...
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
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual bool is_serial() const
const BoundaryInfo & get_boundary_info() const
The information about boundary ids on the mesh.
virtual const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
virtual dof_id_type n_elem() const =0
PeriodicBoundaries * get_disjoint_neighbor_boundary_pairs()
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
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.
virtual dof_id_type n_nodes() const =0
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
unsigned int n_partitions() const
virtual Node * add_node(Node *n)=0
Add Node n to the end of the vertex array.
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.
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.
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
void skip_partitioning(bool skip)
If true is passed in then nothing on this mesh will be (re)partitioned.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
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.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
static const boundary_id_type left_id
static const boundary_id_type right_id
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
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
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...