kimauth / MaterialModels.jl

A libary of mechanical material models for finite element simulations.
MIT License
12 stars 6 forks source link

Additional functions for postprocessing / dissipation #46

Open kimauth opened 2 years ago

kimauth commented 2 years ago

Perhaps it would be nice to have some additional functionality for each material that allows recovering information e.g. for postprocessing. Here is an example for the material that's currently called Plastic:

function state_conjugates(
    ε::SymmetricTensor{2,3,T,6}, 
    material::Plastic,
    state::PlasticState{3},
)
    (; Eᵉ, r, H) = material

    σ = Eᵉ ⊡ (ε - state.εᵖ)
    k = - state.κ / (r * H)
    a = - 3/2 / ((1-r)*H) * state.α

    return σ, k, a
end

function strain_rates(
    material::Plastic,
    σ::SymmetricTensor{2,3},
    κ::Real,
    α::SymmetricTensor{2,3},
    λ::Real,
)
    (; κ_∞, α_∞) = material

    σʳᵉᵈ = σ - α
    σʳᵉᵈ_dev = dev(σʳᵉᵈ)
    σₑʳᵉᵈ = sqrt(3/2) * norm(σʳᵉᵈ_dev)
    α_dev = dev(α)

    # flow + hardening rules
    ν = 3/2 * σʳᵉᵈ_dev / σₑʳᵉᵈ
    ζ_κ = -1. + κ / κ_∞
    ζ_α = -ν + 3. / (2α_∞) * α_dev

    # evolution equations
    dεᵖdt = λ * ν
    dkdt = λ * ζ_κ
    dadt = λ * ζ_α

    return dεᵖdt, dkdt, dadt
end

function dissipation(
    ::Plastic, # could perhaps be more general
    σ::SymmetricTensor{2,3},
    κ::Real,
    α::SymmetricTensor{2,3},
    dεᵖdt::SymmetricTensor{2,3},
    dkdt::Real,
    dadt::SymmetricTensor{2,3},
)
    # dissipation
    𝔇 = σ ⊡ dεᵖdt + κ * dkdt + α ⊡ dadt

    return 𝔇
end

This design tries to avoid recomputations of variables where possible, thus the function signatures. For convenience, these functions can of course be glued together and then have simpler signatures:

## convenience wrappers if intermediate results are not needed
function strain_rates(
    ε::SymmetricTensor{2,3}, 
    material::Plastic,
    state::PlasticState{3},
    Δt::Float64,
)
    σ, _, _ = state_conjugates(ε, material, state)
    (; κ, α, μ) = state

    λ = μ / Δt
    return strain_rates(material, σ, κ, α, λ)
end

function dissipation(
    ε::SymmetricTensor{2,3}, 
    material::Plastic,
    state::PlasticState{3},
    Δt::Float64,
)
    σ, _, _ = state_conjugates(ε, material, state)
    (; κ, α, μ) = state

    λ = μ / Δt
    dεᵖdt, dkdt, dadt = strain_rates(material, σ, κ, α, λ)

    return dissipation(material, σ, κ, α, dεᵖdt, dkdt, dadt)
end

Happy to hear some feedback!

lijas commented 2 years ago

Perhaps they should have the same function call as material_response? Seems to fit for the dissipation-function (but you have switched material and \varepsilon). And I like your idea of having an internal _dissipation() or _strain_rates() function for code re-usibility.

This functions can be documented in the docs under each material :)