Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
teno_setup.h
Go to the documentation of this file.
1
12#ifndef TENO_SETUP_H
13#define TENO_SETUP_H
14
15#include <array>
16#include <memory>
17#include <string>
18#include <type_traits>
19#include <vector>
20
21#include <Kokkos_Core.hpp>
22
23#include "boundary.h"
24#include "mesh.h"
25#include "teno.h"
26
27namespace teno_setup {
28
29// Relative tolerance for geometric tests on the mesh, whose coordinates are rtype
30constexpr double GEOMETRY_TOL = precision_tol<double>(1e-10, 1e-5);
31
32// Largest accepted Lebesgue constant of a central stencil's reconstruction at
33// the cell's face quadrature points. Full-rank stencils that resolve a
34// direction only through small centroid offsets reach tens to hundreds and
35// amplify the truncation error alike.
36constexpr double MAX_LEBESGUE_2D = 10.0;
37// In 3D a bound of 10 still accepts near-degenerate stencils wherever the ties
38// of a lattice are broken (mirror walls of prism, tetrahedral and mixed
39// tilings, seams, jittered meshes): their face values follow the cells across
40// the face, and the linearized scheme grows (#126, #229). Lattices are stable
41// up to about 10 only because their tie-complete shells skip those sizes.
42constexpr double MAX_LEBESGUE_3D = 4.0;
43// Where no stencil reaches it (order 6 on tetrahedra and pyramids: 4.3-5), the
44// smallest stencil within this factor of the best one found; the best alone is
45// often the largest stencil, and markedly less accurate
46constexpr double LEBESGUE_SLACK = 1.25;
47
49template <typename T>
50struct Lane {
51 T * p;
52 size_t stride;
53
55 template <typename I>
56 KOKKOS_INLINE_FUNCTION T & operator[](const I k) const {
57 static_assert(std::is_integral_v<I>);
58 return p[static_cast<size_t>(k) * stride];
59 }
60
62 Lane at(const size_t k) const { return Lane{p + k * stride, stride}; }
63};
64
70template <typename T, class Space = Kokkos::DefaultExecutionSpace::memory_space>
71struct SlotArray {
72 Kokkos::View<T *, Kokkos::LayoutRight, Space> data;
73 size_t cap = 0;
74 size_t slots = 0;
75 bool interleaved = false;
76
77 SlotArray() = default;
78 SlotArray(const std::string & label, const size_t cap_in, const size_t slots_in, const bool interleaved_in)
81
83 Lane<T> lane(const size_t slot) const {
84 return interleaved ? Lane<T>{data.data() + slot, slots} : Lane<T>{data.data() + slot * cap, 1};
85 }
86};
87
92template <class Space>
94 template <typename T>
95 using V = Kokkos::View<T, Kokkos::LayoutRight, Space>;
98 uint16_t max_large = 0; // central stencil entries per cell
99 uint16_t max_small = 0; // sector stencil entries per cell, all faces
100 V<uint8_t *> status; // (slot): OK, or why the cell must be redone on the host
102 V<uint8_t *> failed_large; // (slot): no central stencil, and the search was not cut by the halo
103 V<uint8_t *> invalid_small; // (slot): sector stencils left out
105 V<uint16_t **> small_size; // (slot, face)
110
111 TableBatchT() = default;
113 const bool interleaved)
115 status("teno_batch_status", n), gather_depth("teno_batch_depth", n), failed_large("teno_batch_failed", n),
116 invalid_small("teno_batch_invalid", n), large_size("teno_batch_large_size", n),
117 small_size("teno_batch_small_size", n, teno::MAX_FACES), small_total("teno_batch_small_total", n),
118 scale("teno_batch_scale", 1, n, interleaved), basis_mean("teno_batch_mean", nk_in, n, interleaved),
119 si("teno_batch_si", N_DIM == 2 ? size_t(nk_in) * (nk_in + 1) / 2 : 0, n, interleaved),
120 large_cells("teno_batch_large_cells", max_large_in, n, interleaved),
121 large_faces("teno_batch_large_faces", max_large_in, n, interleaved),
122 small_cells("teno_batch_small_cells", max_small_in, n, interleaved),
123 small_faces("teno_batch_small_faces", max_small_in, n, interleaved),
124 large_pinv("teno_batch_large_pinv", size_t(max_large_in) * nk_in, n, interleaved),
125 small_pinv("teno_batch_small_pinv", size_t(max_small_in) * teno::NK_SMALL, n, interleaved) {}
126};
127
129
136inline bool one_sided_face(const Mesh & mesh, const BoundaryCondition & bc, const uint32_t f, const bool curved_mirrors) {
137 return mesh.curved_geometry && !curved_mirrors && mesh.curved_geometry->face_is_curved(f) &&
138 (bc.is_wall() || bc.type == BoundaryType::SYMMETRY);
139}
140
142bool batch_interleaved();
143
146
148enum Status : uint8_t { OK = 0, OUT_OF_SCRATCH = 1 };
149
151struct Options {
154 uint16_t ns = 0; // central stencil size to start from
155 uint16_t nss = 0; // sector stencil size
156 double max_condition = 1e8;
157 uint32_t batch_cells = 0; // cells per device batch; 0 picks one from the device memory
158 bool host_only = false; // run every cell on the host (tests)
159 const std::vector<uint32_t> * cells = nullptr; // the cells that will be set up, if not all reconstructed ones
160 bool curved_mirrors = false; // mirror images across curved wall and symmetry faces (their planes) too
161 uint8_t curved_wall_degree = 3; // largest central degree of stencils reaching a curved wall without mirrors
162 uint16_t wall_ns = 0; // central stencil size to start from at that degree
163};
164
166struct Timings {
167 double geometry = 0.0; // per-cell scales, metrics, moments and bounding boxes
168 double tables = 0.0; // stencils, pseudo-inverses and smoothness indicators
169 double host_cells = 0.0; // cells redone on the host
171};
172
173class Setup3D;
174
184 public:
185 Setup3DHandle(const Mesh & mesh, const BoundaryData & boundaries, Kokkos::View<rtype ***> face_quad_points,
186 Kokkos::View<rtype **> face_quad_weights, const Options & options);
188
193 void compute(const Kokkos::View<uint32_t *> & cells, uint32_t n, TableBatch & out);
194
196 uint32_t batch_cells() const;
197
198 uint16_t max_large() const;
199 uint16_t max_small() const;
200 const Timings & timings() const;
201
208
209 private:
210 std::unique_ptr<Setup3D> impl;
211};
212
215
218
225std::array<double, 9> ranking_metric(const Mesh & mesh, const Kokkos::View<int32_t *>::host_mirror_type & face_bc,
226 const Kokkos::View<BoundaryCondition *>::host_mirror_type & bcs, uint32_t i);
227
228} // namespace teno_setup
229
230#endif // TENO_SETUP_H
Boundary conditions.
Definition mesh.h:111
std::shared_ptr< const curved::Geometry > curved_geometry
Definition mesh.h:422
The 3D TENO-E precomputation of a mesh: the geometry it needs (cell moments, bounding boxes and ranki...
Definition teno_setup.h:183
void compute(const Kokkos::View< uint32_t * > &cells, uint32_t n, TableBatch &out)
Tables of cells[0..n) into slots 0..n of out (out.slots >= n); cells must be reconstructed cells.
Definition teno_setup.cpp:3452
uint32_t batch_cells() const
Cells per batch that fit the device.
Definition teno_setup.cpp:3456
const Timings & timings() const
Definition teno_setup.cpp:3459
uint16_t max_large() const
Definition teno_setup.cpp:3457
uint16_t max_small() const
Definition teno_setup.cpp:3458
The setup of one mesh.
Definition teno_setup.cpp:2994
KOKKOS_INLINE_FUNCTION rtype dot(const rtype *a, const rtype *b)
Compute the dot product of two arrays.
Definition common_math.h:32
#define N_DIM
Definition common_typedef.h:28
Mesh class declaration.
Definition teno_setup.cpp:32
teno::SmoothnessTerms smoothness_terms(const uint8_t degree)
The terms of every smoothness-matrix entry of the given degree, in the order the setup sums them.
Definition teno_setup.cpp:3463
constexpr double LEBESGUE_SLACK
Definition teno_setup.h:46
TableBatchT< Kokkos::DefaultExecutionSpace::memory_space > TableBatch
Definition teno_setup.h:128
constexpr double MAX_LEBESGUE_3D
Definition teno_setup.h:42
bool one_sided_face(const Mesh &mesh, const BoundaryCondition &bc, const uint32_t f, const bool curved_mirrors)
Whether stencils take no mirror images across boundary face f (with condition bc): curved wall and sy...
Definition teno_setup.h:136
constexpr double MAX_LEBESGUE_2D
Definition teno_setup.h:36
std::array< double, 9 > ranking_metric(const Mesh &mesh, const Kokkos::View< int32_t * >::host_mirror_type &face_bc, const Kokkos::View< BoundaryCondition * >::host_mirror_type &bcs, const uint32_t i)
Metric (3 x 3, row-major) in which the stencil candidates of cell i are ranked by distance: the ident...
Definition teno_setup.cpp:3573
Status
Why a cell's device setup must be redone on the host.
Definition teno_setup.h:148
@ OUT_OF_SCRATCH
Definition teno_setup.h:148
@ OK
Definition teno_setup.h:148
bool batch_interleaved()
Whether batches interleave their cells (GPUs).
Definition teno_setup.cpp:2957
TableBatch device_copy(const TableBatchT< Kokkos::HostSpace > &h)
The device copy of a host batch.
Definition teno_setup.cpp:2960
constexpr double GEOMETRY_TOL
Definition teno_setup.h:30
Definition teno.h:19
Kokkos::View< double **, Kokkos::LayoutRight > Moments
(cell, k): central moments of each cell, mean of ((x - x_c) / h_c)^a ... (3D).
Definition teno.h:118
Device-copyable boundary condition.
Definition boundary.h:97
Device-side lookup from faces to boundary conditions.
Definition boundary.h:229
The terms of the smoothness-indicator matrix (3D): entry e (upper_index(l, m)) is sum_t weight(t) mom...
Definition teno.h:126
Element k of one cell's array in a batch: interleaved across cells on GPUs.
Definition teno_setup.h:50
size_t stride
Definition teno_setup.h:52
KOKKOS_INLINE_FUNCTION Lane at(const size_t k) const
Definition teno_setup.h:62
T * p
Definition teno_setup.h:51
KOKKOS_INLINE_FUNCTION T & operator[](const I k) const
Element k, of any integral type like a View's indices (the loops index in int).
Definition teno_setup.h:56
Options and sizes of the 3D setup.
Definition teno_setup.h:151
uint16_t ns
Definition teno_setup.h:154
uint16_t nss
Definition teno_setup.h:155
bool curved_mirrors
Definition teno_setup.h:160
uint8_t curved_wall_degree
Definition teno_setup.h:161
uint32_t batch_cells
Definition teno_setup.h:157
bool host_only
Definition teno_setup.h:158
double max_condition
Definition teno_setup.h:156
const std::vector< uint32_t > * cells
Definition teno_setup.h:159
uint8_t nk
Definition teno_setup.h:153
uint8_t degree
Definition teno_setup.h:152
uint16_t wall_ns
Definition teno_setup.h:162
An array of cap elements for each of slots cells. On GPUs element k of every cell is contiguous,...
Definition teno_setup.h:71
Kokkos::View< T *, Kokkos::LayoutRight, Space > data
Definition teno_setup.h:72
size_t slots
Definition teno_setup.h:74
size_t cap
Definition teno_setup.h:73
bool interleaved
Definition teno_setup.h:75
SlotArray(const std::string &label, const size_t cap_in, const size_t slots_in, const bool interleaved_in)
Definition teno_setup.h:78
KOKKOS_INLINE_FUNCTION Lane< T > lane(const size_t slot) const
Definition teno_setup.h:83
Tables of a batch of cells before packing, one slot per cell, at the largest stencil sizes the search...
Definition teno_setup.h:93
SlotArray< int32_t, Space > small_faces
Definition teno_setup.h:108
V< uint8_t * > failed_large
Definition teno_setup.h:102
V< uint16_t * > small_total
Definition teno_setup.h:106
V< uint16_t * > large_size
Definition teno_setup.h:104
uint16_t max_large
Definition teno_setup.h:98
V< uint8_t * > gather_depth
Definition teno_setup.h:101
Kokkos::View< T, Kokkos::LayoutRight, Space > V
Definition teno_setup.h:95
SlotArray< rtype, Space > si
Definition teno_setup.h:107
V< uint8_t * > status
Definition teno_setup.h:100
SlotArray< rtype, Space > small_pinv
Definition teno_setup.h:109
TableBatchT(const uint32_t n, const uint8_t nk_in, const uint16_t max_large_in, const uint16_t max_small_in, const bool interleaved)
Definition teno_setup.h:112
uint8_t nk
Definition teno_setup.h:97
SlotArray< int32_t, Space > large_faces
Definition teno_setup.h:108
V< uint8_t * > invalid_small
Definition teno_setup.h:103
SlotArray< rtype, Space > scale
Definition teno_setup.h:107
SlotArray< int32_t, Space > large_cells
Definition teno_setup.h:108
SlotArray< rtype, Space > large_pinv
Definition teno_setup.h:109
uint32_t slots
Definition teno_setup.h:96
V< uint16_t ** > small_size
Definition teno_setup.h:105
uint16_t max_small
Definition teno_setup.h:99
SlotArray< int32_t, Space > small_cells
Definition teno_setup.h:108
SlotArray< rtype, Space > basis_mean
Definition teno_setup.h:107
Timings of the last setup, in seconds.
Definition teno_setup.h:166
double geometry
Definition teno_setup.h:167
double tables
Definition teno_setup.h:168
uint64_t n_host_cells
Definition teno_setup.h:170
double host_cells
Definition teno_setup.h:169
Device helpers for the TENO-E reconstruction.
TableBatchT< Space > out
Definition teno_setup.cpp:681
int n_moments
Definition teno_setup.cpp:300
R< double ** > moments
Definition teno_setup.cpp:406
Kokkos::View< uint32_t *, Space > cells
Definition teno_setup.cpp:682