Skip to content

Commit

Permalink
viscoelastic trait compatibility with AbstractPlasticty (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat authored Aug 16, 2024
1 parent 05c8f1c commit 74a3e1d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Traits/rheology.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ struct NonPlasticRheologyTrait <: RheologyTrait end
@inline isviscoelastic(::RheologyTrait, ::ElasticRheologyTrait) = ElasticRheologyTrait()
@inline isviscoelastic(::ElasticRheologyTrait, ::RheologyTrait) = ElasticRheologyTrait()
@inline isviscoelastic(::RheologyTrait, ::RheologyTrait) = NonElasticRheologyTrait()
@inline isviscoelastic(v1::AbstractConstitutiveLaw, v2::AbstractConstitutiveLaw) = isviscoelastic(isviscoelastic(v1), isviscoelastic(v2))
@inline isviscoelastic(v1::Union{AbstractConstitutiveLaw, AbstractPlasticity}, v2::Union{AbstractConstitutiveLaw, AbstractPlasticity}) = isviscoelastic(isviscoelastic(v1), isviscoelastic(v2))

# traits for composite rheologies
@inline isviscoelastic(c::CompositeRheology) = isviscoelastic(c.elements)
# traits for MaterialParams
@inline isviscoelastic(r::MaterialParams) = isviscoelastic(r.CompositeRheology...)

# recursively (pairwise, right-to-left) compare rheology traits of a composite or tuple of material params
@inline isviscoelastic(r::NTuple{N, Union{AbstractConstitutiveLaw, MaterialParams}}) where N = isviscoelastic(isviscoelastic(first(r)), isviscoelastic(Base.tail(r)))
@inline isviscoelastic(v::NTuple{1, Union{AbstractConstitutiveLaw, MaterialParams}}) = isviscoelastic(v...)
@inline isviscoelastic(r::NTuple{N, Union{AbstractConstitutiveLaw, AbstractPlasticity, MaterialParams}}) where N = isviscoelastic(isviscoelastic(first(r)), isviscoelastic(Base.tail(r)))
@inline isviscoelastic(v::NTuple{1, Union{AbstractConstitutiveLaw, AbstractPlasticity, MaterialParams}}) = isviscoelastic(v...)

## PLASTIC RHEOLOGY TRAITS

Expand Down
4 changes: 2 additions & 2 deletions test/test_Traits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ using Test, GeoParams
@test isviscoelastic(tuple(v1, v3)) isa NonElasticRheologyTrait
@test isviscoelastic(tuple(v3, el)) isa ElasticRheologyTrait

@test isviscoelastic(CompositeRheology(v1, v2, v3)) isa NonElasticRheologyTrait
@test isviscoelastic(CompositeRheology(el, v3)) isa ElasticRheologyTrait
@test isviscoelastic(CompositeRheology(v1, v2, v3, pl)) isa NonElasticRheologyTrait
@test isviscoelastic(CompositeRheology(el, v3, pl)) isa ElasticRheologyTrait

# test MaterialParams cases
@test isviscoelastic(r1[1]) isa ElasticRheologyTrait
Expand Down

0 comments on commit 74a3e1d

Please sign in to comment.