1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* SPDX-License-Identifier: MIT
* Copyright (c) 2023 - 2026. The DeepCausality Authors and Contributors. All Rights Reserved.
*/
//! Compressible Newtonian Navier-Stokes regime evaluators.
//!
//! **These are pointwise right-hand-side contributions only.** Each function evaluates the RHS of one
//! conservation law at a single sample point from divergences the caller supplies. No thermodynamic
//! closure is provided or checked here: the equation of state `p(ρ, e)` that ties pressure to the
//! conserved variables is the **caller's responsibility**, and nothing in this module verifies that the
//! `p` passed in is consistent with the `ρ` and `ρE` passed in. `deep_causality_physics` ships
//! `speed_of_sound_ideal_gas_kernel` and the ideal-gas pressure kernels if an ideal-gas closure is
//! wanted; a real-gas or reacting closure is the caller's to supply.
//!
//! Three pointwise RHS kernels for the compressible NS system:
//!
//! ```text
//! ∂ρ/∂t = − ∇·(ρ u)
//! ∂u/∂t = − (u·∇)u − (1/ρ) ∇p + (1/ρ) ∇·τ + g
//! ∂(ρE)/∂t = − ∇·(ρ u E) − ∇·(p u) + ∇·(τ·u) − ∇·q + ρ (u·g)
//! ```
//!
//! Conserved variables: `ρ` (density), `ρu` (momentum), `ρE` (total energy
//! per unit volume), with `E = e + 0.5‖u‖²`. The momentum kernel returns the
//! Eulerian acceleration `∂u/∂t` (primitive form) for consistency with the
//! other regime evaluators; the energy kernel returns the conservative-form
//! scalar `∂(ρE)/∂t`.
//!
//! Sign convention follows continuum mechanics: viscous stress positive in
//! tension; heat-flux vector `q` follows Fourier's law `q = −κ∇T`, so the
//! `-∇·q` term in the energy equation is a heat *source*.
//!
//! Caller computes the spatial divergences (`∇·τ`, `∇·q`, `∇·(p u)`,
//! `∇·(τ·u)`, `∇·(ρ u E)`) at the sample point; these kernels do not
//! discretise space.
use RealField;
use PhysicsError;
use ;
use ;
/// Continuity equation RHS: `∂ρ/∂t = − u·∇ρ − ρ ∇·u`.
///
/// Reduces to `0` for incompressible divergence-free flow. Returned as a
/// scalar in kg/(m³·s).
/// Momentum equation RHS in primitive velocity form:
/// `∂u/∂t = − (u·∇)u − (1/ρ) ∇p + (1/ρ) ∇·τ + g`.
///
/// Reduces to `incompressible_ns_rhs` when the viscous-stress
/// divergence equals `ρ ν ∇²u` (constant `μ`, divergence-free flow).
///
/// - `div_tau` — divergence of the viscous stress tensor (Pa/m)
/// - errors when `ρ = 0` (inherited from `pressure_gradient_force_kernel`)
/// Total-energy equation RHS in conservative form:
///
/// `∂(ρE)/∂t = − ∇·(ρ u E) − ∇·(p u) + ∇·(τ·u) − ∇·q + ρ (u·g)`
///
/// All four divergences are supplied by the caller at the sample point.
///
/// **`div_q` sign convention, which this function cannot check.** It takes `∇·q` where `q` is the
/// Fourier heat flux `q = −k∇T`, pointing down-gradient. The term enters as `−∇·q`, so `−∇·q > 0` is
/// net heat *deposited* at the point. The convention lives in this docstring rather than in the type:
/// `div_q` is a bare scalar, so passing `∇·(k∇T)` (the opposite sign) compiles and silently flips the
/// energy source. A `HeatFlux`/`HeatFluxDivergence` newtype would carry the convention in the type
/// instead; that is a follow-up, and until then the caller owns the sign.