Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cls_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(CLSBoundaryDuplicated,
18 types::boundary_id,
19 << "CLS 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 for the CLS.",
34 {},
36
37 prm.declare_entry("id",
38 Utilities::int_to_string(default_boundary_id, 2),
39 Patterns::List(Patterns::Integer()),
40 "Mesh id for boundary conditions");
41
42 Functions::ParsedFunction<dim> temporary_function;
43 prm.enter_subsection("dirichlet");
44 temporary_function.declare_parameters(prm);
45 prm.leave_subsection();
46
47 // Periodic boundary condition parameters for CLS physics
48 prm.declare_entry(
49 "periodic id",
50 "-1",
51 Patterns::Integer(),
52 "Mesh id for periodic face matching. Default entry is -1 to ensure that the periodic id is set by the user");
53
54 prm.declare_entry("periodic direction",
55 "0",
56 Patterns::Integer(),
57 "Direction for periodic boundary condition");
58 }
59
60 template <int dim>
61 void
63 ParameterHandler &prm,
64 const unsigned int number_of_boundary_conditions)
65 {
66 prm.enter_subsection("boundary conditions CLS");
67 {
68 prm.declare_entry("number",
69 "0",
70 Patterns::Integer(),
71 "Number of boundary conditions");
72 prm.declare_entry(
73 "time dependent",
74 "false",
75 Patterns::Bool(),
76 "Bool to define if the boundary condition is time-dependent");
77
78 for (unsigned int n = 0; n < number_of_boundary_conditions; n++)
79 {
80 prm.enter_subsection("bc " + std::to_string(n));
81 {
83 }
84 prm.leave_subsection();
85 }
86 }
87 prm.leave_subsection();
88 }
89
90 template <int dim>
91 void
93 {
94 // Parse the list of boundary ids
95 std::vector<types::boundary_id> boundary_ids =
97
98 // Check if the list contains at least one boundary id
99 AssertThrow(
100 boundary_ids.size() > 0,
101 ExcMessage(
102 "A boundary id has not been set for one of the CLS boundary conditions. Please ensure that the id is set for every boundary condition."));
103
104 // Loop through all boundary ids to ensure that they are all non-negative
105 // and unique
106 for (const auto boundary_id : boundary_ids)
107 {
108 AssertThrow(this->type.find(boundary_id) == this->type.end(),
109 CLSBoundaryDuplicated(boundary_id));
110
111 const CLSBoundaryType boundary_type =
112 string_to_enum<CLSBoundaryType>(prm.get("type"));
113 this->type[boundary_id] = boundary_type;
114 if (boundary_type == CLSBoundaryType::dirichlet)
115 {
116 prm.enter_subsection("dirichlet");
117 phase_indicator[boundary_id] =
118 std::make_shared<Functions::ParsedFunction<dim>>();
119 phase_indicator[boundary_id]->parse_parameters(prm);
120 prm.leave_subsection();
121 }
122 else if (boundary_type == CLSBoundaryType::periodic)
123 {
124 types::boundary_id periodic_boundary_id =
125 prm.get_integer("periodic id");
126
127 // We attribute a periodic neighbor boundary type to the neighbor
128 // boundary to ensure that all boundaries have a defined type
129 this->type[periodic_boundary_id] =
131
132 // We store the periodic id and direction
133 this->periodic_boundaries[boundary_id] = {
134 .neighbor_id = periodic_boundary_id,
135 .direction = static_cast<unsigned int>(
136 prm.get_integer("periodic direction"))};
137 }
138 }
139 }
140
141 template <int dim>
142 void
144 {
145 prm.enter_subsection("boundary conditions CLS");
146 {
147 this->number_of_boundary_conditions = prm.get_integer("number");
148 this->time_dependent = prm.get_bool("time dependent");
149
150 for (unsigned int n = 0; n < this->number_of_boundary_conditions; n++)
151 {
152 prm.enter_subsection("bc " + std::to_string(n));
153 {
154 parse_boundary(prm);
155 }
156 prm.leave_subsection();
157 }
158 }
159 prm.leave_subsection();
160 }
161
162 template class CLSBoundaryConditions<2>;
163 template class CLSBoundaryConditions<3>;
164} // namespace BoundaryConditions
std::map< types::boundary_id, CLSBoundaryType > type
This class manages the boundary conditions for CLS solver It introduces the boundary functions and de...
void declare_default_entry(ParameterHandler &prm, types::boundary_id default_boundary_id)
Declare the default parameters for one CLS boundary condition.
void parse_parameters(ParameterHandler &prm)
Parse the CLS boundary condition parameters.
void declare_parameters(ParameterHandler &prm, unsigned int number_of_boundary_conditions)
Declare the CLS boundary condition parameters.
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > phase_indicator
void parse_boundary(ParameterHandler &prm)
Parse the information for one CLS boundary condition.
DeclException1(CLSBoundaryDuplicated, types::boundary_id,<< "CLS boundary id: "<< arg1<< " has already been declared as a boundary condition")
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
const std::vector< CLSBoundaryType > cls_boundary_types