Functionals
HyperShape.Functionals — Module
HyperShape.FunctionalsObjectives and constraints. A Functional evaluates a quantity of interest and its derivative with respect to the optimisation variables z, from forms written by the user with respect to the physical fields θ.
HyperShape.Functionals.AbstractFunctional — Type
AbstractFunctionalSupertype of the objectives and constraints. What the optimisation oracle uses of a subtype F: functional_value, functional_gradient! (alone and in a weighted tuple), get_scale(F), is_design_only(F) (no state is solved for it), is_linear(F) (declared affine in z), physical_fields(F), responses(F) (the states it reads) and invalidate!(F). The internals of the reverse sweep (_seed!, _pull_back!) will change with chains of states.
HyperShape.Functionals.Constraint — Type
Constraint(F::AbstractFunctional; max = nothing, min = nothing, equal = nothing)A constraint on the functional F, in the units of F (before scaling): F ≤ max, F ≥ min, min ≤ F ≤ max or F = equal. Without bounds, F ≤ 0; a functional given alone in the constraints of an Optimization is Constraint(F; max = 0.0) (as Volume). With scale = :bound in F, its scale is the largest finite bound in absolute value, so the bound is written once:
Tip = Functional((u, θ) -> ∫(g ⋅ u)dΓo, S; dJdu = u -> (w -> ∫(g ⋅ w)dΓo), scale = :bound)
problem = Optimization(objective = C, constraints = (volume = Vol, tip = Constraint(Tip; max = 0.25)))The optimiser sees g = (F − r)/s, with s the scale of F and r the upper bound (the lower one if there is no upper), and its bounds [(min − r)/s, (max − r)/s]. The scale belongs to the functional: with scale = :bound, build one functional per Constraint (a second Constraint with another bound on the same functional throws).
HyperShape.Functionals.Functional — Type
Functional(J, S::StateOperator; dJdu, dJdθ = nothing, scale, fields = nothing, parameters = ())
Functional(J, θ::PhysicalFields; dJdθ, scale, linear = false, parameters = ())Objective or constraint.
With a state (first form), S a StateOperator built with an AdjointProblem (it declares how to solve the transposed system and the forms pᵀ ∂R/∂θ of the state):
J(u, θ): value, aDomainContribution(∫(…)dΩ) or a number;u = get_state(S).dJdu(mandatory): the partial derivative with respect to the state,u -> (w -> ∫(…)dΩ)(a linear form in the test functionwof the adjoint),LinearInState()whenJis linear inu(a mean displacement, a temperature at a probe: thendJduisJitself withwin place ofu), orSelfAdjoint()when it is the load of a linear and symmetric state (the compliance): thenp = uand no adjoint is solved.dJdθ: the partial derivative with respect to the physical fields,(u, θ) -> (δ -> ∫(… * δ)dΩ), or a named tuple of such forms ((ρ = δ -> …, E = δ -> …)) when θ has several fields;nothing(default) whenJdoes not read θ directly.fields: the physical fields θ, the onlyPhysicalFieldsamong the dependencies ofS(deduced; a state that depends on several is not supported yet).
The derivative with respect to θ is dJdθ − pᵀ ∂R/∂θ, with p the adjoint of S seeded by dJdu: the signs are put by HyperShape. A state that depends on another state is not supported yet (an error here): the sensitivity through the upstream state would be missing.
Design only (second form, volume, perimeter): J(θ) and dJdθ(θ), the derivative with respect to θ.
scale is mandatory: a positive number, :initial (the absolute value of the first finite evaluation; an error if it is zero or at the level of rounding: checked at the first derivative, when moving z across its bounds would change the scaled value by more than 10⁸), :bound (for a constraint: the largest finite bound of its Constraint in absolute value) or 1.0 for no scaling. The value and the derivative are divided by it.
parameters: Parameters (or other objects with a state_version) that J reads directly, not through θ or a state (a weight that is continued, for example): the value is computed again when they change. A parameter read by a model goes in the dependencies of its operator instead; one read by a map, in the parameters of the PointwiseMap. linear (design-only form) declares a functional affine in z, checked when it is used as a constraint.
The value is kept until θ, a state or a parameter changes. Each gradient is one reverse sweep: the seeds of the functional, one adjoint solve of the state (a back substitution after the first gradient of a design; none for SelfAdjoint()), one transposed solve per filter and the assemblies of the forms.
If a state does not converge, functional_value returns NaN and functional_gradient! fills the gradient with NaN (the optimisers treat it as a failed trial).
HyperShape.Functionals.LinearInState — Type
LinearInState()dJdu of a Functional whose value J(u, θ) is linear in the state u (no constant term), such as J = (u, θ) -> ∫(g ⋅ u)dΓ: its derivative in the direction w is J(w, θ), so it is not written twice. J must return a DomainContribution; check_consistency detects a functional that is not linear.
HyperShape.Functionals.Volume — Method
Volume(θ::PhysicalFields, dΩ; max_fraction, field = nothing, scale = Vmax)
Volume(x::DesignFields, dΩ; max_fraction, field = nothing, scale = Vmax)
Volume(θ::PhysicalFields, dΩ::DesignMeasures; …) # the domain of design_measures(θ; degree)Volume constraint g = ∫ θ.field dΩ - Vmax ≤ 0 with Vmax = max_fraction ⋅ |Ω| (0 < max_fraction ≤ 1, |Ω| the measure of dΩ), a design-only Functional with its value and derivative written in. With physical fields θ, the volume of the physical density: nonlinear in z if its chain has a TanhProjection, an Ersatz() or another nonlinear map, linear otherwise. With design fields x, the volume of the design density (linear; the identity physical fields are built inside). field is mandatory when there are several fields. scale divides the value and the derivative; default Vmax. A field that the bounds of its design field and its maps can make negative (a level set in [-1, 1] read without Ersatz() or Step()) is an error: its volume is not a volume of material (with a PointwiseMap in the chain it is not checked).
HyperShape.Functionals.functional_gradient! — Method
functional_gradient!(gz, F::Functional, ctx) -> gzScaled derivative of the functional with respect to z, written into gz: one reverse sweep (solves the forward state if needed, the adjoint of the state, the transposed filters). Filled with NaN if a state did not converge.
HyperShape.Functionals.functional_gradient! — Method
functional_gradient!(gz, Fs::Tuple, w, ctx) -> gzDerivative with respect to z of Σᵢ wᵢ Fᵢ (each Fᵢ scaled) in one reverse sweep per set of physical fields θ: every state is solved once whatever the number of functionals that read it (one adjoint solve per state, not per functional) and every filter is solved once. The seeds are wᵢ sᵣ/sᵢ and the result is divided by sᵣ, the scale of the first functional of the sweep, so that a tuple of one functional gives the same bits as functional_gradient!(gz, F, ctx). Functionals on different θ (a Volume of the design fields) are summed sweep by sweep. A functional with weight zero costs nothing (its state is not solved). Filled with NaN if a state did not converge.
HyperShape.Functionals.functional_value — Method
functional_value(F::Functional, ctx) -> Float64Scaled value of the functional at the current design (states solved again only if the design changed). NaN if a state did not converge.