Skip to content

Commit

Permalink
Add missing methods to get_Kb and get_G (#217)
Browse files Browse the repository at this point in the history
* missing methods for get_Kb and get_G

* revert change

* more methods

* fix test

* and more methods

* bump minor
  • Loading branch information
albert-de-montserrat authored Sep 12, 2024
1 parent 602e704 commit b8f88d5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
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

2 comments on commit b8f88d5

@albert-de-montserrat
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/115036

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.3 -m "<description of version>" b8f88d537b01b9a22e0cc43a9fd7eb17a40fe313
git push origin v0.6.3

Please sign in to comment.