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 missing methods to get_Kb and get_G #217

Merged
merged 6 commits into from
Sep 12, 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoParams"
uuid = "e018b62d-d9de-4a26-8697-af89c310ae38"
authors = ["Boris Kaus <kaus@uni-mainz.de>, Albert De Montserrat <albertdemontserratnavarro@erdw.ethz.ch>"]
version = "0.6.2"
version = "0.6.3"

[deps]
BibTeX = "7b0aa2c9-049f-5cec-894a-2b6b781bb25e"
Expand Down
9 changes: 6 additions & 3 deletions src/GeoParams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -436,20 +436,23 @@ end
include("aliases.jl")
export ntuple_idx


for modulus in (:G, :Kb)
fun = Symbol("get_$(string(modulus))")
@eval begin
@inline $(fun)(a::ConstantElasticity) = a.$(modulus).val
@inline $(fun)(c::CompositeRheology) = $(fun)(isviscoelastic(c), c)
@inline $(fun)(::ElasticRheologyTrait, c::CompositeRheology) = mapreduce(x->$(fun)(x), +, c.elements)
@inline $(fun)(::AbstractCreepLaw) = 0
@inline $(fun)(::AbstractPlasticity) = 0
@inline $(fun)(r::AbstractMaterialParamsStruct) = $(fun)(r.CompositeRheology[1])
@inline $(fun)(a::NTuple{N, AbstractMaterialParamsStruct}, phase) where N = nphase($(fun), phase, a)
end
end

@inline get_G(::NonElasticRheologyTrait, c::CompositeRheology) = 0
@inline get_G(::Union{NonElasticRheologyTrait, AbstractCreepLaw, AbstractPlasticity, AbstractConstitutiveLaw}) = 0

@inline get_Kb(::NonElasticRheologyTrait, c::CompositeRheology) = Inf
@inline get_Kb(::Union{NonElasticRheologyTrait, AbstractCreepLaw, AbstractPlasticity, AbstractConstitutiveLaw}) = Inf

export get_G, get_Kb

const get_shearmodulus = get_G
Expand Down
8 changes: 7 additions & 1 deletion test/test_Traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ using Test, GeoParams
@test isviscoelastic(r1[3]) isa ElasticRheologyTrait
@test isviscoelastic(r1[4]) isa NonElasticRheologyTrait

# test get_G and get_Kb
r = CompositeRheology(v1, v2, v3)
@test GeoParams.get_G(isviscoelastic(r), r) == 0
@test GeoParams.get_Kb(isviscoelastic(r), r) == Inf

## linear rheology traits
# test basic cases
for r in (v1, v2, pl)
Expand Down Expand Up @@ -133,4 +138,5 @@ end
@test isconstant(r1) isa NonConstantDensityTrait
@test isconstant(r2) isa ConstantDensityTrait
@test_throws ArgumentError isconstant("potato")
end
end

Loading