@@ -66,26 +66,59 @@ get_params_eltype(::AbstractMaterial) = Float64
6666
6767# Conversion functions
6868"""
69- tovector!(v::AbstractVector, m::AbstractMaterial)
69+ tovector!(v::AbstractVector, m::AbstractMaterial; offset = 0)
70+
7071Put the material parameters of `m` into the vector `v`.
7172This is typically used when the parameters should be fitted.
7273
73- tovector!(v::AbstractVector, s::AbstractMaterialState)
74+ tovector!(v::AbstractVector, s::AbstractMaterialState; offset = 0)
75+
7476Put the state variables in `s` into the vector `v`.
7577This is typically used when differentiating the material
7678wrt. the the old state variables.
79+
80+ tovector!(v::AbstractVector, a::Union{SecondOrderTensor, FourthOrderTensor}; offset = 0)
81+
82+ Puts the Mandel components of `a` into the vector `v`.
7783"""
7884function tovector! end
7985
86+ # Tensors.jl implementation
87+ function tovector! (v:: AbstractVector , a:: SecondOrderTensor ; offset = 0 )
88+ return tomandel! (v, a; offset)
89+ end
90+ function tovector! (v:: AbstractVector , a:: Union{Tensor{4, <:Any, <:Any, M}, SymmetricTensor{4, <:Any, <:Any, M}} ; offset = 0 ) where {M}
91+ N = round (Int, sqrt (M))
92+ m = reshape (view (v, offset .+ (1 : M)), (N, N))
93+ tomandel! (m, a)
94+ return v
95+ end
96+
8097"""
81- fromvector(v::AbstractVector, ::MT) where {MT<:AbstractMaterial}
98+ fromvector(v::AbstractVector, ::MT; offset = 0 ) where {MT<:AbstractMaterial}
8299Create a material of type `MT` with the parameters according to `v`
83100
84- fromvector(v::AbstractVector, ::ST) where {ST<:AbstractMaterialState}
101+ fromvector(v::AbstractVector, ::ST; offset = 0 ) where {ST<:AbstractMaterialState}
85102Create a material state of type `ST` with the values according to `v`
103+
104+ fromvector(v, ::TT; offset = 0) where {TT <: Union{SecondOrderTensor, FourthOrderTensor}}
105+
106+ Create a tensor with shape of `TT` with entries from the Mandel components in `v`.
86107"""
87108function fromvector end
88109
110+ # Tensors.jl implementation
111+ function fromvector (v:: AbstractVector , :: TT ; offset = 0 ) where {TT <: SecondOrderTensor }
112+ return frommandel (Tensors. get_base (TT), v; offset)
113+ end
114+
115+ function fromvector (v:: AbstractVector , :: TT ; offset = 0 ) where {TT <: FourthOrderTensor }
116+ TB = Tensors. get_base (TT)
117+ M = Tensors. n_components (TB)
118+ N = round (Int, sqrt (M))
119+ return frommandel (TB, reshape (view (v, offset .+ (1 : M)), (N, N)))
120+ end
121+
89122"""
90123 tovector(m::AbstractMaterial)
91124
@@ -108,6 +141,8 @@ function tovector(s::AbstractMaterialState)
108141 return tovector! (zeros (T, get_num_statevars (s)), s)
109142end
110143
144+ tovector (a:: Union{SecondOrderTensor, FourthOrderTensor} ) = (m = tomandel (a); reshape (m, length (m)))
145+
111146# Backwards compatibility
112147const get_parameter_type = get_params_eltype
113148const material2vector! = tovector!
0 commit comments