DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
EulerP_Evaluator_impl.hpp
Go to the documentation of this file.
1/** @file EulerP_Evaluator_impl.hpp
2 * @brief Backend-specific implementation layer for EulerP Evaluator kernel dispatch.
3 *
4 * Defines Evaluator_impl<B>, a template struct parameterized by DeviceBackend (Host or CUDA).
5 * For each Evaluator kernel, an inner argument struct wraps the host-side shared_ptr-based
6 * Evaluator::*_Arg into device views suitable for kernel execution. The inner Portable
7 * sub-struct is trivially copyable and can be passed to CUDA kernels.
8 *
9 * Also defines helper macros for constructing device views from Evaluator argument members.
10 */
11#pragma once
12
13#include "EulerP_Evaluator.hpp"
14#include <memory>
15#include <type_traits>
16
17namespace DNDS::EulerP
18{
19/** @name Argument construction macros
20 * @brief Helper macros used inside Evaluator_impl inner arg struct constructors to
21 * create device views from host-side Evaluator argument members.
22 * @{
23 */
24#define DNDS_EULERP_IMPL_ARG_GET_REF(member) auto &member = arg.member;
25#define DNDS_EULERP_IMPL_ARG_GET_REF_PORTABLE(member) auto &member = arg.portable.member;
26
27#define DNDS_EULERP_IMPL_ARG_CTOR_INIT_SELF() \
28 self(self_), \
29 this_v(self.template deviceView<B>()), \
30 self_view(this_v)
31#define DNDS_EULERP_IMPL_ARG_CTOR_INIT_SSPARR(member) \
32 member(arg.member->template deviceView<B>())
33#define DNDS_EULERP_IMPL_ARG_CTOR_INIT_VECSSPARR(member, member_v) \
34 member_v(arg.member.size(), [&](int i) \
35 { return arg.member.at(i)->template deviceView<B>(); }), \
36 member((member_v).deviceView())
37
38#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_SSPARR(member) \
39 { \
40 portable.member = arg.member->template deviceView<B>(); \
41 }
42#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_SSPARR_BUF(member, buf_name) \
43 { \
44 portable.member = (buf_name).template deviceView<B>(); \
45 }
46#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_VECSSPARR(member, member_v) \
47 \
48 { \
49 member_v = std::make_unique<typename decltype(member_v)::element_type>( \
50 arg.member.size(), [&](int i) \
51 { return arg.member.at(i)->template deviceView<B>(); }); \
52 portable.member = (member_v)->deviceView(); \
53 }
54
55#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_VECSSPARR_BUF(member, member_v, buf_name) \
56 \
57 { \
58 member_v = std::make_unique<typename decltype(member_v)::element_type>( \
59 (buf_name).size(), [&](int i) \
60 { return (buf_name).at(i).template deviceView<B>(); }); \
61 portable.member = (member_v)->deviceView(); \
62 }
63
64/** @} */ // end of argument construction macros
65
66 /**
67 * @brief Backend-specific implementation of EulerP Evaluator kernels.
68 *
69 * Each kernel (RecGradient, Cons2PrimMu, EstEigenDt, RecFace2nd, Flux2nd) is wrapped
70 * in an inner Arg struct that converts host-side shared_ptr arrays into device views,
71 * and a static method that dispatches the actual computation. The inner Portable struct
72 * within each Arg is trivially copyable for CUDA kernel launch.
73 *
74 * @tparam B The DeviceBackend (Host or CUDA). Explicit specializations live in
75 * EulerP_Evaluator_impl.cpp (Host) and the CUDA compilation unit.
76 */
77 template <DeviceBackend B>
79 {
80 /** @brief Unique pointer to a device view vector of scalar array views. */
81 using t_Scalar_deviceViewVector_sup = std::unique_ptr<deviceViewVector<TUScalar::t_deviceView<B>, B>>;
82 /** @brief Unique pointer to a device view vector of scalar-gradient array views. */
83 using t_ScalarGrad_deviceViewVector_sup = std::unique_ptr<deviceViewVector<TUScalarGrad::t_deviceView<B>, B>>;
84 /**
85 * @brief Device-side argument struct for gradient reconstruction kernels.
86 *
87 * Wraps Evaluator::RecGradient_Arg by converting shared_ptr arrays into device views.
88 * The Portable sub-struct is trivially copyable for CUDA kernel parameters.
89 */
91 {
93 Evaluator::t_deviceView<B> this_v; //! must keep this alive
95
96 /** @brief Trivially-copyable payload holding device views of all kernel data. */
97 struct Portable
98 {
99 // buffer
100 TUDof::t_deviceView<B> faceBCBuffer; /**< @brief Face BC ghost DOF buffer (device view). */
101 vector_DeviceView<B, TUScalar::t_deviceView<B>> faceBCScalarBuffer; /**< @brief Face BC ghost scalar buffers (device view). */
102
103 TUDof::t_deviceView<B> u; /**< @brief Conservative state (device view). */
104 TUGrad::t_deviceView<B> uGrad; /**< @brief Gradient of conservative state (device view). */
105 vector_DeviceView<B, TUScalar::t_deviceView<B>> uScalar; /**< @brief Transported scalar fields (device view). */
106 vector_DeviceView<B, TUScalarGrad::t_deviceView<B>> uScalarGrad; /**< @brief Gradients of transported scalars (device view). */
108 static_assert(std::is_trivially_copyable_v<Portable>);
109
110 t_Scalar_deviceViewVector_sup faceBCScalarBuffer_v; /**< @brief Owning storage for face BC scalar buffer device views. */
111 // out
112 t_Scalar_deviceViewVector_sup uScalar_v; /**< @brief Owning storage for scalar field device views. */
113 t_ScalarGrad_deviceViewVector_sup uScalarGrad_v; /**< @brief Owning storage for scalar gradient device views. */
114
115 /**
116 * @brief Constructs device views from the host-side RecGradient_Arg.
117 * @param self_ Reference to the Evaluator.
118 * @param arg Host-side argument struct providing shared_ptr arrays.
119 */
132 };
133 /**
134 * @brief Green-Gauss gradient reconstruction: boundary ghost values + cell gradient computation.
135 * @param arg Device-side argument struct with all required views.
136 */
138
139 /**
140 * @brief Barth-Jespersen gradient limiter applied to reconstructed gradients.
141 * @param arg Device-side argument struct with all required views.
142 */
144
145 /**
146 * @brief Device-side argument struct for conservative-to-primitive + viscosity kernel.
147 *
148 * Wraps Evaluator::Cons2PrimMu_Arg by converting all shared_ptr arrays into device views.
149 */
151 {
153 Evaluator::t_deviceView<B> this_v; //! must keep this alive
155
156 /** @brief Trivially-copyable payload for Cons2PrimMu kernel data. */
157 struct Portable
158 {
159 TUDof::t_deviceView<B> u; /**< @brief Conservative state (device view). */
160 TUGrad::t_deviceView<B> uGrad; /**< @brief Gradient of conservative state (device view). */
161 vector_DeviceView<B, TUScalar::t_deviceView<B>> uScalar; /**< @brief Transported scalars (device view). */
162 vector_DeviceView<B, TUScalarGrad::t_deviceView<B>> uScalarGrad; /**< @brief Scalar gradients (device view). */
163 TUDof::t_deviceView<B> uPrim; /**< @brief Primitive state output (device view). */
164 TUGrad::t_deviceView<B> uGradPrim; /**< @brief Primitive gradient output (device view). */
165 vector_DeviceView<B, TUScalar::t_deviceView<B>> uScalarPrim; /**< @brief Primitive scalars output (device view). */
166 vector_DeviceView<B, TUScalarGrad::t_deviceView<B>> uScalarGradPrim; /**< @brief Primitive scalar gradients output (device view). */
167 TUScalar::t_deviceView<B> p; /**< @brief Pressure output (device view). */
168 TUScalar::t_deviceView<B> T; /**< @brief Temperature output (device view). */
169 TUScalar::t_deviceView<B> a; /**< @brief Speed of sound output (device view). */
170 TUScalar::t_deviceView<B> gamma; /**< @brief Gamma output (device view). */
171 TUScalar::t_deviceView<B> mu; /**< @brief Total viscosity output (device view). */
172 vector_DeviceView<B, TUScalar::t_deviceView<B>> muComp; /**< @brief Component viscosities output (device view). */
174 static_assert(std::is_trivially_copyable_v<Portable>);
177 // out
181
202 };
203
204 /**
205 * @brief Executes conservative-to-primitive conversion with viscosity computation.
206 * @param arg Device-side argument struct with all required views.
207 */
208 static void Cons2PrimMu(Cons2PrimMu_Arg &arg);
209
210 /**
211 * @brief Device-side argument struct for conservative-to-primitive conversion (no gradients/viscosity).
212 */
252
253 /**
254 * @brief Executes conservative-to-primitive conversion (no gradients/viscosity).
255 * @param arg Device-side argument struct with all required views.
256 */
257 static void Cons2Prim(Cons2Prim_Arg &arg);
258
259 /**
260 * @brief Device-side argument struct for eigenvalue estimation and time-step computation.
261 */
295
296 /**
297 * @brief First pass: computes per-face eigenvalue estimates from cell states.
298 * @param arg Device-side argument struct with all required views.
299 */
301
302 /**
303 * @brief Second pass: accumulates face eigenvalues to cells and computes local dt.
304 * @param arg Device-side argument struct with all required views.
305 */
307
308 /**
309 * @brief Device-side argument struct for 2nd-order face value reconstruction.
310 */
312 {
314 Evaluator::t_deviceView<B> this_v; //! must keep this alive
316
332 static_assert(std::is_trivially_copyable_v<Portable>);
333
339
356 };
357
358 /**
359 * @brief Executes 2nd-order face value reconstruction from cell-centered data.
360 * @param arg Device-side argument struct with all required views.
361 */
362 static void RecFace2nd(RecFace2nd_Arg &arg);
363
364 /**
365 * @brief Device-side argument struct for 2nd-order flux evaluation and RHS accumulation.
366 *
367 * The largest impl arg struct, wrapping all state, thermodynamic, face-reconstructed,
368 * and output arrays as device views for kernel execution.
369 */
371 {
373 Evaluator::t_deviceView<B> this_v; //! must keep this alive
375
414 static_assert(std::is_trivially_copyable_v<Portable>);
415
418
422
426
429
432 {
433 //
438
450 //
457
460 // out
465 }
466 };
467
468 /**
469 * @brief Evaluates 2nd-order Roe flux per face and scatters to cell RHS.
470 * @param arg Device-side argument struct with all required views.
471 */
472 static void Flux2nd(Flux2nd_Arg &arg);
473 };
474}
Main evaluator class for the EulerP compressible Navier-Stokes solver module.
#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_SSPARR(member)
#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_VECSSPARR_BUF(member, member_v, buf_name)
#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_SSPARR_BUF(member, buf_name)
#define DNDS_EULERP_IMPL_ARG_CTOR_INIT_SELF()
#define DNDS_EULERP_IMPL_ARG_CTOR_PORTABLE_COPY_VECSSPARR(member, member_v)
Mutable device view of an ArrayDof father/son pair.
Definition ArrayDOF.hpp:34
ArrayDofDeviceView< B, n_m, n_n > t_deviceView
Mutable device view alias.
Definition ArrayDOF.hpp:179
Device-callable view of the Evaluator, combining finite volume, BC handler, and physics views.
Main EulerP evaluator orchestrating CFD kernel dispatch for compressible N-S solvers.
TUDof u_face_bufferL
Left-side face DOF buffer for boundary value storage.
std::vector< TUScalar > uScalar_face_bufferL
Left-side face scalar buffers for additional transported scalars.
Non-owning device-callable view {pointer, size} over a typed array.
Definition Vector.hpp:148
Namespace for the EulerP alternative evaluator module with GPU support.
Definition EulerP.hpp:29
Packed argument struct for conservative-to-primitive conversion with viscosity computation.
Packed argument struct for conservative-to-primitive conversion without gradients or viscosity.
Packed argument struct for eigenvalue estimation and local time-step computation.
Packed argument struct for 2nd-order inviscid (and eventually viscous) flux evaluation.
Packed argument struct for 2nd-order face value reconstruction.
Packed argument struct for Green-Gauss gradient reconstruction with Barth-Jespersen limiting.
Non-trivially-copyable device view holding shared_ptr to fv and device views of BC/physics.
Trivially-copyable payload for Cons2PrimMu kernel data.
vector_DeviceView< B, TUScalar::t_deviceView< B > > muComp
Component viscosities output (device view).
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGrad
Scalar gradients (device view).
TUDof::t_deviceView< B > uPrim
Primitive state output (device view).
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalar
Transported scalars (device view).
TUGrad::t_deviceView< B > uGradPrim
Primitive gradient output (device view).
TUScalar::t_deviceView< B > a
Speed of sound output (device view).
TUScalar::t_deviceView< B > T
Temperature output (device view).
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGradPrim
Primitive scalar gradients output (device view).
TUScalar::t_deviceView< B > gamma
Gamma output (device view).
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarPrim
Primitive scalars output (device view).
TUScalar::t_deviceView< B > p
Pressure output (device view).
TUDof::t_deviceView< B > u
Conservative state (device view).
TUScalar::t_deviceView< B > mu
Total viscosity output (device view).
TUGrad::t_deviceView< B > uGrad
Gradient of conservative state (device view).
Device-side argument struct for conservative-to-primitive + viscosity kernel.
EvaluatorDeviceView< B > self_view
must keep this alive
struct DNDS::EulerP::Evaluator_impl::Cons2PrimMu_Arg::Portable portable
Cons2PrimMu_Arg(Evaluator &self_, Evaluator::Cons2PrimMu_Arg &arg)
t_ScalarGrad_deviceViewVector_sup uScalarGradPrim_v
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalar
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarPrim
Device-side argument struct for conservative-to-primitive conversion (no gradients/viscosity).
struct DNDS::EulerP::Evaluator_impl::Cons2Prim_Arg::Portable portable
Cons2Prim_Arg(Evaluator &self_, Evaluator::Cons2Prim_Arg &arg)
EvaluatorDeviceView< B > self_view
must keep this alive
Device-side argument struct for eigenvalue estimation and time-step computation.
struct DNDS::EulerP::Evaluator_impl::EstEigenDt_Arg::Portable portable
EstEigenDt_Arg(Evaluator &self_, Evaluator::EstEigenDt_Arg &arg)
EvaluatorDeviceView< B > self_view
must keep this alive
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarFR
vector_DeviceView< B, TUScalar::t_deviceView< B > > rhsScalar
vector_DeviceView< B, TUScalar::t_deviceView< B > > fluxScalarFF
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGradPrim
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarFL
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalar
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGradFF
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGrad
vector_DeviceView< B, TUScalar::t_deviceView< B > > muComp
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarPrim
Device-side argument struct for 2nd-order flux evaluation and RHS accumulation.
Flux2nd_Arg(Evaluator &self_, Evaluator::Flux2nd_Arg &arg)
t_ScalarGrad_deviceViewVector_sup uScalarGrad_v
struct DNDS::EulerP::Evaluator_impl::Flux2nd_Arg::Portable portable
t_ScalarGrad_deviceViewVector_sup uScalarGradPrim_v
EvaluatorDeviceView< B > self_view
must keep this alive
t_ScalarGrad_deviceViewVector_sup uScalarGradFF_v
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGrad
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarFL
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalarFR
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGradFF
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalar
Device-side argument struct for 2nd-order face value reconstruction.
RecFace2nd_Arg(Evaluator &self_, Evaluator::RecFace2nd_Arg &arg)
struct DNDS::EulerP::Evaluator_impl::RecFace2nd_Arg::Portable portable
EvaluatorDeviceView< B > self_view
must keep this alive
t_ScalarGrad_deviceViewVector_sup uScalarGradFF_v
Trivially-copyable payload holding device views of all kernel data.
TUGrad::t_deviceView< B > uGrad
Gradient of conservative state (device view).
vector_DeviceView< B, TUScalarGrad::t_deviceView< B > > uScalarGrad
Gradients of transported scalars (device view).
vector_DeviceView< B, TUScalar::t_deviceView< B > > uScalar
Transported scalar fields (device view).
TUDof::t_deviceView< B > u
Conservative state (device view).
TUDof::t_deviceView< B > faceBCBuffer
Face BC ghost DOF buffer (device view).
vector_DeviceView< B, TUScalar::t_deviceView< B > > faceBCScalarBuffer
Face BC ghost scalar buffers (device view).
Device-side argument struct for gradient reconstruction kernels.
t_ScalarGrad_deviceViewVector_sup uScalarGrad_v
Owning storage for scalar gradient device views.
EvaluatorDeviceView< B > self_view
must keep this alive
t_Scalar_deviceViewVector_sup faceBCScalarBuffer_v
Owning storage for face BC scalar buffer device views.
t_Scalar_deviceViewVector_sup uScalar_v
Owning storage for scalar field device views.
RecGradient_Arg(Evaluator &self_, Evaluator::RecGradient_Arg &arg)
Constructs device views from the host-side RecGradient_Arg.
struct DNDS::EulerP::Evaluator_impl::RecGradient_Arg::Portable portable
Backend-specific implementation of EulerP Evaluator kernels.
static void Flux2nd(Flux2nd_Arg &arg)
Evaluates 2nd-order Roe flux per face and scatters to cell RHS.
static void Cons2PrimMu(Cons2PrimMu_Arg &arg)
Executes conservative-to-primitive conversion with viscosity computation.
static void EstEigenDt_GetFaceLam(EstEigenDt_Arg &arg)
First pass: computes per-face eigenvalue estimates from cell states.
std::unique_ptr< deviceViewVector< TUScalar::t_deviceView< B >, B > > t_Scalar_deviceViewVector_sup
Unique pointer to a device view vector of scalar array views.
static void Cons2Prim(Cons2Prim_Arg &arg)
Executes conservative-to-primitive conversion (no gradients/viscosity).
static void EstEigenDt_FaceLam2CellDt(EstEigenDt_Arg &arg)
Second pass: accumulates face eigenvalues to cells and computes local dt.
static void RecFace2nd(RecFace2nd_Arg &arg)
Executes 2nd-order face value reconstruction from cell-centered data.
std::unique_ptr< deviceViewVector< TUScalarGrad::t_deviceView< B >, B > > t_ScalarGrad_deviceViewVector_sup
Unique pointer to a device view vector of scalar-gradient array views.
static void RecGradient_BarthLimiter(RecGradient_Arg &arg)
Barth-Jespersen gradient limiter applied to reconstructed gradients.
static void RecGradient_GGRec(RecGradient_Arg &arg)
Green-Gauss gradient reconstruction: boundary ghost values + cell gradient computation.