Skip to content

Commit 8e81dc0

Browse files
committed
Fix TLSPH viscosity
1 parent 798a97e commit 8e81dc0

File tree

3 files changed

+53
-45
lines changed

3 files changed

+53
-45
lines changed

src/schemes/fluid/viscosity.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,13 @@ end
110110
# approaching particles and turn it off for receding particles. In this way, the
111111
# viscosity is used for shocks and not rarefactions."
112112
if vr < 0
113-
(; alpha, beta, epsilon) = viscosity
114-
115113
h_a = smoothing_length(particle_system, particle)
116114
h_b = smoothing_length(neighbor_system, neighbor)
117115
h = (h_a + h_b) / 2
118116

119117
rho_mean = (rho_a + rho_b) / 2
120118

119+
(; alpha, beta, epsilon) = viscosity
121120
mu = h * vr / (distance^2 + epsilon * h^2)
122121
c = sound_speed
123122
dv_viscosity = m_b * (alpha * c * mu + beta * mu^2) / rho_mean * grad_kernel

src/schemes/structure/total_lagrangian_sph/rhs.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ end
5656
current_pos_diff, current_distance,
5757
system, m_a, m_b, rho_a, rho_b)
5858

59-
dv_viscosity = @inbounds dv_viscosity_tlsph(system, v_system, particle, neighbor,
60-
current_pos_diff, current_distance,
61-
m_a, m_b, rho_a, rho_b, grad_kernel)
62-
63-
dv_particle = dv_stress + dv_penalty_force_ + dv_viscosity
59+
dv_particle = Ref(dv_stress + dv_penalty_force_)
60+
@inbounds dv_viscosity_tlsph!(dv_particle, system, v_system, particle, neighbor,
61+
current_pos_diff, current_distance,
62+
m_a, m_b, rho_a, rho_b, grad_kernel)
6463

6564
for i in 1:ndims(system)
66-
@inbounds dv[i, particle] += dv_particle[i]
65+
@inbounds dv[i, particle] += dv_particle[][i]
6766
end
6867

6968
# TODO continuity equation for boundary model with `ContinuityDensity`?
Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,83 @@
11
# Unpack the neighboring systems viscosity to dispatch on the viscosity type.
22
# This function is only necessary to allow `nothing` as viscosity.
33
# Otherwise, we could just apply the viscosity as a function directly.
4-
@propagate_inbounds function dv_viscosity_tlsph(system, v_system, particle, neighbor,
5-
current_pos_diff, current_distance,
6-
m_a, m_b, rho_a, rho_b, grad_kernel)
4+
@propagate_inbounds function dv_viscosity_tlsph!(dv_particle, system, v_system,
5+
particle, neighbor,
6+
current_pos_diff, current_distance,
7+
m_a, m_b, rho_a, rho_b, grad_kernel)
78
viscosity = system.viscosity
89

9-
return dv_viscosity_tlsph(viscosity, system, v_system, particle, neighbor,
10-
current_pos_diff, current_distance,
11-
m_a, m_b, rho_a, rho_b, grad_kernel)
10+
return dv_viscosity_tlsph!(dv_particle, viscosity, system, v_system,
11+
particle, neighbor, current_pos_diff, current_distance,
12+
m_a, m_b, rho_a, rho_b, grad_kernel)
1213
end
1314

