Skip to content
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ used in the Julia ecosystem. Notable changes will be documented in this file for

### Important Bugfixes

- Fixed asymmetric DEM contact forces near coincidence by using a pair-local
radius scale for the near-zero distance cutoff (#1347).
Comment thread
svchb marked this conversation as resolved.
Resolved
- Fixed the sign of the quadratic term in `ArtificialViscosityMonaghan` (#1295).
- Fixed mathematical inconsistencies in the SPH documentation, including incorrect
formulas, inconsistent force-vs-acceleration notation, and wrong LaTeX text-mode
Expand Down
15 changes: 8 additions & 7 deletions src/schemes/structure/discrete_element_method/rhs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ function interact!(dv, v_particle_system, u_particle_system, v_neighbor_system,
system_coords = current_coordinates(u_particle_system, particle_system)
neighbor_coords = current_coordinates(u_neighbor_system, neighbor_system)

r = maximum(particle_system.radius)

foreach_point_neighbor(particle_system, neighbor_system, system_coords, neighbor_coords,
semi;
points=each_integrated_particle(particle_system)) do particle,
neighbor,
pos_diff,
distance
# Skip neighbors with (almost) the same position to avoid division by zero
# when computing the normal below (see `almostzero`).
distance < almostzero(r) && return

# Retrieve particle properties
m_a = particle_system.mass[particle]
r_a = particle_system.radius[particle]
r_b = neighbor_system.radius[neighbor]

# The contact normal is undefined for coincident centers, although the force
# magnitude need not vanish as `distance` approaches zero.
# Use the larger pair radius as the length scale for `almostzero`, so both
# directions make the same skip decision independently of unrelated particles.
distance < almostzero(max(r_a, r_b)) && return

m_a = particle_system.mass[particle]

# Compute the overlap (penetration depth)
overlap = r_a + r_b - distance
if overlap > 0
Expand Down
25 changes: 25 additions & 0 deletions test/systems/dem_system.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,31 @@ end
# Define ndims for DummySystem so that any call to ndims returns 2 (for 2D systems).
Base.ndims(::DummySystem) = 2

@testset "DEM near-zero pair symmetry" begin
ic = InitialCondition(; coordinates=zeros(Float32, 2, 1), mass=Float32[1],
density=1.0f0, particle_spacing=1.0f0)
model = LinearContactModel(1.0f0)
system_a = DEMSystem(ic; contact_model=model, radius=0.3f0,
damping_coefficient=0.0f0, acceleration=(0.0f0, 0.0f0))
system_b = DEMSystem(ic; contact_model=model, radius=1.0f0,
damping_coefficient=0.0f0, acceleration=(0.0f0, 0.0f0))
v = zeros(Float32, 2, 1)
u_a, u_b = ic.coordinates, copy(ic.coordinates)
semi = DummySemidiscretization()

# The first separation is between the old cutoffs; the second retains the contact.
for factor in (0.75f0, 1.5f0)
u_b[1, 1] = factor * sqrt(eps(Float32))
dv_a, dv_b = zero(v), zero(v)
TrixiParticles.interact!(dv_a, v, u_a, v, u_b,
system_a, system_b, semi)
TrixiParticles.interact!(dv_b, v, u_b, v, u_a,
system_b, system_a, semi)
@test system_a.mass[1] * dv_a ≈ -system_b.mass[1] * dv_b
@test iszero(dv_a) == (factor < 1)
end
end

@testset "ContactModels Physical Behavior" begin

# === HertzContactModel Tests ===
Expand Down
Loading