Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
checkpoint_control.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2024 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_checkpoint_control_h
5#define lethe_checkpoint_control_h
6
7#include <core/parameters.h>
8
9#include <boost/archive/text_iarchive.hpp>
10#include <boost/archive/text_oarchive.hpp>
11
13{
14public:
15 /**
16 * @brief The CheckpointControl is responsible for keeping track of the
17 * next checkpoint id to use.
18 *
19 * @param param Restart struct - Controls writing and reading
20 * simulation checkpoints.
21 */
25 , checkpointing_frequency(param.frequency)
26 , restart(param.checkpoint)
27 , filename(param.filename)
28 {}
29
30 /**
31 * @brief Return true if a checkpoint should be made at the current time step.
32 * @param time_step_number Current time step.
33 */
34 bool
35 is_checkpoint_time_step(const unsigned int time_step_number)
36 {
37 if (restart && !(time_step_number % checkpointing_frequency))
38 {
40 return true;
41 }
42 return false;
43 }
44
45 /**
46 * @brief Return the next checkpoint id.
47 */
48 unsigned int
50 {
51 return next_checkpoint_id;
52 }
53
54 /**
55 * @brief Return the prefix for the restart files.
56 */
57 std::string
59 {
60 return filename;
61 }
62
63 /**
64 * @brief Serialize the checkpoint controller object to an output archive.
65 * @param ar Output archive where the attributes are stored.
66 */
67 void
68 serialize(boost::archive::text_oarchive &ar) const
69 {
71 }
72
73 /**
74 * @brief Deserialize an input archive to the checkpoint controller object.
75 * @param ar Input archive where the attributes are stored.
76 */
77 void
78 deserialize(boost::archive::text_iarchive &ar)
79 {
81 }
82
83private:
84 /**
85 * @brief Calculate the next checkpoint id.
86 */
87 void
92
93 const unsigned int max_checkpoint_id;
94 unsigned int next_checkpoint_id;
95 const unsigned int checkpointing_frequency;
96 const bool restart;
97 const std::string filename;
98};
99#endif
void serialize(boost::archive::text_oarchive &ar) const
Serialize the checkpoint controller object to an output archive.
const unsigned int max_checkpoint_id
const unsigned int checkpointing_frequency
bool is_checkpoint_time_step(const unsigned int time_step_number)
Return true if a checkpoint should be made at the current time step.
unsigned int get_next_checkpoint_id() const
Return the next checkpoint id.
unsigned int next_checkpoint_id
void increment_checkpoint_id()
Calculate 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.
const std::string filename
CheckpointControl(Parameters::Restart &param)
The CheckpointControl is responsible for keeping track of the next checkpoint id to use.
Restart - Controls writing and reading simulation checkpoints.