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

Fix softening bug #154

Merged
merged 2 commits into from
Jan 24, 2024
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
14 changes: 8 additions & 6 deletions src/Softening/Softening.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ struct LinearSoftening{T} <: AbstractSoftening
lo::T
max_value::T
min_value::T
damage::T
slope::T

function LinearSoftening(min_value::T, max_value::T, lo::T, hi::T) where T
damage = max_value + (max_value - min_value) / (hi - lo)
new{T}(hi, lo, max_value, min_value, damage)
slope = (max_value - min_value) / (hi - lo)
new{T}(hi, lo, max_value, min_value, slope)
end
end

LinearSoftening(min_max_values::NTuple{2, T}, lo_hi::NTuple{2, T}) where T = LinearSoftening(min_max_values..., lo_hi...)

function (softening::LinearSoftening)(max_value, softening_var::T) where T
@inline (softening::LinearSoftening)(args::Vararg{Any, N}) where N = softening(promote(args...)...)

@inline function (softening::LinearSoftening)(max_value::T, softening_var::T) where T

softening_var ≥ softening.hi && return softening.min_value
softening_var ≤ softening.lo && return T(max_value)
softening_var ≤ softening.lo && return max_value

return softening_var * softening.damage
return softening.min_value + (one(T) - softening_var) * softening.slope
end
22 changes: 16 additions & 6 deletions test/test_Softening.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ using GeoParams, Test
@test x === soft(x, rand())

# Test LinearSoftening
min_v, max_v = 15e0, 30e0
min_v, max_v = rand()*15, (rand()+1)*15
lo, hi = 0.0, 1.0

@test LinearSoftening(min_v, max_v, lo, hi) === LinearSoftening((min_v, max_v), (lo, hi))

soft_ϕ = LinearSoftening(min_v, max_v, lo, hi)

@test soft_ϕ(30, 1) == min_v
@test soft_ϕ(30, 0) == max_v
@test soft_ϕ(30, 0.5) == 0.5 * (min_v + max_v)
@test soft_ϕ(max_v, 1) == min_v
@test soft_ϕ(max_v, 0) == max_v
@test soft_ϕ(max_v, 0.5) ≈ 0.5 * (min_v + max_v)

min_v, max_v = 20e0, 20e0
soft_ϕ = LinearSoftening(min_v, max_v, lo, hi)

@test soft_ϕ(max_v, 1) == 20e0
@test soft_ϕ(max_v, 0) == 20e0
@test soft_ϕ(max_v, 0.5) == 20e0

# test Drucker-Prager with softening
min_v, max_v = 15e0, 30e0
lo, hi = 0.0, 1.0
soft_ϕ = LinearSoftening(min_v, max_v, lo, hi)

τII = 20e6
P = 1e6
args = (P=P, τII=τII)
Expand Down Expand Up @@ -51,5 +62,4 @@ using GeoParams, Test
@test compute_yieldfunction(p2, args) ≈ 1.95e7
@test compute_yieldfunction(p3, args) ≈ 1.974118095489748e7

end

end