Skip to content

Commit c76842b

Browse files
committed
[BUGFIX] Correct particle velocity calculation
When updating particle velocity, if `velocity_update` is True, then nodal velocity is *assigned* to the particle velocity but if `velocity_update` is False, then velocity due to acceleration is *added* to the current particle velocity.
1 parent e4f8afb commit c76842b

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

diffmpm/particle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,12 @@ def update_position_velocity(
208208
mapped_positions * elements.nodes.acceleration[mapped_ids],
209209
axis=1,
210210
)
211-
self.velocity = self.velocity.at[:].add(
211+
self.velocity = self.velocity.at[:].set(
212212
lax.cond(
213213
velocity_update,
214-
lambda nv, na, t: nv,
215-
lambda nv, na, t: na * t,
214+
lambda sv, nv, na, t: nv,
215+
lambda sv, nv, na, t: sv + na * t,
216+
self.velocity,
216217
nodal_velocity,
217218
nodal_acceleration,
218219
dt,

0 commit comments

Comments
 (0)