Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
flux_functor.h
Go to the documentation of this file.
1
12#ifndef FLUX_FUNCTOR_H
13#define FLUX_FUNCTOR_H
14
15#include <Kokkos_Core.hpp>
16
17#include "common.h"
18#include "boundary.h"
19#include "riemann_solver.h"
20
33void low_mach_correction(rtype * W_l, rtype * W_r, const rtype gamma, const rtype M_cut) {
34 const rtype M_l2 = dot<N_DIM>(W_l + 1, W_l + 1) * W_l[0] / (gamma * W_l[N_DIM + 1]);
35 const rtype M_r2 = dot<N_DIM>(W_r + 1, W_r + 1) * W_r[0] / (gamma * W_r[N_DIM + 1]);
36 const rtype z = Kokkos::fmin(1.0_r, Kokkos::fmax(M_cut, Kokkos::sqrt(Kokkos::fmax(M_l2, M_r2))));
37 FOR_I_DIM {
38 const rtype mean = 0.5_r * (W_l[1 + i] + W_r[1 + i]);
39 const rtype half_jump = 0.5_r * (W_l[1 + i] - W_r[1 + i]);
40 W_l[1 + i] = mean + z * half_jump;
41 W_r[1 + i] = mean - z * half_jump;
42 }
43}
44
50const rtype * quad_normal(const Kokkos::View<rtype ***> & quad_normals, const uint32_t f, const uint8_t q,
51 const rtype * n_face, rtype * n_q) {
52 if (quad_normals.extent(0) == 0) return n_face;
53 FOR_I_DIM n_q[i] = quad_normals(f, q, i);
54 return n_q;
55}
56
63rtype face_upwind_fraction(const Kokkos::View<rtype *> & upwind, const BoundaryData & boundaries,
64 const int32_t c0, const int32_t c1, const uint32_t i_face) {
65 if (c1 >= 0) return Kokkos::fmax(upwind(c0), upwind(c1));
66 const BoundaryCondition & bc = boundaries.bcs(boundaries.face_bc(i_face));
67 return (bc.is_wall() || bc.type == BoundaryType::SYMMETRY) ? upwind(c0) : 1.0_r;
68}
69
78 Kokkos::View<rtype *[N_CONSERVATIVE][N_DIM]> gradients;
79 Kokkos::View<rtype *> upwind;
82
84 void operator()(const uint32_t c) const {
85 rtype div = 0.0_r;
86 FOR_I_DIM div += gradients(c, 1 + i, i);
88 if constexpr (N_DIM == 2) {
89 const rtype w = gradients(c, 2, 0) - gradients(c, 1, 1);
90 omega2 = w * w;
91 } else {
92 omega2 = 0.0_r;
93 for (uint8_t k = 0; k < 3; k++) {
94 const uint8_t a = static_cast<uint8_t>((k + 1) % 3), b = static_cast<uint8_t>((k + 2) % 3);
95 const rtype w = gradients(c, 1 + b, a) - gradients(c, 1 + a, b);
96 omega2 += w * w;
97 }
98 }
99 const rtype div2 = div * div;
100 const bool shock = div < 0.0_r && div2 > threshold * (div2 + omega2);
101 upwind(c) = shock ? 1.0_r : floor;
102 }
103};
104
117template <typename T_riemann_solver>
119 Kokkos::View<rtype *[N_DIM]> normals;
120 Kokkos::View<rtype *> face_area;
121 Kokkos::View<int32_t *[2]> cells_of_face;
122 Kokkos::View<rtype *> quad_weights;
123 Kokkos::View<rtype **> face_weights; // (face, q): 3D, zero on padding points; 2D axisymmetric, Gauss weight times r; else empty
124 Kokkos::View<rtype **[2][N_CONSERVATIVE]> face_solution;
126 Kokkos::View<rtype *[N_CONSERVATIVE]> W_cells;
127 Kokkos::View<rtype *[N_CONSERVATIVE]> face_flux;
129 rtype low_mach_cutoff; // 1 disables the low-Mach correction
130 Kokkos::View<rtype *> upwind; // hybrid flux: upwind fraction of each cell (UpwindSensorFunctor), else empty
131 Kokkos::View<rtype ***> quad_normals; // curved meshes: (face, q, dim) unit normals; else empty
132
134 void operator()(const uint32_t i_face) const {
135 uint8_t n_quad;
136 if constexpr (N_DIM == 2) {
137 n_quad = static_cast<uint8_t>(quad_weights.extent(0));
138 } else {
139 n_quad = static_cast<uint8_t>(face_weights.extent(1));
140 }
141 const int32_t c1 = cells_of_face(i_face, 1);
146
147 const bool hybrid = upwind.extent(0) > 0;
148 const rtype phi =
150
152 for (uint8_t i_quad = 0; i_quad < n_quad; i_quad++) {
153 rtype n_q[N_DIM];
155 rtype w_q;
156 if constexpr (N_DIM == 2) {
158 } else {
160 if (w_q == 0.0_r) continue;
161 }
164 if (c1 >= 0) {
166 } else {
168 }
169 rtype central[N_CONSERVATIVE] = {};
171 if (phi > 0.0_r) {
172 if (low_mach_cutoff < 1.0_r &&
173 (c1 >= 0 || boundaries.bcs(boundaries.face_bc(i_face)).is_characteristic())) {
175 }
176 T_riemann_solver::calc_flux(flux_q, n_point, W_l, W_r, gamma);
177 if (hybrid) FOR_I_CONSERVATIVE flux_q[i] = central[i] + phi * (flux_q[i] - central[i]);
178 } else {
179 FOR_I_CONSERVATIVE flux_q[i] = central[i];
180 }
182 }
183
184 // Weights sum to 2 (Gauss-Legendre on [-1, 1] in 2D), on curved faces
185 // to twice their area over face_area
186 const rtype scale = 0.5_r * face_area(i_face);
188 }
189};
190
196 Kokkos::View<uint32_t *> offsets_faces_of_cell;
197 Kokkos::View<uint32_t *> faces_of_cell;
198 Kokkos::View<int32_t *[2]> cells_of_face;
199 Kokkos::View<rtype *[N_CONSERVATIVE]> face_flux;
200 Kokkos::View<rtype *[N_CONSERVATIVE]> rhs;
201
203 void operator()(const uint32_t i_cell) const {
204 rtype sum[N_CONSERVATIVE] = {};
206 const uint32_t i_face = faces_of_cell(k);
207 const rtype sign = (cells_of_face(i_face, 0) == static_cast<int32_t>(i_cell)) ? 1.0 : -1.0;
209 }
211 }
212};
213
214#endif // FLUX_FUNCTOR_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
KOKKOS_INLINE_FUNCTION const rtype * quad_normal(const Kokkos::View< rtype *** > &quad_normals, const uint32_t f, const uint8_t q, const rtype *n_face, rtype *n_q)
Unit normal at quadrature point q of face f: the point's own on curved meshes (quad_normals,...
Definition flux_functor.h:50
KOKKOS_INLINE_FUNCTION rtype face_upwind_fraction(const Kokkos::View< rtype * > &upwind, const BoundaryData &boundaries, const int32_t c0, const int32_t c1, const uint32_t i_face)
Upwind fraction of a face of the hybrid convective flux: the larger of its cells' (boundary faces oth...
Definition flux_functor.h:63
KOKKOS_INLINE_FUNCTION void low_mach_correction(rtype *W_l, rtype *W_r, const rtype gamma, const rtype M_cut)
Low-Mach correction of Thornber et al. (J. Comput. Phys. 227, 2008): scales the jump of the reconstru...
Definition flux_functor.h:33
Approximate Riemann solvers.
Device-copyable boundary condition.
Definition boundary.h:97
Device-side lookup from faces to boundary conditions.
Definition boundary.h:229
Kokkos::View< int32_t * > face_bc
Definition boundary.h:230
Kokkos::View< BoundaryCondition * > bcs
Definition boundary.h:249
KOKKOS_INLINE_FUNCTION void exterior_W(const uint32_t i_face, const uint8_t i_quad, const uint8_t n_quad, const rtype *W_i, const rtype *n, const T_W &W_cells, const T_F &face_solution, rtype *W_g) const
Exterior state seen by the Riemann solver on boundary face i_face.
Definition boundary.h:335
Integrates the convective flux over every face into face_flux, the rate of change it causes in cells_...
Definition flux_functor.h:118
Kokkos::View< rtype * > upwind
Definition flux_functor.h:130
Kokkos::View< rtype **[2][N_CONSERVATIVE]> face_solution
Definition flux_functor.h:124
Kokkos::View< rtype *** > quad_normals
Definition flux_functor.h:131
Kokkos::View< int32_t *[2]> cells_of_face
Definition flux_functor.h:121
Kokkos::View< rtype *[N_CONSERVATIVE]> W_cells
Definition flux_functor.h:126
Kokkos::View< rtype ** > face_weights
Definition flux_functor.h:123
Kokkos::View< rtype *[N_CONSERVATIVE]> face_flux
Definition flux_functor.h:127
BoundaryData boundaries
Definition flux_functor.h:125
Kokkos::View< rtype * > quad_weights
Definition flux_functor.h:122
Kokkos::View< rtype * > face_area
Definition flux_functor.h:120
rtype gamma
Definition flux_functor.h:128
KOKKOS_INLINE_FUNCTION void operator()(const uint32_t i_face) const
Definition flux_functor.h:134
Kokkos::View< rtype *[N_DIM]> normals
Definition flux_functor.h:119
rtype low_mach_cutoff
Definition flux_functor.h:129
Sums the face fluxes of each cell into its RHS in faces_of_cell order, so that the result does not de...
Definition flux_functor.h:195
Kokkos::View< uint32_t * > faces_of_cell
Definition flux_functor.h:197
Kokkos::View< rtype *[N_CONSERVATIVE]> face_flux
Definition flux_functor.h:199
Kokkos::View< uint32_t * > offsets_faces_of_cell
Definition flux_functor.h:196
KOKKOS_INLINE_FUNCTION void operator()(const uint32_t i_cell) const
Definition flux_functor.h:203
Kokkos::View< rtype *[N_CONSERVATIVE]> rhs
Definition flux_functor.h:200
Kokkos::View< int32_t *[2]> cells_of_face
Definition flux_functor.h:198
Upwind fraction of each cell for the hybrid convective flux: 1 where the Ducros sensor restricted to ...
Definition flux_functor.h:77
Kokkos::View< rtype * > upwind
Definition flux_functor.h:79
rtype threshold
Definition flux_functor.h:80
rtype floor
Definition flux_functor.h:81
Kokkos::View< rtype *[N_CONSERVATIVE][N_DIM]> gradients
Definition flux_functor.h:78
KOKKOS_INLINE_FUNCTION void operator()(const uint32_t c) const
Definition flux_functor.h:84
static KOKKOS_INLINE_FUNCTION void calc_flux(rtype *flux, const rtype *n, const rtype *W_l, const rtype *W_r, const rtype gamma)
Definition riemann_solver.h:569
CellSetup< ExecSpace > c
Definition teno_setup.cpp:1810
Lane< rtype > scale
Definition teno_setup.cpp:531