PRISMS-PF Manual
Loading...
Searching...
No Matches
load_initial_condition_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
6#include <deal.II/base/exceptions.h>
7#include <deal.II/base/parameter_handler.h>
8#include <deal.II/base/types.h>
9
10#include <boost/algorithm/string/predicate.hpp>
11
14
15#include <prismspf/config.h>
16
17#include <cstdint>
18#include <filesystem>
19#include <string>
20#include <vector>
21
23
28{
29 // File name
30 std::string filename;
31
32 // Grid type
34
35 // File variable names
36 std::vector<std::string> file_variable_names;
37
38 // Simulation variable names
39 std::vector<std::string> simulation_variable_names;
40
41 // Number of data points in each direction
42 std::array<dealii::types::global_dof_index, 3> n_data_points = {
43 {0, 0, 0}
44 };
45};
46
51{
52public:
56 static constexpr unsigned int max_files = 8;
57
61 void
63
67 void
69
73 void
75 {
77 ic_files.clear();
78 }
79
83 void
84 set_read_initial_conditions_from_file(bool _read_initial_conditions_from_file)
85 {
86 read_initial_conditions_from_file = _read_initial_conditions_from_file;
87 }
88
92 [[nodiscard]] bool
97
101 void
103 {
105 {
106 ic_files.push_back(_ic_file);
107 }
108 }
109
113 [[nodiscard]] unsigned int
115 {
116 return ic_files.size();
117 }
118
122 [[nodiscard]] const std::vector<InitialConditionFile> &
124 {
125 return ic_files;
126 }
127
131 void
132 declare_parameters(dealii::ParameterHandler &parameter_handler,
133 unsigned int max_criteria = 5) const;
134
138 void
139 assign_parameters(dealii::ParameterHandler &parameter_handler,
140 unsigned int max_criteria = 5);
141
142private:
143 // Whether to read initial conditions from file
145
146 // IC files
147 std::vector<InitialConditionFile> ic_files;
148};
149
150inline void
152{
153 for (const auto &ic_file : ic_files)
154 {
155 // Check that the file variables are the same length as the simulation variables
156 AssertThrow(ic_file.file_variable_names.size() ==
157 ic_file.simulation_variable_names.size(),
158 dealii::ExcMessage("The number of file variables must be the same as "
159 "the number of simulation variables"));
160 }
161
162 // TODO (landinjm): Check that there are no duplicate field names so we don't double
163 // assign.
164}
165
166inline void
168{
170 {
172 << "================================================\n"
173 << " Load IC Parameters\n"
174 << "================================================\n";
175
176 for (const auto &ic_file : ic_files)
177 {
179 << "File name: " << ic_file.filename << "\n"
180 << "Dataset format: " << to_string(ic_file.dataset_format) << "\n"
181 << "File variable names: ";
182 for (const auto &file_variable_name : ic_file.file_variable_names)
183 {
184 ConditionalOStreams::pout_summary() << file_variable_name << " ";
185 }
187 << "Simulation variable names: ";
188 for (const auto &simulation_variable_name : ic_file.simulation_variable_names)
189 {
190 ConditionalOStreams::pout_summary() << simulation_variable_name << " ";
191 }
192 if (ic_file.dataset_format == FlatBinary)
193 {
194 ConditionalOStreams::pout_summary() << "\n Data points in each direction: ";
195 for (const auto &n_data_points : ic_file.n_data_points)
196 {
197 ConditionalOStreams::pout_summary() << n_data_points << " ";
198 }
199 }
200 }
201
202 ConditionalOStreams::pout_summary() << "\n" << std::flush;
203 }
204}
205
206inline void
208 dealii::ParameterHandler &parameter_handler,
209 unsigned int max_criteria) const
210{
211 parameter_handler.declare_entry("read initial conditions from file",
212 "false",
213 dealii::Patterns::Bool(),
214 "Whether to read any initial conditions from file.");
215
216 for (unsigned int i = 0; i < max_criteria; i++)
217 {
218 parameter_handler.enter_subsection("initial condition file " + std::to_string(i));
219 {
220 parameter_handler.declare_entry("file name",
221 "",
222 dealii::Patterns::Anything(),
223 "The file name to load from for each variable.");
224 parameter_handler.declare_entry("dataset format",
225 "vtk_unstructured_grid",
226 dealii::Patterns::Anything(),
227 "The type of grid in the file.");
228 parameter_handler.declare_entry("file variable names",
229 "",
230 dealii::Patterns::List(
231 dealii::Patterns::Anything()),
232 "The name of the variable in the file.");
233 parameter_handler.declare_entry("simulation variable names",
234 "",
235 dealii::Patterns::List(
236 dealii::Patterns::Anything()),
237 "The name of the variable in the file.");
238 parameter_handler.declare_entry(
239 "data points in x direction",
240 "-1",
241 dealii::Patterns::Integer(-1, INT_MAX),
242 "The number of data points of the input file in the x direction.");
243 parameter_handler.declare_entry(
244 "data points in y direction",
245 "-1",
246 dealii::Patterns::Integer(-1, INT_MAX),
247 "The number of data points of the input file in the y direction.");
248 parameter_handler.declare_entry(
249 "data points in z direction",
250 "-1",
251 dealii::Patterns::Integer(-1, INT_MAX),
252 "The number of data points of the input file in the z direction.");
253 }
254 parameter_handler.leave_subsection();
255 }
256}
257
258inline void
260 dealii::ParameterHandler &parameter_handler,
261 unsigned int max_criteria)
262{
264 parameter_handler.get_bool("read initial conditions from file"));
265 static std::array<std::string, 3> axis_labels = {
266 {"x", "y", "z"}
267 };
268 for (unsigned int i = 0; i < max_criteria; i++)
269 {
270 parameter_handler.enter_subsection("initial condition file " + std::to_string(i));
271 {
272 // Check if the file is specified
273 if (!parameter_handler.get("file name").empty())
274 {
275 // Create the LoadICFile object
276 InitialConditionFile ic_file;
277 ic_file.filename = parameter_handler.get("file name");
278 const std::string type_string = parameter_handler.get("dataset format");
279 bool found_type = false;
280 for (unsigned int j = 0;
281 j < static_cast<unsigned int>(DataFormatType::LastEntry);
282 j++)
283 {
284 if (boost::iequals(type_string,
285 to_string(static_cast<DataFormatType>(j))))
286 {
287 ic_file.dataset_format = static_cast<DataFormatType>(j);
288 found_type = true;
289 break;
290 }
291 }
292 AssertThrow(found_type,
293 dealii::ExcMessage("Unsupported dataset format: " + type_string));
294 ic_file.file_variable_names = dealii::Utilities::split_string_list(
295 parameter_handler.get("file variable names"));
296 ic_file.simulation_variable_names = dealii::Utilities::split_string_list(
297 parameter_handler.get("simulation variable names"));
298 // Defaults to 0 for unused dimensions/cases that don't require it
299 for (unsigned int k = 0; k < 3; ++k)
300 {
301 ic_file.n_data_points.at(k) =
302 static_cast<unsigned int>(parameter_handler.get_integer(
303 "data points in " + axis_labels.at(k) + " direction"));
304 }
306 }
307 }
308 parameter_handler.leave_subsection();
309 }
310}
311
312PRISMS_PF_END_NAMESPACE
static dealii::ConditionalOStream & pout_summary()
Log output stream for writing a summary.log file.
Definition conditional_ostreams.cc:35
Definition conditional_ostreams.cc:20
Struct that store the read-in information for a single file.
Definition load_initial_condition_parameters.h:28
std::vector< std::string > simulation_variable_names
Definition load_initial_condition_parameters.h:39
std::array< dealii::types::global_dof_index, 3 > n_data_points
Definition load_initial_condition_parameters.h:42
std::vector< std::string > file_variable_names
Definition load_initial_condition_parameters.h:36
DataFormatType dataset_format
Definition load_initial_condition_parameters.h:33
std::string filename
Definition load_initial_condition_parameters.h:30
Struct that stores relevant load initial condition information.
Definition load_initial_condition_parameters.h:51
void postprocess_and_validate()
Postprocess and validate parameters.
Definition load_initial_condition_parameters.h:151
bool read_initial_conditions_from_file
Definition load_initial_condition_parameters.h:144
unsigned int get_n_initial_condition_files() const
Get the number of initial condition files.
Definition load_initial_condition_parameters.h:114
void print_parameter_summary() const
Print parameters to summary.log.
Definition load_initial_condition_parameters.h:167
static constexpr unsigned int max_files
Maximum number of initial condition files.
Definition load_initial_condition_parameters.h:56
std::vector< InitialConditionFile > ic_files
Definition load_initial_condition_parameters.h:147
void add_initial_condition_file(InitialConditionFile _ic_file)
Add a initial condition file.
Definition load_initial_condition_parameters.h:102
const std::vector< InitialConditionFile > & get_initial_condition_files() const
Get the initial condition files.
Definition load_initial_condition_parameters.h:123
void declare_parameters(dealii::ParameterHandler &parameter_handler, unsigned int max_criteria=5) const
Declare the parameters to be read from an input file.
Definition load_initial_condition_parameters.h:207
bool get_read_initial_conditions_from_file() const
Get the read initial conditions from file flag.
Definition load_initial_condition_parameters.h:93
void assign_parameters(dealii::ParameterHandler &parameter_handler, unsigned int max_criteria=5)
Assign the parameters read from an input file to this object.
Definition load_initial_condition_parameters.h:259
void set_read_initial_conditions_from_file(bool _read_initial_conditions_from_file)
Set the read initial conditions from file flag.
Definition load_initial_condition_parameters.h:84
void clear()
Clear the initial condition parameters.
Definition load_initial_condition_parameters.h:74
std::string to_string(ElasticityModel type)
Enum to string for ElasticityModel.
Definition type_enums.h:164
DataFormatType
Data formats for input initial conditions. LastEntry is used for loop bounds.
Definition type_enums.h:154
@ FlatBinary
Definition type_enums.h:156
@ LastEntry
Definition type_enums.h:157