Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
write_checkpoint.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2021-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
7
8#include <boost/archive/text_oarchive.hpp>
9
10#include <fstream>
11
12using namespace dealii;
13
14template <int dim, typename PropertiesIndex>
15void
17 TimerOutput &computing_timer,
18 const DEMSolverParameters<dim> &parameters,
19 std::shared_ptr<SimulationControl> &simulation_control,
20 PVDHandler &particles_pvdhandler,
21 PVDHandler &grid_pvdhandler,
22 parallel::distributed::Triangulation<dim> &triangulation,
23 Particles::ParticleHandler<dim> &particle_handler,
24 std::shared_ptr<Insertion<dim, PropertiesIndex>> &insertion_object,
25 std::vector<std::shared_ptr<SerialSolid<dim - 1, dim>>> &solid_objects,
26 const ConditionalOStream &pcout,
27 MPI_Comm &mpi_communicator,
28 const CheckpointControl &checkpoint_controller)
29{
30 TimerOutput::Scope timer(computing_timer, "Write checkpoint");
31
32 pcout << "Writing restart file" << std::endl;
33
34 std::string prefix =
35 checkpoint_controller.get_filename() + "_" +
36 Utilities::int_to_string(checkpoint_controller.get_next_checkpoint_id());
37
38 // Prepare the particle handler for checkpointing
39 particle_handler.prepare_for_serialization();
40
41 // Save the triangulation
42 triangulation.save(prefix + ".triangulation");
43
44 if (Utilities::MPI::this_mpi_process(mpi_communicator) == 0)
45 {
46 std::ostringstream oss;
47 boost::archive::text_oarchive oa(oss, boost::archive::no_header);
48 oa << particle_handler;
49
50 simulation_control->save(prefix);
51 particles_pvdhandler.save(prefix);
52
54 {
55 grid_pvdhandler.save(prefix + "_lagrangian_postprocessing");
56 }
57
58 // Write additional particle information for deserialization
59 std::string particle_filename = prefix + ".particles";
60 std::ofstream output(particle_filename.c_str());
61 output << oss.str() << std::endl;
62
63 // Prepare the insertion object for checkpointing
64 std::string insertion_object_filename = prefix + ".insertion_object";
65 std::ofstream oss_insertion_obj(insertion_object_filename);
66 boost::archive::text_oarchive oa_insertion_obj(oss_insertion_obj,
67 boost::archive::no_header);
68 insertion_object->serialize(oa_insertion_obj);
69
70 // Checkpoint the serial solid objects one by one
71 for (unsigned int i = 0; i < solid_objects.size(); ++i)
72 {
73 solid_objects[i]->write_checkpoint(prefix);
74 }
75
76 // Prepare the checkpoint controller for checkpointing
77 // We don't use the same prefix, since this file needs to have the same
78 // name regardless of the checkpoint id being used. This file is giving
79 // the information of which checkpoint id to use when restarting.
80 std::string checkpoint_controller_object_filename =
81 checkpoint_controller.get_filename() + ".checkpoint_controller";
82 std::ofstream oss_checkpoint_controller_obj(
83 checkpoint_controller_object_filename);
84 boost::archive::text_oarchive oa_checkpoint_controller_obj(
85 oss_checkpoint_controller_obj, boost::archive::no_header);
86 checkpoint_controller.serialize(oa_checkpoint_controller_obj);
87 }
88}
89
90template void
92 TimerOutput &computing_timer,
93 const DEMSolverParameters<2> &parameters,
94 std::shared_ptr<SimulationControl> &simulation_control,
95 PVDHandler &particles_pvdhandler,
96 PVDHandler &grid_pvdhandler,
97 parallel::distributed::Triangulation<2> &triangulation,
98 Particles::ParticleHandler<2> &particle_handler,
100 &insertion_object,
101 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_objects,
102 const ConditionalOStream &pcout,
103 MPI_Comm &mpi_communicator,
104 const CheckpointControl &checkpoint_controller);
105
106template void
108 TimerOutput &computing_timer,
109 const DEMSolverParameters<3> &parameters,
110 std::shared_ptr<SimulationControl> &simulation_control,
111 PVDHandler &particles_pvdhandler,
112 PVDHandler &grid_pvdhandler,
113 parallel::distributed::Triangulation<3> &triangulation,
114 Particles::ParticleHandler<3> &particle_handler,
116 &insertion_object,
117 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_objects,
118 const ConditionalOStream &pcout,
119 MPI_Comm &mpi_communicator,
120 const CheckpointControl &checkpoint_controller);
121
122template void
124 TimerOutput &computing_timer,
125 const DEMSolverParameters<2> &parameters,
126 std::shared_ptr<SimulationControl> &simulation_control,
127 PVDHandler &particles_pvdhandler,
128 PVDHandler &grid_pvdhandler,
129 parallel::distributed::Triangulation<2> &triangulation,
130 Particles::ParticleHandler<2> &particle_handler,
132 &insertion_object,
133 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_objects,
134 const ConditionalOStream &pcout,
135 MPI_Comm &mpi_communicator,
136 const CheckpointControl &checkpoint_controller);
137
138template void
140 TimerOutput &computing_timer,
141 const DEMSolverParameters<3> &parameters,
142 std::shared_ptr<SimulationControl> &simulation_control,
143 PVDHandler &particles_pvdhandler,
144 PVDHandler &grid_pvdhandler,
145 parallel::distributed::Triangulation<3> &triangulation,
146 Particles::ParticleHandler<3> &particle_handler,
148 &insertion_object,
149 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_objects,
150 const ConditionalOStream &pcout,
151 MPI_Comm &mpi_communicator,
152 const CheckpointControl &checkpoint_controller);
153
154template void
156 TimerOutput &computing_timer,
157 const DEMSolverParameters<2> &parameters,
158 std::shared_ptr<SimulationControl> &simulation_control,
159 PVDHandler &particles_pvdhandler,
160 PVDHandler &grid_pvdhandler,
161 parallel::distributed::Triangulation<2> &triangulation,
162 Particles::ParticleHandler<2> &particle_handler,
164 &insertion_object,
165 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_objects,
166 const ConditionalOStream &pcout,
167 MPI_Comm &mpi_communicator,
168 const CheckpointControl &checkpoint_controller);
169
170template void
172 TimerOutput &computing_timer,
173 const DEMSolverParameters<2> &parameters,
174 std::shared_ptr<SimulationControl> &simulation_control,
175 PVDHandler &particles_pvdhandler,
176 PVDHandler &grid_pvdhandler,
177 parallel::distributed::Triangulation<2> &triangulation,
178 Particles::ParticleHandler<2> &particle_handler,
180 &insertion_object,
181 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_objects,
182 const ConditionalOStream &pcout,
183 MPI_Comm &mpi_communicator,
184 const CheckpointControl &checkpoint_controller);
185
186template void
188 TimerOutput &computing_timer,
189 const DEMSolverParameters<3> &parameters,
190 std::shared_ptr<SimulationControl> &simulation_control,
191 PVDHandler &particles_pvdhandler,
192 PVDHandler &grid_pvdhandler,
193 parallel::distributed::Triangulation<3> &triangulation,
194 Particles::ParticleHandler<3> &particle_handler,
196 &insertion_object,
197 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_objects,
198 const ConditionalOStream &pcout,
199 MPI_Comm &mpi_communicator,
200 const CheckpointControl &checkpoint_controller);
201
202template void
204 TimerOutput &computing_timer,
205 const DEMSolverParameters<3> &parameters,
206 std::shared_ptr<SimulationControl> &simulation_control,
207 PVDHandler &particles_pvdhandler,
208 PVDHandler &grid_pvdhandler,
209 parallel::distributed::Triangulation<3> &triangulation,
210 Particles::ParticleHandler<3> &particle_handler,
212 &insertion_object,
213 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_objects,
214 const ConditionalOStream &pcout,
215 MPI_Comm &mpi_communicator,
216 const CheckpointControl &checkpoint_controller);
void serialize(boost::archive::text_oarchive &ar) const
Serialize the checkpoint controller object to an output archive.
unsigned int get_next_checkpoint_id() const
Return the next checkpoint id.
std::string get_filename() const
Return the prefix for the restart files.
Handles all the parameters declared in the parameter handler file.
Parameters::Lagrangian::LagrangianPostProcessing post_processing
Base interface for classes that carry out the insertion of particles in the system.
Definition insertion.h:33
The PVDHandler class manages the storage of the information required to write pvd file....
Definition pvd_handler.h:17
void save(const std::string &filename) const
save Saves the content of the pvd times_and_names to a file
bool lagrangian_post_processing_enabled
Enable Lagrangian post-processing.
void write_checkpoint(TimerOutput &computing_timer, const DEMSolverParameters< dim > &parameters, std::shared_ptr< SimulationControl > &simulation_control, PVDHandler &particles_pvdhandler, PVDHandler &grid_pvdhandler, parallel::distributed::Triangulation< dim > &triangulation, Particles::ParticleHandler< dim > &particle_handler, std::shared_ptr< Insertion< dim, PropertiesIndex > > &insertion_object, std::vector< std::shared_ptr< SerialSolid< dim - 1, dim > > > &solid_objects, const ConditionalOStream &pcout, MPI_Comm &mpi_communicator, const CheckpointControl &checkpoint_controller)
Write_checkpoint Write a DEM simulation checkpointing to allow for DEM simulation restart.