Skip to content

Conversation

@lijas
Copy link
Collaborator

@lijas lijas commented Feb 4, 2022

This is how I think material cache should be implemented.
I once implemented a material that needed to store 2 vectors, and I think the current implementation of caches does to allow for that...

So now each material that needs cache, can wrap their vectors etc in their own type.

I had to refactor the planestress-wrapper aswell.

@kimauth
Copy link
Owner

kimauth commented Feb 4, 2022

I think I would separate the two types of cache that we need at the moment completely. That is, have one SolverCache (the OnceDifferentiable for now) and one PlaneStressCache that only stores the fields for plane stress iterations (but not the SolverCache. Then we could have different constructors, e.g.

cache1 = get_cache(::Material) # the OnceDifferentiable
cache2 = get_cache(::Material, ::PlaneStress) # a wrapper type with OnceDifferentiable and PlaneStressCache as fields
cache3 = get_cache(::Material, ::PlaneStrain) # only OnceDifferentiable again

and access their fields via accessor functions, e.g.

get_solver_cache(c::OnceDifferentiable) = c
get_solver_cache(c::CacheWrapper) = c.nlsolve_cache
get_plane_stress_cache(c::CacheWrapper) = c.plane_stress_cache

@lijas
Copy link
Collaborator Author

lijas commented Apr 1, 2022

It the advanced material mechanics course I need a costum chache since i am not using nlsolve.

struct Plastic2Cache <: MaterialModels.AbstractCache
    x::Vector{Float64}
    R::Vector{Float64}
    J::Matrix{Float64}
end

Is it ok if I merge this (after some cleanup) since #44 removed the need for cache plane stress iterations?

"""
function get_cache(::AbstractMaterial)
return nothing
nothing
Copy link
Owner

Choose a reason for hiding this comment

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

I usually prefer being explicit with the return statements (and I think we pretty much are in the rest of the package).

Base.zero(::Type{PlasticState{dim,T,M}}) where {dim,T,M} = PlasticState(zero(SymmetricTensor{2,dim,T,M}), zero(T), zero(SymmetricTensor{2,dim,T,M}), zero(T))
initial_material_state(::Plastic) = zero(PlasticState{3,Float64,6})

struct PlasticCache{T<:OnceDifferentiable} <: AbstractCache
Copy link
Owner

Choose a reason for hiding this comment

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

I think this could be NLsolveCache and live in a seperate cache.jl file. It is not really specific to the plastic material at all, rather applies to any material that would use nlsolve as a non-linear solver.

@lijas lijas merged commit de50ffb into main Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants