Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add f64 support #61

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["build/salva2d", "build/salva3d", "examples2d", "examples3d"]
members = ["build/salva2d", "build/salva2d-f64", "build/salva3d", "build/salva3d-f64", "examples2d", "examples3d"]
resolver = "2"

[profile.release]
Expand Down
57 changes: 57 additions & 0 deletions build/salva2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[package]
name = "salva2d-f64"
version = "0.9.0"
authors = [ "Sébastien Crozet <[email protected]>" ]
description = "2-dimensional particle-based fluid dynamics in Rust."
documentation = "https://salva.rs/docs"
homepage = "https://salva.rs"
repository = "https://github.com/dimforge/salva"
readme = "README.md"
categories = [ "science", "game-development", "mathematics", "simulation", "wasm"]
keywords = [ "physics", "dynamics", "particles", "fluids", "SPH" ]
license = "Apache-2.0"
edition = "2021"

[badges]
maintenance = { status = "actively-developed" }

[features]
default = [ "dim2", "f64" ]
dim2 = [ ]
f64 = [ ]
parallel = [ "rayon" ]
sampling = [ "rapier" ]
rapier = [ "parry", "rapier2d" ]
rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry2d" ]
wasm-bindgen = [ "rapier2d/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lib]
name = "salva2d_f64"
path = "../../src/lib.rs"
required-features = [ "dim2", "f64" ]

[dependencies]
approx = "0.5"
num-traits = "0.2"
fnv = "1.0"
itertools = "0.13"
generational-arena = "0.2"
instant = { version = "0.1", features = [ "now" ] }
rayon = { version = "1.8", optional = true }

nalgebra = "0.33"
parry2d = { version = "0.16", optional = true }
rapier2d = { version = "0.21", optional = true }
rapier_testbed2d = { version = "0.21", optional = true }
Ughuuu marked this conversation as resolved.
Show resolved Hide resolved

bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy = { version = "0.13.2", default-features = false, features = ["bevy_winit", "bevy_render", "x11"], optional = true }

# Dependencies for WASM only.
[target.'cfg(target_arch = "wasm32")'.dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render"], optional = true }
23 changes: 12 additions & 11 deletions build/salva2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ edition = "2021"
maintenance = { status = "actively-developed" }

[features]
default = ["dim2"]
dim2 = []
parallel = ["rayon"]
sampling = ["rapier"]
rapier = ["parry", "rapier2d"]
rapier-testbed = ["rapier", "rapier_testbed2d", "graphics"]
rapier-harness = ["rapier-testbed"]
parry = ["parry2d"]
wasm-bindgen = ["rapier2d/wasm-bindgen"]
graphics = ["bevy", "bevy_egui"]
default = [ "dim2", "f32" ]
dim2 = [ ]
f32 = [ ]
parallel = [ "rayon" ]
sampling = [ "rapier" ]
rapier = [ "parry", "rapier2d" ]
rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry2d" ]
wasm-bindgen = [ "rapier2d/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
Expand All @@ -41,7 +42,7 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
[lib]
name = "salva2d"
path = "../../src/lib.rs"
required-features = ["dim2"]
required-features = [ "dim2", "f32" ]

[dependencies]
approx = "0.5"
Expand Down
53 changes: 53 additions & 0 deletions build/salva3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[package]
name = "salva3d-f64"
version = "0.9.0"
authors = [ "Sébastien Crozet <[email protected]>" ]
description = "3-dimensional particle-based fluid dynamics in Rust."
documentation = "https://salva.rs/rustdoc/salva3d/index.html"
homepage = "https://salva.rs"
repository = "https://github.com/dimforge/salva"
readme = "README.md"
keywords = [ "physics", "dynamics", "particles", "fluids", "SPH" ]
license = "Apache-2.0"
edition = "2021"

[features]
default = [ "dim3", "f64" ]
dim3 = [ ]
f64 = [ ]
parallel = [ "rayon" ]
rapier = [ "parry", "rapier3d" ]
sampling = [ "rapier" ]
rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry3d" ]
wasm-bindgen = [ "rapier3d/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lib]
name = "salva3d_f64"
path = "../../src/lib.rs"
required-features = [ "dim3", "f64" ]

[dependencies]
approx = "0.5"
num-traits = "0.2"
fnv = "1.0"
itertools = "0.13"
generational-arena = "0.2"
instant = { version = "0.1", features = [ "now" ] }
rayon = { version = "1.8", optional = true }

nalgebra = "0.33"
parry3d = { version = "0.16", optional = true }
rapier3d = { version = "0.21", optional = true }
rapier_testbed3d = { version = "0.21", optional = true }

bevy_egui = { version = "0.26", features = ["immutable_ctx"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render", "x11"], optional = true }

# Dependencies for WASM only.
[target.'cfg(target_arch = "wasm32")'.dependencies]
bevy = { version = "0.13", default-features = false, features = ["bevy_winit", "bevy_render"], optional = true }
23 changes: 12 additions & 11 deletions build/salva3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@ rust.unexpected_cfgs = { level = "warn", check-cfg = [
] }

[features]
default = ["dim3"]
dim3 = []
parallel = ["rayon"]
rapier = ["parry", "rapier3d"]
sampling = ["rapier"]
rapier-testbed = ["rapier", "rapier_testbed3d", "graphics"]
rapier-harness = ["rapier-testbed"]
parry = ["parry3d"]
wasm-bindgen = ["rapier3d/wasm-bindgen"]
graphics = ["bevy", "bevy_egui"]
default = [ "dim3", "f32" ]
dim3 = [ ]
f32 = [ ]
parallel = [ "rayon" ]
rapier = [ "parry", "rapier3d" ]
sampling = [ "rapier" ]
rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry3d" ]
wasm-bindgen = [ "rapier3d/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lib]
name = "salva3d"
path = "../../src/lib.rs"
required-features = ["dim3"]
required-features = [ "dim3", "f32" ]

[dependencies]
approx = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion examples2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors = [ "Sébastien Crozet <[email protected]>" ]
edition = "2018"

[features]
default = []
default = ["parallel"]
parallel = [ "rapier_testbed2d/parallel"]

[dependencies]
Expand Down
26 changes: 13 additions & 13 deletions src/integrations/rapier/fluids_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::coupling::CouplingManager;
use crate::geometry::{HGrid, HGridEntry};
use crate::object::{BoundaryHandle, BoundarySet, Fluid};
use crate::solver::DFSPHSolver;
use crate::LiquidWorld;
use crate::{math, LiquidWorld};
use crate::TimestepManager;
use approx::AbsDiffEq;
use na::Unit;
Expand Down Expand Up @@ -31,7 +31,7 @@ impl FluidsPipeline {
/// - `particle_radius`: the radius of every particle for the fluid simulation.
/// - `smoothing_factor`: the smoothing factor used to compute the SPH kernel radius.
/// The kernel radius will be computed as `particle_radius * smoothing_factor * 2.0.
pub fn new(particle_radius: f32, smoothing_factor: f32) -> Self {
pub fn new(particle_radius: math::Real, smoothing_factor: math::Real) -> Self {
let dfsph: DFSPHSolver = DFSPHSolver::new();

Self {
Expand All @@ -47,8 +47,8 @@ impl FluidsPipeline {
/// However, it will not integrate these forces. Use the `PhysicsPipeline` for this integration.
pub fn step(
&mut self,
gravity: &Vector<f32>,
dt: f32,
gravity: &Vector<math::Real>,
dt: math::Real,
colliders: &ColliderSet,
bodies: &mut RigidBodySet,
) {
Expand All @@ -66,7 +66,7 @@ pub enum ColliderSampling {
///
/// It is recommended that those points are separated by a distance smaller or equal to twice
/// the particle radius used to initialize the LiquidWorld.
StaticSampling(Vec<Point<f32>>),
StaticSampling(Vec<Point<math::Real>>),
/// The collider shape is approximated by a dynamic set of points automatically computed based on contacts with fluid particles.
DynamicContactSampling,
}
Expand Down Expand Up @@ -147,8 +147,8 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> {
fn update_boundaries(
&mut self,
timestep: &TimestepManager,
h: f32,
particle_radius: f32,
h: math::Real,
particle_radius: math::Real,
hgrid: &HGrid<HGridEntry>,
fluids: &mut [Fluid],
boundaries: &mut BoundarySet,
Expand Down Expand Up @@ -187,11 +187,11 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> {
.push(velocity.unwrap_or(Vector::zeros()));
}

boundary.volumes.resize(points.len(), na::zero::<f32>());
boundary.volumes.resize(points.len(), na::zero::<math::Real>());
}
ColliderSampling::DynamicContactSampling => {
let prediction = h * na::convert::<_, f32>(0.5);
let margin = particle_radius * na::convert::<_, f32>(0.1);
let prediction = h * na::convert::<_, math::Real>(0.5);
let margin = particle_radius * na::convert::<_, math::Real>(0.1);
let collider_pos = collider.position();
let aabb = collider
.shape()
Expand All @@ -218,7 +218,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> {
let dpt = particle_pos - proj.point;

if let Some((normal, depth)) =
Unit::try_new_and_get(dpt, f32::default_epsilon())
Unit::try_new_and_get(dpt, math::Real::default_epsilon())
{
if proj.is_inside {
fluid.positions[*particle_id] -=
Expand All @@ -227,7 +227,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> {
let vel_err =
normal.dot(&fluid.velocities[*particle_id]);

if vel_err > na::zero::<f32>() {
if vel_err > na::zero::<math::Real>() {
fluid.velocities[*particle_id] -=
*normal * vel_err;
}
Expand All @@ -243,7 +243,7 @@ impl<'a> CouplingManager for ColliderCouplingManager<'a> {
.velocities
.push(velocity.unwrap_or(Vector::zeros()));
boundary.positions.push(proj.point);
boundary.volumes.push(na::zero::<f32>());
boundary.volumes.push(na::zero::<math::Real>());
coupling.features.push(feature);
}
}
Expand Down
36 changes: 18 additions & 18 deletions src/integrations/rapier/testbed_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ pub enum FluidsRenderingMode {
/// Use a red taint the closer to `max` the velocity is.
VelocityColor {
/// Fluids with a velocity smaller than this will not have any red taint.
min: f32,
min: math::Real,
/// Fluids with a velocity greater than this will be completely red.
max: f32,
max: math::Real,
},
// /// Use a red taint the closer to `max` the velocity is, with opacity, low velocity is more transparent
// VelocityColorOpacity {
// /// Fluids with a velocity smaller than this will not have any red taint.
// min: f32,
// min: math::Real,
// /// Fluids with a velocity greater than this will be completely red.
// max: f32,
// max: math::Real,
// },
/// Show particles as arrows indicating the velocity
VelocityArrows {
/// Fluids with a velocity smaller than this will not have any red taint.
min: f32,
min: math::Real,
/// Fluids with a velocity greater than this will be completely red.
max: f32,
max: math::Real,
},
}

Expand All @@ -84,9 +84,9 @@ pub struct FluidsTestbedPlugin {
fluids_pipeline: FluidsPipeline,
f2sn: HashMap<FluidHandle, Vec<EntityWithGraphics>>,
boundary2sn: HashMap<BoundaryHandle, Vec<EntityWithGraphics>>,
f2color: HashMap<FluidHandle, Point3<f32>>,
ground_color: Point3<f32>,
default_fluid_color: Point3<f32>,
f2color: HashMap<FluidHandle, Point3<math::Real>>,
ground_color: Point3<math::Real>,
default_fluid_color: Point3<math::Real>,
queue_graphics_reset: bool,
}

Expand Down Expand Up @@ -120,7 +120,7 @@ impl FluidsTestbedPlugin {
}

/// Sets the color used to render the specified fluid.
pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3<f32>) {
pub fn set_fluid_color(&mut self, fluid: FluidHandle, color: Point3<math::Real>) {
let _ = self.f2color.insert(fluid, color);
}

Expand All @@ -138,14 +138,14 @@ impl FluidsTestbedPlugin {
fn add_particle_graphics(
&self,
particle: &Point<Real>,
particle_radius: f32,
particle_radius: math::Real,
graphics: &mut GraphicsManager,
commands: &mut Commands,
meshes: &mut Assets<Mesh>,
materials: &mut Assets<BevyMaterial>,
_components: &mut Query<&mut Transform>,
_harness: &mut Harness,
color: &Point3<f32>,
color: &Point3<math::Real>,
force_shape: Option<SharedShape>,
) -> Vec<EntityWithGraphics> {
let shape = if let Some(shape) = force_shape {
Expand Down Expand Up @@ -186,11 +186,11 @@ impl FluidsTestbedPlugin {
}

fn lerp_velocity(
velocity: Vector<f32>,
start: Vector3<f32>,
min: f32,
max: f32,
) -> Vector3<f32> {
velocity: Vector<math::Real>,
start: Vector3<math::Real>,
min: math::Real,
max: math::Real,
) -> Vector3<math::Real> {
let end = Vector3::new(1.0, 0.0, 0.0);
let vel: Vector<Real> = na::convert_unchecked(velocity);
let vel: Vector<Real> = na::convert(vel);
Expand Down Expand Up @@ -357,7 +357,7 @@ impl TestbedPlugin for FluidsTestbedPlugin {
self.queue_graphics_reset = false;
}

let (mut min, mut max) = (f32::MAX, f32::MIN);
let (mut min, mut max) = (math::Real::MAX, math::Real::MIN);
for (handle, fluid) in self.fluids_pipeline.liquid_world.fluids().iter() {
if let Some(entities) = self.f2sn.get_mut(&handle) {
for (idx, particle) in fluid.positions.iter().enumerate() {
Expand Down
Loading
Loading