14-
@propagate_inbounds function dv_viscosity_tlsph(viscosity, system,
15-
v_system, particle, neighbor,
16-
current_pos_diff, current_distance,
17-
m_a, m_b, rho_a, rho_b, grad_kernel)
18-
return viscosity(system, v_system, particle, neighbor,
15+
@propagate_inbounds function dv_viscosity_tlsph!(dv_particle, viscosity, system,
16+
v_system, particle, neighbor,
17+
current_pos_diff, current_distance,
18+
m_a, m_b, rho_a, rho_b, grad_kernel)
19+
return viscosity(dv_particle, system, v_system, particle, neighbor,
1920
current_pos_diff, current_distance,
2021
m_a, m_b, rho_a, rho_b, grad_kernel)
2122
end
2223

23-
@inline function dv_viscosity_tlsph(viscosity::Nothing, system,
24-
v_system, particle, neighbor,
25-
current_pos_diff, current_distance,
26-
m_a, m_b, rho_a, rho_b, grad_kernel)
24+
@inline function dv_viscosity_tlsph!(dv_particle, viscosity::Nothing, system,
25+
v_system, particle, neighbor,
26+
current_pos_diff, current_distance,
27+
m_a, m_b, rho_a, rho_b, grad_kernel)
2728
return zero(current_pos_diff)
2829
end
2930

3031
# Applying the viscosity according to Lin et al. (2015):
3132
# "Geometrically nonlinear analysis of two-dimensional structures using an improved
3233
# smoothed particle hydrodynamics method"
33-
@propagate_inbounds function (viscosity::ArtificialViscosityMonaghan)(system::TotalLagrangianSPHSystem,
34+
@propagate_inbounds function (viscosity::ArtificialViscosityMonaghan)(dv_particle,
35+
system::TotalLagrangianSPHSystem,
3436
v_system,
3537
particle, neighbor,
3638
current_pos_diff,
3739
current_distance,
3840
m_a, m_b, rho_a,
3941
rho_b, grad_kernel)
40-
rho_mean = (rho_a + rho_b) / 2
41-
4242
v_a = current_velocity(v_system, system, particle)
4343
v_b = current_velocity(v_system, system, neighbor)
4444
v_diff = v_a - v_b
4545

46-
smoothing_length_particle = smoothing_length(system, particle)
47-
smoothing_length_neighbor = smoothing_length(system, neighbor)
48-
smoothing_length_average = (smoothing_length_particle + smoothing_length_neighbor) / 2
46+
# v_ab ⋅ r_ab
47+
vr = dot(v_diff, current_pos_diff)
4948

50-
# Compute bulk modulus from Young's modulus and Poisson's ratio.
51-
# See the table at the end of https://en.wikipedia.org/wiki/Lam%C3%A9_parameters
52-
E = young_modulus(system, particle)
53-
K = E / (ndims(system) * (1 - 2 * poisson_ratio(system, particle)))
49+
# Monaghan 2005 p. 1741 (doi: 10.1088/0034-4885/68/8/r01):
50+
# "In the case of shock tube problems, it is usual to turn the viscosity on for
51+
# approaching particles and turn it off for receding particles. In this way, the
52+
# viscosity is used for shocks and not rarefactions."
53+
if vr < 0
54+
# Compute bulk modulus from Young's modulus and Poisson's ratio.
55+
# See the table at the end of https://en.wikipedia.org/wiki/Lam%C3%A9_parameters
56+
E = young_modulus(system, particle)
57+
K = E / (ndims(system) * (1 - 2 * poisson_ratio(system, particle)))
5458

55-
# Newton–Laplace equation
56-
sound_speed = sqrt(K / rho_a)
59+
# Newton–Laplace equation
60+
sound_speed = sqrt(K / rho_a)
5761

58-
# This is not needed for `ArtificialViscosityMonaghan`
59-
nu_a = nu_b = 0
62+
h_a = smoothing_length(system, particle)
63+
h_b = smoothing_length(system, neighbor)
64+
h = (h_a + h_b) / 2
6065

61-
pi_ab = viscosity(sound_speed, v_diff, current_pos_diff, current_distance,
62-
rho_mean, rho_a, rho_b, smoothing_length_average,
63-
grad_kernel, nu_a, nu_b)
66+
rho_mean = (rho_a + rho_b) / 2
6467

65-
# See eq. 26 of Lin et al. (2015)
66-
F = deformation_gradient(system, particle)
68+
(; alpha, beta, epsilon) = viscosity
69+
mu = h * vr / (current_distance^2 + epsilon * h^2)
70+
c = sound_speed
71+
pi_ab = (alpha * c * mu + beta * mu^2) / rho_mean * grad_kernel
6772

68-
if abs(det(F)) < 1.0f-9
69-
return zero(grad_kernel)
73+
F = deformation_gradient(system, particle)
74+
det_F = det(F)
75+
if abs(det_F) < 1.0f-9
76+
return dv_particle
77+
end
78+
# See eq. 26 of Lin et al. (2015)
79+
dv_particle[] += m_b * det_F * inv(F)' * pi_ab
7080
end
7181

72-
return m_b * det(F) * inv(F)' * pi_ab
82+
return dv_particle
7383
end

0 commit comments

Comments
 (0)