DNDSR 0.1.0.dev1+gcd065ad
Distributed Numeric Data Structure for CFV
Loading...
Searching...
No Matches
EulerP.hpp
Go to the documentation of this file.
1/**
2 * @file EulerP.hpp
3 * @brief Core type definitions and utilities for the EulerP alternative Navier-Stokes evaluator module.
4 *
5 * The EulerP module is an alternative compressible Navier-Stokes evaluator with CUDA GPU support.
6 * Unlike the Euler module (which uses Eigen compile-time nVars and template-heavy dispatch),
7 * EulerP uses scalar loops, is device-callable, and supports both Host and CUDA backends
8 * via the @c DeviceBackend template parameter.
9 *
10 * This header defines:
11 * - Fixed flow variable count and index constants
12 * - Eigen vector/matrix type aliases for state and gradient storage
13 * - ArrayDof-based distributed array type aliases for MPI-parallel data
14 * - Helper functions for extracting momentum and coordinate sub-vectors
15 * - CRTP base class for packed kernel argument structs with MPI ghost exchange
16 */
17#pragma once
18#include "DNDS/ArrayDOF.hpp"
19#include "DNDS/Defines.hpp"
20#include "Eigen/Core"
21
22/**
23 * @brief Namespace for the EulerP alternative evaluator module with GPU support.
24 *
25 * Provides device-callable (Host + CUDA) compressible Navier-Stokes solvers using
26 * scalar loops instead of Eigen compile-time templates, enabling GPU offloading.
27 */
28namespace DNDS::EulerP
29{
30 static constexpr int nVarsFlow = 5; ///< Number of flow variables: rho, rhoU, rhoV, rhoW, E.
31 static constexpr int I4 = 4; ///< Index of the energy variable in the conservative state vector.
32
33 using TU = Eigen::Vector<real, nVarsFlow>; ///< Fixed-size 5-component conservative state vector (rho, rhoU, rhoV, rhoW, E).
34 using TDiffU = Eigen::Matrix<real, 3, nVarsFlow>; ///< Fixed-size 3x5 spatial gradient of the conservative state (one row per spatial dimension).
35
36 using TUFull = Eigen::Vector<real, Eigen::Dynamic>; ///< Dynamic-size state vector for extended variables (flow + turbulence model variables).
37 using TDiffUFull = Eigen::Matrix<real, 3, Eigen::Dynamic>; ///< Dynamic-size 3xN spatial gradient for extended variables.
38
39 using TUFullMap = Eigen::Map<TUFull>; ///< Eigen::Map wrapper for non-owning access to a dynamic-size state vector.
40 using TDiffUFullMap = Eigen::Map<TDiffUFull>; ///< Eigen::Map wrapper for non-owning access to a dynamic-size gradient matrix.
41
42 using TUDof = ArrayDof<nVarsFlow, 1>; ///< Distributed array of 5-component flow state vectors (one per DOF).
43 using TUGrad = ArrayDof<3, nVarsFlow>; ///< Distributed array of 3x5 gradient matrices (one per DOF).
44
45 using TUScalar = ArrayDof<1, 1>; ///< Distributed array of scalar values (e.g., pressure, temperature).
46 using TUScalarGrad = ArrayDof<3, 1>; ///< Distributed array of 3-component scalar gradients.
47
48 using TUScalar2 = ArrayDof<2, 1>; ///< Distributed array of 2-component scalar values (e.g., paired quantities).
49
50 using TUVec = ArrayDof<3, 1>; ///< Distributed array of 3-component vectors (e.g., velocity, coordinates).
51 using TUVecGrad = ArrayDof<3, 3>; ///< Distributed array of 3x3 vector gradient tensors.
52
53 /**
54 * @brief Extracts the momentum components (indices 1,2,3) from a state vector as a 3x1 block.
55 * @tparam TU Eigen vector type (deduced).
56 * @param v State vector of at least 4 components (rho, rhoU, rhoV, rhoW, ...).
57 * @return A 3x1 Eigen block expression referencing (rhoU, rhoV, rhoW).
58 */
59 template <class TU>
61 {
62 return v.template block<3, 1>(1, 0);
63 }
64
65 /**
66 * @brief Extracts the first 3 components (indices 0,1,2) from a vector as a 3x1 block.
67 * @tparam TU Eigen vector type (deduced).
68 * @param v Vector of at least 3 components.
69 * @return A 3x1 Eigen block expression referencing components (0, 1, 2).
70 */
71 template <class TU>
73 {
74 return v.template block<3, 1>(0, 0);
75 }
76
77 /**
78 * @brief CRTP base class for packed kernel argument structs used by the Evaluator.
79 *
80 * Kernel argument structs (e.g., RecGradient_Arg, Flux2nd_Arg) inherit from this
81 * base using CRTP. Each derived class must provide a static @c member_list() function
82 * returning a list of named pointers to its ArrayDof shared_ptr members.
83 *
84 * The base provides @c WaitAllPull(B), which iterates over all ArrayDof members
85 * and completes their MPI persistent ghost-exchange pull operations on the
86 * specified device backend.
87 *
88 * @tparam TDerived The derived packed argument struct type (CRTP pattern).
89 */
90 template <class TDerived>
92 {
93 public:
94 /**
95 * @brief Completes MPI ghost exchange for all ArrayDof members on the specified backend.
96 *
97 * Iterates over every ArrayDof shared_ptr registered in @c TDerived::member_list(),
98 * validates that both father and son arrays exist and reside on backend @p B,
99 * then calls @c waitPersistentPull(B) on each transformer to finalize
100 * non-blocking MPI receives.
101 *
102 * @param B The device backend (Host or CUDA) on which to perform the wait.
103 * @throws std::runtime_error If father/son arrays are missing or on the wrong device.
104 */
106 {
107 auto *dThis = static_cast<TDerived *>(this);
108
109 auto wait_all = [&](std::string name, auto &v)
110 {
111 auto do_wait = [B, name](auto &vv)
112 {
113 DNDS_check_throw_info(vv->father && vv->son, name + " needs father and son");
114 //! this assertion should be provided by ArrayTransformer
115 DNDS_check_throw_info(vv->trans.father.get() == vv->father.get(), name + " needs father == trans.father");
116 DNDS_check_throw_info(vv->trans.son.get() == vv->son.get(), name + " needs son == trans.son");
117 DNDS_check_throw_info(vv->father->device() == B,
118 name +
119 " father on " + device_backend_name(vv->father->device()) +
120 " wait on " + device_backend_name(B));
121 DNDS_check_throw_info(vv->son->device() == B,
122 name +
123 " son on " + device_backend_name(vv->father->device()) +
124 " wait on " + device_backend_name(B));
125
126 vv->trans.waitPersistentPull(B);
127 };
128 if constexpr (is_ssp_v<remove_cvref_t<decltype(v)>>)
129 do_wait(v);
130 else
131 for (size_t i = 0; i < v.size(); i++)
132 do_wait(v[i]);
133 };
134 for_each_member_ptr_list(*dThis, TDerived::member_list(), wait_all);
135 }
136 };
137}
Degree-of-freedom array with vector-space operations (MPI-collective).
Core type aliases, constants, and metaprogramming utilities for the DNDS framework.
#define DNDS_DEVICE_CALLABLE
Definition Defines.hpp:76
#define DNDS_FORCEINLINE
Definition Defines.hpp:978
#define DNDS_check_throw_info(expr, info)
Same as DNDS_check_throw but attaches a user-supplied info message to the thrown std::runtime_error.
Definition Errors.hpp:96
CRTP base class for packed kernel argument structs used by the Evaluator.
Definition EulerP.hpp:92
void WaitAllPull(DeviceBackend B)
Completes MPI ghost exchange for all ArrayDof members on the specified backend.
Definition EulerP.hpp:105
Namespace for the EulerP alternative evaluator module with GPU support.
Definition EulerP.hpp:29
Eigen::Vector< real, Eigen::Dynamic > TUFull
Dynamic-size state vector for extended variables (flow + turbulence model variables).
Definition EulerP.hpp:36
Eigen::Map< TUFull > TUFullMap
Eigen::Map wrapper for non-owning access to a dynamic-size state vector.
Definition EulerP.hpp:39
Eigen::Matrix< real, 3, Eigen::Dynamic > TDiffUFull
Dynamic-size 3xN spatial gradient for extended variables.
Definition EulerP.hpp:37
DNDS_DEVICE_CALLABLE DNDS_FORCEINLINE auto U123(TU &&v)
Extracts the momentum components (indices 1,2,3) from a state vector as a 3x1 block.
Definition EulerP.hpp:60
Eigen::Map< TDiffUFull > TDiffUFullMap
Eigen::Map wrapper for non-owning access to a dynamic-size gradient matrix.
Definition EulerP.hpp:40
Eigen::Vector< real, nVarsFlow > TU
Fixed-size 5-component conservative state vector (rho, rhoU, rhoV, rhoW, E).
Definition EulerP.hpp:33
DNDS_DEVICE_CALLABLE DNDS_FORCEINLINE auto U012(TU &&v)
Extracts the first 3 components (indices 0,1,2) from a vector as a 3x1 block.
Definition EulerP.hpp:72
Eigen::Matrix< real, 3, nVarsFlow > TDiffU
Fixed-size 3x5 spatial gradient of the conservative state (one row per spatial dimension).
Definition EulerP.hpp:34
DeviceBackend
Enumerates the backends a DeviceStorage / Array can live on.
const char * device_backend_name(DeviceBackend B)
Canonical string name for a DeviceBackend (used in log messages).
constexpr bool is_ssp_v
Definition Defines.hpp:152
std::remove_cv_t< std::remove_reference_t< T > > remove_cvref_t
Convenience remove_cv + remove_reference composition (C++17 port of C++20's std::remove_cvref_t).
Definition Defines.hpp:156
void for_each_member_ptr_list(Class &obj, TList &&obj_member_ptr_list, F &&f)
Invoke f(name, obj.*ptr) for every member in a list of MemberPtr.
Eigen::Matrix< real, 5, 1 > v