Skip to content

Commit

Permalink
Translational damping option
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterchef365 committed Dec 13, 2023
1 parent 78e2fd9 commit fe2e765
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub struct TemplateApp {
enable_incompress: bool,
enable_particle_collisions: bool,
enable_grid_transfer: bool,
translational_damping: f32,

well: bool,
source_color_idx: ParticleType,
Expand Down Expand Up @@ -84,6 +85,7 @@ impl TemplateApp {
//grid_vel_scale: 0.05,
//show_grid: false,
show_settings_only: false,
translational_damping: 0.0,
//mult: 1.0,
}
}
Expand Down Expand Up @@ -152,6 +154,7 @@ impl TemplateApp {
self.enable_incompress,
self.enable_particle_collisions,
self.enable_grid_transfer,
self.translational_damping,
);

self.single_step = false;
Expand Down Expand Up @@ -283,6 +286,7 @@ impl TemplateApp {
ui.add(Slider::new(&mut self.sim.damping, 0.0..=1.0).text("Damping"));
ui.checkbox(&mut self.enable_grid_transfer, "Grid transfer (required for incompressibility solver!)");
ui.add(Slider::new(&mut self.pic_apic_ratio, 0.0..=1.0).text("PIC - APIC"));
ui.add(Slider::new(&mut self.translational_damping, 0.0..=1.0).text("Translational damping"));
}

ui.separator();
Expand Down
15 changes: 15 additions & 0 deletions src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ impl Sim {
enable_incompress: bool,
enable_particle_collisions: bool,
enable_grid_transfer: bool,
translational_damping: f32,
) {
// Step particles
apply_global_force(&mut self.particles, Vec2::new(0., -gravity), dt);
Expand All @@ -167,7 +168,21 @@ impl Sim {

// Step grid
if enable_grid_transfer {
let mut pic_only_grid = None;
if translational_damping != 0.0 {
let mut dup_grid = self.grid.clone();
particles_to_grid(&self.particles, &mut dup_grid, 0.);
pic_only_grid = Some(dup_grid);
}

particles_to_grid(&self.particles, &mut self.grid, pic_apic_ratio);

if let Some(pic_only_grid) = pic_only_grid {
for (apic, pic_only) in self.grid.data_mut().iter_mut().zip(pic_only_grid.data()) {
apic.vel -= pic_only.vel * translational_damping;
}
}

let solver_fn = match solver {
IncompressibilitySolver::Jacobi => solve_incompressibility_jacobi,
IncompressibilitySolver::GaussSeidel => solve_incompressibility_gauss_seidel,
Expand Down

0 comments on commit fe2e765

Please sign in to comment.