PRISMS-PF Manual
Loading...
Searching...
No Matches
checkpoint_parameters.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
8
10
12
13#include <prismspf/config.h>
14
15#include <climits>
16#include <set>
17#include <string>
18
20
25{
29 [[nodiscard]] bool
30 should_checkpoint(unsigned int increment) const
31 {
32 return checkpoint_list.contains(increment);
33 }
34
38 void
40 { // todo
41 }
42
46 void
48
52 template <typename ListType>
53 void
55 {
56 checkpoint_list.insert(list.begin(), list.end());
57 }
58
62 void
63 add_equal_spacing_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
64 {
65 if (!num_checkpoints)
66 {
67 return;
68 }
69 for (unsigned int checkpoint = 0; checkpoint <= num_increments;
70 checkpoint += num_increments / num_checkpoints)
71 {
73 }
74 }
75
79 void
80 add_log_spacing_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
81 {
82 if (!num_checkpoints)
83 {
84 return;
85 }
86 for (unsigned int checkpoint = 1; checkpoint <= num_checkpoints; checkpoint++)
87 {
88 checkpoint_list.insert(static_cast<unsigned int>(
89 std::round(std::pow(double(num_increments),
90 double(checkpoint) / double(num_checkpoints)))));
91 }
92 }
93
97 void
98 add_n_per_decade_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
99 {
100 if (!num_checkpoints)
101 {
102 return;
103 }
104 AssertThrow(num_increments > 1,
105 dealii::ExcMessage("For n per decaded spaced checkpoints, the number of "
106 "increments must be greater than 1."));
107
108 for (unsigned int iteration = 2; iteration <= num_increments; iteration++)
109 {
110 const auto decade = static_cast<unsigned int>(std::ceil(std::log10(iteration)));
111 const auto step_size =
112 static_cast<unsigned int>(std::pow(10, decade) / num_checkpoints);
113 if (iteration % step_size == 0)
114 {
116 }
117 }
118 }
119
123 void
125 {
126 checkpoint_list.clear();
127 }
128
132 [[nodiscard]] unsigned int
134 {
135 return checkpoint_list.size();
136 }
137
138 // Whether to load from a checkpoint
140
141 // Checkpoint file name
142 std::string file_name;
143
144 // Whether to print timing information with checkpoint
145 // TODO (landinjm): Implement this.
147
148 // List of increments that checkpoint the solution to file
149 std::set<unsigned int> checkpoint_list;
150};
151
152inline void
154{
156 << "================================================\n"
157 << " Checkpoint Parameters\n"
158 << "================================================\n"
159 << "Checkpoint file name: " << file_name << "\n"
160 << "Number of checkpoints: " << get_num_checkpoints() << "\n"
161 << "Print timing info: " << bool_to_string(print_timing_with_checkpoint) << "\n";
162
163 ConditionalOStreams::pout_summary() << "Checkpoint increment list: ";
164 for (const auto &iteration : checkpoint_list)
165 {
167 }
168 ConditionalOStreams::pout_summary() << "\n\n" << std::flush;
169}
170
static dealii::ConditionalOStream & pout_summary()
Log output stream for writing a summary.log file.
Definition conditional_ostreams.cc:34
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20
Struct that holds checkpoint parameters.
Definition checkpoint_parameters.h:25
std::set< unsigned int > checkpoint_list
Definition checkpoint_parameters.h:149
bool print_timing_with_checkpoint
Definition checkpoint_parameters.h:146
void print_parameter_summary() const
Print parameters to summary.log.
Definition checkpoint_parameters.h:153
void clear_checkpoint_list()
Set the user checkpoint list.
Definition checkpoint_parameters.h:124
std::string file_name
Definition checkpoint_parameters.h:142
void add_log_spacing_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
Set the user checkpoint list.
Definition checkpoint_parameters.h:80
void validate()
Postprocess and validate parameters.
Definition checkpoint_parameters.h:39
void add_n_per_decade_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
Set the user checkpoint list.
Definition checkpoint_parameters.h:98
bool should_load_checkpoint
Definition checkpoint_parameters.h:139
void add_equal_spacing_checkpoints(unsigned int num_checkpoints, unsigned int num_increments)
Set the user checkpoint list.
Definition checkpoint_parameters.h:63
void add_checkpoint_list(const ListType &list)
Set the user checkpoint list.
Definition checkpoint_parameters.h:54
bool should_checkpoint(unsigned int increment) const
Return if the increment should be checkpointted.
Definition checkpoint_parameters.h:30
unsigned int get_num_checkpoints() const
Get the number of checkpoints that will be made.
Definition checkpoint_parameters.h:133
const char * bool_to_string(bool boolean)
Convert bool to string.
Definition utilities.h:232