ExaDG
Loading...
Searching...
No Matches
weak_boundary_conditions.h
1/* ______________________________________________________________________
2 *
3 * ExaDG - High-Order Discontinuous Galerkin for the Exa-Scale
4 *
5 * Copyright (C) 2023 by the ExaDG authors
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 * ______________________________________________________________________
20 */
21
22#ifndef EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SPATIAL_DISCRETIZATION_OPERATORS_WEAK_BOUNDARY_CONDITIONS_H_
23#define EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SPATIAL_DISCRETIZATION_OPERATORS_WEAK_BOUNDARY_CONDITIONS_H_
24
25#include <exadg/acoustic_conservation_equations/user_interface/boundary_descriptor.h>
26#include <exadg/functions_and_boundary_conditions/boundary_face_integrator_base.h>
27#include <exadg/functions_and_boundary_conditions/evaluate_functions.h>
28#include <exadg/matrix_free/integrators.h>
29
30namespace ExaDG
31{
32namespace Acoustics
33{
34// compute exterior pressure values for different boundary types
35template<int dim, typename Number>
36inline DEAL_II_ALWAYS_INLINE //
37 dealii::VectorizedArray<Number>
38 calculate_exterior_value_pressure(unsigned int const q,
39 FaceIntegrator<dim, 1, Number> const & pressure_m,
40 BoundaryType const & boundary_type,
41 dealii::types::boundary_id const boundary_id,
42 BoundaryDescriptor<dim> const & boundary_descriptor,
43 Number const time)
44{
45 if(boundary_type == BoundaryType::PressureDirichlet)
46 {
47 auto const g = FunctionEvaluator<0, dim, Number>::value(
48 *boundary_descriptor.pressure_dbc.find(boundary_id)->second,
49 pressure_m.quadrature_point(q),
50 time);
51 return -pressure_m.get_value(q) + Number{2.0} * g;
52 }
53 else if(boundary_type == BoundaryType::VelocityDirichlet or
54 boundary_type == BoundaryType::Admittance)
55 {
56 return pressure_m.get_value(q);
57 }
58 else
59 {
60 AssertThrow(false, dealii::ExcMessage("Boundary type of face is invalid or not implemented."));
61 }
62}
63
64// compute exterior velocity values for different boundary types
65template<int dim, typename Number>
66inline DEAL_II_ALWAYS_INLINE //
67 dealii::Tensor<1, dim, dealii::VectorizedArray<Number>>
68 calculate_exterior_value_velocity(unsigned int const q,
69 FaceIntegrator<dim, dim, Number> const & velocity_m,
70 FaceIntegrator<dim, 1, Number> const & pressure_m,
71 double const speed_of_sound,
72 BoundaryType const & boundary_type,
73 dealii::types::boundary_id const boundary_id,
74 BoundaryDescriptor<dim> const & boundary_descriptor,
75 Number const time)
76{
77 if(boundary_type == BoundaryType::VelocityDirichlet)
78 {
79 auto const g = FunctionEvaluator<1, dim, Number>::value(
80 *boundary_descriptor.velocity_dbc.find(boundary_id)->second,
81 velocity_m.quadrature_point(q),
82 time);
83 return -velocity_m.get_value(q) + Number{2.0} * g;
84 }
85 else if(boundary_type == BoundaryType::PressureDirichlet)
86 {
87 return velocity_m.get_value(q);
88 }
89 else if(boundary_type == BoundaryType::Admittance)
90 {
91 auto const Y = FunctionEvaluator<0, dim, Number>::value(
92 *boundary_descriptor.admittance_bc.find(boundary_id)->second,
93 velocity_m.quadrature_point(q),
94 time);
95
96 auto const n = velocity_m.normal_vector(q);
97 auto const rho_um = velocity_m.get_value(q);
98 auto const pm = pressure_m.get_value(q);
99
100 auto const rho_um_normal = (rho_um * n) * n;
101 auto const rho_um_tangential = rho_um - rho_um_normal;
102
103 // normal share of velocity
104 auto const rho_up_normal = (Number{2.0} * Y * pm / speed_of_sound) * n - rho_um_normal;
105
106 // tangential share of velocity stays the same (rho_up_tangential = rho_um_tangential)
107 return rho_up_normal + rho_um_tangential;
108 }
109 else
110 {
111 AssertThrow(false, dealii::ExcMessage("Boundary type of face is invalid or not implemented."));
112 }
113}
114
115
119template<int dim, typename Number>
120class BoundaryFaceIntegratorP : public BoundaryFaceIntegratorBase<BoundaryDescriptor<dim>, Number>
121{
122 using FaceIntegratorP = FaceIntegrator<dim, 1, Number>;
123
124public:
125 BoundaryFaceIntegratorP(FaceIntegratorP const & integrator_m_in,
126 BoundaryDescriptor<dim> const & boundary_descriptor_in)
127 : BoundaryFaceIntegratorBase<BoundaryDescriptor<dim>, Number>(integrator_m_in.get_matrix_free(),
128 boundary_descriptor_in),
129 integrator_m(integrator_m_in)
130 {
131 }
132
133 inline DEAL_II_ALWAYS_INLINE //
134 typename FaceIntegratorP::value_type
135 get_value(unsigned int const q) const
136 {
137 return calculate_exterior_value_pressure(q,
138 integrator_m,
139 this->boundary_type,
140 this->boundary_id,
141 this->boundary_descriptor,
142 this->evaluation_time);
143 }
144
145private:
146 FaceIntegratorP const & integrator_m;
147};
148
152template<int dim, typename Number>
153class BoundaryFaceIntegratorU : public BoundaryFaceIntegratorBase<BoundaryDescriptor<dim>, Number>
154{
155 using FaceIntegratorU = FaceIntegrator<dim, dim, Number>;
156 using FaceIntegratorP = FaceIntegrator<dim, 1, Number>;
157
158public:
159 BoundaryFaceIntegratorU(FaceIntegratorU const & integrator_velocity_m_in,
160 FaceIntegratorP const & integrator_pressure_m_in,
161 double const speed_of_sound,
162 BoundaryDescriptor<dim> const & boundary_descriptor_in)
164 integrator_velocity_m_in.get_matrix_free(),
165 boundary_descriptor_in),
166 integrator_velocity_m(integrator_velocity_m_in),
167 integrator_pressure_m(integrator_pressure_m_in),
168 c(speed_of_sound)
169 {
170 }
171
172 inline DEAL_II_ALWAYS_INLINE //
173 typename FaceIntegratorU::value_type
174 get_value(unsigned int const q) const
175 {
176 return calculate_exterior_value_velocity(q,
177 integrator_velocity_m,
178 integrator_pressure_m,
179 c,
180 this->boundary_type,
181 this->boundary_id,
182 this->boundary_descriptor,
183 this->evaluation_time);
184 }
185
186private:
187 FaceIntegratorU const & integrator_velocity_m;
188 FaceIntegratorP const & integrator_pressure_m;
189 double const c;
190};
191
192} // namespace Acoustics
193} // namespace ExaDG
194
195#endif /*EXADG_ACOUSTIC_CONSERVATION_EQUATIONS_SPATIAL_DISCRETIZATION_OPERATORS_WEAK_BOUNDARY_CONDITIONS_H_*/
Definition weak_boundary_conditions.h:121
Definition weak_boundary_conditions.h:154
Definition boundary_face_integrator_base.h:38
Definition driver.cpp:33
Definition boundary_descriptor.h:64