API — Sensitivities
Public lenses and autodiff entry points provided by MeanFieldHom.Schemes. ForwardDiff is a strong dependency of MeanFieldHom since v0.7.0 — the four derivative / gradient / jacobian / sensitivity functions are available out of the box, and the built-in SelfConsistent Newton-Raphson solver (NewtonDefault) uses the same machinery internally.
Lenses
MeanFieldHom.Schemes.AbstractParameter — Type
AbstractParameterSupertype of parameter lenses. Concrete subtypes designate a single scalar input of a homogenization computation :
AmountParameter— volume fraction or crack density of a phase.PropertyParameter— a scalar coefficient of a property tensor (:C,:K, …) of a phase, designated either by a named selector (:bulk,:shear, …) or by a positional index.GeometryParameter— a scalar geometry field of a phase (semi- axis of an ellipsoid, radius of a layer, …).DistributionShapeParameter— a scalar field of the PCW / Maxwell distribution shape.
The get_param / set_param functions read and replace the designated scalar in a RVE. See also the convenience constructors amount, property, geometry, shape_param.
MeanFieldHom.Schemes.AmountParameter — Type
AmountParameter(phase::Symbol)Lens on the amount (volume fraction or crack density) of phase phase. Prefer the helper amount.
MeanFieldHom.Schemes.PropertyParameter — Type
PropertyParameter(phase, property, selector)Lens on a scalar coefficient of a property tensor :
phase::Symbol— phase name (:Mfor the matrix by default, or any inclusion phase).property::Symbol— property key in the phase (:C,:K, …).selector::Union{Symbol,Int}— coefficient selector :Symbolfor canonical names (:bulk/:shearforTensISO{4,3};:scalarforTensISO{2};:ℓ₁..:ℓ₆forTensTI{4};:transverse/:axialforTensTI{2}),Intfor the positional index intoget_data(tensor)(universal fallback).
Prefer the helper property.
MeanFieldHom.Schemes.GeometryParameter — Type
GeometryParameter(phase, field, index = nothing)Lens on a scalar geometry field of a phase. For an NTuple field (e.g. semi_axes), index selects one element of the tuple ; otherwise leave index = nothing.
Prefer the helper geometry.
MeanFieldHom.Schemes.DistributionShapeParameter — Type
DistributionShapeParameter(field, index = nothing)Lens on a scalar field of the (Maxwell / PCW) distribution shape. Prefer the helper shape_param.
MeanFieldHom.Schemes.amount — Function
amount(phase::Symbol) -> AmountParameterHelper. Equivalent to AmountParameter(phase).
MeanFieldHom.Schemes.property — Function
property(phase::Symbol, property::Symbol, selector) -> PropertyParameterHelper. Equivalent to PropertyParameter(phase, property, selector).
MeanFieldHom.Schemes.geometry — Function
geometry(phase::Symbol, field::Symbol, index=nothing) -> GeometryParameterHelper. Equivalent to GeometryParameter(phase, field, index).
MeanFieldHom.Schemes.shape_param — Function
shape_param(field::Symbol, index=nothing) -> DistributionShapeParameterHelper. Equivalent to DistributionShapeParameter(field, index).
MeanFieldHom.Schemes.get_param — Function
get_param(rve, p::AbstractParameter) -> NumberRead the scalar designated by lens p in rve.
MeanFieldHom.Schemes.set_param — Function
set_param(rve, p::AbstractParameter, value) -> RVEReturn a new rve instance in which the scalar designated by lens p has been replaced by value. The element type of the affected fields (amounts, tensors, geometries) is promoted to absorb typeof(value) ; all other fields are preserved unchanged (no mutation of the original).
Autodiff entry points
MeanFieldHom.Schemes.derivative — Function
derivative(rve, scheme, param::AbstractParameter;
output = :C, indexer = identity, kw...) -> Number | AbstractTensScalar derivative of homogenize(rve, scheme; property=output) with respect to the parameter selected by the lens param.
indexer is a function that extracts a scalar from the effective tensor (for example C -> get_data(C)[1] / 3 for the bulk modulus). Without an indexer, the derivative of the full tensor is returned — this is valid as long as ForwardDiff can propagate through the result (typically when the output is itself a structured object whose components ForwardDiff handles natively, via the _data Dual fields).
Extra kw... (e.g. Chunk, Tag) are forwarded to ForwardDiff.
The method is only available with using ForwardDiff; calling it without the extension loaded raises an explicit error pointing at the extension.
See also gradient, jacobian, sensitivity.
MeanFieldHom.Schemes.gradient — Function
gradient(rve, scheme, params::AbstractVector{<:AbstractParameter};
output = :C, indexer, kw...) -> VectorGradient of a scalar functional (extracted via indexer) of the effective tensor returned by homogenize(rve, scheme; property=output), with respect to the vector of lenses params.
Implementation: ForwardDiff.gradient with automatic chunking (ForwardDiff.Chunk(length(params)) via the standard pickchunksize rule).
Without using ForwardDiff: error.
MeanFieldHom.Schemes.jacobian — Function
jacobian(rve, scheme, params::AbstractVector{<:AbstractParameter};
output = :C, indexer = identity, kw...) -> ArrayJacobian (returned as a flat array length(output_flat) × length(params)) of homogenize(rve, scheme; property=output) with respect to the vector of lenses params.
indexer can be used to reduce the output to a sub-tensor before flattening. Without an indexer, the full effective tensor is flattened via get_array then vec.
Without using ForwardDiff: error.
MeanFieldHom.Schemes.sensitivity — Function
sensitivity(f, x₀; kind = :auto, kw...)Generic ForwardDiff wrapper. f(x) is a user-supplied closure that builds or perturbs an RVE, runs homogenize, and returns a scalar (or a tensor).
kind:
:derivative— scalarx₀, scalar output; returnsf'(x₀).:gradient— vectorx₀, scalar output; returns∇f(x₀).:jacobian— vectorx₀, tensor output; returns the flattened Jacobian.:auto(default) — pick one of the above from the types ofx₀andf(x₀).
This entry point covers cases the AbstractParameter lenses cannot express (compound parametrizations, user-defined inclusion types without an exposed scalar field, etc.).
Without using ForwardDiff: error.