Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
characteristic.h
Go to the documentation of this file.
1
12#ifndef CHARACTERISTIC_H
13#define CHARACTERISTIC_H
14
15#include <Kokkos_Core.hpp>
16
17#include "boundary.h"
18#include "common.h"
19#include "gradient.h"
20
45 Kokkos::View<rtype *[N_DIM]> face_coords;
46 Kokkos::View<rtype *[N_DIM]> face_normals;
47 Kokkos::View<rtype *> face_area;
48 Kokkos::View<int32_t *[2]> cells_of_face;
49 Kokkos::View<rtype *[N_CONSERVATIVE]> W_cells;
50
53 void face_state(const uint32_t f, rtype * W) const {
55 }
56
58 void operator()(const uint32_t k) const {
59 constexpr uint8_t E = N_DIM + 1;
60 const uint32_t f = boundaries.char_faces(k);
65 face_state(f, W_f);
66
67 // Neighbors in the plane, and a point along the normal that sets the normal derivatives to zero
69 const rtype ell = (N_DIM == 2) ? face_area(f) : Kokkos::sqrt(face_area(f));
71 FOR_I_DIM dx_n[i] = ell * n[i];
72 lsq.add(dx_n, W_f, W_f);
74 if (n_neighbors + 1 < N_DIM || boundaries.char_edge(k)) {
75 for (uint8_t m = 0; m < 3; m++) boundaries.char_transverse(k, m) = 0.0_r;
76 return;
77 }
78 for (uint32_t j = boundaries.char_offsets(k); j < boundaries.char_offsets(k + 1); j++) {
82 const rtype dx_n_g = dot<N_DIM>(dx, n);
83 FOR_I_DIM dx[i] -= dx_n_g * n[i];
85 lsq.add(dx, W_f, W_g);
86 }
88 lsq.solve(g);
89
90 const rtype u_n = dot<N_DIM>(W_f + 1, n);
92 FOR_I_DIM u_t[i] = W_f[1 + i] - u_n * n[i];
94 FOR_I_DIM {
95 div_tangential += g[1 + i][i];
96 for (uint8_t j = 0; j < N_DIM; j++) {
97 div_tangential -= n[i] * g[1 + i][j] * n[j];
98 u_t_grad_u_n += n[i] * g[1 + i][j] * u_t[j];
99 }
100 }
104 }
105};
106
126 Kokkos::View<rtype *[N_DIM]> face_normals;
127 Kokkos::View<rtype **[2][N_CONSERVATIVE]> face_solution;
128 Kokkos::View<rtype **[2][2]> face_thermo; // Gas mixtures: [gamma, e0]; empty for a single gas
129 Kokkos::View<rtype *> quad_weights; // 2D
130 Kokkos::View<rtype **> face_weights; // 3D: (face, q)
133
135 void operator()(const uint32_t k) const {
136 using Relax = BoundaryCondition::Relax;
137 constexpr uint8_t E = N_DIM + 1;
138 const uint32_t f = boundaries.char_faces(k);
140 uint8_t n_quad;
141 if constexpr (N_DIM == 2) {
142 n_quad = static_cast<uint8_t>(quad_weights.extent(0));
143 } else {
144 n_quad = static_cast<uint8_t>(face_weights.extent(1));
145 }
146 rtype W[N_CONSERVATIVE] = {};
147 rtype gamma = 0.0_r, w_sum = 0.0_r;
148 for (uint8_t q = 0; q < n_quad; q++) {
149 rtype w;
150 if constexpr (N_DIM == 2) {
151 w = quad_weights(q);
152 } else {
153 w = face_weights(f, q);
154 }
155 if (w == 0.0_r) continue;
156 w_sum += w;
157 FOR_I_CONSERVATIVE W[i] += w * face_solution(f, q, 0, i);
158 gamma += w * (face_thermo.extent(0) > 0 ? face_thermo(f, q, 0, 0) : boundaries.gamma);
159 }
161 gamma /= w_sum;
162 rtype n[N_DIM], n_vec[N_DIM];
164 unit<N_DIM>(n_vec, n);
165
166 const rtype c2 = gamma * W[E] / W[0];
167 const rtype c = Kokkos::sqrt(c2);
168 const rtype Z = W[0] * c;
169 const rtype u_n = dot<N_DIM>(W + 1, n);
170 const rtype w_out = W[E] + Z * u_n;
171 if (initialize || u_n >= c) {
172 boundaries.char_state(k, 0) = W[E];
173 boundaries.char_state(k, 1) = u_n;
174 if (u_n >= c) return;
175 }
176 const bool inlet = bc.type == BoundaryType::NSCBC_INLET;
178 FOR_I_DIM {
181 }
182 if (inlet && u_n <= -c) {
183 boundaries.char_state(k, 0) = bc.data[E];
185 return;
186 }
188 const rtype p_b = 0.5_r * (w_out + w_in);
189 const rtype u_b = 0.5_r * (w_out - w_in) / Z;
190 const rtype M2 = dot<N_DIM>(W + 1, W + 1) / c2;
191 const rtype K = Kokkos::fmin(bc.relax[Relax::ACOUSTIC] * c * Kokkos::fmax(1.0_r - M2, 0.0_r), 1.0_r / dt);
192 const rtype relaxation = inlet ? K * Z * (u_b - dot<N_DIM>(u_target, n)) : -K * (p_b - bc.data[E]);
193 // None on reversed faces of outlets, which nothing leaves through
194 const rtype beta = (!inlet && u_n < 0.0_r) ? 0.0_r
195 : (bc.relax[Relax::BETA] < 0.0_r) ? Kokkos::fmin(Kokkos::sqrt(M2), 1.0_r)
196 : bc.relax[Relax::BETA];
199 w_in += dt * (relaxation - beta * T_in);
200 // A target that varies in time carries its own incoming wave, -Z du_n,t (Guezennec & Poinsot 2009)
201 if (inlet) w_in -= Z * dot<N_DIM>(du_target, n);
202 boundaries.char_state(k, 0) = 0.5_r * (w_out + w_in);
203 boundaries.char_state(k, 1) = 0.5_r * (w_out - w_in) / Z;
204 }
205};
206
207#endif // CHARACTERISTIC_H
Boundary conditions.
Common header file.
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
float rtype
Definition common_typedef.h:39
#define N_DIM
Definition common_typedef.h:28
#define FOR_I_CONSERVATIVE
Definition common_typedef.h:33
#define N_CONSERVATIVE
Definition common_typedef.h:29
#define FOR_I_DIM
Definition common_typedef.h:32
Cell gradient reconstruction.
Device-copyable boundary condition.
Definition boundary.h:97
Relax
Entries of relax: relaxation rates over the sound speed are sigma / L (1/length).
Definition boundary.h:99
Device-side lookup from faces to boundary conditions.
Definition boundary.h:229
Kokkos::View< rtype *[N_DIM]> char_target
Definition boundary.h:243
Kokkos::View< int32_t * > face_bc
Definition boundary.h:230
Kokkos::View< rtype *[3]> char_transverse
Definition boundary.h:241
Kokkos::View< rtype *[N_DIM]> char_target_next
Definition boundary.h:244
Kokkos::View< rtype *[2]> char_state
Definition boundary.h:242
Kokkos::View< uint32_t * > char_faces
Definition boundary.h:239
Kokkos::View< uint8_t * > char_edge
Definition boundary.h:248
Kokkos::View< rtype *[N_DIM]> char_neighbor_dx
Definition boundary.h:247
Kokkos::View< BoundaryCondition * > bcs
Definition boundary.h:249
rtype gamma
Definition boundary.h:250
Kokkos::View< uint32_t * > char_offsets
Definition boundary.h:245
Kokkos::View< uint32_t * > char_neighbors
Definition boundary.h:246
Advances the incoming acoustic wave w- = p - rho c u_n of every characteristic face by one forward-Eu...
Definition characteristic.h:124
BoundaryData boundaries
Definition characteristic.h:125
Kokkos::View< rtype **[2][N_CONSERVATIVE]> face_solution
Definition characteristic.h:127
bool initialize
Definition characteristic.h:132
Kokkos::View< rtype * > quad_weights
Definition characteristic.h:129
KOKKOS_INLINE_FUNCTION void operator()(const uint32_t k) const
Definition characteristic.h:135
Kokkos::View< rtype ** > face_weights
Definition characteristic.h:130
Kokkos::View< rtype *[N_DIM]> face_normals
Definition characteristic.h:126
rtype dt
Definition characteristic.h:131
Kokkos::View< rtype **[2][2]> face_thermo
Definition characteristic.h:128
Pieces of the transverse terms of the incoming acoustic wave at every characteristic face (Yoo & Im 2...
Definition characteristic.h:43
Kokkos::View< rtype *[N_DIM]> face_normals
Definition characteristic.h:46
KOKKOS_INLINE_FUNCTION void operator()(const uint32_t k) const
Definition characteristic.h:58
Kokkos::View< int32_t *[2]> cells_of_face
Definition characteristic.h:48
Kokkos::View< rtype *[N_CONSERVATIVE]> W_cells
Definition characteristic.h:49
KOKKOS_INLINE_FUNCTION void face_state(const uint32_t f, rtype *W) const
State of the cell of boundary face f.
Definition characteristic.h:53
Kokkos::View< rtype * > face_area
Definition characteristic.h:47
Kokkos::View< rtype *[N_DIM]> face_coords
Definition characteristic.h:45
BoundaryData boundaries
Definition characteristic.h:44
Inverse-distance-squared weighted least-squares normal equations M g = b, with M stored as its upper ...
Definition gradient.h:25
CellSetup< ExecSpace > c
Definition teno_setup.cpp:1810
Geometry< Space > g
Definition teno_setup.cpp:678
uint8_t beta[teno::MAX_NK][3]
Definition teno_setup.cpp:315