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

Implement Compatible Particle-In-Cel (CPIC) Particle-Rigid-Body Coupling #3

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a64f964
implemented rigid particle generation
kurtkuehnert Mar 14, 2023
694a6ea
implemented a debug visualization for the rigid particles
kurtkuehnert Mar 15, 2023
e90e836
improved rigid particle cover function
kurtkuehnert Mar 15, 2023
eb852c4
implemented the cdf kernel
kurtkuehnert Mar 15, 2023
283cdac
improved the threading of the kernel
kurtkuehnert Mar 15, 2023
a77ef47
added a grid debug visualization
kurtkuehnert Mar 16, 2023
8deba54
fix the bug in the get_node_id_at_coord method
kurtkuehnert Mar 16, 2023
7bc7439
implemented CDF visualization
kurtkuehnert Mar 17, 2023
6103f44
implemented CDF triangle check
kurtkuehnert Mar 17, 2023
a4eed0d
started working on CDF reconstruction
kurtkuehnert Mar 20, 2023
cda4ba9
fixed atomic exchange bug in the CDF update method
kurtkuehnert Mar 21, 2023
38b0243
implemented particle CDF reconstruction
kurtkuehnert Mar 21, 2023
b4bafd4
upload old ptx files for a cleaner diff
kurtkuehnert Mar 21, 2023
46e6eb2
added particle CDF debug visualizations
kurtkuehnert Mar 23, 2023
d32ddcf
improved particle visualization
kurtkuehnert Mar 23, 2023
76b0222
added penetration correction
kurtkuehnert Mar 24, 2023
701735a
split p2g and g2p into separate functions
kurtkuehnert Mar 27, 2023
4ff24a1
implemented basic CPIC without collider velocity
kurtkuehnert Mar 27, 2023
cba8360
fixed some CPIC bugs
kurtkuehnert Mar 27, 2023
d9cfd8e
implemented the visualization UI
kurtkuehnert Mar 28, 2023
6544f89
fix some warnings
kurtkuehnert Mar 28, 2023
47dd4fa
improved visualization
kurtkuehnert Mar 29, 2023
a1a93d4
improved visualization
kurtkuehnert Mar 30, 2023
328c0bd
fixed node CDF tag error
kurtkuehnert Mar 30, 2023
2ffb401
re-added the penalty force
kurtkuehnert Mar 30, 2023
252b45e
check that CDF disable is equal to main
kurtkuehnert Mar 31, 2023
2c36fc3
made CDF toggleable
kurtkuehnert Mar 31, 2023
db0ab67
rewritten projection code
kurtkuehnert Mar 31, 2023
73d2b6d
transitioned to the new GpuColliderSet
kurtkuehnert Apr 3, 2023
36ac66a
Fix explosion bug
sebcrozet Apr 3, 2023
a864cd0
Re-enable penalty force.
sebcrozet Apr 3, 2023
45ba56b
Use a single BoundaryCondition enum + use the collider’s friction coe…
sebcrozet Apr 3, 2023
7fbd812
adapted the CDF and rigid particle generation for 2D
kurtkuehnert Apr 3, 2023
e2a8610
added cutting sand 2D example
kurtkuehnert Apr 3, 2023
03ce287
fixed 2D examples
kurtkuehnert Apr 4, 2023
10c89f9
added penalty stiffness slider
kurtkuehnert Apr 4, 2023
c2adf93
improved elasticity2 example
kurtkuehnert Apr 4, 2023
62ebc7c
particle projection now takes the collider velocity into account (One…
kurtkuehnert Apr 5, 2023
45c9347
made collider mode configurable
kurtkuehnert Apr 5, 2023
4df8f23
added cube through sand 2D example
kurtkuehnert Apr 5, 2023
be01618
Fix indexing in the SharedKernel
sebcrozet Apr 6, 2023
66021f4
Typo fixes
sebcrozet Apr 6, 2023
25e9c65
implemented two-way coupling
kurtkuehnert Apr 6, 2023
cd1e392
added 2D sand wheel example
kurtkuehnert Apr 11, 2023
582398a
added 3D sand wheel example
kurtkuehnert Apr 11, 2023
a78e0d3
feat: add conveyor belt example
sebcrozet Nov 9, 2023
30d1b54
chore: update ptx files
sebcrozet Nov 22, 2023
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
18 changes: 8 additions & 10 deletions examples2d/basic2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ pub fn init_world(testbed: &mut Testbed) {
for i in 0..=n {
heigths.push(-(i as f32 * std::f32::consts::PI / (n as f32)).sin());
}
colliders.insert(
ColliderBuilder::heightfield(heigths.into(), vector![2.0, 1.0])
.translation(vector![0.5, 1.5])
.build(),
);
colliders.insert(ColliderBuilder::heightfield(heigths.into(), vector![2.0, 1.0]).build());

for _ in 0..1 {
let snow_model = models.insert(ParticleModel::with_plasticity(
Expand All @@ -47,7 +43,7 @@ pub fn init_world(testbed: &mut Testbed) {

let snow = helper::sample_shape(
&*SharedShape::cuboid(0.1, 0.2), // w, w / 2.0),
Isometry::translation(cell_width * 40.0, ground_shift + 0.6 + 0.2),
Isometry::translation(-0.2, -0.6),
snow_model,
cell_width / 4.0,
1000.0,
Expand All @@ -64,7 +60,8 @@ pub fn init_world(testbed: &mut Testbed) {

for p in &mut sand {
p.model = sand_model;
p.position.y += 0.5;
p.position.x += 0.4;
p.position.y += 0.4;
}
particles.insert_batch(sand);
}
Expand All @@ -89,14 +86,14 @@ pub fn init_world(testbed: &mut Testbed) {
let shape = SharedShape::convex_decomposition(&star, &indices);

let model = ParticleModel::with_failure(
CorotatedLinearElasticity::new(1.0e5, 0.2),
CorotatedLinearElasticity::new(1.0e5, -0.2),
MaximumStressFailure::new(1.0e5, Real::MAX),
);
let star_model = models.insert(model);

let star = helper::sample_shape(
&*shape.0,
Isometry::translation(cell_width * 40.0, 1.7),
Isometry::translation(0.0, 0.0),
star_model,
cell_width / 4.0,
4000.0,
Expand All @@ -114,7 +111,8 @@ pub fn init_world(testbed: &mut Testbed) {
ImpulseJointSet::new(),
MultibodyJointSet::new(),
);
testbed.integration_parameters_mut().dt = 1.0 / 60.0;
testbed.integration_parameters_mut().dt = 1.0 / 120.0;
testbed.look_at(Point::new(0.0, -0.3), 400.0);
}

fn main() {
Expand Down
84 changes: 84 additions & 0 deletions examples2d/cube_through_sand2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use crate::helper;
use na::{point, vector};
use rapier2d::prelude::*;
use rapier_testbed2d::{Testbed, TestbedApp};
use sparkl2d::cuda::CudaColliderOptions;
use sparkl2d::prelude::*;
use sparkl2d::third_party::rapier::MpmTestbedPlugin;

pub fn init_world(testbed: &mut Testbed) {
let mut models = ParticleModelSet::new();
let mut particles = ParticleSet::new();
let mut colliders = ColliderSet::new();
let mut bodies = RigidBodySet::new();

let cell_width = 0.1;
let particle_rad = cell_width / 2.0;
let particles_width = 100;
let particles_height = 50;

let height_offset = 10.0 * particle_rad;
let width = 30.0;
let height = (particles_height as f32 + 1.0) * particle_rad * 2.0;
let thickness = 3.0 * cell_width;

colliders.insert(
ColliderBuilder::cuboid(width, thickness)
.translation(vector![0.0, -thickness])
.build(),
);

let block_body = RigidBodyBuilder::new(RigidBodyType::Dynamic)
.translation(vector![-3.0, 2.0])
.linvel(vector![10.0, 0.0])
.angvel(0.0)
.gravity_scale(1.0)
.build();

let block_collider = ColliderBuilder::cuboid(1.0, 1.0).density(10000.0).build();

let block_body_handle = bodies.insert(block_body);
let block_collider_handle =
colliders.insert_with_parent(block_collider, block_body_handle, &mut bodies);

let collider_options = vec![CudaColliderOptions {
handle: block_collider_handle,
enable_cdf: true,
..Default::default()
}];

let sand_model = models.insert(ParticleModel::with_plasticity(
CorotatedLinearElasticity::new(1.0e6, 0.2),
DruckerPragerPlasticity::new(1.0e6, 0.2),
));

let block1 = helper::cube_particles(
point![5.0 - (particles_width as f32) * particle_rad, height_offset],
particles_width,
particles_height,
sand_model,
particle_rad,
1000.0,
false,
);

particles.insert_batch(block1);

let mut plugin = MpmTestbedPlugin::new(models, particles, cell_width);
plugin.solver_params.force_fluids_volume_recomputation = true;
plugin.collider_options = collider_options;
testbed.add_plugin(plugin);
testbed.set_world(
bodies,
colliders,
ImpulseJointSet::new(),
MultibodyJointSet::new(),
);
testbed.integration_parameters_mut().dt = 1.0 / 60.0;
testbed.look_at(Point::new(0.0, 3.0), 30.0);
}

fn main() {
let testbed = TestbedApp::from_builders(0, vec![("Elasticity", init_world)]);
testbed.run()
}
83 changes: 83 additions & 0 deletions examples2d/cutting_sand2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use crate::helper;
use na::{point, vector};
use rapier2d::prelude::*;
use rapier_testbed2d::{Testbed, TestbedApp};
use sparkl2d::cuda::CudaColliderOptions;
use sparkl2d::prelude::*;
use sparkl2d::third_party::rapier::MpmTestbedPlugin;

pub fn init_world(testbed: &mut Testbed) {
/*
* World
*/
let mut models = ParticleModelSet::new();
let mut particles = ParticleSet::new();
let mut colliders = ColliderSet::new();

let cell_width = 0.1;
let particle_rad = cell_width / 2.0;
let particles_width = 100;
let particles_height = 50;

let height_offset = 100.0 * particle_rad;
let width = 30.0;
let height = (particles_height as f32 + 1.0) * particle_rad * 2.0;
let thickness = 3.0 * cell_width;

colliders.insert(
ColliderBuilder::cuboid(width, thickness)
.translation(vector![0.0, -thickness])
.build(),
);

let collider_handle = colliders.insert(
ColliderBuilder::polyline(vec![point![0.0, 0.0], point![0.0, height]], None).build(),
);

const NU: Real = 0.2;
const E: Real = 1.0e6;

let plasticity = DruckerPragerPlasticity::new(E, NU);
let sand_model = models.insert(ParticleModel::with_plasticity(
CorotatedLinearElasticity::new(E, NU),
plasticity,
));

let block1 = helper::cube_particles(
point![-(particles_width as f32) * particle_rad, height_offset],
particles_width,
particles_height,
sand_model,
particle_rad,
1000.0,
false,
);

particles.insert_batch(block1);

let bodies = RigidBodySet::new();

let collider_options = vec![CudaColliderOptions {
handle: collider_handle,
enable_cdf: true,
..Default::default()
}];

let mut plugin = MpmTestbedPlugin::new(models, particles, cell_width);
plugin.solver_params.force_fluids_volume_recomputation = true;
plugin.collider_options = collider_options;
testbed.add_plugin(plugin);
testbed.set_world(
bodies,
colliders,
ImpulseJointSet::new(),
MultibodyJointSet::new(),
);
testbed.integration_parameters_mut().dt = 1.0 / 60.0;
testbed.look_at(Point::new(0.0, 3.0), 30.0);
}

fn main() {
let testbed = TestbedApp::from_builders(0, vec![("Elasticity", init_world)]);
testbed.run()
}
37 changes: 21 additions & 16 deletions examples2d/elasticity2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,34 @@ pub fn init_world(testbed: &mut Testbed) {
*/
let mut particles = ParticleSet::new();
let mut models = ParticleModelSet::new();
let mut colliders = ColliderSet::new();

let cell_width = 0.05;
let mut colliders = ColliderSet::new();
let ground_height = cell_width * 10.0;
let ground_shift = cell_width * 40.0;
let particle_rad = cell_width / 4.0;

let height_offset = 0.5;
let width = 6.0;
let height = 3.0;
let thickness = cell_width * 3.0;

colliders.insert(
ColliderBuilder::cuboid(1000.0, ground_height)
.translation(vector![0.0, ground_shift - ground_height])
// .rotation(0.1)
ColliderBuilder::cuboid(width, thickness)
.translation(vector![width, -thickness])
.friction(0.0)
.build(),
);

colliders.insert(
ColliderBuilder::cuboid(ground_height, 1000.0)
.translation(vector![ground_shift - ground_height, 0.0])
ColliderBuilder::cuboid(thickness, height)
.translation(vector![-thickness, height - 2.0 * thickness])
.friction(0.0)
.build(),
);

colliders.insert(
ColliderBuilder::cuboid(ground_height, 1000.0)
.translation(vector![
ground_shift - ground_height + ground_shift * 8.0,
0.0
])
ColliderBuilder::cuboid(thickness, height)
.translation(vector![2.0 * width + thickness, height - 2.0 * thickness])
.friction(0.0)
.build(),
);

Expand All @@ -64,7 +69,7 @@ pub fn init_world(testbed: &mut Testbed) {
let shape = SharedShape::convex_decomposition(&star, &indices);

let mut rng = oorandom::Rand32::new(42);
let mut gen = || ground_shift + cell_width * 40.0 * (rng.rand_u32() % 5 + 1) as Real;
let mut gen = || height_offset + cell_width * 40.0 * (rng.rand_u32() % 5 + 1) as Real;
let model = ParticleModel::with_plasticity(
CorotatedLinearElasticity::new(E, NU),
RankinePlasticity::new(E, NU, 1.0e2, 5.0),
Expand All @@ -76,7 +81,7 @@ pub fn init_world(testbed: &mut Testbed) {
&*shape.0,
Isometry::translation(gen(), gen()),
model,
cell_width / 4.0,
particle_rad,
2.0,
false,
);
Expand All @@ -101,7 +106,7 @@ pub fn init_world(testbed: &mut Testbed) {
MultibodyJointSet::new(),
);
testbed.integration_parameters_mut().dt = 1.0 / 60.0;
// testbed.physics_state_mut().gravity.y = -981.0;
testbed.look_at(Point::new(width, 2.0), 39.0);
}

fn main() {
Expand Down
6 changes: 3 additions & 3 deletions examples2d/fluids2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ pub fn init_world(testbed: &mut Testbed) {
colliders.insert(
ColliderBuilder::cuboid(1000.0, ground_height)
.translation(vector![0.0, ground_shift - ground_height])
.friction(0.0)
.friction(1.0)
.build(),
);
colliders.insert(
ColliderBuilder::cuboid(ground_height, 1000.0)
.translation(vector![ground_shift - ground_height, 0.0])
.friction(0.0)
.friction(1.0)
.build(),
);

Expand All @@ -35,7 +35,7 @@ pub fn init_world(testbed: &mut Testbed) {
ground_shift - ground_height + ground_shift * 8.0,
0.0
])
.friction(0.0)
.friction(1.0)
.build(),
);

Expand Down
2 changes: 1 addition & 1 deletion examples2d/l_panel2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub fn init_world(testbed: &mut Testbed) {
plugin.hooks = Box::new(BoundaryConditions {
origins: l_panel_origins,
});
plugin.solver_params.boundary_handling = BoundaryHandling::Stick;
plugin.solver_params.boundary_condition = BoundaryCondition::Stick;
plugin.solver_params.damage_model = DamageModel::Eigenerosion;
testbed.add_plugin(plugin);
testbed.set_world(
Expand Down
6 changes: 6 additions & 0 deletions examples2d/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
extern crate nalgebra as na;

mod basic2;
mod cube_through_sand2;
mod cutting_sand2;
mod elasticity2;
mod fluids2;
mod helper;
mod l_panel2;
mod wheel2;

#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
Expand Down Expand Up @@ -56,6 +59,9 @@ pub fn main() {

let mut builders: Vec<(_, fn(&mut Testbed))> = vec![
("Basic", basic2::init_world),
("Cube through sand", cube_through_sand2::init_world),
("Cutting sand", cutting_sand2::init_world),
("Wheel", wheel2::init_world),
("Elasticity", elasticity2::init_world),
("Fluids", fluids2::init_world),
];
Expand Down
Loading