Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
time_harmonic_maxwell_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(TimeHarmonicMaxwellDuplicated,
18 types::boundary_id,
19 << "Time Harmonic Maxwell 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 prm,
32 "type",
34 "Type of boundary condition for Time Harmonic Maxwell equations.",
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 // Create a dummy TimeHarmonicMaxwellBoundaryFunctions object to
43 // declare the appropriate parameters for the relevant boundary conditions.
44 TimeHarmonicMaxwellBoundaryFunctions<dim> temporary_em_functions;
45
46 prm.enter_subsection("E x real part");
47 temporary_em_functions.e_x_real.declare_parameters(prm);
48 prm.leave_subsection();
49
50 prm.enter_subsection("E y real part");
51 temporary_em_functions.e_y_real.declare_parameters(prm);
52 prm.leave_subsection();
53
54 prm.enter_subsection("E z real part");
55 temporary_em_functions.e_z_real.declare_parameters(prm);
56 prm.leave_subsection();
57
58 prm.enter_subsection("E x imag part");
59 temporary_em_functions.e_x_imag.declare_parameters(prm);
60 prm.leave_subsection();
61
62 prm.enter_subsection("E y imag part");
63 temporary_em_functions.e_y_imag.declare_parameters(prm);
64 prm.leave_subsection();
65
66 prm.enter_subsection("E z imag part");
67 temporary_em_functions.e_z_imag.declare_parameters(prm);
68 prm.leave_subsection();
69
70 prm.enter_subsection("H x real part");
71 temporary_em_functions.h_x_real.declare_parameters(prm);
72 prm.leave_subsection();
73
74 prm.enter_subsection("H y real part");
75 temporary_em_functions.h_y_real.declare_parameters(prm);
76 prm.leave_subsection();
77
78 prm.enter_subsection("H z real part");
79 temporary_em_functions.h_z_real.declare_parameters(prm);
80 prm.leave_subsection();
81
82 prm.enter_subsection("H x imag part");
83 temporary_em_functions.h_x_imag.declare_parameters(prm);
84 prm.leave_subsection();
85
86 prm.enter_subsection("H y imag part");
87 temporary_em_functions.h_y_imag.declare_parameters(prm);
88 prm.leave_subsection();
89
90 prm.enter_subsection("H z imag part");
91 temporary_em_functions.h_z_imag.declare_parameters(prm);
92 prm.leave_subsection();
93
94 // Create a dummy object to declare the appropriate parameters for the
95 // relevant boundary conditions.
96 Functions::ParsedFunction<dim> temporary_function;
97
98 prm.enter_subsection("surface admittance real part");
99 temporary_function.declare_parameters(prm);
100 prm.leave_subsection();
101
102 prm.enter_subsection("surface admittance imag part");
103 temporary_function.declare_parameters(prm);
104 prm.leave_subsection();
105
106 prm.enter_subsection("excitation x real part");
107 temporary_function.declare_parameters(prm);
108 prm.leave_subsection();
109
110 prm.enter_subsection("excitation x imag part");
111 temporary_function.declare_parameters(prm);
112 prm.leave_subsection();
113
114 prm.enter_subsection("excitation y real part");
115 temporary_function.declare_parameters(prm);
116 prm.leave_subsection();
117
118 prm.enter_subsection("excitation y imag part");
119 temporary_function.declare_parameters(prm);
120 prm.leave_subsection();
121
122 prm.enter_subsection("excitation z real part");
123 temporary_function.declare_parameters(prm);
124 prm.leave_subsection();
125
126 prm.enter_subsection("excitation z imag part");
127 temporary_function.declare_parameters(prm);
128 prm.leave_subsection();
129 }
130
131 template <int dim>
132 void
134 ParameterHandler &prm,
135 const unsigned int number_of_boundary_conditions)
136 {
137 prm.enter_subsection("boundary conditions time harmonic maxwell");
138 {
139 prm.declare_entry("number",
140 "0",
141 Patterns::Integer(),
142 "Number of boundary conditions");
143 prm.declare_entry(
144 "time dependent",
145 "false",
146 Patterns::Bool(),
147 "Bool to define if the boundary condition is time-dependent");
148
149 for (unsigned int n = 0; n < number_of_boundary_conditions; n++)
150 {
151 prm.enter_subsection("bc " + std::to_string(n));
152 {
153 declare_default_entry(prm, n);
154 }
155 prm.leave_subsection();
156 }
157 }
158 prm.leave_subsection();
159 }
160
161 template <int dim>
162 void
164 ParameterHandler &prm)
165 {
166 // Parse the list of boundary ids
167 std::vector<types::boundary_id> boundary_ids =
169
170 // Check if the list contains at least one boundary id
171 AssertThrow(
172 boundary_ids.size() > 0,
173 ExcMessage(
174 "A boundary id has not been set for one of the time harmonic maxwell boundary conditions. Please ensure that the id is set for every boundary condition."));
175
176 // Loop through all boundary ids to ensure that they are all non-negative
177 // and unique
178 for (const auto boundary_id : boundary_ids)
179 {
180 AssertThrow(this->type.find(boundary_id) == this->type.end(),
181 TimeHarmonicMaxwellDuplicated(boundary_id));
182
183 // Allocate the imposed electromagnetic field functions object for every
184 // boundary condition
185 imposed_electromagnetic_fields[boundary_id] =
186 std::make_shared<TimeHarmonicMaxwellBoundaryFunctions<dim>>();
187
188 prm.enter_subsection("E x real part");
189 imposed_electromagnetic_fields[boundary_id]->e_x_real.parse_parameters(
190 prm);
191 prm.leave_subsection();
192
193 prm.enter_subsection("E y real part");
194 imposed_electromagnetic_fields[boundary_id]->e_y_real.parse_parameters(
195 prm);
196 prm.leave_subsection();
197
198 prm.enter_subsection("E z real part");
199 imposed_electromagnetic_fields[boundary_id]->e_z_real.parse_parameters(
200 prm);
201 prm.leave_subsection();
202
203 prm.enter_subsection("E x imag part");
204 imposed_electromagnetic_fields[boundary_id]->e_x_imag.parse_parameters(
205 prm);
206 prm.leave_subsection();
207
208 prm.enter_subsection("E y imag part");
209 imposed_electromagnetic_fields[boundary_id]->e_y_imag.parse_parameters(
210 prm);
211 prm.leave_subsection();
212
213 prm.enter_subsection("E z imag part");
214 imposed_electromagnetic_fields[boundary_id]->e_z_imag.parse_parameters(
215 prm);
216 prm.leave_subsection();
217
218 prm.enter_subsection("H x real part");
219 imposed_electromagnetic_fields[boundary_id]->h_x_real.parse_parameters(
220 prm);
221 prm.leave_subsection();
222
223 prm.enter_subsection("H y real part");
224 imposed_electromagnetic_fields[boundary_id]->h_y_real.parse_parameters(
225 prm);
226 prm.leave_subsection();
227
228 prm.enter_subsection("H z real part");
229 imposed_electromagnetic_fields[boundary_id]->h_z_real.parse_parameters(
230 prm);
231 prm.leave_subsection();
232
233 prm.enter_subsection("H x imag part");
234 imposed_electromagnetic_fields[boundary_id]->h_x_imag.parse_parameters(
235 prm);
236 prm.leave_subsection();
237
238 prm.enter_subsection("H y imag part");
239 imposed_electromagnetic_fields[boundary_id]->h_y_imag.parse_parameters(
240 prm);
241 prm.leave_subsection();
242
243 prm.enter_subsection("H z imag part");
244 imposed_electromagnetic_fields[boundary_id]->h_z_imag.parse_parameters(
245 prm);
246 prm.leave_subsection();
247
248 /// The following functions are parsed individually because they will be
249 /// used for Robin boundary conditions and will not be applied on the
250 /// global solution vector.
251 prm.enter_subsection("surface admittance real part");
252 this->surface_admittance_real[boundary_id] =
253 std::make_shared<Functions::ParsedFunction<dim>>();
254 this->surface_admittance_real[boundary_id]->parse_parameters(prm);
255 prm.leave_subsection();
256
257 prm.enter_subsection("surface admittance imag part");
258 this->surface_admittance_imag[boundary_id] =
259 std::make_shared<Functions::ParsedFunction<dim>>();
260 this->surface_admittance_imag[boundary_id]->parse_parameters(prm);
261 prm.leave_subsection();
262
263 prm.enter_subsection("excitation x real part");
264 this->excitation_x_real[boundary_id] =
265 std::make_shared<Functions::ParsedFunction<dim>>();
266 this->excitation_x_real[boundary_id]->parse_parameters(prm);
267 prm.leave_subsection();
268
269 prm.enter_subsection("excitation y real part");
270 this->excitation_y_real[boundary_id] =
271 std::make_shared<Functions::ParsedFunction<dim>>();
272 this->excitation_y_real[boundary_id]->parse_parameters(prm);
273 prm.leave_subsection();
274
275 prm.enter_subsection("excitation z real part");
276 this->excitation_z_real[boundary_id] =
277 std::make_shared<Functions::ParsedFunction<dim>>();
278 this->excitation_z_real[boundary_id]->parse_parameters(prm);
279 prm.leave_subsection();
280
281 prm.enter_subsection("excitation x imag part");
282 this->excitation_x_imag[boundary_id] =
283 std::make_shared<Functions::ParsedFunction<dim>>();
284 this->excitation_x_imag[boundary_id]->parse_parameters(prm);
285 prm.leave_subsection();
286
287 prm.enter_subsection("excitation y imag part");
288 this->excitation_y_imag[boundary_id] =
289 std::make_shared<Functions::ParsedFunction<dim>>();
290 this->excitation_y_imag[boundary_id]->parse_parameters(prm);
291 prm.leave_subsection();
292
293 prm.enter_subsection("excitation z imag part");
294 this->excitation_z_imag[boundary_id] =
295 std::make_shared<Functions::ParsedFunction<dim>>();
296 this->excitation_z_imag[boundary_id]->parse_parameters(prm);
297 prm.leave_subsection();
298
299 // Establish the type of boundary condition
300 this->type[boundary_id] =
302 prm.get("type"),
304 "type");
305 }
306 }
307
308 template <int dim>
309 void
311 ParameterHandler &prm)
312 {
313 prm.enter_subsection("boundary conditions time harmonic maxwell");
314 {
315 this->number_of_boundary_conditions = prm.get_integer("number");
316 this->time_dependent = prm.get_bool("time dependent");
317
318 for (unsigned int n = 0; n < this->number_of_boundary_conditions; n++)
319 {
320 prm.enter_subsection("bc " + std::to_string(n));
321 {
322 parse_boundary(prm);
323 }
324 prm.leave_subsection();
325 }
326 }
327 prm.leave_subsection();
328 }
329
332} // namespace BoundaryConditions
333
334
335template <int dim>
336double
338 const Point<dim> &point,
339 const unsigned int component) const
340{
341 Assert(component < this->n_components,
342 ExcIndexRange(component, 0, this->n_components));
343
344 if (component == 0)
345 {
346 return e_x_real->value(point);
347 }
348 if (component == 1)
349 {
350 return e_y_real->value(point);
351 }
352 if (component == 2)
353 {
354 return e_z_real->value(point);
355 }
356 if (component == 3)
357 {
358 return e_x_imag->value(point);
359 }
360 if (component == 4)
361 {
362 return e_y_imag->value(point);
363 }
364 if (component == 5)
365 {
366 return e_z_imag->value(point);
367 }
368 return 0.;
369}
370
371
372template <int dim>
373double
375 const Point<dim> &point,
376 const unsigned int component) const
377{
378 Assert(component < this->n_components,
379 ExcIndexRange(component, 0, this->n_components));
380
381 if (component == 6)
382 {
383 return h_x_real->value(point);
384 }
385 if (component == 7)
386 {
387 return h_y_real->value(point);
388 }
389 if (component == 8)
390 {
391 return h_z_real->value(point);
392 }
393 if (component == 9)
394 {
395 return h_x_imag->value(point);
396 }
397 if (component == 10)
398 {
399 return h_y_imag->value(point);
400 }
401 if (component == 11)
402 {
403 return h_z_imag->value(point);
404 }
405 return 0.;
406}
407
std::map< types::boundary_id, TimeHarmonicMaxwellBoundaryType > type
This class manages the boundary conditions for Time Harmonic Maxwell solver. It introduces the bounda...
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > surface_admittance_imag
void declare_default_entry(ParameterHandler &prm, types::boundary_id default_boundary_id)
Declare the default parameters for one time-harmonic Maxwell boundary condition.
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_y_imag
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_z_imag
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_z_real
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_y_real
void declare_parameters(ParameterHandler &prm, unsigned int number_of_boundary_conditions)
Declare the Time Harmonic Maxwell boundary conditions.
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_x_real
Excitation.
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > excitation_x_imag
void parse_parameters(ParameterHandler &prm)
Parse the Time Harmonic Maxwell boundary conditions.
std::map< types::boundary_id, std::shared_ptr< TimeHarmonicMaxwellBoundaryFunctions< dim > > > imposed_electromagnetic_fields
void parse_boundary(ParameterHandler &prm)
Parse the information for one time-harmonic Maxwell boundary condition.
std::map< types::boundary_id, std::shared_ptr< Functions::ParsedFunction< dim > > > surface_admittance_real
This class manages the functions associated with both imposed electric and magnetic fields boundary c...
Functions::ParsedFunction< dim > h_x_real
Magnetic field components.
This class implements a boundary condition type for the Time Harmonic Maxwell equation where the elec...
double value(const Point< dim > &point, const unsigned int component) const override
Calculates the value of an imposed electric field equations.
This class implements a boundary condition type for the Time Harmonic Maxwell equation where the magn...
double value(const Point< dim > &point, const unsigned int component) const override
Calculates the value of an imposed magnetic field 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
const DeprecatedEnumNames< TimeHarmonicMaxwellBoundaryType > deprecated_time_harmonic_maxwell_boundary_type_names
DeclException1(TimeHarmonicMaxwellDuplicated, types::boundary_id,<< "Time Harmonic Maxwell boundary id: "<< arg1<< " has already been declared as a boundary condition")