Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
fluid_dynamics_boundary_conditions.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 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
7#include <deal.II/base/parameter_handler.h>
8#include <deal.II/base/parsed_function.h>
9#include <deal.II/base/patterns.h>
10
11#include <memory>
12#include <string>
13#include <vector>
14
15using namespace dealii;
16
17DeclException1(NavierStokesBoundaryDuplicated,
18 types::boundary_id,
19 << "Fluid dynamics boundary id: " << arg1
20 << " has already been declared as a boundary condition");
21
22namespace BoundaryConditions
23{
24 template <int dim>
25 void
27 ParameterHandler &prm,
28 const types::boundary_id default_boundary_id)
29 {
31 "type",
33 "Type of boundary condition.",
36
37 prm.declare_entry("id",
38 Utilities::to_string(default_boundary_id, 2),
39 Patterns::List(Patterns::Integer()),
40 "Mesh id for boundary conditions.");
41
42 prm.declare_entry(
43 "periodic id",
44 "-1",
45 Patterns::Integer(),
46 "Mesh id for periodic face matching. Default entry is -1 to ensure that the periodic id is set by the user");
47
48 prm.declare_entry("periodic direction",
49 "0",
50 Patterns::Integer(),
51 "Direction for periodic boundary condition");
52
53 // Create a dummy NavierStokesBoundaryFunctions object to declare the
54 // appropriate parameters for this boundary condition.
55 NavierStokesBoundaryFunctions<dim> temporary_fluid_dynamics_functions;
56
57 prm.enter_subsection("u");
58 temporary_fluid_dynamics_functions.u.declare_parameters(prm);
59 prm.leave_subsection();
60
61 prm.enter_subsection("v");
62 temporary_fluid_dynamics_functions.v.declare_parameters(prm);
63 prm.leave_subsection();
64
65 prm.enter_subsection("w");
66 temporary_fluid_dynamics_functions.w.declare_parameters(prm);
67 prm.leave_subsection();
68
69 prm.enter_subsection("p");
70 temporary_fluid_dynamics_functions.p.declare_parameters(prm);
71 prm.leave_subsection();
72
73 /*
74 Vector-valued function for the traction with dim components for the
75 traction vector and 1 component for the pressure value at the boundary
76 which is dummy and is needed to properly assemble the traction term as
77 FEFaceIntegrator uses MatrixFree which in turn is based on the DoFHandler
78 which in turn is based on the FE system that has dim velocity components
79 and 1 pressure component.
80 */
81
82 prm.enter_subsection("traction fn");
83 temporary_fluid_dynamics_functions.traction_fn.declare_parameters(prm,
84 dim + 1);
85 prm.leave_subsection();
86
87 // Center of rotation of the boundary condition for torque calculation
88 prm.enter_subsection("center of rotation");
89 prm.declare_entry("x", "0", Patterns::Double(), "X COR");
90 prm.declare_entry("y", "0", Patterns::Double(), "Y COR");
91 prm.declare_entry("z", "0", Patterns::Double(), "Z COR");
92 prm.leave_subsection();
93
94 prm.declare_entry(
95 "beta",
96 "1",
97 Patterns::Double(),
98 "Penalty parameter for weak boundary condition imposed through Nitsche's method or outlets");
99
100 prm.declare_entry(
101 "boundary layer thickness",
102 "0",
103 Patterns::Double(),
104 "Thickness of the boundary layer used to calculate the penalty parameter for partial slip boundary condition in tangent direction imposed through Nitsche's method or outlets");
105 }
106
107 template <int dim>
108 void
110 ParameterHandler &prm,
111 const unsigned int number_of_boundary_conditions)
112 {
113 prm.enter_subsection("boundary conditions");
114 {
115 prm.declare_entry("number",
116 Utilities::int_to_string(number_of_boundary_conditions),
117 Patterns::Integer(),
118 "Number of boundary conditions");
119 prm.declare_entry(
120 "time dependent",
121 "false",
122 Patterns::Bool(),
123 "Bool to define if the boundary condition is time dependent");
124
125 prm.declare_entry(
126 "fix pressure constant",
127 "false",
128 Patterns::Bool(),
129 "Bool to define if zero pressure is used as a constraint one node");
130
131 for (unsigned int n = 0; n < number_of_boundary_conditions; n++)
132 {
133 prm.enter_subsection("bc " + std::to_string(n));
134 {
135 declare_default_entry(prm, n);
136 }
137 prm.leave_subsection();
138 }
139 }
140 prm.leave_subsection();
141 }
142
143 template <int dim>
144 void
146 {
147 // Parse the list of boundary ids
148 std::vector<types::boundary_id> boundary_ids =
150
151 // Check if the list contains at least one boundary id
152 AssertThrow(
153 boundary_ids.size() > 0,
154 ExcMessage(
155 "A boundary id has not been set for one of the fluid dynamics boundary conditions. Please ensure that the id is set for every boundary condition."));
156
157 // and unique
158 for (const auto boundary_id : boundary_ids)
159 {
160 AssertThrow(this->type.find(boundary_id) == this->type.end(),
161 NavierStokesBoundaryDuplicated(boundary_id));
162
163 // Allocate the navier_stokes_functions object for every boundary
164 // condition to ensure that they have a defined function and a center of
165 // rotation.
166 navier_stokes_functions[boundary_id] =
167 std::make_shared<NavierStokesBoundaryFunctions<dim>>();
168
169 prm.enter_subsection("u");
170 navier_stokes_functions[boundary_id]->u.parse_parameters(prm);
171 prm.leave_subsection();
172
173 prm.enter_subsection("v");
174 navier_stokes_functions[boundary_id]->v.parse_parameters(prm);
175 prm.leave_subsection();
176
177 prm.enter_subsection("w");
178 navier_stokes_functions[boundary_id]->w.parse_parameters(prm);
179 prm.leave_subsection();
180
181 prm.enter_subsection("p");
182 navier_stokes_functions[boundary_id]->p.parse_parameters(prm);
183 prm.leave_subsection();
184
185 prm.enter_subsection("traction fn");
186 navier_stokes_functions[boundary_id]->traction_fn.parse_parameters(prm);
187 prm.leave_subsection();
188
189 prm.enter_subsection("center of rotation");
190 navier_stokes_functions[boundary_id]->center_of_rotation[0] =
191 prm.get_double("x");
192 navier_stokes_functions[boundary_id]->center_of_rotation[1] =
193 prm.get_double("y");
194
195 if (dim == 3)
196 navier_stokes_functions[boundary_id]->center_of_rotation[2] =
197 prm.get_double("z");
198 prm.leave_subsection();
199
200 // Establish the type of boundary condition
201 const FluidDynamicsBoundaryType boundary_type =
203 prm.get("type"),
205 "type");
206 this->type[boundary_id] = boundary_type;
207 if (boundary_type == FluidDynamicsBoundaryType::periodic)
208 {
209 types::boundary_id periodic_boundary_id =
210 prm.get_integer("periodic id");
211
212 this->type[boundary_id] = FluidDynamicsBoundaryType::periodic;
213
214 // We attribute a periodic neighbor boundary type to the neighbor
215 // boundary to ensure that all boundaries have a defined type
216 this->type[periodic_boundary_id] =
218
219 // We store the periodic id and direction
220 this->periodic_boundaries[boundary_id] = {
221 .neighbor_id = periodic_boundary_id,
222 .direction = static_cast<unsigned int>(
223 prm.get_integer("periodic direction"))};
224
225 // Allocate the navier_stokes_functions object for the periodic
226 // neighbor condition to ensure that they have a defined function
227 // and a center of rotation. Parse the information of the boundary
228 // id to duplicate it.
229 navier_stokes_functions[periodic_boundary_id] =
230 std::make_shared<NavierStokesBoundaryFunctions<dim>>();
231
232 prm.enter_subsection("u");
233 navier_stokes_functions[periodic_boundary_id]->u.parse_parameters(
234 prm);
235 prm.leave_subsection();
236
237 prm.enter_subsection("v");
238 navier_stokes_functions[periodic_boundary_id]->v.parse_parameters(
239 prm);
240 prm.leave_subsection();
241
242 prm.enter_subsection("w");
243 navier_stokes_functions[periodic_boundary_id]->w.parse_parameters(
244 prm);
245 prm.leave_subsection();
246
247 prm.enter_subsection("traction fn");
248 navier_stokes_functions[periodic_boundary_id]
249 ->traction_fn.parse_parameters(prm);
250 prm.leave_subsection();
251
252 prm.enter_subsection("p");
253 navier_stokes_functions[periodic_boundary_id]->p.parse_parameters(
254 prm);
255 prm.leave_subsection();
256
257 prm.enter_subsection("center of rotation");
258 navier_stokes_functions[periodic_boundary_id]
259 ->center_of_rotation[0] = prm.get_double("x");
260 navier_stokes_functions[periodic_boundary_id]
261 ->center_of_rotation[1] = prm.get_double("y");
262
263 if (dim == 3)
264 navier_stokes_functions[periodic_boundary_id]
265 ->center_of_rotation[2] = prm.get_double("z");
266 prm.leave_subsection();
267 }
268 this->beta[boundary_id] = prm.get_double("beta");
269 this->boundary_layer_thickness[boundary_id] =
270 prm.get_double("boundary layer thickness");
271 }
272 }
273
274 template <int dim>
275 void
277 {
278 prm.enter_subsection("boundary conditions");
279 {
280 this->number_of_boundary_conditions = prm.get_integer("number");
281 this->time_dependent = prm.get_bool("time dependent");
282 this->fix_pressure_constant = prm.get_bool("fix pressure constant");
283
284 for (unsigned int n = 0; n < this->number_of_boundary_conditions; n++)
285 {
286 prm.enter_subsection("bc " + std::to_string(n));
287 {
288 parse_boundary(prm);
289 }
290 prm.leave_subsection();
291 }
292 }
293 prm.leave_subsection();
294 }
295
298} // namespace BoundaryConditions
299
300template <int dim>
301double
303 const Point<dim> &point,
304 const unsigned int component) const
305{
306 Assert(component < this->n_components,
307 ExcIndexRange(component, 0, this->n_components));
308
309 if (component == 0)
310 {
311 return u->value(point);
312 }
313 if (component == 1)
314 {
315 return v->value(point);
316 }
317 if (component == 2)
318 {
319 return w->value(point);
320 }
321 return 0.;
322}
323
324template <int dim>
325double
327 const Point<dim> &point,
328 const unsigned int component) const
329{
330 if (std::cmp_equal(component, dim))
331 {
332 return p->value(point);
333 }
334 return 0.;
335}
336
std::map< types::boundary_id, FluidDynamicsBoundaryType > type
This class manages the boundary conditions forhe fluid dynamics solver It introduces the boundary fun...
void parse_boundary(ParameterHandler &prm)
Parse the information for one fluid dynamics boundary condition.
void declare_default_entry(ParameterHandler &prm, types::boundary_id default_boundary_id)
Declare the default parameters for one fluid dynamics boundary condition.
std::map< types::boundary_id, std::shared_ptr< NavierStokesBoundaryFunctions< dim > > > navier_stokes_functions
void parse_parameters(ParameterHandler &prm)
Parse the fluid dynamics boundary conditions.
void declare_parameters(ParameterHandler &prm, unsigned int number_of_boundary_conditions)
Declare the fluid dynamics boundary conditions.
This class manages the functions associated with function-type boundary conditions of the Navier-Stok...
This class implements a pressure boundary condition for the Navier-Stokes equations.
double value(const Point< dim > &point, unsigned int component) const override
Calculates the value of a Function-type fluid dynamics equations.
This class implements a boundary conditions for the fluid dynamics solver where the velocity componen...
double value(const Point< dim > &point, const unsigned int component) const override
Calculates the value of a Function-type fluid dynamics equations.
std::vector< T > convert_string_to_vector(const ParameterHandler &prm, const std::string &entry_string)
Return the vector of size N of entry @entry_string. If the entry is specified in the ....
Definition utilities.h:1330
EnumType string_to_enum(const std::string &name)
Return the enumerator whose identifier is name, e.g. to parse the value of a parameter entry into its...
Definition utilities.h:734
void declare_enum_entry(ParameterHandler &prm, const std::string &entry_name, const EnumType default_value, const std::string &description, const DeprecatedEnumNames< EnumType > &deprecated_names={}, const std::vector< EnumType > &allowed_values={})
Declare a parameter entry whose value is an enumerator. The default value, the accepted values and th...
Definition utilities.h:888
DeclException1(NavierStokesBoundaryDuplicated, types::boundary_id,<< "Fluid dynamics boundary id: "<< arg1<< " has already been declared as a boundary condition")
const DeprecatedEnumNames< FluidDynamicsBoundaryType > deprecated_fluid_dynamics_boundary_type_names
const std::vector< FluidDynamicsBoundaryType > fluid_dynamics_boundary_types