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