1#include "libmesh/cell_c0polyhedron.h"
2#include "libmesh/checkpoint_io.h"
3#include "libmesh/distributed_mesh.h"
4#include "libmesh/face_c0polygon.h"
5#include "libmesh/int_range.h"
6#include "libmesh/mesh.h"
7#include "libmesh/mesh_generation.h"
8#include "libmesh/node.h"
9#include "libmesh/parallel.h"
10#include "libmesh/partitioner.h"
11#include "libmesh/replicated_mesh.h"
57 template <
typename MeshA,
typename MeshB>
58 void testSplitter(
bool binary,
bool using_distmesh,
bool skip_partition =
false)
61#ifdef LIBMESH_HAVE_XDR
66 const unsigned int n_procs = using_distmesh ?
74 const std::string filename =
75 std::string(
"checkpoint_splitter.cp") + (binary ?
"r" :
"a");
126 std::size_t read_in_elements = 0;
130 read_in_elements += std::distance(
mesh.pid_elements_begin(pid),
131 mesh.pid_elements_end(pid));
136 CPPUNIT_ASSERT_EQUAL(
static_cast<dof_id_type>(read_in_elements), original_n_elem);
143#ifdef LIBMESH_HAVE_XDR
150 const std::string filename =
151 std::string(
"checkpoint_c0polygon.cp") + (binary ?
"r" :
"a");
152 const std::vector<Point> points =
153 {{0., 0.}, {1., 0.}, {1.5, 0.5}, {1., 1.}, {0., 1.}};
160 std::make_unique<C0Polygon>(cast_int<unsigned int>(points.size()));
161 polygon->set_id() = 0;
169 checkpoint.
write(filename);
175 checkpoint.
read(filename);
182 bool found_elem = elem;
184 CPPUNIT_ASSERT(found_elem);
189 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_nodes());
191 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_sides());
192 CPPUNIT_ASSERT_EQUAL(5u, elem->
n_edges());
196 CPPUNIT_ASSERT_EQUAL(cast_int<dof_id_type>(n), elem->
node_id(n));
197 CPPUNIT_ASSERT_EQUAL(points[n], elem->
point(n));
200 CPPUNIT_ASSERT_EQUAL(std::size_t(2), side_nodes.size());
201 CPPUNIT_ASSERT_EQUAL(cast_int<unsigned int>(n), side_nodes[0]);
203 (cast_int<unsigned int>((n + 1) % points.size()), side_nodes[1]);
215#ifdef LIBMESH_HAVE_XDR
222 const std::string filename =
223 std::string(
"checkpoint_c0polyhedron.cp") + (binary ?
"r" :
"a");
224 const std::vector<Point> points =
225 {{0., -2., 0.}, {-1., -1., 0.}, {-1., 1., 0.},
226 {0., 2., 0.}, {1., 1., 0.}, {1., -1., 0.},
227 {0., -2., 1.}, {-1., -1., 1.}, {-1., 1., 1.},
228 {0., 2., 1.}, {1., 1., 1.}, {1., -1., 1.}};
229 const std::vector<std::vector<unsigned int>> nodes_on_sides =
237 {6, 7, 8, 9, 10, 11}};
245 std::vector<std::shared_ptr<Polygon>> sides(nodes_on_sides.size());
248 const auto & side_nodes = nodes_on_sides[s];
250 std::make_shared<C0Polygon>
251 (cast_int<unsigned int>(side_nodes.size()));
254 sides[s] = std::move(side);
257 std::unique_ptr<Node> mid_elem_node;
259 std::make_unique<C0Polyhedron>(sides, mid_elem_node);
260 CPPUNIT_ASSERT(mid_elem_node);
263 mid_elem_node->set_id(points.size());
271 checkpoint.
write(filename);
277 checkpoint.
read(filename);
284 bool found_elem = elem;
286 CPPUNIT_ASSERT(found_elem);
291 CPPUNIT_ASSERT_EQUAL(12u, elem->
n_vertices());
292 CPPUNIT_ASSERT_EQUAL(13u, elem->
n_nodes());
293 CPPUNIT_ASSERT_EQUAL(8u, elem->
n_sides());
294 CPPUNIT_ASSERT_EQUAL(18u, elem->
n_edges());
301 CPPUNIT_ASSERT_EQUAL(nodes_on_sides[s].size(), side_nodes.size());
304 (cast_int<dof_id_type>(nodes_on_sides[s][n]),
319 testSplitter<DistributedMesh, ReplicatedMesh>(
false,
true);
326 testSplitter<DistributedMesh, ReplicatedMesh>(
true,
true);
333 testSplitter<ReplicatedMesh, DistributedMesh>(
false,
true);
340 testSplitter<ReplicatedMesh, DistributedMesh>(
true,
true);
347 testSplitter<ReplicatedMesh, ReplicatedMesh>(
false,
false);
354 testSplitter<ReplicatedMesh, ReplicatedMesh>(
true,
false);
361 testSplitter<DistributedMesh, DistributedMesh>(
false,
true);
368 testSplitter<DistributedMesh, DistributedMesh>(
true,
true);
405 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 testBinaryRepDistSplitter()
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.
void testAsciiDistDistSplitter()
void testBinaryRepRepSplitter()
void testC0PolygonCheckpoint(bool binary)
void testAsciiC0Polygon()
void testAsciiRepRepSplitter()
void testAsciiC0Polyhedron()
CPPUNIT_TEST(testBinaryRepDistSplitter)
void testAsciiDistRepSplitter()
CPPUNIT_TEST(testAsciiC0Polygon)
CPPUNIT_TEST(testBinaryC0Polyhedron)
CPPUNIT_TEST(testBinaryRepRepSplitter)
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 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 unsigned int n_vertices() const =0
const Point & point(const unsigned int i) const
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
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
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.
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.
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
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...
uint8_t processor_id_type