include/meltpooldg/compressible_flow/boundary_conditions.templates.hpp Source File

Developer Documentation: include/meltpooldg/compressible_flow/boundary_conditions.templates.hpp Source File
Developer Documentation
boundary_conditions.templates.hpp
Go to the documentation of this file.
1#include <deal.II/base/vectorization.h>
2
5
7{
8 template <int dim, typename number>
9 template <typename DofReadView, typename DofWriteView>
10 void
12 DofReadView w_m,
13 DofWriteView w_p,
14 const dealii::Tensor<1, dim, dealii::VectorizedArray<number>> &normal) const
15 {
16 // homogeneous Neumann
17 w_p.density() = w_m.density();
18 w_p.grad_density() = -(w_m.grad_density());
19
20 // homogeneous Neumann
21 VectorizedArrayType rho_u_dot_n = 0;
22 for (unsigned int d = 0; d < dim; ++d)
23 rho_u_dot_n += w_m.momentum(d) * normal[d];
24 // symmetry
25 for (unsigned int d = 0; d < dim; ++d)
26 {
27 w_p.momentum(d) = w_m.momentum(d) - 2. * rho_u_dot_n * normal[d];
28 w_p.grad_momentum(d) =
29 w_m.grad_momentum(d) - 2. * scalar_product(w_m.grad_momentum(d), normal) * normal;
30 }
31 // homogeneous Neumann
32 w_p.grad_total_energy() = -(w_m.grad_total_energy());
33 w_p.total_energy() = w_m.total_energy();
34 }
35
36 template <int dim, typename number>
37 template <typename DofReadView, typename DofWriteView>
38 void
40 DofReadView w_m,
41 DofWriteView w_p) const
42 {
43 // homogeneous Neumann
44 w_p.density() = w_m.density();
45 w_p.grad_density() = -(w_m.grad_density());
46
47 // Dirichlet
48 for (unsigned int d = 0; d < dim; ++d)
49 {
50 w_p.momentum(d) = 0.;
51 w_p.grad_momentum(d) = w_m.grad_momentum(d);
52 }
53 // homogeneous Neumann
54 w_p.grad_total_energy() = -(w_m.grad_total_energy());
55 w_p.total_energy() = w_m.total_energy();
56 }
57
58 template <int dim, typename number>
59 template <typename DofReadView, typename DofWriteView, typename DirichletValueInterpretation>
60 void
62 const dealii::types::boundary_id boundary_id,
63 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
64 DofReadView w_m,
65 DofWriteView w_p,
66 const BoundaryType bc_value_type) const
67 {
68 w_p.density() = get_boundary_value(boundary_id,
69 bc_value_type,
70 q_point,
71 DirichletValueInterpretation::density);
72 w_p.grad_density() = w_m.grad_density();
73
74 for (unsigned int d = 0; d < dim; ++d)
75 {
76 w_p.momentum(d) = get_boundary_value(boundary_id,
77 bc_value_type,
78 q_point,
79 DirichletValueInterpretation::velocity + d);
80 w_p.grad_momentum(d) = w_m.grad_momentum(d);
81 }
82
83 w_p.total_energy() =
84 get_boundary_value(boundary_id, bc_value_type, q_point, DirichletValueInterpretation::energy);
85 w_p.grad_total_energy() = w_m.grad_total_energy();
86 }
87
88 template <int dim, typename number>
89 template <typename DofReadView, typename DofWriteView>
90 void
93 const dealii::types::boundary_id boundary_id,
94 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
95 DofReadView w_m,
96 DofWriteView w_p) const
97 {
98 // homogeneous Neumann
99 w_p.density() = w_m.density();
100 w_p.grad_density() = -(w_m.grad_density());
101
102 for (unsigned int d = 0; d < dim; ++d)
103 {
104 w_p.momentum(d) = w_m.momentum(d);
105 w_p.grad_momentum(d) = -(w_m.grad_momentum(d));
106 }
107
108 // Dirichlet
109 auto p_dyn = dealii::VectorizedArray<number>(0.);
110 for (unsigned int i = 0; i < dim; ++i)
111 p_dyn += w_m.momentum(i) * w_m.momentum(i);
112
113 p_dyn /= (w_m.density() * 2.);
114 const dealii::VectorizedArray<number> pressure =
115 get_boundary_value(boundary_id, BoundaryType::subsonic_outflow_fixed_pressure, q_point, 0);
116
117 // consider equation of state for computation of inner energy from given pressure
118 const dealii::VectorizedArray<number> inner_energy = w_m.inner_energy_from_pressure(pressure);
119
120 w_p.total_energy() = inner_energy + p_dyn;
121 w_p.grad_total_energy() = w_m.grad_total_energy();
122 }
123
124 template <int dim, typename number>
125 template <typename DofReadView, typename DofWriteView>
126 void
129 const dealii::types::boundary_id boundary_id,
130 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
131 DofReadView w_m,
132 DofWriteView w_p) const
133 {
134 // homogeneous Neumann
135 w_p.density() = w_m.density();
136 w_p.grad_density() = -(w_m.grad_density());
137 for (unsigned int i = 0; i < dim; ++i)
138 {
139 w_p.momentum(i) = w_m.momentum(i);
140 w_p.grad_momentum(i) = -(w_m.grad_momentum(i));
141 }
142
143 // Dirichlet
144 w_p.total_energy() =
145 get_boundary_value(boundary_id, BoundaryType::subsonic_outflow_fixed_energy, q_point, 0);
146 w_p.grad_total_energy() = w_m.grad_total_energy();
147 }
148
149 template <int dim, typename number>
150 template <typename DofReadView, typename DofWriteView>
151 void
154 const dealii::types::boundary_id boundary_id,
155 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
156 DofReadView w_m,
157 DofWriteView w_p) const
158 {
159 dealii::VectorizedArray<number> is_inflow =
160 get_boundary_value(boundary_id,
161 BoundaryType::combined_inflow_no_slip_wall,
162 q_point,
164
165 apply_inflow_boundary<DofReadView,
166 DofWriteView,
168 boundary_id, q_point, w_m, w_p, BoundaryType::combined_inflow_no_slip_wall);
169
170 auto inflow_density = w_p.density();
171 auto inflow_momentum = w_p.momentum();
172 auto inflow_energy = w_p.total_energy();
173
174 auto inflow_grad_density = w_p.grad_density();
175 auto inflow_grad_momentum = w_p.grad_momentum();
176 auto inflow_grad_energy = w_p.grad_total_energy();
177
178 apply_no_slip_wall_boundary(w_m, w_p);
179
180 auto apply_mask = [](auto mask, auto true_value, auto false_value) -> auto {
181 return dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
182 mask, dealii::VectorizedArray<number>(1.0), true_value, false_value);
183 };
184
185 w_p.density() = apply_mask(is_inflow, inflow_density, w_p.density());
186 for (unsigned int d = 0; d < dim; ++d)
187 w_p.grad_density()[d] = apply_mask(is_inflow, inflow_grad_density[d], w_p.grad_density()[d]);
188
189 w_p.total_energy() = apply_mask(is_inflow, inflow_energy, w_p.total_energy());
190 for (unsigned int d = 0; d < dim; ++d)
191 w_p.grad_total_energy()[d] =
192 apply_mask(is_inflow, inflow_grad_energy[d], w_p.grad_total_energy()[d]);
193
194 for (unsigned int d = 0; d < dim; ++d)
195 {
196 w_p.momentum(d) = apply_mask(is_inflow, inflow_momentum[d], w_p.momentum(d));
197 for (unsigned int d2 = 0; d2 < dim; ++d2)
198 w_p.grad_momentum(d)[d2] =
199 apply_mask(is_inflow, inflow_grad_momentum[d][d2], w_p.grad_momentum(d)[d2]);
200 }
201 }
202
203
204 template <int dim, typename number>
205 template <typename DofReadView, typename DofWriteView>
206 void
209 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
210 const dealii::Tensor<1, dim, dealii::VectorizedArray<number>> &normal,
211 dealii::types::boundary_id boundary_id,
212 const DofReadView &w_m,
213 const DofWriteView &w_p) const
214 {
215 if (const BoundaryType boundary_type = get_boundary_type(boundary_id);
216 boundary_type == BoundaryType::slip_wall)
217 {
218 apply_slip_wall_boundary(w_m, w_p, normal);
219 }
220 else if (boundary_type == BoundaryType::no_slip_wall)
221 {
222 apply_no_slip_wall_boundary(w_m, w_p);
223 }
224 else if (boundary_type == BoundaryType::inflow)
225 {
226 apply_inflow_boundary(boundary_id, q_point, w_m, w_p);
227 }
228 else if (boundary_type == BoundaryType::subsonic_outflow_fixed_pressure)
229 {
230 apply_subsonic_outflow_with_fixed_pressure_boundary(boundary_id, q_point, w_m, w_p);
231 }
232 else if (boundary_type == BoundaryType::subsonic_outflow_fixed_energy)
233 {
234 apply_subsonic_outflow_with_fixed_energy_boundary(boundary_id, q_point, w_m, w_p);
235 }
236 else if (boundary_type == BoundaryType::combined_inflow_no_slip_wall)
237 {
238 apply_combined_inflow_no_slip_wall_boundary(boundary_id, q_point, w_m, w_p);
239 }
240 else
241 {
242 std::cout << "ID: " << boundary_id << std::endl;
243 std::cout << "Condition:" << boundary_type << std::endl;
244 AssertThrow(false,
245 dealii::ExcMessage("Unknown boundary id, did "
246 "you set a boundary condition for "
247 "this part of the domain boundary?"));
248 }
249 }
250
251 template <int dim, typename number>
252 template <int n_species, typename DofReadView, typename DofWriteView>
253 void
256 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
257 dealii::types::boundary_id boundary_id,
258 const DofReadView &w_m,
259 const DofWriteView &w_p) const
260 {
261 if (const BoundaryType boundary_type = get_boundary_type(boundary_id);
262 boundary_type == BoundaryType::inflow)
263 {
264 // For inflow boundary conditions we assume that the partial densities are given and we set
265 // them as Dirichlet values.
266
267 // Remember for compressible flow we only need to prescribe n_species - 1 partial densities.
268 std::array<dealii::VectorizedArray<number>, n_species - 1> dirichlet_boundary_values;
269
270 for (unsigned int species = 0; species < n_species - 1; ++species)
271 {
272 dirichlet_boundary_values[species] =
273 get_boundary_value(boundary_id,
274 BoundaryType::inflow,
275 q_point,
276 CompressibleFlow::n_conserved_variables<dim, 1> + species);
277 }
278
279
281 w_p, w_m, SpeciesTransport::BoundaryConditionType::dirichlet, dirichlet_boundary_values);
282 }
283 else if (boundary_type == BoundaryType::combined_inflow_no_slip_wall)
284 {
286 get_boundary_value(boundary_id,
287 BoundaryType::combined_inflow_no_slip_wall,
288 q_point,
290
291 std::array<dealii::VectorizedArray<number>, n_species - 1> dirichlet_boundary_values;
292 for (unsigned int species = 0; species < n_species - 1; ++species)
293 {
294 dirichlet_boundary_values[species] =
295 get_boundary_value(boundary_id,
296 BoundaryType::combined_inflow_no_slip_wall,
297 q_point,
299 species);
300 }
301
303 w_p, w_m, SpeciesTransport::BoundaryConditionType::dirichlet, dirichlet_boundary_values);
304
305 std::vector<dealii::VectorizedArray<number>> w_p_partial_densities(n_species - 1);
306 for (unsigned int species = 0; species < n_species - 1; ++species)
307 w_p_partial_densities[species] = w_p.partial_density(species);
308
309 std::vector<dealii::Tensor<1, dim, dealii::VectorizedArray<number>>>
310 w_p_partial_density_gradients(n_species - 1);
311 for (unsigned int species = 0; species < n_species - 1; ++species)
312 w_p_partial_density_gradients[species] = w_p.grad_partial_density(species);
313
315 dealii::VectorizedArray<number>,
316 DofReadView,
317 DofWriteView>(
319
320 for (unsigned int species = 0; species < n_species - 1; ++species)
321 {
322 w_p.partial_density(species) =
323 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
324 mask,
325 dealii::VectorizedArray<number>(1.0),
326 w_p_partial_densities[species],
327 w_p.partial_density(species));
328
329 for (unsigned int d = 0; d < dim; ++d)
330 w_p.grad_partial_density(species)[d] =
331 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
332 mask,
333 dealii::VectorizedArray<number>(1.0),
334 w_p_partial_density_gradients[species][d],
335 w_p.grad_partial_density(species)[d]);
336 }
337 }
338 else
339 {
340 // For all other boundary conditions we assume homogeneous Neumann for the partial
341 // densities.
343 dealii::VectorizedArray<number>,
344 DofReadView,
345 DofWriteView>(
347 }
348 }
349} // namespace MeltPoolDG::CompressibleFlow
void set_partial_density_boundary_value_and_gradient(const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, dealii::types::boundary_id boundary_id, const DofReadView &w_m, const DofWriteView &w_p) const
Definition boundary_conditions.templates.hpp:255
dealii::VectorizedArray< number > VectorizedArrayType
Definition boundary_conditions.hpp:99
void apply_no_slip_wall_boundary(DofReadView w_m, DofWriteView w_p) const
Definition boundary_conditions.templates.hpp:39
void apply_subsonic_outflow_with_fixed_energy_boundary(const dealii::types::boundary_id boundary_id, const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, DofReadView w_m, DofWriteView w_p) const
Definition boundary_conditions.templates.hpp:128
void apply_inflow_boundary(const dealii::types::boundary_id boundary_id, const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, DofReadView w_m, DofWriteView w_p, const BoundaryType bc_value_type=BoundaryType::inflow) const
Definition boundary_conditions.templates.hpp:61
void apply_subsonic_outflow_with_fixed_pressure_boundary(const dealii::types::boundary_id boundary_id, const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, DofReadView w_m, DofWriteView w_p) const
Definition boundary_conditions.templates.hpp:92
void apply_slip_wall_boundary(DofReadView w_m, DofWriteView w_p, const dealii::Tensor< 1, dim, dealii::VectorizedArray< number > > &normal) const
Definition boundary_conditions.templates.hpp:11
void apply_combined_inflow_no_slip_wall_boundary(const dealii::types::boundary_id boundary_id, const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, DofReadView w_m, DofWriteView w_p) const
Definition boundary_conditions.templates.hpp:153
void set_conserved_variables_boundary_value_and_gradient(const dealii::Point< dim, dealii::VectorizedArray< number > > &q_point, const dealii::Tensor< 1, dim, dealii::VectorizedArray< number > > &normal, dealii::types::boundary_id boundary_id, const DofReadView &w_m, const DofWriteView &w_p) const
Definition boundary_conditions.templates.hpp:208
BoundaryConditionType BoundaryType
Definition boundary_conditions.hpp:97
This file contains various functions that can be used to set and evaluate boundary conditions for the...
Definition boundary_condition_functions.hpp:17
void set_boundary_value_and_gradient(const WritableDofView &w_p, const ReadOnlyDofView &w_m, const BoundaryConditionType boundary_type, const std::array< VectorizedArrayType, n_partial_densities > &dirichlet_boundary_values={})
Definition boundary_conditions.hpp:35
dealii::VectorizedArray< number, N > scalar_product(const dealii::VectorizedArray< number, N > &scalar, const dealii::Tensor< 1, 1, dealii::VectorizedArray< number, N > > &vec)
Definition dealii_tensor.hpp:60