Utilities
This sub-module of TopOpt defines penalty functions, projections, and low-level helpers shared across the package. The penalty and projection types control how raw design variables are mapped to physical densities before they enter the stiffness assembly.
Penalties
Penalties (SIMP-style) push intermediate densities toward 0 or 1 so that the optimization converges to a near-binary design.
TopOpt.Utilities.AbstractPenalty — Type
AbstractPenalty{T}Abstract type for SIMP-style penalties applied to density variables. T is the numeric type. Concrete subtypes: PowerPenaltyFun, RationalPenaltyFun, SinhPenaltyFun, ProjectedPenaltyFun.
TopOpt.Utilities.PowerPenaltyFun — Type
PowerPenaltyFun(p)Classic SIMP power penalty: ρ^p. p > 1 penalises intermediate densities. The most common choice in topology optimization.
TopOpt.Utilities.RationalPenaltyFun — Type
RationalPenaltyFun(p)Rational SIMP penalty: x / (1 + p * (1 - x)). Produces a smoother penalty than PowerPenaltyFun for the same exponent.
TopOpt.Utilities.SinhPenaltyFun — Type
SinhPenaltyFun(p)Hyperbolic-sine penalty: sinh(p*x) / sinh(p). An alternative smooth penalty.
TopOpt.Utilities.ProjectedPenaltyFun — Type
ProjectedPenaltyFun(penalty, proj)Composite penalty that applies a projection (default HeavisideProjectionFun(10)) before the penalty. Pushes the design toward 0/1 and then penalises.
Projections
Projections are smooth approximations of a step function, used to sharpen the design. They can be applied standalone or composed with a penalty via ProjectedPenaltyFun.
TopOpt.Utilities.AbstractProjection — Type
AbstractProjectionAbstract type for projection functions that push densities toward 0/1. Subtypes: HeavisideProjectionFun, SigmoidProjectionFun.
TopOpt.Utilities.HeavisideProjectionFun — Type
HeavisideProjectionFun(β)Heaviside projection with steepness β. Larger β produces sharper 0/1 transitions. y = 1 - exp(-β*x) + x*exp(-β).
TopOpt.Utilities.SigmoidProjectionFun — Type
SigmoidProjectionFun(β)Sigmoid projection with steepness β. y = 1 / (1 + exp((β+1)*(-x+0.5))).
Penalty accessors
TopOpt.Utilities.getpenalty — Function
getpenalty(solver)Return the current penalty object of solver (or of a function wrapping a solver).
TopOpt.Utilities.getprevpenalty — Function
getprevpenalty(solver)Return the previous penalty object (before the last setpenalty! call).
TopOpt.Utilities.setpenalty! — Function
setpenalty!(solver, p)Update the penalty of solver to p (a number or an AbstractPenalty). Stashes the old penalty in getprevpenalty.
Design-density helper
TopOpt.Utilities.density — Function
density(var, xmin)Map a design variable var ∈ [0, 1] to a physical density in [xmin, 1]: ρ = var * (1 - xmin) + xmin. This is the interpolation step that gives void (xmin) a small but nonzero stiffness to keep the system non-singular.
Low-level helpers
TopOpt.Utilities.RaggedArray — Type
RaggedArray(vv::Vector{Vector{T}})Store a vector of variable-length vectors in a single flat values array with an offsets array marking where each row begins. Used to pack the per-cell DOF and cell connectivity tables of the FEA metadata.
TopOpt.Utilities.compliance — Function
compliance(Ke, u, dofs)Compute the local compliance uᵀ Ke u over the degrees of freedom dofs.
TopOpt.Utilities.sumdiag — Function
sumdiag(K::Union{StaticMatrix, Symmetric{<:Any, <:StaticMatrix}})
Computes the sum of the diagonal of the static matrix K.
TopOpt.Utilities.meandiag — Function
meandiag(K::AbstractMatrix)Compute the mean of the absolute diagonal entries of K.
TopOpt.Utilities.getsolver — Function
getsolver(f)Return the solver wrapped by f (a function or algorithm that stores its solver in the solver field).
TopOpt.Utilities.@debug — Macro
@debug exprEvaluate expr only when the package-level DEBUG flag is enabled.
TopOpt.Utilities.@forward_property — Macro
@forward_property T fieldForward any getproperty/setproperty! access on T to its field, so T transparently exposes that field's properties.