Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
teno_scalars.h
Go to the documentation of this file.
1
13#ifndef TENO_SCALARS_H
14#define TENO_SCALARS_H
15
16#include <Kokkos_Core.hpp>
17
18#include "boundary.h"
19#include "common.h"
20#include "face_reconstruction.h"
21#include "mesh.h"
22#include "teno.h"
23
36template <uint8_t DEG>
38 static constexpr uint8_t NK = teno::n_dof(DEG);
39 static constexpr uint8_t MAX_Q = teno::MAX_FACE_QUAD;
40
41 Kokkos::View<uint32_t *> offsets_faces_of_cell;
42 Kokkos::View<uint32_t *> faces_of_cell;
43 Kokkos::View<int32_t *[2]> cells_of_face;
44 Kokkos::View<uint32_t *> offsets_nodes_of_face;
45 Kokkos::View<uint32_t *> nodes_of_face;
46 Kokkos::View<rtype *[N_DIM]> node_coords;
47 Kokkos::View<rtype *[N_DIM]> cell_coords;
48 Kokkos::View<rtype *[N_DIM]> face_coords;
49 Kokkos::View<rtype *[N_DIM]> shifts;
50 Kokkos::View<uint8_t *> face_shift;
51 Kokkos::View<rtype **> quad_points;
52 Kokkos::View<rtype ***> face_quad_points;
53 Kokkos::View<rtype **> face_quad_weights;
54 Kokkos::View<rtype *> scale;
55 Kokkos::View<rtype **> basis_mean;
56 Kokkos::View<uint16_t *> stencil_large_size;
58 Kokkos::View<uint16_t **> stencil_small_size;
60 Kokkos::View<rtype *> sigma;
61 Kokkos::View<uint8_t **> selection;
64 Kokkos::View<rtype **, Kokkos::LayoutRight> scalars;
65 Kokkos::View<rtype *> theta; // (cell); empty: no scaling
67
69 uint8_t n_quad() const {
70 if constexpr (N_DIM == 2) {
71 return static_cast<uint8_t>(quad_points.extent(0));
72 } else {
73 return static_cast<uint8_t>(face_quad_weights.extent(1));
74 }
75 }
76
78 uint8_t n_faces(const uint32_t c) const {
79 return static_cast<uint8_t>(offsets_faces_of_cell(c + 1) - offsets_faces_of_cell(c));
80 }
81
84 rtype entry_value(const int32_t c, const int32_t f, const uint32_t j) const {
85 if (f >= 0) {
86 const int32_t i_bc = boundaries.face_bc(f);
87 if (boundaries.bcs(i_bc).type == BoundaryType::UPT) {
88 return j < n_species ? boundaries.bc_Y(i_bc, j) : boundaries.bc_thermo(i_bc, j - n_species);
89 }
90 }
91 return scalars(c, j);
92 }
93
96 bool face_point_basis(const uint32_t f, const uint8_t q, const uint32_t c, rtype * psi) const {
97 const rtype h = scale(c);
98 const uint8_t s = (cells_of_face(f, 1) == static_cast<int32_t>(c)) ? face_shift(f) : 0;
99 if constexpr (N_DIM == 2) {
100 if (face_quad_points.extent(0) > 0) {
101 // Curved meshes: the faces' own points
102 teno::monomials(DEG, ((face_quad_points(f, q, 0) - shifts(s, 0)) - cell_coords(c, 0)) / h,
103 ((face_quad_points(f, q, 1) - shifts(s, 1)) - cell_coords(c, 1)) / h, psi);
104 for (uint8_t l = 0; l < NK; l++) psi[l] -= basis_mean(c, l);
105 return true;
106 }
109 const rtype s_q = 0.5_r * quad_points(q, 0);
110 const rtype x = face_coords(f, 0) + s_q * (node_coords(node_1, 0) - node_coords(node_0, 0));
111 const rtype y = face_coords(f, 1) + s_q * (node_coords(node_1, 1) - node_coords(node_0, 1));
112 teno::monomials(DEG, ((x - shifts(s, 0)) - cell_coords(c, 0)) / h,
113 ((y - shifts(s, 1)) - cell_coords(c, 1)) / h, psi);
114 } else {
115 if (face_quad_weights(f, q) == 0.0_r) return false;
116 rtype xi[N_DIM];
117 FOR_I_DIM xi[i] = ((face_quad_points(f, q, i) - shifts(s, i)) - cell_coords(c, i)) / h;
118 teno::monomials(DEG, xi, psi);
119 }
120 for (uint8_t l = 0; l < NK; l++) psi[l] -= basis_mean(c, l);
121 return true;
122 }
123
125 void large_coefficients(const uint32_t c, const uint32_t j, rtype * a) const {
126 const rtype S_c = scalars(c, j);
127 for (uint8_t l = 0; l < NK; l++) a[l] = 0.0_r;
129 for (uint16_t s = 0; s < stencil_large_size(c); s++) {
130 const rtype d = entry_value(stencil.cell(s), stencil.face(s), j) - S_c;
131 for (uint8_t l = 0; l < NK; l++) a[l] += stencil.pinv<NK>(s, l) * d;
132 }
133 }
134
136 void sector_coefficients(const uint32_t c, const uint8_t s, const uint32_t j, rtype * a) const {
137 const rtype S_c = scalars(c, j);
138 for (uint8_t l = 0; l < teno::NK_SMALL; l++) a[l] = 0.0_r;
139 // The cell's sector stencils are stored one after another
140 uint16_t start = 0;
141 for (uint8_t t = 0; t < s; t++) start += stencil_small_size(c, t);
143 for (uint16_t e = 0; e < stencil_small_size(c, s); e++) {
144 const rtype d = entry_value(stencil.cell(start + e), stencil.face(start + e), j) - S_c;
145 for (uint8_t l = 0; l < teno::NK_SMALL; l++) a[l] += stencil.pinv<teno::NK_SMALL>(start + e, l) * d;
146 }
147 }
148
154 void evaluate(const uint32_t c, const uint32_t j, const uint8_t k, const rtype * aK,
155 const rtype aS[][teno::NK_SMALL], rtype * out) const {
157 const uint8_t side = (cells_of_face(f, 0) == static_cast<int32_t>(c)) ? 0 : 1;
158 const bool troubled = sigma(c) >= sigma_threshold;
159 const uint8_t mask = troubled ? selection(f, side) : TENO::SELECT_LARGE;
160 uint8_t n_kept = 0;
161 for (uint8_t s = 0; s < teno::MAX_FACES; s++) n_kept += (mask != TENO::SELECT_LARGE && ((mask >> s) & 1u));
162 const rtype S_c = scalars(c, j);
163 const rtype t = theta.extent(0) ? theta(c) : 1.0_r;
164 for (uint8_t q = 0; q < n_quad(); q++) {
165 rtype psi[NK];
166 if (!face_point_basis(f, q, c, psi)) {
167 out[q] = S_c;
168 continue;
169 }
170 rtype d = 0.0_r;
171 if (n_kept == 0) {
172 for (uint8_t l = 0; l < NK; l++) d += aK[l] * psi[l];
173 } else {
174 for (uint8_t s = 0; s < teno::MAX_FACES; s++) {
175 if (!((mask >> s) & 1u)) continue;
176 rtype p = 0.0_r;
177 for (uint8_t l = 0; l < teno::NK_SMALL; l++) p += aS[s][l] * psi[l];
178 d += p / n_kept;
179 }
180 }
181 out[q] = S_c + t * d;
182 }
183 }
184
187 void coefficients(const uint32_t c, const uint32_t j, rtype * aK, rtype aS[][teno::NK_SMALL]) const {
189 if (sigma(c) < sigma_threshold) return;
190 uint8_t used = 0;
191 for (uint8_t k = 0; k < n_faces(c); k++) {
193 const uint8_t side = (cells_of_face(f, 0) == static_cast<int32_t>(c)) ? 0 : 1;
194 const uint8_t mask = selection(f, side);
195 if (mask != TENO::SELECT_LARGE) used |= mask;
196 }
197 for (uint8_t s = 0; s < n_faces(c); s++) {
198 if ((used >> s) & 1u) sector_coefficients(c, s, j, aS[s]);
199 }
200 }
201
204 void cell_values(const uint32_t c, const uint32_t j, rtype out[][MAX_Q]) const {
205 rtype aK[NK];
207 coefficients(c, j, aK, aS);
208 for (uint8_t k = 0; k < n_faces(c); k++) evaluate(c, j, k, aK, aS, out[k]);
209 }
210
213 void face_values(const uint32_t c, const uint32_t j, const uint8_t k, rtype * out) const {
214 rtype aK[NK];
216 coefficients(c, j, aK, aS);
217 evaluate(c, j, k, aK, aS, out);
218 }
219};
220
222template <uint8_t DEG>
223TENOScalarValues<DEG> make_teno_scalar_values(const TENO & teno, const Mesh & mesh, const BoundaryData & boundaries,
224 Kokkos::View<rtype **, Kokkos::LayoutRight> scalars,
225 Kokkos::View<rtype *> theta, uint32_t n_species) {
228 mesh.cell_coords, mesh.face_coords, mesh.shifts, mesh.face_shift,
229 teno.quadrature_face.points, teno.face_quad_points, teno.face_quad_weights,
230 teno.scale, teno.basis_mean, teno.stencil_large_size, teno.stencil_large,
231 teno.stencil_small_size, teno.stencil_small, teno.troubled,
232 teno.selection, teno.sigma_threshold, boundaries, scalars, theta, n_species};
233}
234
235#endif // TENO_SCALARS_H
Boundary conditions.
Definition mesh.h:111
Kokkos::View< rtype *[N_DIM]> cell_coords
Definition mesh.h:450
Kokkos::View< uint8_t * > face_shift
Definition mesh.h:468
Kokkos::View< uint32_t * > nodes_of_face
Definition mesh.h:459
Kokkos::View< uint32_t * > offsets_nodes_of_face
Definition mesh.h:460
Kokkos::View< uint32_t * > offsets_faces_of_cell
Definition mesh.h:458
Kokkos::View< uint32_t * > faces_of_cell
Definition mesh.h:457
Kokkos::View< int32_t *[2]> cells_of_face
Definition mesh.h:461
Kokkos::View< rtype *[N_DIM]> node_coords
Definition mesh.h:449
Kokkos::View< rtype *[N_DIM]> shifts
Definition mesh.h:467
Kokkos::View< rtype *[N_DIM]> face_coords
Definition mesh.h:454
High-order TENO-E reconstruction on unstructured meshes (Liang, Shyy & Fu, J. Sci....
Definition face_reconstruction.h:282
static constexpr uint8_t SELECT_LARGE
Definition face_reconstruction.h:415
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_DIM
Definition common_typedef.h:32
Face reconstruction class declaration.
Mesh class declaration.
Definition teno.h:19
constexpr uint8_t MAX_FACES
Definition teno.h:37
constexpr uint8_t NK_SMALL
Definition teno.h:36
KOKKOS_INLINE_FUNCTION void monomials(const uint8_t r, const T xi, const T eta, T *phi)
Evaluate all monomials of degree 1..r at (xi, eta).
Definition teno.h:225
KOKKOS_INLINE_FUNCTION constexpr uint8_t n_dof(const uint8_t r)
Number of non-constant N_DIM-variate monomials of total degree <= r.
Definition teno.h:27
constexpr uint8_t MAX_FACE_QUAD
Definition teno.h:38
Device-side lookup from faces to boundary conditions.
Definition boundary.h:229
Kokkos::View< int32_t * > face_bc
Definition boundary.h:230
Kokkos::View< rtype **, Kokkos::LayoutRight > bc_Y
Definition boundary.h:257
Kokkos::View< BoundaryCondition * > bcs
Definition boundary.h:249
Kokkos::View< rtype *[2]> bc_thermo
Definition boundary.h:258
Linear reconstruction of the scalars [Y_1 .. Y_Ns, gamma, e0] with the weights the flow block already...
Definition teno_scalars.h:37
KOKKOS_INLINE_FUNCTION void large_coefficients(const uint32_t c, const uint32_t j, rtype *a) const
Definition teno_scalars.h:125
static constexpr uint8_t MAX_Q
Definition teno_scalars.h:39
Kokkos::View< uint8_t * > face_shift
Definition teno_scalars.h:50
Kokkos::View< rtype *[N_DIM]> node_coords
Definition teno_scalars.h:46
Kokkos::View< uint16_t * > stencil_large_size
Definition teno_scalars.h:56
KOKKOS_INLINE_FUNCTION void evaluate(const uint32_t c, const uint32_t j, const uint8_t k, const rtype *aK, const rtype aS[][teno::NK_SMALL], rtype *out) const
Scalar j of cell c at the points of its local face k, given the large-stencil coefficients aK and (tr...
Definition teno_scalars.h:154
KOKKOS_INLINE_FUNCTION void cell_values(const uint32_t c, const uint32_t j, rtype out[][MAX_Q]) const
Scalar j of cell c at the points of all its faces, out[k][q] for local face k.
Definition teno_scalars.h:204
Kokkos::View< rtype ** > basis_mean
Definition teno_scalars.h:55
teno::PackedStencils stencil_small
Definition teno_scalars.h:59
Kokkos::View< rtype ** > quad_points
Definition teno_scalars.h:51
BoundaryData boundaries
Definition teno_scalars.h:63
Kokkos::View< int32_t *[2]> cells_of_face
Definition teno_scalars.h:43
Kokkos::View< rtype **, Kokkos::LayoutRight > scalars
Definition teno_scalars.h:64
static constexpr uint8_t NK
Definition teno_scalars.h:38
Kokkos::View< uint32_t * > faces_of_cell
Definition teno_scalars.h:42
rtype sigma_threshold
Definition teno_scalars.h:62
Kokkos::View< uint32_t * > offsets_nodes_of_face
Definition teno_scalars.h:44
KOKKOS_INLINE_FUNCTION void face_values(const uint32_t c, const uint32_t j, const uint8_t k, rtype *out) const
Scalar j of cell c at the points of its local face k.
Definition teno_scalars.h:213
Kokkos::View< rtype *[N_DIM]> face_coords
Definition teno_scalars.h:48
Kokkos::View< rtype * > sigma
Definition teno_scalars.h:60
KOKKOS_INLINE_FUNCTION rtype entry_value(const int32_t c, const int32_t f, const uint32_t j) const
Scalar j of a stencil entry: cell c, or its mirror across boundary face f.
Definition teno_scalars.h:84
Kokkos::View< rtype ** > face_quad_weights
Definition teno_scalars.h:53
KOKKOS_INLINE_FUNCTION uint8_t n_quad() const
Definition teno_scalars.h:69
Kokkos::View< rtype *** > face_quad_points
Definition teno_scalars.h:52
Kokkos::View< uint32_t * > offsets_faces_of_cell
Definition teno_scalars.h:41
KOKKOS_INLINE_FUNCTION bool face_point_basis(const uint32_t f, const uint8_t q, const uint32_t c, rtype *psi) const
Monomials minus their cell means at point q of face f, in cell c's frame.
Definition teno_scalars.h:96
KOKKOS_INLINE_FUNCTION void coefficients(const uint32_t c, const uint32_t j, rtype *aK, rtype aS[][teno::NK_SMALL]) const
Coefficients of cell c for scalar j: large, and the sectors its troubled faces use.
Definition teno_scalars.h:187
KOKKOS_INLINE_FUNCTION void sector_coefficients(const uint32_t c, const uint8_t s, const uint32_t j, rtype *a) const
Definition teno_scalars.h:136
Kokkos::View< uint32_t * > nodes_of_face
Definition teno_scalars.h:45
Kokkos::View< uint16_t ** > stencil_small_size
Definition teno_scalars.h:58
Kokkos::View< rtype *[N_DIM]> cell_coords
Definition teno_scalars.h:47
Kokkos::View< rtype *[N_DIM]> shifts
Definition teno_scalars.h:49
teno::PackedStencils stencil_large
Definition teno_scalars.h:57
KOKKOS_INLINE_FUNCTION uint8_t n_faces(const uint32_t c) const
Definition teno_scalars.h:78
uint32_t n_species
Definition teno_scalars.h:66
Kokkos::View< rtype * > theta
Definition teno_scalars.h:65
Kokkos::View< rtype * > scale
Definition teno_scalars.h:54
Kokkos::View< uint8_t ** > selection
Definition teno_scalars.h:61
One cell's stencil, resolved once per cell, for pseudo-inverse entries of type T.
Definition teno.h:83
KOKKOS_INLINE_FUNCTION int32_t cell(const uint32_t s) const
Definition teno.h:90
KOKKOS_INLINE_FUNCTION rtype pinv(const uint32_t s, const uint32_t l) const
Entry l of slot s, for pseudo-inverses of WIDTH entries per slot.
Definition teno.h:98
KOKKOS_INLINE_FUNCTION int32_t face(const uint32_t s) const
Definition teno.h:93
Per-cell stencils of different sizes, stored without padding to the largest one in the mesh....
Definition teno.h:66
KOKKOS_INLINE_FUNCTION RowT< T > row(const uint32_t c) const
Definition teno.h:109
Device helpers for the TENO-E reconstruction.
TENOScalarValues< DEG > make_teno_scalar_values(const TENO &teno, const Mesh &mesh, const BoundaryData &boundaries, Kokkos::View< rtype **, Kokkos::LayoutRight > scalars, Kokkos::View< rtype * > theta, uint32_t n_species)
TENOScalarValues of degree DEG over a TENO reconstruction's stencils.
Definition teno_scalars.h:223
SlotArray< double, Space > psi
Definition teno_setup.cpp:478
CellSetup< ExecSpace > c
Definition teno_setup.cpp:1810
TableBatchT< Space > out
Definition teno_setup.cpp:681