-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/KnutAM/MaterialModelsBase.jl
- Loading branch information
Showing
5 changed files
with
84 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Checks to ensure that e.g. calls are allocation-free | ||
# If functions that shouldn't allocate do, this could be a | ||
# sign of type-instability, would have caught e.g. | ||
# https://github.com/KnutAM/MaterialModelsBase.jl/pull/10 | ||
|
||
function get_run_allocations(ss, m, ϵv, t = collect(range(0, 1, length(ϵv)))) | ||
state, cache, σv, ϵv_full = setup_run_timehistory(m, ϵv) | ||
run_timehistory!(σv, ϵv_full, state, cache, ss, m, ϵv, t) # Compilation | ||
return @allocated run_timehistory!(σv, ϵv_full, state, cache, ss, m, ϵv, t) | ||
end | ||
|
||
@testset "performance" begin | ||
# Load cases | ||
N = 100 | ||
load_cases = ( | ||
(UniaxialStress(), | ||
collect((SymmetricTensor{2,1}((0.1*(i-1)/N,)) for i in 1:N+1))), | ||
) | ||
# Materials | ||
G = 80.e3; K = 160.e3; η = 20.e3 | ||
linear_elastic = LinearElastic(G, K) | ||
visco_elastic = ViscoElastic(linear_elastic, LinearElastic(G*0.5, K*0.5), η) | ||
materials = (linear_elastic, visco_elastic) | ||
|
||
for (stress_state, ϵv) in load_cases | ||
for m in materials | ||
allocs = get_run_allocations(stress_state, m, ϵv) | ||
allocs > 0 && println(allocs, " allocations for m::", typeof(m), ", ss::", typeof(stress_state)) | ||
@test allocs == 0 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
_getdim(::MaterialModelsBase.State1D) = 1 | ||
_getdim(::MaterialModelsBase.State2D) = 2 | ||
_getdim(::MaterialModelsBase.State3D) = 3 | ||
_getdim(::AbstractTensor{order,dim}) where {order,dim} = dim | ||
|
||
tensortype(::SymmetricTensor) = SymmetricTensor | ||
tensortype(::Tensor) = Tensor | ||
|
||
# Create GeneralStressState from regular states to check compatibility | ||
function MMB.GeneralStressState(::UniaxialStress, TT::Type{<:SecondOrderTensor{3}}) | ||
σ = zero(TT) | ||
σ_ctrl = tensortype(σ){2,3,Bool}((i,j)->!(i==j==1)) | ||
return MMB.GeneralStressState(σ_ctrl, σ) | ||
end | ||
function MMB.GeneralStressState(::PlaneStress, TT::Type{<:SecondOrderTensor{3}}) | ||
σ = zero(TT) | ||
σ_ctrl = tensortype(σ){2,3,Bool}((i,j)->(i==3 || j==3)) | ||
return MMB.GeneralStressState(σ_ctrl, σ) | ||
end | ||
function MMB.GeneralStressState(::UniaxialNormalStress, TT::Type{<:SecondOrderTensor{3}}) | ||
σ = zero(TT) | ||
σ_ctrl = tensortype(σ){2,3,Bool}((i,j)->(i==j∈(2,3))) | ||
return MMB.GeneralStressState(σ_ctrl, σ) | ||
end | ||
|
||
function run_timehistory!(σv::Vector, ϵv_full::Vector, state, cache, s, m, ϵv, t) | ||
local dσdϵ | ||
for i in 1:(length(ϵv)-1) | ||
σ, dσdϵ, state, ϵ_full = material_response(s, m, ϵv[i+1], state, t[i+1]-t[i], cache) | ||
σv[i] = σ | ||
ϵv_full[i] = ϵ_full | ||
end | ||
return dσdϵ | ||
end | ||
|
||
function setup_run_timehistory(m::AbstractMaterial, ϵv::Vector{<:AbstractTensor}) | ||
state = initial_material_state(m) | ||
cache = allocate_material_cache(m) | ||
σv = zeros(eltype(ϵv), length(ϵv)-1) | ||
ϵv_full = zeros(tensortype(first(ϵv)){2,3}, length(ϵv)-1) | ||
return state, cache, σv, ϵv_full | ||
end | ||
|
||
function run_timehistory(s, m::AbstractMaterial, ϵv, t = collect(range(0, 1, length(ϵv)))) | ||
state, cache, σv, ϵv_full = setup_run_timehistory(m, ϵv) | ||
dσdϵ = run_timehistory!(σv, ϵv_full, state, cache, s, m, ϵv, t) | ||
return σv, ϵv_full, dσdϵ | ||
end |