Mallard 0.8.0
Unstructured, GPU accelerated, high-order finite volume CFD solver
Mallard website
Loading...
Searching...
No Matches
synthetic_inflow.h
Go to the documentation of this file.
1
13#ifndef SYNTHETIC_INFLOW_H
14#define SYNTHETIC_INFLOW_H
15
16#include <array>
17#include <cstdint>
18#include <memory>
19#include <string>
20#include <vector>
21
22#include <Kokkos_Core.hpp>
23#include <toml.hpp>
24
25#include "common.h"
26#include "expression.h"
27
28class Mesh;
29
31constexpr uint8_t N_STRESS = N_DIM * (N_DIM + 1) / 2;
32
34using Point = std::array<double, N_DIM>;
35
45 public:
46 InletProfile(const toml::value & boundary, const std::string & where);
47
49 static bool turbulent(const toml::value & boundary) { return boundary.contains("turbulence"); }
50
52 bool uniform() const { return uniform_; }
53
54 std::array<double, N_DIM> velocity(const Point & x) const;
55
57 std::array<double, N_STRESS> stress_at(const Point & x) const;
58
59 private:
61 struct Field {
62 double value = 0.0;
63 std::shared_ptr<Expression> expression;
64 double at(const Point & x) const;
65 };
66 bool uniform_ = true;
67 std::vector<Field> u; // per component
68 std::vector<Field> stress; // per N_STRESS component, empty without turbulence
69 // Profile table: coordinate axis, sorted coordinates, and N_DIM mean + N_STRESS stress columns
70 int axis = -1;
71 std::vector<double> coordinate;
72 std::vector<std::vector<double>> columns;
73
74 void read_table(const toml::value & turbulence, const std::string & where);
75 double table(size_t column, double s) const;
76};
77
98 public:
107 SyntheticInflow(const toml::value & boundary, const std::string & where, uint64_t stream, const Mesh & mesh,
108 const std::vector<uint32_t> & faces, const std::vector<int32_t> & char_index);
109
111 void fill(double t, const Kokkos::View<rtype *[N_DIM]> & target);
112
114 std::string summary() const { return summary_; }
115
117 double time_spacing() const { return dt_plane; }
119 double convection_velocity() const { return U_c; }
120
121 // Public because nvcc rejects device lambdas in non-public member functions
123 void random_plane(int64_t m, uint32_t slot);
124 void time_filter(int64_t m, uint32_t slot);
125 void net_flux(uint32_t slot);
126
127 private:
128 static constexpr int N_T = N_DIM - 1; // transverse directions
129 static constexpr uint32_t N_CACHE = 4; // filtered planes kept
130 static constexpr uint32_t CHUNK = 256; // points per partial sum of the net flux
131
132 std::string summary_;
133 uint64_t seed = 1;
134 uint64_t stream = 0;
135 uint32_t normal_axis = 0;
136 uint32_t axes[N_T] = {}; // global axes of the transverse directions
137 // Auxiliary grid: points, spacing, origin and periodicity per transverse direction
138 int32_t n_grid[N_T] = {};
139 double spacing[N_T] = {};
140 double origin[N_T] = {};
141 bool periodic[N_T] = {};
142 int32_t pad[N_T] = {}; // random points beyond the grid on each side (0 if periodic)
143 int32_t n_padded[N_T] = {};
144 int32_t n_points = 0; // grid points of a plane
145 double dt_plane = 0.0; // time between planes
146 double U_c = 0.0; // convection velocity of Taylor's hypothesis
147 bool zero_net_flux = true;
148 double area = 0.0; // of the whole inlet
149 // Filters: (component, direction: transverse ones, then time), half widths and kernels
150 int32_t half_width[N_DIM][N_DIM] = {};
151 double rho1[N_DIM][N_DIM] = {}; // correlation of neighboring points of the filtered field
152 int32_t n_time = 0; // largest half width in time
153 Kokkos::View<rtype ***> kernels; // (component, direction, k + half width)
154
155 // Faces of this rank
156 uint32_t n_faces = 0;
157 Kokkos::View<int32_t *> face_char;
158 Kokkos::View<int32_t *[N_T][2]> face_corner; // grid index below and above per direction
159 Kokkos::View<rtype *[N_T]> face_fraction;
160 Kokkos::View<rtype *[N_DIM]> face_scale; // 1 / standard deviation of the interpolated field
161 Kokkos::View<rtype *[N_DIM]> face_mean;
162 Kokkos::View<rtype *[N_STRESS]> face_cholesky; // lower triangle, row by row
163
164 // Planes
165 Kokkos::View<rtype **> random_work; // (component, padded point)
166 Kokkos::View<rtype **> filter_work; // (component, point after the first direction)
167 Kokkos::View<rtype ***> filtered; // (slot, component, point): filtered in space, slot = plane mod
168 std::vector<int64_t> filtered_index; // plane of each slot
169 Kokkos::View<rtype ***> planes; // (cache slot, component, point): filtered in space and time
170 std::vector<int64_t> plane_index;
171 std::vector<uint64_t> plane_used;
172 uint64_t use_count = 0;
173 Kokkos::View<rtype **> flux_weight; // (component, point): weight of the net normal flux
174 Kokkos::View<rtype **> chunk_sums; // (chunk, component)
175 Kokkos::View<rtype **> plane_flux; // (cache slot, component): sum of flux_weight * plane
176};
177
178#endif // SYNTHETIC_INFLOW_H
Mean velocity and Reynolds stress of an nscbc_inlet at given points: u (numbers or expressions in x,...
Definition synthetic_inflow.h:44
bool uniform() const
Whether the mean velocity is the same everywhere.
Definition synthetic_inflow.h:52
std::array< double, N_DIM > velocity(const Point &x) const
Definition synthetic_inflow.cpp:285
std::array< double, N_STRESS > stress_at(const Point &x) const
Reynolds stress in N_STRESS order (zero without turbulence).
Definition synthetic_inflow.cpp:291
static bool turbulent(const toml::value &boundary)
Whether the boundary has a [boundaries.turbulence] table.
Definition synthetic_inflow.h:49
Definition mesh.h:111
Synthetic turbulence for one nscbc_inlet: the digital filter of Klein, Sadiki & Janicka (2003),...
Definition synthetic_inflow.h:97
void time_filter(int64_t m, uint32_t slot)
Definition synthetic_inflow.cpp:725
double time_spacing() const
Time between filtered planes.
Definition synthetic_inflow.h:117
std::string summary() const
One-line description for the run log.
Definition synthetic_inflow.h:114
uint32_t plane(int64_t m)
Definition synthetic_inflow.cpp:631
double convection_velocity() const
Convection velocity of Taylor's hypothesis.
Definition synthetic_inflow.h:119
void net_flux(uint32_t slot)
Definition synthetic_inflow.cpp:740
void random_plane(int64_t m, uint32_t slot)
Definition synthetic_inflow.cpp:654
void fill(double t, const Kokkos::View< rtype *[N_DIM]> &target)
Write the target velocity (mean plus fluctuation) of the inlet's faces at time t into target(k).
Definition synthetic_inflow.cpp:761
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
Host-side analytical expressions of (x, y, z, t) from input files.
std::array< double, N_DIM > Point
Point in space.
Definition synthetic_inflow.h:34
constexpr uint8_t N_STRESS
Independent components of a symmetric tensor: 2D [xx, yy, xy], 3D [xx, yy, zz, xy,...
Definition synthetic_inflow.h:31