Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
read_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#include <core/utilities.h>
6
9
10#include <boost/archive/text_iarchive.hpp>
11
12#include <fstream>
13
14using namespace dealii;
15
16template <int dim, typename PropertiesIndex>
17void
19 TimerOutput &computing_timer,
20 const DEMSolverParameters<dim> &parameters,
21 std::shared_ptr<SimulationControl> &simulation_control,
22 PVDHandler &particles_pvdhandler,
23 PVDHandler &grid_pvdhandler,
24 parallel::distributed::Triangulation<dim> &triangulation,
25 Particles::ParticleHandler<dim> &particle_handler,
26 std::shared_ptr<Insertion<dim, PropertiesIndex>> &insertion_object,
27 std::vector<std::shared_ptr<SerialSolid<dim - 1, dim>>> &solid_surfaces,
28 CheckpointControl &checkpoint_controller)
29{
30 if (!DEMActionManager::get_action_manager()->check_restart_simulation())
31 return;
32
33 TimerOutput::Scope timer(computing_timer, "Read checkpoint");
34 std::string prefix = checkpoint_controller.get_filename();
35
36 // Load checkpoint controller
37 std::string checkpoint_controller_object_filename =
38 prefix + ".checkpoint_controller";
39 check_file_exists(checkpoint_controller_object_filename,
40 "checkpoint file of the checkpoint controller, given by "
41 "'subsection restart' - 'set filename'");
42 std::ifstream iss_checkpoint_controller_obj(
43 checkpoint_controller_object_filename);
44
45 boost::archive::text_iarchive ia_checkpoint_controller_obj(
46 iss_checkpoint_controller_obj, boost::archive::no_header);
47 checkpoint_controller.deserialize(ia_checkpoint_controller_obj);
48
49 // Update prefix with the checkpoint id
50 prefix =
51 prefix + "_" +
52 Utilities::int_to_string(checkpoint_controller.get_next_checkpoint_id());
53
54 simulation_control->read(prefix);
55 particles_pvdhandler.read(prefix);
56
58 {
59 grid_pvdhandler.read(prefix + "_lagrangian_postprocessing");
60 }
61
62 // Gather particle serialization information
63 std::string particle_filename = prefix + ".particles";
64 check_file_exists(particle_filename,
65 "checkpoint file of the particles, given by "
66 "'subsection restart' - 'set filename'");
67 std::ifstream input(particle_filename.c_str());
68
69 std::string buffer;
70 std::getline(input, buffer);
71 std::istringstream iss(buffer);
72 boost::archive::text_iarchive ia(iss, boost::archive::no_header);
73
74 ia >> particle_handler;
75
76 const std::string filename = prefix + ".triangulation";
77 check_file_exists(filename,
78 "checkpoint file of the triangulation, given by "
79 "'subsection restart' - 'set filename'");
80
81 try
82 {
83 triangulation.load(filename.c_str());
84 }
85 catch (...)
86 {
87 AssertThrow(false,
88 ExcMessage("Cannot open snapshot mesh file or read the "
89 "triangulation stored there."));
90 }
91
92
93 // Unpack the information in the particle handler
94 particle_handler.deserialize();
95
96
97 // Load insertion object
98 std::string insertion_object_filename = prefix + ".insertion_object";
99 check_file_exists(insertion_object_filename,
100 "checkpoint file of the insertion object, given by "
101 "'subsection restart' - 'set filename'");
102 std::ifstream iss_insertion_obj(insertion_object_filename);
103 boost::archive::text_iarchive ia_insertion_obj(iss_insertion_obj,
104 boost::archive::no_header);
105 insertion_object->deserialize(ia_insertion_obj);
106
107 // Load solid surfaces
108 for (unsigned int i = 0; i < solid_surfaces.size(); ++i)
109 {
110 solid_surfaces[i]->read_checkpoint(prefix);
111 }
112}
113
114template void
116 TimerOutput &computing_timer,
117 const DEMSolverParameters<2> &parameters,
118 std::shared_ptr<SimulationControl> &simulation_control,
119 PVDHandler &particles_pvdhandler,
120 PVDHandler &grid_pvdhandler,
121 parallel::distributed::Triangulation<2> &triangulation,
122 Particles::ParticleHandler<2> &particle_handler,
124 &insertion_object,
125 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_surfaces,
126 CheckpointControl &checkpoint_controller);
127
128template void
130 TimerOutput &computing_timer,
131 const DEMSolverParameters<3> &parameters,
132 std::shared_ptr<SimulationControl> &simulation_control,
133 PVDHandler &particles_pvdhandler,
134 PVDHandler &grid_pvdhandler,
135 parallel::distributed::Triangulation<3> &triangulation,
136 Particles::ParticleHandler<3> &particle_handler,
138 &insertion_object,
139 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_surfaces,
140 CheckpointControl &checkpoint_controller);
141
142template void
144 TimerOutput &computing_timer,
145 const DEMSolverParameters<2> &parameters,
146 std::shared_ptr<SimulationControl> &simulation_control,
147 PVDHandler &particles_pvdhandler,
148 PVDHandler &grid_pvdhandler,
149 parallel::distributed::Triangulation<2> &triangulation,
150 Particles::ParticleHandler<2> &particle_handler,
152 &insertion_object,
153 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_surfaces,
154 CheckpointControl &checkpoint_controller);
155
156template void
158 TimerOutput &computing_timer,
159 const DEMSolverParameters<3> &parameters,
160 std::shared_ptr<SimulationControl> &simulation_control,
161 PVDHandler &particles_pvdhandler,
162 PVDHandler &grid_pvdhandler,
163 parallel::distributed::Triangulation<3> &triangulation,
164 Particles::ParticleHandler<3> &particle_handler,
166 &insertion_object,
167 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_surfaces,
168 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_surfaces,
182 CheckpointControl &checkpoint_controller);
183
184template void
186 TimerOutput &computing_timer,
187 const DEMSolverParameters<2> &parameters,
188 std::shared_ptr<SimulationControl> &simulation_control,
189 PVDHandler &particles_pvdhandler,
190 PVDHandler &grid_pvdhandler,
191 parallel::distributed::Triangulation<2> &triangulation,
192 Particles::ParticleHandler<2> &particle_handler,
194 &insertion_object,
195 std::vector<std::shared_ptr<SerialSolid<1, 2>>> &solid_surfaces,
196 CheckpointControl &checkpoint_controller);
197
198template void
200 TimerOutput &computing_timer,
201 const DEMSolverParameters<3> &parameters,
202 std::shared_ptr<SimulationControl> &simulation_control,
203 PVDHandler &particles_pvdhandler,
204 PVDHandler &grid_pvdhandler,
205 parallel::distributed::Triangulation<3> &triangulation,
206 Particles::ParticleHandler<3> &particle_handler,
208 &insertion_object,
209 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_surfaces,
210 CheckpointControl &checkpoint_controller);
211
212template void
214 TimerOutput &computing_timer,
215 const DEMSolverParameters<3> &parameters,
216 std::shared_ptr<SimulationControl> &simulation_control,
217 PVDHandler &particles_pvdhandler,
218 PVDHandler &grid_pvdhandler,
219 parallel::distributed::Triangulation<3> &triangulation,
220 Particles::ParticleHandler<3> &particle_handler,
222 &insertion_object,
223 std::vector<std::shared_ptr<SerialSolid<2, 3>>> &solid_surfaces,
224 CheckpointControl &checkpoint_controller);
unsigned int get_next_checkpoint_id() const
Return the next checkpoint id.
void deserialize(boost::archive::text_iarchive &ar)
Deserialize an input archive to the checkpoint controller object.
std::string get_filename() const
Return the prefix for the restart files.
static DEMActionManager * get_action_manager()
Getter of the unique instance of the DEMActionManager.
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 read(const std::string &filename)
read Reads the content of a pvd times_and_names checpoint
void check_file_exists(const std::string &file_name, const std::string &file_description)
Verify that a file that Lethe must read exists and can be opened, and raise an error stated in the us...
Definition utilities.cc:225
void read_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_surfaces, CheckpointControl &checkpoint_controller)
Read a DEM simulation checkpoint, allowing the simulation to restart from where it stopped.
bool lagrangian_post_processing_enabled
Enable Lagrangian post-processing.