sparkl2d_kernels/
gpu_timestep.rs

1use sparkl_core::math::Real;
2
3#[cfg_attr(
4    not(target_os = "cuda"),
5    derive(cust::DeviceCopy)
6)]
7#[derive(Copy, Clone, Debug, bytemuck::Zeroable, bytemuck::Pod)]
8#[repr(transparent)]
9pub struct GpuTimestepLength(pub u64);
10
11impl Default for GpuTimestepLength {
12    fn default() -> Self {
13        GpuTimestepLength(0)
14    }
15}
16
17impl GpuTimestepLength {
18    pub const FACTOR: f32 = 1_000_000_000_000.0;
19
20    pub fn from_sec(dt: Real) -> Self {
21        Self((dt * Self::FACTOR) as u64)
22    }
23
24    pub fn into_sec(self) -> f32 {
25        self.0 as f32 / Self::FACTOR
26    }
27}