libMesh
Public Member Functions | List of all members
CheckpointIOTest Class Reference
Inheritance diagram for CheckpointIOTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (CheckpointIOTest)
 This test verifies that we can write files with the CheckpointIO object. More...
 
 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_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
template<typename MeshA , typename MeshB >
void testSplitter (bool binary, bool using_distmesh)
 
void testAsciiDistRepSplitter ()
 
void testBinaryDistRepSplitter ()
 
void testAsciiRepDistSplitter ()
 
void testBinaryRepDistSplitter ()
 
void testAsciiRepRepSplitter ()
 
void testBinaryRepRepSplitter ()
 
void testAsciiDistDistSplitter ()
 
void testBinaryDistDistSplitter ()
 

Detailed Description

Definition at line 27 of file checkpoint.C.

Member Function Documentation

CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistRepSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistRepSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepDistSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepDistSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testAsciiRepRepSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testBinaryRepRepSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testAsciiDistDistSplitter  )
CheckpointIOTest::CPPUNIT_TEST ( testBinaryDistDistSplitter  )
CheckpointIOTest::CPPUNIT_TEST_SUITE ( CheckpointIOTest  )

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

CheckpointIOTest::CPPUNIT_TEST_SUITE_END ( )
void CheckpointIOTest::setUp ( )

Definition at line 48 of file checkpoint.C.

49  {
50  }
void CheckpointIOTest::tearDown ( )

Definition at line 52 of file checkpoint.C.

53  {
54  }
void CheckpointIOTest::testAsciiDistDistSplitter ( )

Definition at line 161 of file checkpoint.C.

162  {
163  testSplitter<DistributedMesh, DistributedMesh>(false, true);
164  }
void CheckpointIOTest::testAsciiDistRepSplitter ( )

Definition at line 131 of file checkpoint.C.

132  {
133  testSplitter<DistributedMesh, ReplicatedMesh>(false, true);
134  }
void CheckpointIOTest::testAsciiRepDistSplitter ( )

Definition at line 141 of file checkpoint.C.

142  {
143  testSplitter<ReplicatedMesh, DistributedMesh>(false, true);
144  }
void CheckpointIOTest::testAsciiRepRepSplitter ( )

Definition at line 151 of file checkpoint.C.

152  {
153  testSplitter<ReplicatedMesh, ReplicatedMesh>(false, false);
154  }
void CheckpointIOTest::testBinaryDistDistSplitter ( )

Definition at line 166 of file checkpoint.C.

References CPPUNIT_TEST_SUITE_REGISTRATION().

167  {
168  testSplitter<DistributedMesh, DistributedMesh>(true, true);
169  }
void CheckpointIOTest::testBinaryDistRepSplitter ( )

Definition at line 136 of file checkpoint.C.

137  {
138  testSplitter<DistributedMesh, ReplicatedMesh>(true, true);
139  }
void CheckpointIOTest::testBinaryRepDistSplitter ( )

Definition at line 146 of file checkpoint.C.

147  {
148  testSplitter<ReplicatedMesh, DistributedMesh>(true, true);
149  }
void CheckpointIOTest::testBinaryRepRepSplitter ( )

Definition at line 156 of file checkpoint.C.

157  {
158  testSplitter<ReplicatedMesh, ReplicatedMesh>(true, false);
159  }
template<typename MeshA , typename MeshB >
void CheckpointIOTest::testSplitter ( bool  binary,
bool  using_distmesh 
)

Definition at line 58 of file checkpoint.C.

References libMesh::Parallel::Communicator::barrier(), libMesh::CheckpointIO::binary(), libMesh::MeshTools::Generation::build_square(), libMesh::CheckpointIO::current_n_processors(), libMesh::CheckpointIO::current_processor_ids(), distance(), mesh, std::min(), libMesh::CheckpointIO::parallel(), libMesh::QUAD4, libMesh::CheckpointIO::read(), libMesh::Parallel::Communicator::size(), TestCommWorld, and libMesh::CheckpointIO::write().

59  {
60  // The CheckpointIO-based splitter requires XDR.
61 #ifdef LIBMESH_HAVE_XDR
62 
63  // In this test, we partition the mesh into n_procs parts. Don't
64  // try to partition a DistributedMesh into more parts than we have
65  // processors, though.
66  const unsigned int n_procs = using_distmesh ?
67  std::min(static_cast<unsigned int>(2), TestCommWorld->size()) :
68  2;
69 
70  // The number of elements in the original mesh. For verification
71  // later.
72  dof_id_type original_n_elem = 0;
73 
74  const std::string filename =
75  std::string("checkpoint_splitter.cp") + (binary ? "r" : "a");
76 
77  {
78  MeshA mesh(*TestCommWorld);
79 
81  4, 4,
82  0., 1.,
83  0., 1.,
84  QUAD4);
85 
86  // Store the number of elements that were in the original mesh.
87  original_n_elem = mesh.n_elem();
88 
89  // Partition the mesh into n_procs pieces
90  mesh.partition(n_procs);
91 
92  // Write out checkpoint files for each piece. Since on a
93  // ReplicatedMesh we might have more pieces than we do
94  // processors, some processors may have to write out more than
95  // one piece.
96  CheckpointIO cpr(mesh);
97  cpr.current_processor_ids().clear();
98  for (processor_id_type pid = mesh.processor_id(); pid < n_procs; pid += mesh.n_processors())
99  cpr.current_processor_ids().push_back(pid);
100  cpr.current_n_processors() = n_procs;
101  cpr.binary() = binary;
102  cpr.parallel() = true;
103  cpr.write(filename);
104  }
105 
107 
108  // Test that we can read in the files we wrote and sum up to the
109  // same total number of elements.
110  {
111  MeshB mesh(*TestCommWorld);
112  CheckpointIO cpr(mesh);
113  cpr.binary() = binary;
114  cpr.read(filename);
115 
116  std::size_t read_in_elements = 0;
117 
118  for (unsigned pid=mesh.processor_id(); pid<n_procs; pid += mesh.n_processors())
119  {
120  read_in_elements += std::distance(mesh.pid_elements_begin(pid),
121  mesh.pid_elements_end(pid));
122  }
123  mesh.comm().sum(read_in_elements);
124 
125  // Verify that we read in exactly as many elements as we started with.
126  CPPUNIT_ASSERT_EQUAL(static_cast<dof_id_type>(read_in_elements), original_n_elem);
127  }
128 #endif // LIBMESH_HAVE_XDR
129  }
The CheckpointIO class can be used to write simplified restart files that can be used to restart simu...
Definition: checkpoint_io.h:50
unsigned int size() const
Definition: parallel.h:726
libMesh::Parallel::Communicator * TestCommWorld
Definition: driver.C:28
processor_id_type n_processors() const
MeshBase & mesh
uint8_t processor_id_type
Definition: id_types.h:99
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.
Real distance(const Point &p)
virtual void partition(const unsigned int n_parts)
Call the default partitioner (currently metis_partition()).
Definition: mesh_base.C:462
void barrier() const
Pause execution until all processors reach a certain point.
virtual element_iterator pid_elements_begin(processor_id_type proc_id)=0
Iterate over all elements with a specified processor id.
const Parallel::Communicator & comm() const
virtual dof_id_type n_elem() const =0
void sum(T &r) const
Take a local variable and replace it with the sum of it&#39;s values on all processors.
long double min(long double a, double b)
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:64
virtual element_iterator pid_elements_end(processor_id_type proc_id)=0

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