Conversion
MaterialModelsBase defines an interface for converting parameters, state variables, and other objects to and from AbstractVectors. This is useful when doing parameter identification, or when interfacing with different languages that require information to be passed as arrays.
These function can be divided into those providing information about the material and state variables, and those doing the actual conversion.
Information functions
The following should be defined for new materials,
MaterialModelsBase.get_tensorbase — Function
get_tensorbase(m::AbstractMaterial)Return the type of the primary input (strain-like) and associated output (stress-like) to the material model. The default is SymmetricTensor{2, 3} for small-strain material models in 3D, but it can be
- Small strain material model: Small strain tensor,
ϵ::SymmetricTensor{2, dim} - Large strain material model: Deformation gradient,
F::Tensor{2, dim} - Traction-separation law: Displacement jump,
Δu::Vec{dim}
Where dim = 3 is most common, but any value, 1, 2, or 3, is valid.
MaterialModelsBase.get_vector_length — Function
get_vector_length(obj)Return the length of the vector representation of obj when using tovector or tovector!. The default implementation of tovector relies on this function being defined.
MaterialModelsBase.get_vector_eltype — Function
get_vector_eltype(obj)Return the element type of the vector representation of obj when using tovector, i.e. with T = get_vector_eltype(obj) and N = get_vector_length(obj), we have typeof(obj) == typeof(fromvector(zeros(T, N), obj)).
Whereas the following already have default implementations that should work provided that the above are implemented.
MaterialModelsBase.get_num_statevars — Function
get_num_statevars(m::AbstractMaterial)Return the number of scalar values required to store the state of m, i.e. length(tovector(initial_material_state(m))). The default implementation works provided that s = initial_material_state(m) and get_vector_length(s) is defined.
MaterialModelsBase.get_num_tensorcomponents — Function
get_num_tensorcomponents(::AbstractMaterial)Returns the number of independent components for the given material.
It is not required to implement this function, it is inferred by the implementation of get_tensorbase
Conversion functions
The following should be defined for new materials, state variables, and alike
MaterialModelsBase.tovector! — Function
tovector!(v::AbstractVector, obj; offset = 0)Store the parameters in the object obj in v. This is typically used with obj as an AbstractMaterial, an AbstractMaterialState, or an AbstractTensor. The offset input makes it possible to write values starting at an offset location in v.
The implementation for AbstractTensors is included in the MaterialModelsBase.jl package, and use the Mandel notation for the conversion.
MaterialModelsBase.fromvector — Function
fromvector(v::AbstractVector, ::OT; offset = 0)Output an object of similar type to OT, but with parameters according to v. This is typically used with an AbstractMaterial, an AbstractMaterialState, or an AbstractTensor. The offset input makes it possible to read values starting at an offset location in v.
The implementation for AbstractTensors is included in the MaterialModelsBase.jl package, and use the Mandel notation for the conversion.
whereas the following already have default implementations that should work provided that the above functions are implemented,
MaterialModelsBase.tovector — Function
tovector([T::Type{<:AbstractArray}], obj)::TOut-of place version of tovector!. Relies on get_vector_length and get_vector_eltype to be correctly defined, and defaults to T = Array.
Experimental support for T = SArray is also available, but performance may be suboptimal, and can be improved by implementing a custom function for the given type.