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

Add power law strain/stress functions #226

Merged
merged 6 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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: 1 addition & 1 deletion src/ConstitutiveRelationships.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export param_info,
# add methods programmatically
for myType in (:LinearViscous, :LinearMeltViscosity, :ViscosityPartialMelt_Costa_etal_2009,
:DiffusionCreep, :DislocationCreep, :ConstantElasticity, :DruckerPrager, :ArrheniusType,
:GrainBoundarySliding, :PeierlsCreep, :NonLinearPeierlsCreep)
:GrainBoundarySliding, :PeierlsCreep, :NonLinearPeierlsCreep, :PowerlawViscous)
@eval begin
@inline compute_εII(a::$(myType), TauII, args) = compute_εII(a, TauII; args...)
@inline compute_εvol(a::$(myType), P, args) = compute_εvol(a, P; args...)
Expand Down
75 changes: 47 additions & 28 deletions src/CreepLaw/CreepLaw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ or
where ``\\eta_0`` is the reference viscosity [Pa*s] at reference strain rate ``\\dot{\\varepsilon}_0``[1/s], and ``n`` the power law exponent [].
"""
@with_kw_noshow struct ArrheniusType{_T,U1,U2,U3} <: AbstractCreepLaw{_T}
η_0::GeoUnit{_T,U1} = 1.0NoUnits # Pre-exponential factor
η0::GeoUnit{_T,U1} = 1.0NoUnits # Pre-exponential factor
E_η::GeoUnit{_T,U2} = 23.03NoUnits # Activation energy (non-dimensional)
T_O::GeoUnit{_T,U3} = 1.0NoUnits # Offset temperature
T_η::GeoUnit{_T,U3} = 1.0NoUnits # Reference temperature at which viscosity is unity
Expand All @@ -215,10 +215,11 @@ function param_info(a::ArrheniusType) # info about the struct
Equation=L"\tau_{ij} = 2 \eta_0 exp( E_η/(T + T_O) + E_η/(T_η + T_O)) \dot{\varepsilon}_{ij}",
)
end

# Calculation routines for linear viscous rheologies
function compute_εII(a::ArrheniusType, TauII; T=one(precision(a)), kwargs...)
@unpack_val η_0, E_η, T_O, T_η = a
η = η_0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
@unpack_val η0, E_η, T_O, T_η = a
η = η0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
return (TauII / η) * 0.5
end

Expand All @@ -241,8 +242,8 @@ function compute_εII!(
end

function dεII_dτII(a::ArrheniusType, TauII; T=one(precision(a)), kwargs...)
@unpack_val η_0, E_η, T_O, T_η = a
η = η_0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
@unpack_val η0, E_η, T_O, T_η = a
η = η0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
return 0.5 * inv(η)
end

Expand All @@ -252,9 +253,9 @@ end
Returns second invariant of the stress tensor given a 2nd invariant of strain rate tensor
"""
function compute_τII(a::ArrheniusType, EpsII; T=one(precision(a)), kwargs...)
@unpack_val η_0, E_η, T_O, T_η = a
@unpack_val η0, E_η, T_O, T_η = a

η = η_0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
η = η0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))

return 2 * (η * EpsII)
end
Expand All @@ -274,8 +275,8 @@ function compute_τII!(
end

function dτII_dεII(a::ArrheniusType, EpsII; T=one(precision(a)), kwargs...)
@unpack_val η_0, E_η, T_O, T_η = a
η = η_0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))
@unpack_val η0, E_η, T_O, T_η = a
η = η0 * exp(E_η / (T + T_O) - E_η / (T_η + T_O))

return 2 * η
end
Expand All @@ -284,7 +285,7 @@ end
function show(io::IO, g::ArrheniusType)
return print(
io,
"ArrheniusType: η_0 = $(Value(g.η_0)), E_η = $(Value(g.E_η)), T_O = $(Value(g.T_O)), T_η = $(Value(g.T_η))",
"ArrheniusType: η0 = $(Value(g.η0)), E_η = $(Value(g.E_η)), T_O = $(Value(g.T_O)), T_η = $(Value(g.T_η))",
)
end

