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.