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 all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ STYLE.md
Cargo.lock
.idea
.vscode
.DS_Store
4 changes: 3 additions & 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 All @@ -12,7 +12,9 @@ opt-level = 1

[patch.crates-io]
salva2d = { path = "./build/salva2d" }
salva2d-f64 = { path = "./build/salva2d-f64" }
salva3d = { path = "./build/salva3d" }
salva3d-f64 = { path = "./build/salva3d-f64" }

#parry2d = { git = "https://github.com/sebcrozet/parry" }
#parry3d = { git = "https://github.com/sebcrozet/parry" }
Expand Down
63 changes: 63 additions & 0 deletions build/salva2d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[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-f64" ]
rapier-testbed = [ "rapier", "rapier_testbed2d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry2d-f64" ]
wasm-bindgen = [ "rapier2d-f64/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(feature, values("dim3", "f32"))',
] }

[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-f64 = { version = "0.16", optional = true }
rapier2d-f64 = { version = "0.21", optional = true }
# TODO update it to f64
rapier_testbed2d = { 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.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 }
25 changes: 13 additions & 12 deletions build/salva2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,27 @@ 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 = [
'cfg(feature, values("dim3"))',
'cfg(feature, values("dim3", "f64"))',
] }

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

[dependencies]
approx = "0.5"
Expand Down
59 changes: 59 additions & 0 deletions build/salva3d-f64/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[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-f64" ]
sampling = [ "rapier" ]
rapier-testbed = [ "rapier", "rapier_testbed3d", "graphics" ]
rapier-harness = [ "rapier-testbed" ]
parry = [ "parry3d-f64" ]
wasm-bindgen = [ "rapier3d-f64/wasm-bindgen" ]
graphics = [ "bevy", "bevy_egui" ]

[lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(feature, values("dim2", "f32"))',
] }

[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-f64 = { version = "0.16", optional = true }
rapier3d-f64 = { version = "0.21", optional = true }
# TODO update it to f64
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 }
25 changes: 13 additions & 12 deletions build/salva3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ edition = "2021"

[lints]
rust.unexpected_cfgs = { level = "warn", check-cfg = [
'cfg(feature, values("dim2"))',
'cfg(feature, values("dim2", "f64"))',
] }

[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
2 changes: 1 addition & 1 deletion examples3d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ parallel = [ "rapier_testbed3d/parallel", "salva3d/parallel"]
[dependencies]
num-traits = "0.2"
Inflector = "0.11"
nalgebra = "0.33"
nalgebra = "0.33"
rapier3d = "0.21"
rapier_testbed3d = "0.21"
parry3d = "0.16"
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
Loading