Expand All @@ -300,33 +301,51 @@ Defines a power law viscous creeplaw as:
where ``\\eta`` is the effective viscosity [Pa*s].
"""
@with_kw_noshow struct PowerlawViscous{T,U1,U2,U3} <: AbstractCreepLaw{T}
η0::GeoUnit{T,U1} = 1e18Pa * s # reference viscosity
n::GeoUnit{T,U2} = 2.0 * NoUnits # powerlaw exponent
ε0::GeoUnit{T,U3} = 1e-15 * 1 / s # reference strainrate
η0::GeoUnit{T,U1} = 1e18Pa * s # reference viscosity
n::GeoUnit{T,U2} = 2.0 * NoUnits # powerlaw exponent
ε0::GeoUnit{T,U3} = 1e-15/s # reference strainrate
end
PowerlawViscous(a...) = PowerlawViscous(convert.(GeoUnit, a)...)

# Print info
function show(io::IO, g::PowerlawViscous)
return print(io, "Powerlaw viscosity: η0=$(g.η0.val), n=$(g.n.val), ε0=$(g.ε0.val) ")
end
#-------------------------------------------------------------------------

#=
# add methods programmatically
#for myType in (:LinearViscous, :DiffusionCreep, :DislocationCreep, :ConstantElasticity)
for myType in (:LinearViscous, :DiffusionCreep, :DislocationCreep)

@eval begin
compute_εII(TauII, a::$(myType), args) = compute_εII(TauII, a; args...)
dεII_dτII(TauII, a::$(myType), args) = dεII_dτII(TauII, a; args...)
compute_τII(EpsII, a::$(myType), args) = compute_τII(EpsII, a; args...)
if Symbol($myType) !== :ConstantElasticity
dτII_dεII(EpsII, a::$(myType), args) = dτII_dεII(EpsII, a; args...)
end
end
# Calculation routines for linear viscous rheologies
function compute_εII(a::PowerlawViscous, TauII; kwargs...)
@unpack_val η0, n, ε0 = a

@pow EpsII = (TauII / η0)^(1/n) * ε0

return EpsII
end
=#

function dεII_dτII(a::PowerlawViscous, TauII; kwargs...)
@unpack_val η0, n, ε0 = a

return @pow ((TauII^((1 - n) / n))*(1^(1 / n))) / (n*(η0^(1 / n)))
end

"""
compute_τII(s::PowerlawViscous, EpsII; kwargs...)

Returns second invariant of the stress tensor given a 2nd invariant of strain rate tensor
"""
function compute_τII(a::PowerlawViscous, EpsII; kwargs...)
@unpack_val η0, n, ε0 = a

τII = @pow ε0 * η0 * (EpsII / ε0)^n

return τII
end

function dτII_dεII(a::PowerlawViscous, EpsII; kwargs...)
@unpack_val η0, n, ε0 = a

return @pow η0 * EpsII^(n - 1) * (1 / ε0)^n
end
#-------------------------------------------------------------------------

# Help info for the calculation routines
"""
Expand Down
4 changes: 2 additions & 2 deletions src/MeltFraction/MeltingParameterization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ for myType in (
:SmoothMelting,
)
@eval begin
(p::$(myType))(args) = p(; args...)
compute_meltfraction(p::$(myType), args) = p(; args...)
(p::$(myType))(args) = clamp(p(; args...), one(eltype(args)), zero(eltype(args)))
compute_meltfraction(p::$(myType), args) = clamp(p(; args...), one(eltype(args)), zero(eltype(args)))
compute_dϕdT(p::$(myType), args) = compute_dϕdT(p; args...)
end
end
Expand Down
18 changes: 16 additions & 2 deletions test/test_CreepLaw.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Test, Statistics
using GeoParams


@testset "CreepLaw" begin

#Make sure structs are isbits
Expand Down Expand Up @@ -29,7 +30,7 @@ using GeoParams

x1_ND = LinearViscous(; η=1e18Pa * s)
@test isDimensional(x1_ND) == true
x1_ND = nondimensionalize(x1_ND, CharUnits_GEO) # check that we can nondimensionalize all entries within the struct
x1_ND = nondimensionalize(x1_ND, CharUnits_GEO) # check that we can nondimensionalize all entries within the struct
@test isDimensional(x1_ND) == false
@test x1_ND.η * 1.0 == 0.1
x1_D = dimensionalize(x1_ND, CharUnits_GEO) # check that we can dimensionalize it again
Expand All @@ -53,11 +54,23 @@ using GeoParams
ε = [0.0; 0.0]
compute_τII!(ε, x1_ND, [1e0; 2.0], args)
@test ε == [0.2; 0.4] # vector input

# -------------------------------------------------------------------

# -------------------------------------------------------------------
# Define powerlaw viscous rheology
η0 = 10
n = 2.3
ε0 = 1
x2 = PowerlawViscous(; η0 = 10, n=2.3, ε0 = 1)

τII = 1e0
εII = 1e0
@test compute_τII(x2, τII) == η0
@test compute_εII(x2, εII) == 0.36746619407366893

@test compute_viscosity_εII(x2, τII, (;)) == 5e0
@test compute_viscosity_τII(x2, εII, (;)) == 1.3606693841876538

x2 = PowerlawViscous()
x2 = nondimensionalize(x2, CharUnits_GEO)
@test NumValue(x2.ε0) == 0.001 # powerlaw
Expand Down Expand Up @@ -269,3 +282,4 @@ using GeoParams


end

Loading