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 // Dirichlet
103 auto p_dyn = dealii::VectorizedArray<number>(0.);
104 for (unsigned int i = 0; i < dim; ++i)
105 p_dyn += w_m.momentum(i) * w_m.momentum(i);
106
107 p_dyn /= (w_m.density() * 2.);
108 const dealii::VectorizedArray<number> pressure =
109 get_boundary_value(boundary_id, BoundaryType::subsonic_outflow_fixed_pressure, q_point, 0);
110
111 // consider equation of state for computation of inner energy from given pressure
112 const dealii::VectorizedArray<number> inner_energy = w_m.inner_energy_from_pressure(pressure);
113
114 w_p.total_energy() = inner_energy + p_dyn;
115 w_p.grad_total_energy() = w_m.grad_total_energy();
116 }
117
118 template <int dim, typename number>
119 template <typename DofReadView, typename DofWriteView>
120 void
123 const dealii::types::boundary_id boundary_id,
124 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
125 DofReadView w_m,
126 DofWriteView w_p) const
127 {
128 // homogeneous Neumann
129 w_p.density() = w_m.density();
130 w_p.grad_density() = -(w_m.grad_density());
131 for (unsigned int i = 0; i < dim; ++i)
132 {
133 w_p.momentum(i) = w_m.momentum(i);
134 w_p.grad_momentum(i) = -(w_m.grad_momentum(i));
135 }
136
137 // Dirichlet
138 w_p.total_energy() =
139 get_boundary_value(boundary_id, BoundaryType::subsonic_outflow_fixed_energy, q_point, 0);
140 w_p.grad_total_energy() = w_m.grad_total_energy();
141 }
142
143 template <int dim, typename number>
144 template <typename DofReadView, typename DofWriteView>
145 void
148 const dealii::types::boundary_id boundary_id,
149 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
150 DofReadView w_m,
151 DofWriteView w_p) const
152 {
153 dealii::VectorizedArray<number> is_inflow =
154 get_boundary_value(boundary_id,
155 BoundaryType::combined_inflow_no_slip_wall,
156 q_point,
158
159 apply_inflow_boundary<DofReadView,
160 DofWriteView,
162 boundary_id, q_point, w_m, w_p, BoundaryType::combined_inflow_no_slip_wall);
163
164 auto inflow_density = w_p.density();
165 auto inflow_momentum = w_p.momentum();
166 auto inflow_energy = w_p.total_energy();
167
168 auto inflow_grad_density = w_p.grad_density();
169 auto inflow_grad_momentum = w_p.grad_momentum();
170 auto inflow_grad_energy = w_p.grad_total_energy();
171
172 apply_no_slip_wall_boundary(w_m, w_p);
173
174 auto apply_mask = [](auto mask, auto true_value, auto false_value) -> auto {
175 return dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
176 mask, dealii::VectorizedArray<number>(1.0), true_value, false_value);
177 };
178
179 w_p.density() = apply_mask(is_inflow, inflow_density, w_p.density());
180 for (unsigned int d = 0; d < dim; ++d)
181 w_p.grad_density()[d] = apply_mask(is_inflow, inflow_grad_density[d], w_p.grad_density()[d]);
182
183 w_p.total_energy() = apply_mask(is_inflow, inflow_energy, w_p.total_energy());
184 for (unsigned int d = 0; d < dim; ++d)
185 w_p.grad_total_energy()[d] =
186 apply_mask(is_inflow, inflow_grad_energy[d], w_p.grad_total_energy()[d]);
187
188 for (unsigned int d = 0; d < dim; ++d)
189 {
190 w_p.momentum(d) = apply_mask(is_inflow, inflow_momentum[d], w_p.momentum(d));
191 for (unsigned int d2 = 0; d2 < dim; ++d2)
192 w_p.grad_momentum(d)[d2] =
193 apply_mask(is_inflow, inflow_grad_momentum[d][d2], w_p.grad_momentum(d)[d2]);
194 }
195 }
196
197
198 template <int dim, typename number>
199 template <typename DofReadView, typename DofWriteView>
200 void
203 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
204 const dealii::Tensor<1, dim, dealii::VectorizedArray<number>> &normal,
205 dealii::types::boundary_id boundary_id,
206 const DofReadView &w_m,
207 const DofWriteView &w_p) const
208 {
209 if (const BoundaryType boundary_type = get_boundary_type(boundary_id);
210 boundary_type == BoundaryType::slip_wall)
211 {
212 apply_slip_wall_boundary(w_m, w_p, normal);
213 }
214 else if (boundary_type == BoundaryType::no_slip_wall)
215 {
216 apply_no_slip_wall_boundary(w_m, w_p);
217 }
218 else if (boundary_type == BoundaryType::inflow)
219 {
220 apply_inflow_boundary(boundary_id, q_point, w_m, w_p);
221 }
222 else if (boundary_type == BoundaryType::subsonic_outflow_fixed_pressure)
223 {
224 apply_subsonic_outflow_with_fixed_pressure_boundary(boundary_id, q_point, w_m, w_p);
225 }
226 else if (boundary_type == BoundaryType::subsonic_outflow_fixed_energy)
227 {
228 apply_subsonic_outflow_with_fixed_energy_boundary(boundary_id, q_point, w_m, w_p);
229 }
230 else if (boundary_type == BoundaryType::combined_inflow_no_slip_wall)
231 {
232 apply_combined_inflow_no_slip_wall_boundary(boundary_id, q_point, w_m, w_p);
233 }
234 else
235 {
236 std::cout << "ID: " << boundary_id << std::endl;
237 std::cout << "Condition:" << boundary_type << std::endl;
238 AssertThrow(false,
239 dealii::ExcMessage("Unknown boundary id, did "
240 "you set a boundary condition for "
241 "this part of the domain boundary?"));
242 }
243 }
244
245 template <int dim, typename number>
246 template <int n_species, typename DofReadView, typename DofWriteView>
247 void
250 const dealii::Point<dim, dealii::VectorizedArray<number>> &q_point,
251 dealii::types::boundary_id boundary_id,
252 const DofReadView &w_m,
253 const DofWriteView &w_p) const
254 {
255 if (const BoundaryType boundary_type = get_boundary_type(boundary_id);
256 boundary_type == BoundaryType::inflow)
257 {
258 // For inflow boundary conditions we assume that the partial densities are given and we set
259 // them as Dirichlet values.
260
261 // Remember for compressible flow we only need to prescribe n_species - 1 partial densities.
262 std::array<dealii::VectorizedArray<number>, n_species - 1> dirichlet_boundary_values;
263
264 for (unsigned int species = 0; species < n_species - 1; ++species)
265 {
266 dirichlet_boundary_values[species] =
267 get_boundary_value(boundary_id,
268 BoundaryType::inflow,
269 q_point,
270 CompressibleFlow::n_conserved_variables<dim, 1> + species);
271 }
272
273
275 w_p, w_m, SpeciesTransport::BoundaryConditionType::dirichlet, dirichlet_boundary_values);
276 }
277 else if (boundary_type == BoundaryType::combined_inflow_no_slip_wall)
278 {
280 get_boundary_value(boundary_id,
281 BoundaryType::combined_inflow_no_slip_wall,
282 q_point,
284
285 std::array<dealii::VectorizedArray<number>, n_species - 1> dirichlet_boundary_values;
286 for (unsigned int species = 0; species < n_species - 1; ++species)
287 {
288 dirichlet_boundary_values[species] =
289 get_boundary_value(boundary_id,
290 BoundaryType::combined_inflow_no_slip_wall,
291 q_point,
293 species);
294 }
295
297 w_p, w_m, SpeciesTransport::BoundaryConditionType::dirichlet, dirichlet_boundary_values);
298
299 std::vector<dealii::VectorizedArray<number>> w_p_partial_densities(n_species - 1);
300 for (unsigned int species = 0; species < n_species - 1; ++species)
301 w_p_partial_densities[species] = w_p.partial_density(species);
302
303 std::vector<dealii::Tensor<1, dim, dealii::VectorizedArray<number>>>
304 w_p_partial_density_gradients(n_species - 1);
305 for (unsigned int species = 0; species < n_species - 1; ++species)
306 w_p_partial_density_gradients[species] = w_p.grad_partial_density(species);
307
309 dealii::VectorizedArray<number>,
310 DofReadView,
311 DofWriteView>(
313
314 for (unsigned int species = 0; species < n_species - 1; ++species)
315 {
316 w_p.partial_density(species) =
317 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
318 mask,
319 dealii::VectorizedArray<number>(1.0),
320 w_p_partial_densities[species],
321 w_p.partial_density(species));
322
323 for (unsigned int d = 0; d < dim; ++d)
324 w_p.grad_partial_density(species)[d] =
325 dealii::compare_and_apply_mask<dealii::SIMDComparison::equal>(
326 mask,
327 dealii::VectorizedArray<number>(1.0),
328 w_p_partial_density_gradients[species][d],
329 w_p.grad_partial_density(species)[d]);
330 }
331 }
332 else
333 {
334 // For all other boundary conditions we assume homogeneous Neumann for the partial
335 // densities.
337 dealii::VectorizedArray<number>,
338 DofReadView,
339 DofWriteView>(
341 }
342 }
343} // 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:249
dealii::VectorizedArray< number > VectorizedArrayType
Definition boundary_conditions.hpp:100
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:122
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:147
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:202
BoundaryConditionType BoundaryType
Definition boundary_conditions.hpp:98
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