Skip to main content

euv_core/game/fluid_kit/wake/
struct.rs

1use super::*;
2
3/// Declarative configuration for the interactive 2D shallow-water `WaveHeightfield2D` solver.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct WaveHeightfieldConfig {
6    /// Grid cell count along the X axis (`WAKE_MIN_GRID_DIM..=WAKE_MAX_GRID_DIM`).
7    #[get(type(copy))]
8    pub(crate) width: usize,
9    /// Grid cell count along the Z axis (`WAKE_MIN_GRID_DIM..=WAKE_MAX_GRID_DIM`).
10    #[get(type(copy))]
11    pub(crate) height: usize,
12    /// Uniform physical cell spacing in meters.
13    #[get(type(copy))]
14    pub(crate) cell_size_m: f32,
15    /// Shallow-water wave propagation speed `c` in meters per second.
16    #[get(type(copy))]
17    pub(crate) wave_speed_mps: f32,
18    /// Uniform interior viscous wave damping rate in `s^-1`.
19    #[get(type(copy))]
20    pub(crate) damping: f32,
21    /// Width in cells of the perimeter absorbing sponge boundary layer.
22    #[get(type(copy))]
23    pub(crate) sponge_width: usize,
24    /// Peak damping rate added at the outer boundary of the sponge layer.
25    #[get(type(copy))]
26    pub(crate) sponge_strength: f32,
27    /// Exponential decay rate per second for accumulated surface wake foam.
28    #[get(type(copy))]
29    pub(crate) foam_decay_rate: f32,
30    /// World-space `(x, z)` coordinate of cell `(0, 0)`.
31    #[get(type(copy))]
32    pub(crate) origin_xz: Vec2,
33    /// Mean resting world-space water surface elevation along `+Y`.
34    #[get(type(copy))]
35    pub(crate) base_water_y: f32,
36}
37
38/// Internal substep scalar parameters for `WaveHeightfield2D` integration.
39#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
40pub(crate) struct WakeSubstepParams {
41    /// Grid cell count along X.
42    #[get(type(copy))]
43    pub(crate) width: usize,
44    /// Grid cell count along Z.
45    #[get(type(copy))]
46    pub(crate) height: usize,
47    /// Dimensionless squared Courant number `(c * dt / dx)^2`.
48    #[get(type(copy))]
49    pub(crate) courant_sq: f32,
50    /// Substep time interval in seconds.
51    #[get(type(copy))]
52    pub(crate) dt_sub: f32,
53    /// Exponential foam decay rate per second.
54    #[get(type(copy))]
55    pub(crate) foam_decay_rate: f32,
56}
57
58/// Internal radial impulse descriptor for splash and wake injection.
59#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
60pub(crate) struct WakeImpulseDesc {
61    /// World X center coordinate.
62    #[get(type(copy))]
63    pub(crate) world_x: f32,
64    /// World Z center coordinate.
65    #[get(type(copy))]
66    pub(crate) world_z: f32,
67    /// Influence footprint radius in meters.
68    #[get(type(copy))]
69    pub(crate) radius_m: f32,
70    /// Peak vertical displacement amplitude in meters.
71    #[get(type(copy))]
72    pub(crate) amplitude_m: f32,
73    /// Peak wake foam boost in `[0.0, 1.0]`.
74    #[get(type(copy))]
75    pub(crate) foam_boost: f32,
76}
77
78/// Interactive 2D shallow-water damped wave heightfield with absorbing sponge boundaries and solid obstacle reflections.
79#[derive(Clone, Data, Debug, PartialEq)]
80pub struct WaveHeightfield2D {
81    /// Sanitized solver configuration.
82    #[get(type(copy))]
83    pub(crate) config: WaveHeightfieldConfig,
84    /// Current wave surface displacement field in meters (`width * height`).
85    pub(crate) heights_curr: Vec<f32>,
86    /// Previous substep wave surface displacement field in meters (`width * height`).
87    pub(crate) heights_prev: Vec<f32>,
88    /// Pre-allocated next-step displacement buffer avoiding steady-state allocations (`width * height`).
89    pub(crate) heights_next: Vec<f32>,
90    /// Solid obstacle cell mask (`0` = fluid, `1` = solid reflective wall, `width * height`).
91    pub(crate) obstacle_mask: Vec<u8>,
92    /// Accumulated whitewater wake foam intensity in `[0.0, 1.0]` (`width * height`).
93    pub(crate) foam: Vec<f32>,
94    /// Precomputed per-cell total damping rate combining interior and sponge absorption (`width * height`).
95    pub(crate) cell_damping: Vec<f32>,
96    /// Most recent substep duration in seconds used for exact discrete kinetic-energy diagnostics.
97    #[get(type(copy))]
98    pub(crate) last_dt_sub: f32,
99    /// Accumulated simulation time in seconds.
100    #[get(type(copy))]
101    pub(crate) sim_time_secs: f32,
102}