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) 2021 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_POISSON_SPATIAL_DISCRETIZATION_WEAK_BOUNDARY_CONDITIONS_H_
23#define EXADG_POISSON_SPATIAL_DISCRETIZATION_WEAK_BOUNDARY_CONDITIONS_H_
24
25// ExaDG
26#include <exadg/functions_and_boundary_conditions/evaluate_functions.h>
27#include <exadg/matrix_free/integrators.h>
28#include <exadg/operators/operator_type.h>
29
30namespace ExaDG
31{
32namespace Poisson
33{
34/*
35 * The following two functions calculate the interior_value/exterior_value
36 * depending on the operator type, the type of the boundary face
37 * and the given boundary conditions.
38 *
39 * +----------------------+--------------------+
40 * | Dirichlet boundaries | Neumann boundaries |
41 * +-------------------------+----------------------+--------------------+
42 * | full operator | phi⁺ = -phi⁻ + 2g | phi⁺ = phi⁻ |
43 * +-------------------------+----------------------+--------------------+
44 * | homogeneous operator | phi⁺ = -phi⁻ | phi⁺ = phi⁻ |
45 * +-------------------------+----------------------+--------------------+
46 * | inhomogeneous operator | phi⁻ = 0, phi⁺ = 2g | phi⁻ = 0, phi⁺ = 0 |
47 * +-------------------------+----------------------+--------------------+
48 */
49template<int dim, typename Number, int n_components, int rank>
50inline DEAL_II_ALWAYS_INLINE //
51 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>
52 calculate_interior_value(unsigned int const q,
53 FaceIntegrator<dim, n_components, Number> const & integrator,
54 OperatorType const & operator_type)
55{
56 if(operator_type == OperatorType::full or operator_type == OperatorType::homogeneous)
57 {
58 return integrator.get_value(q);
59 }
60 else if(operator_type == OperatorType::inhomogeneous)
61 {
62 return dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>();
63 }
64 else
65 {
66 AssertThrow(false, dealii::ExcMessage("Specified OperatorType is not implemented!"));
67 }
68
69 return dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>();
70}
71
72template<int dim, typename Number, int n_components, int rank>
73inline DEAL_II_ALWAYS_INLINE //
74 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>
75 calculate_exterior_value(
76 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> const & value_m,
77 unsigned int const q,
78 FaceIntegrator<dim, n_components, Number> const & integrator,
79 OperatorType const & operator_type,
80 BoundaryType const & boundary_type,
81 dealii::types::boundary_id const boundary_id,
82 std::shared_ptr<BoundaryDescriptor<rank, dim> const> boundary_descriptor,
83 double const & time)
84{
85 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> value_p;
86
87 if(boundary_type == BoundaryType::Dirichlet or boundary_type == BoundaryType::DirichletCached)
88 {
89 if(operator_type == OperatorType::full or operator_type == OperatorType::inhomogeneous)
90 {
91 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> g;
92
93 if(boundary_type == BoundaryType::Dirichlet)
94 {
95 auto bc = boundary_descriptor->dirichlet_bc.find(boundary_id)->second;
96 auto q_points = integrator.quadrature_point(q);
97
98 g = FunctionEvaluator<rank, dim, Number>::value(*bc, q_points, time);
99 }
100 else if(boundary_type == BoundaryType::DirichletCached)
101 {
102 auto bc = boundary_descriptor->get_dirichlet_cached_data();
103 g = FunctionEvaluator<rank, dim, Number>::value(*bc,
104 integrator.get_current_cell_index(),
105 q,
106 integrator.get_quadrature_index());
107 }
108 else
109 {
110 AssertThrow(false, dealii::ExcMessage("Not implemented."));
111 }
112
113 value_p = -value_m + dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>(2.0 * g);
114 }
115 else if(operator_type == OperatorType::homogeneous)
116 {
117 value_p = -value_m;
118 }
119 else
120 {
121 AssertThrow(false, dealii::ExcMessage("Specified OperatorType is not implemented!"));
122 }
123 }
124 else if(boundary_type == BoundaryType::Neumann)
125 {
126 value_p = value_m;
127 }
128 else
129 {
130 AssertThrow(false, dealii::ExcMessage("Boundary type of face is invalid or not implemented."));
131 }
132
133 return value_p;
134}
135
136// clang-format off
137 /*
138 * The following two functions calculate the interior/exterior gradient
139 * in normal direction depending on the operator type, the type of the boundary face
140 * and the given boundary conditions.
141 *
142 * +-----------------------------------------------+------------------------------------------------------+
143 * | Dirichlet boundaries | Neumann boundaries |
144 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
145 * | full operator | grad(phi⁺)*n = grad(phi⁻)*n | grad(phi⁺)*n = -grad(phi⁻)*n + 2h |
146 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
147 * | homogeneous operator | grad(phi⁺)*n = grad(phi⁻)*n | grad(phi⁺)*n = -grad(phi⁻)*n |
148 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
149 * | inhomogeneous operator | grad(phi⁺)*n = grad(phi⁻)*n, grad(phi⁻)*n = 0 | grad(phi⁺)*n = -grad(phi⁻)*n + 2h, grad(phi⁻)*n = 0 |
150 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
151 *
152 * +-----------------------------------------------+------------------------------------------------------+
153 * | Dirichlet boundaries | Neumann boundaries |
154 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
155 * | full operator | {{grad(phi)}}*n = grad(phi⁻)*n | {{grad(phi)}}*n = h |
156 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
157 * | homogeneous operator | {{grad(phi)}}*n = grad(phi⁻)*n | {{grad(phi)}}*n = 0 |
158 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
159 * | inhomogeneous operator | {{grad(phi)}}*n = 0 | {{grad(phi)}}*n = h |
160 * +-------------------------+-----------------------------------------------+------------------------------------------------------+
161 */
162// clang-format on
163template<int dim, typename Number, int n_components, int rank>
164inline DEAL_II_ALWAYS_INLINE //
165 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>
166 calculate_interior_normal_gradient(unsigned int const q,
167 FaceIntegrator<dim, n_components, Number> const & integrator,
168 OperatorType const & operator_type)
169{
170 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> normal_gradient_m;
171
172 if(operator_type == OperatorType::full or operator_type == OperatorType::homogeneous)
173 {
174 normal_gradient_m = integrator.get_normal_derivative(q);
175 }
176 else if(operator_type == OperatorType::inhomogeneous)
177 {
178 // do nothing (normal_gradient_m already initialized with 0.0)
179 }
180 else
181 {
182 AssertThrow(false, dealii::ExcMessage("Specified OperatorType is not implemented!"));
183 }
184
185 return normal_gradient_m;
186}
187
188template<int dim, typename Number, int n_components, int rank>
189inline DEAL_II_ALWAYS_INLINE //
190 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>
191 calculate_exterior_normal_gradient(
192 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> const & normal_gradient_m,
193 unsigned int const q,
194 FaceIntegrator<dim, n_components, Number> const & integrator,
195 OperatorType const & operator_type,
196 BoundaryType const & boundary_type,
197 dealii::types::boundary_id const boundary_id,
198 std::shared_ptr<BoundaryDescriptor<rank, dim> const> boundary_descriptor,
199 double const & time)
200{
201 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> normal_gradient_p;
202
203 if(boundary_type == BoundaryType::Dirichlet or boundary_type == BoundaryType::DirichletCached)
204 {
205 normal_gradient_p = normal_gradient_m;
206 }
207 else if(boundary_type == BoundaryType::Neumann)
208 {
209 if(operator_type == OperatorType::full or operator_type == OperatorType::inhomogeneous)
210 {
211 auto bc = boundary_descriptor->neumann_bc.find(boundary_id)->second;
212 auto q_points = integrator.quadrature_point(q);
213
214 auto h = FunctionEvaluator<rank, dim, Number>::value(*bc, q_points, time);
215
216 normal_gradient_p =
217 -normal_gradient_m + dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>(2.0 * h);
218 }
219 else if(operator_type == OperatorType::homogeneous)
220 {
221 normal_gradient_p = -normal_gradient_m;
222 }
223 else
224 {
225 AssertThrow(false, dealii::ExcMessage("Specified OperatorType is not implemented!"));
226 }
227 }
228 else
229 {
230 AssertThrow(false, dealii::ExcMessage("Boundary type of face is invalid or not implemented."));
231 }
232
233 return normal_gradient_p;
234}
235
236/*
237 * This function calculates the Neumann boundary value and is required in case of continuous
238 * Galerkin discretizations.
239 */
240template<int dim, typename Number, int n_components, int rank>
241inline DEAL_II_ALWAYS_INLINE //
242 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>>
243 calculate_neumann_value(unsigned int const q,
244 FaceIntegrator<dim, n_components, Number> const & integrator,
245 BoundaryType const & boundary_type,
246 dealii::types::boundary_id const boundary_id,
247 std::shared_ptr<BoundaryDescriptor<rank, dim> const> boundary_descriptor,
248 double const & time)
249{
250 dealii::Tensor<rank, dim, dealii::VectorizedArray<Number>> normal_gradient;
251
252 if(boundary_type == BoundaryType::Neumann)
253 {
254 auto bc = boundary_descriptor->neumann_bc.find(boundary_id)->second;
255 auto q_points = integrator.quadrature_point(q);
256
257 normal_gradient = FunctionEvaluator<rank, dim, Number>::value(*bc, q_points, time);
258 }
259 else
260 {
261 // do nothing
262
263 Assert(boundary_type == BoundaryType::Dirichlet or
264 boundary_type == BoundaryType::DirichletCached,
265 dealii::ExcMessage("Boundary type of face is invalid or not implemented."));
266 }
267
268 return normal_gradient;
269}
270
271} // namespace Poisson
272} // namespace ExaDG
273
274#endif /* EXADG_POISSON_SPATIAL_DISCRETIZATION_WEAK_BOUNDARY_CONDITIONS_H_ */
Definition driver.cpp:33
Definition boundary_descriptor.h:46