PRISMS-PF Manual
Loading...
Searching...
No Matches
constraint_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/parameter_handler.h>
7#include <deal.II/base/point.h>
8#include <deal.II/base/tensor.h>
9#include <deal.II/base/types.h>
10#include <deal.II/base/utilities.h>
11
12#include <boost/algorithm/string/predicate.hpp>
13
18#include <prismspf/core/types.h>
19
20#include <prismspf/config.h>
21
22#include <algorithm>
23#include <map>
24#include <string>
25#include <unordered_set>
26
28
43
47[[nodiscard]] inline std::string
48to_string(Condition boundary_type)
49{
50 switch (boundary_type)
51 {
53 return "Natural";
55 return "Dirichlet";
57 return "Neumann";
59 return "TimeDependentDirichlet";
61 return "TimeDependentNeumann";
63 return "UniformDirichlet";
65 return "UniformNeumann";
67 return "Periodic";
68 default:
69 return "UNKNOWN";
70 }
71}
72
76[[nodiscard]] inline Condition
77condition_from_string(const std::string &boundary_string)
78{
79 if (boundary_string == "Natural")
80 {
81 return Condition::Natural;
82 }
83 if (boundary_string == "Dirichlet")
84 {
86 }
87 if (boundary_string == "Neumann")
88 {
89 return Condition::Neumann;
90 }
91 if (boundary_string == "TimeDependentDirichlet")
92 {
94 }
95 if (boundary_string == "TimeDependentNeumann")
96 {
98 }
99 if (boundary_string == "UniformDirichlet")
100 {
102 }
103 if (boundary_string == "UniformNeumann")
104 {
106 }
107 if (boundary_string == "Periodic")
108 {
109 return Condition::Periodic;
110 }
111 AssertThrow(false, dealii::ExcMessage("Invalid boundary condition " + boundary_string));
112 return Condition::Natural;
113}
114
120{
121 // Map of boundary conditions and domain boundary for which they correspond to. For a
122 // simple geometry like a square the boundary ids are marked, in order, by x=0, x=max,
123 // y=0, y=max. More complex geometries can have somewhat arbitrary ordering, but will
124 // render some of our assertions moot.
125 std::map<unsigned int, Condition> conditions;
126
127 [[nodiscard]] bool
129 {
130 return std::any_of(conditions.begin(),
131 conditions.end(),
132 [](const auto &dir_cond)
133 {
134 return dir_cond.second == Condition::TimeDependentDirichlet ||
135 dir_cond.second == Condition::TimeDependentNeumann;
136 });
137 }
138};
139
140template <unsigned int dim>
142{
143 std::array<ComponentConditions, dim> component_constraints;
144
145 [[nodiscard]] bool
147 {
148 return std::any_of(component_constraints.begin(),
150 [](const ComponentConditions &comp)
151 {
152 return comp.has_time_dependent_bcs();
153 });
154 }
155};
156
160template <unsigned int dim>
162{
163public:
167 void
168 validate();
169
173 void
175
179 [[nodiscard]] bool
181 { // todo
182 return false;
183 }
184
188 void
189 declare_parameters(dealii::ParameterHandler &parameter_handler,
190 unsigned int max_criteria = 5) const;
191
195 void
196 assign_parameters(dealii::ParameterHandler &parameter_handler,
197 unsigned int max_criteria = 5);
198
199 // Map of boundary conditions. The first key is the field index.
200 std::unordered_map<std::string, FieldConstraints<dim>> boundary_condition_list;
201};
202
203template <unsigned int dim>
204inline void
208
209template <unsigned int dim>
210inline void
212{
214 << "================================================\n"
215 << " Boundary Parameters\n"
216 << "================================================\n";
217
218 for (const auto &[index, component_map] : boundary_condition_list)
219 {
220 // Todo
221 }
222
223 ConditionalOStreams::pout_summary() << "\n" << std::flush;
224}
225
226template <unsigned int dim>
227inline void
228BoundaryParameters<dim>::declare_parameters(dealii::ParameterHandler &parameter_handler,
229 unsigned int max_criteria) const
230{
231 for (unsigned int criterion_id = 0; criterion_id < max_criteria; criterion_id++)
232 {
233 std::string subsection_text =
234 "boundary conditions: " + std::to_string(criterion_id);
235 parameter_handler.enter_subsection(subsection_text);
236 {
237 parameter_handler.declare_entry(
238 "variables",
239 "",
240 dealii::Patterns::Anything(),
241 "The names of the fields that will use these constraints.");
242 parameter_handler.declare_entry("conditions",
243 "",
244 dealii::Patterns::Anything(),
245 "List of conditions.");
246 }
247 parameter_handler.leave_subsection();
248 }
249}
250
251template <unsigned int dim>
252inline void
253BoundaryParameters<dim>::assign_parameters(dealii::ParameterHandler &parameter_handler,
254 unsigned int max_criteria)
255{
256 static const std::vector<std::string> axis_labels = {"x", "y", "z"};
257 for (unsigned int criterion_id = 0; criterion_id < max_criteria; criterion_id++)
258 {
259 std::string subsection_text =
260 "boundary conditions: " + std::to_string(criterion_id);
261 parameter_handler.enter_subsection(subsection_text);
262 {
263 std::vector<std::string> field_names =
264 dealii::Utilities::split_string_list(parameter_handler.get("variables"));
265 std::vector<std::string> conditions_strings =
266 dealii::Utilities::split_string_list(parameter_handler.get("conditions"));
267
268 ComponentConditions component_conditions;
269 if (conditions_strings.size() == 1)
270 {
271 // all the same
272 for (unsigned int boundary_id = 0; boundary_id < 2 * dim; boundary_id++)
273 {
274 component_conditions.conditions[boundary_id] =
275 condition_from_string(conditions_strings[0]);
276 }
277 }
278 else
279 {
280 for (unsigned int boundary_id = 0; boundary_id < conditions_strings.size();
281 boundary_id++)
282 {
283 component_conditions.conditions[boundary_id] =
284 condition_from_string(conditions_strings[boundary_id]);
285 }
286 }
287
288 // Attach conditions to fields
289 for (const auto &field_comp_name : field_names)
290 {
291 int pos = field_comp_name.length() - 2;
292 const std::string end = field_comp_name.substr(pos > 0 ? pos : 0);
293 std::string field_name;
294 std::set<unsigned int> comps;
295 if (end == ":x")
296 {
297 comps = {0};
298 field_name = field_comp_name.substr(0, pos);
299 }
300 else if (end == ":y")
301 {
302 comps = {1};
303 field_name = field_comp_name.substr(0, pos);
304 }
305 else if (end == ":z")
306 {
307 comps = {2};
308 field_name = field_comp_name.substr(0, pos);
309 }
310 else
311 {
312 for (unsigned int comp = 0; comp < dim; ++comp)
313 {
314 comps.insert(comp);
315 }
316 field_name = field_comp_name;
317 }
318 for (unsigned int component : comps)
319 {
320 if (component < dim)
321 {
322 boundary_condition_list[field_name].component_constraints.at(
323 component) = component_conditions;
324 }
325 }
326 }
327 }
328 parameter_handler.leave_subsection();
329 }
330}
331
332PRISMS_PF_END_NAMESPACE
static dealii::ConditionalOStream & pout_summary()
Log output stream for writing a summary.log file.
Definition conditional_ostreams.cc:35
Condition condition_from_string(const std::string &boundary_string)
Enum to string for type.
Definition constraint_parameters.h:77
Condition
Condition of boundary condition.
Definition constraint_parameters.h:33
@ Neumann
Definition constraint_parameters.h:36
@ UniformDirichlet
Definition constraint_parameters.h:39
@ TimeDependentDirichlet
Definition constraint_parameters.h:37
@ Periodic
Definition constraint_parameters.h:41
@ Natural
Definition constraint_parameters.h:34
@ Dirichlet
Definition constraint_parameters.h:35
@ TimeDependentNeumann
Definition constraint_parameters.h:38
@ UniformNeumann
Definition constraint_parameters.h:40
std::string to_string(Condition boundary_type)
Enum to string for type.
Definition constraint_parameters.h:48
Definition conditional_ostreams.cc:20
Struct that holds boundary parameters.
Definition constraint_parameters.h:162
void declare_parameters(dealii::ParameterHandler &parameter_handler, unsigned int max_criteria=5) const
Declare the parameters to be read from an input file.
Definition constraint_parameters.h:228
void print_parameter_summary() const
Print parameters to summary.log.
Definition constraint_parameters.h:211
void assign_parameters(dealii::ParameterHandler &parameter_handler, unsigned int max_criteria=5)
Assign the parameters read from an input file to this object.
Definition constraint_parameters.h:253
void validate()
Postprocess and validate parameters.
Definition constraint_parameters.h:205
bool has_time_dependent_bcs() const
Whether there are time-dependent boundary conditions.
Definition constraint_parameters.h:180
std::unordered_map< std::string, FieldConstraints< dim > > boundary_condition_list
Definition constraint_parameters.h:200
Struct that stores relevant information for boundary conditions of a certain field.
Definition constraint_parameters.h:120
bool has_time_dependent_bcs() const
Definition constraint_parameters.h:128
std::map< unsigned int, Condition > conditions
Definition constraint_parameters.h:125
Definition constraint_parameters.h:142
bool has_time_dependent_bcs() const
Definition constraint_parameters.h:146
std::array< ComponentConditions, dim > component_constraints
Definition constraint_parameters.h:143