TopOptProblems
This sub-module of TopOpt defines a number of standard topology optimization problems for the convenient testing of algorithms.
Problem types
TopOpt.TopOptProblems.AbstractTopOptProblem — Type
AbstractTopOptProblemAbstract supertype for all topology optimization problems (continuum StiffnessTopOptProblem, HeatTransferTopOptProblem, and truss TrussProblem). Every concrete subtype provides a Ferrite.ConstraintHandler (ch), element metadata, and the accessors in this module (getdim, getdh, getncells, ...).
Structural problems
StiffnessTopOptProblem is an abstract type that a number of linear elasticity, quasi-static, topology optimization problems subtype.
TopOpt.TopOptProblems.StiffnessTopOptProblem — Type
abstract type StiffnessTopOptProblem{dim, T} <: AbstractTopOptProblem endAn abstract stiffness topology optimization problem. All subtypes must have the following fields:
ch: aFerrite.ConstraintHandlerstructmetadata: Metadata having various cell-node-dof relationships
The following types are all concrete subtypes of StiffnessTopOptProblem. PointLoadCantilever is a cantilever beam problem with a point load as shown below. HalfMBB is the half Messerschmitt-Bölkow-Blohm (MBB) beam problem commonly used in topology optimization literature. LBeam and TieBeam are the common L-beam and tie-beam test problem used in topology optimization literature. The PointLoadCantilever and HalfMBB problems can be either 2D or 3D depending on the type of the inputs to the constructor. If the number of elements and sizes of elements are 2-tuples, the problem constructed will be 2D. And if they are 3-tuples, the problem constructed will be 3D. For the 3D versions, the point loads are applied at approximately the mid-depth point. The TieBeam and LBeam problems are always 2D.
TopOpt.TopOptProblems.PointLoadCantilever — Type
PointLoadCantilever{dim, T, N, M} <: StiffnessTopOptProblem{dim, T}A cantilever beam problem with a point load applied at the free end. Available in 2D and 3D.
///**********************************///* *///* * |///* * |///********************************** vstruct PointLoadCantilever{dim, T, N, M} <: StiffnessTopOptProblem{dim, T} rect_grid::RectilinearGrid{dim, T, N, M} E::T ν::T ch::ConstraintHandler{<:DofHandler, T} force::T force_dof::Integer metadata::Metadataenddim: dimension of the problemT: number type for computations and coordinatesN: number of nodes in a cell of the gridM: number of faces in a cell of the gridrect_grid: a RectilinearGrid structE: Young's modulusν: Poisson's rationforce: force at the center right of the cantilever beam (positive is downward)force_dof: dof number at which the force is appliedch: aFerrite.ConstraintHandlerstructmetadata: Metadata having various cell-node-dof relationships
TopOpt.TopOptProblems.HalfMBB — Type
HalfMBB{dim, T, N, M} <: StiffnessTopOptProblem{dim, T}The half Messerschmitt-Bölkow-Blohm (MBB) beam problem with a point load at the top-left corner. Available in 2D and 3D.
| | vO*********************************O* *O* *O* *O********************************* Ostruct HalfMBB{dim, T, N, M} <: StiffnessTopOptProblem{dim, T} rect_grid::RectilinearGrid{dim, T, N, M} E::T ν::T ch::ConstraintHandler{<:DofHandler, T} force::T force_dof::Integer metadata::Metadataenddim: dimension of the problemT: number type for computations and coordinatesN: number of nodes in a cell of the gridM: number of faces in a cell of the gridrect_grid: a RectilinearGrid structE: Young's modulusν: Poisson's rationforce: force at the top left of half the MBB (positive is downward)force_dof: dof number at which the force is appliedch: aFerrite.ConstraintHandlerstructmetadata: Metadata having various cell-node-dof relationships
TopOpt.TopOptProblems.LBeam — Type
LBeam{T, N, M} <: StiffnessTopOptProblem{2, T}An L-shaped beam problem with a point load at the free end of the lower slab. Always 2D.
////////////............. .. .. . . . . ....................... .. . . . |................................. v forcestruct LBeam{T, N, M} <: StiffnessTopOptProblem{2, T} E::T ν::T ch::ConstraintHandler{<:DofHandler, T} force::T force_dof::Integer metadata::MetadataendT: number type for computations and coordinatesN: number of nodes in a cell of the gridM: number of faces in a cell of the gridE: Young's modulusν: Poisson's rationforce: force at the center right of the cantilever beam (positive is downward)force_dof: dof number at which the force is appliedch: aFerrite.ConstraintHandlerstructmetadata: Metadata having various cell-node-dof relationships
TopOpt.TopOptProblems.TieBeam — Type
TieBeam{T, N, M} <: StiffnessTopOptProblem{2, T}A tie-beam problem with distributed loading on specified elements. Always 2D.
1 OOO ... . . 4 . . 30 . . / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . <-/ . . <- 2 f / . 3 . <- / . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . <- ^^^ ||| 1 fstruct TieBeam{T, N, M} <: StiffnessTopOptProblem{2, T} E::T ν::T force::T ch::ConstraintHandler{<:DofHandler, T} metadata::MetadataendT: number type for computations and coordinatesN: number of nodes in a cell of the gridM: number of faces in a cell of the gridE: Young's modulusν: Poisson's rationforce: force at the center right of the cantilever beam (positive is downward)ch: aFerrite.ConstraintHandlerstructmetadata: Metadata having various cell-node-dof relationships
Reading INP Files
In TopOpt.jl, you can import a .inp file to an instance of the problem struct InpStiffness. This can be used to construct problems with arbitrary unstructured meshes, complex boundary condition domains and load specifications. The .inp file can be exported from a number of common finite element software such as: FreeCAD or ABAQUS.
TopOpt.TopOptProblems.InputOutput.INP.InpStiffness — Type
InpStiffness{dim, N, TF, TI, Tch, GO, TInds, TMeta} <: StiffnessTopOptProblem{dim, TF}A problem defined by an imported Abaqus .inp file, with arbitrary unstructured mesh, boundary conditions, and loads.
struct InpStiffness{dim, N, TF, TI, Tch <: ConstraintHandler, GO, TInds <: AbstractVector{TI}, TMeta<:Metadata} <: StiffnessTopOptProblem{dim, TF} inp_content::InpContent{dim, TF, N, TI} geom_order::Type{Val{GO}} ch::Tch metadata::TMetaenddim: dimension of the problemTF: number type for computations and coordinatesN: number of nodes in a cell of the gridinp_content: an instance ofParser.InpContentwhich stores all the information from the `.inpfile.geom_order: a field equal toVal{GO}whereGOis an integer representing the order of the finite elements. Linear elements have ageom_orderofVal{1}and quadratic elements have ageom_orderofVal{2}.metadata: Metadata having various cell-node-dof relationships
Heat transfer problems
HeatTransferTopOptProblem is an abstract type for heat-conduction topology optimization. Its concrete subtypes are HeatConductionProblem (rectilinear grid) and HeatTree (tree-shaped grid).
TopOpt.TopOptProblems.HeatTransferTopOptProblem — Type
abstract type HeatTransferTopOptProblem{dim, T} <: AbstractTopOptProblem endAn abstract heat transfer topology optimization problem for steady-state heat conduction.
Governing equation: -∇·(k(ρ)∇T) = q in Ω T = TD on ΓD (Dirichlet BC) k∇T·n = qN on ΓN (Neumann BC)
SIMP interpolation: k(ρ) = kmin + ρ^p (k0 - k_min) Heat source q is NOT penalized (external input, not a material property).
Mathematical note: For thermal compliance J = Q^T T, the gradient is: dJ/dxe = -Te^T Ke Te · dρe/dx_e This is the same form as structural compliance because Q doesn't depend on x.
See [1] §1.3 and §4.1 for thermal topology optimization, and [2] for SIMP-based heat conduction.
All subtypes must have:
ch: ConstraintHandler with temperature DOFs (1 DOF per node)metadata: Metadata with cell-node-dof relationshipsk: thermal conductivityheatfluxdict: surface heat flux on boundaries (Dict{String,Float64})
TopOpt.TopOptProblems.HeatConductionProblem — Type
struct HeatConductionProblem{dim, T, N, M} <: HeatTransferTopOptProblem{dim, T} T = T_left T = T_right ┌────────────────────────────────────────┐ │ │ │ │ │ k(ρ)∇²T = 0 │ │ (heat conduction) │ │ │ │ │ └────────────────────────────────────────┘ ▲ q (heat flux on boundary) │ ┌────────────────────────────────────────┐ │ ρ = design density (0 to 1) │ │ k(ρ) = penalized conductivity │ │ q = heat flux (NOT penalized) │ └────────────────────────────────────────┘A steady-state heat conduction problem with:
- Temperature BCs: T =
T_lefton left boundary, T =T_righton right boundary - Heat flux BCs: q on specified boundaries (facesets)
- Objective: minimize thermal compliance J = ∫ q·T dΓ
Constructor arguments:
nels: tuple of number of elements in each dimensionsizes: tuple of element sizesk: thermal conductivity (W/m·K)Tleft: temperature on left boundaryTright: temperature on right boundaryheatflux: Dict mapping faceset names to heat flux values (W/m²)- Positive values = heat entering the domain (heat source on boundary)
- Negative values = heat leaving the domain (heat sink on boundary)
cload: Dict mapping a node index to a concentrated heat source value (W). Positive values inject heat at that node; negative values remove heat. This is the point-source analogue of the distributedheatfluxand is the setup that produces the classic branching "conductivity tree" topology.Tfix: Dict mapping a node index to a prescribed temperature (K), applied as a point Dirichlet BC. Use it to pin the temperature at individual nodes (e.g. a point cold sink) instead of along a whole boundary face.
Note: Heat flux q and concentrated heat sources are NOT penalized in the assembly. Only conductivity k(ρ) is penalized.
TopOpt.TopOptProblems.HeatTree — Function
HeatTree(nels, sizes, k=1.0; celltype=:Linear, q=1.0)Convenience constructor for the classic heat-conduction topology-optimization benchmark ([1] §1.3, Fig. 1.4): distributed heat flux q enters through the full top edge, the full bottom edge is held at T = 0 (cold sink), and the left/right sides are insulated (free). Minimizing thermal compliance with this setup produces the branching "conductivity tree" — a root structure at the cold bottom that branches and tapers toward the hot top.
Arguments:
nels: tuple of number of elements per dimensionsizes: tuple of element sizesk: thermal conductivityq: heat flux on the top boundary (W/m², positive = into the domain)celltype: either:Linearor:Quadratic
Multi-load problems
TopOpt.TopOptProblems.MultiLoad — Type
MultiLoad(problem, scenarios)Multi-load-case wrapper that generates stochastic load scenarios for robust topology optimization. scenarios is the number of random load cases to draw. Use with MeanComplianceFun or BlockComplianceFun.
Usage example:
using Distributions, LinearAlgebra, TopOptf1 = RandomMagnitudeFun([0, -1], Uniform(0.5, 1.5))f2 = RandomMagnitudeFun(normalize([1, -1]), Uniform(0.5, 1.5))f3 = RandomMagnitudeFun(normalize([-1, -1]), Uniform(0.5, 1.5))base_problem = PointLoadCantilever((160, 40), (1.0, 1.0), 1.0, 0.3, 1.0)problem = MultiLoad(base_problem, [(160, 20) => f1, (80, 40) => f2, (120, 0) => f3], 10000)TopOpt.TopOptProblems.RandomMagnitudeFun — Type
RandomMagnitudeFunRandom load-magnitude sampler used inside MultiLoad.
Grids
Grid types are defined in TopOptProblems because a number of topology optimization problems share the same underlying grid but apply the loads and boundary conditions at different locations. For example, the PointLoadCantilever and HalfMBB problems use the same rectilinear grid type, RectilinearGrid, under the hood. The LBeam problem uses the LGrid function under the hood to construct an L-shaped Ferrite.Grid. New problem types can be defined using the same grids but different loads or boundary conditions.
TopOpt.TopOptProblems.RectilinearGrid — Type
struct RectilinearGrid{dim, T, N, M, TG<:Ferrite.Grid{dim, <:Ferrite.Cell{dim,N,M}, T}} <: AbstractGrid{dim, T}
grid::TG
nels::NTuple{dim, Int}
sizes::NTuple{dim, T}
corners::NTuple{2, Vec{dim, T}}
endA type that represents a rectilinear grid with corner points corners.
dim: dimension of the problemT: number type for computations and coordinatesN: number of nodes in a cell of the gridM: number of faces in a cell of the gridgrid: a Ferrite.Grid structnels: number of elements in every dimensionsizes: dimensions of each rectilinear cellcorners: 2 corner points of the rectilinear grid
TopOpt.TopOptProblems.LGrid — Function
LGrid(::Type{T}=Float64; celltype=:Linear, length = 100, height = 100, upperslab = 50, lowerslab = 50) where {T}
LGrid(nel1::NTuple{2,Int}, nel2::NTuple{2,Int}, LL::Vec{2,T}, UR::Vec{2,T}, MR::Vec{2,T}; celltype=:Linear) where {T}Constructs a Ferrite.Grid that represents the following L-shaped grid.
upperslab UR ............ . . . . . . height . . MR . ...................... . . . . lowerslab . . ................................. LL lengthcelltype is either :Linear or :Quadratic to determine the order of the geometric and field basis functions and element type. Only isoparametric elements are supported for now.
Examples:
LGrid(upperslab = 30, lowerslab = 70)LGrid((2, 4), (2, 2), Vec{2,Float64}((0.0,0.0)), Vec{2,Float64}((2.0, 4.0)), Vec{2,Float64}((4.0, 2.0)))TopOpt.TopOptProblems.TieBeamGrid — Function
TieBeamGrid(::Type{T}=Float64; celltype=:Linear, refine=1)Construct the TieBeam grid — the standard 2D tie-beam benchmark mesh. refine controls the mesh refinement (a value of 1 gives the standard literature problem), and celltype selects :Linear or :Quadratic elements.
Problem accessors
The following accessors are available on every problem type (structural and heat transfer):
TopOpt.TopOptProblems.getdim — Function
getdim(problem::StiffnessTopOptProblem)Return the spatial dimension of the problem.
TopOpt.TopOptProblems.floattype — Function
floattype(problem::StiffnessTopOptProblem)Return the number type used for the problem's coordinates and computations.
TopOpt.TopOptProblems.getdh — Function
getdh(problem::StiffnessTopOptProblem)Return the Ferrite.DofHandler of the problem.
TopOpt.TopOptProblems.getk — Function
getk(problem::HeatTransferTopOptProblem)Return the thermal conductivity of a heat transfer problem.
TopOpt.TopOptProblems.getcloaddict — Function
getcloaddict(problem::StiffnessTopOptProblem)Return the concentrated-load dictionary (node index => load vector).
getcloaddict(TrussProblem{xdim,T})Get a dict (node_idx => force vector) for concentrated loads
TopOpt.TopOptProblems.getfacesets — Function
getfacesets(problem::StiffnessTopOptProblem)Return the face sets of the problem's grid.
TopOpt.TopOptProblems.getpressuredict — Function
getpressuredict(problem::StiffnessTopOptProblem)Return the pressure-load dictionary (faceset name => pressure value).
TopOpt.TopOptProblems.getheatfluxdict — Function
getheatfluxdict(problem::HeatTransferTopOptProblem)Return the surface heat-flux dictionary (faceset name => heat flux value).
Material accessors
TopOpt.TopOptProblems.YoungsModulus — Function
YoungsModulus(p::StiffnessTopOptProblem)Return the Young's modulus of a structural topology optimization problem.
TopOpt.TopOptProblems.PoissonRatio — Function
PoissonRatio(p::StiffnessTopOptProblem)Return the Poisson's ratio of a structural topology optimization problem.
Mesh output
TopOpt.TopOptProblems.InputOutput.VTK.save_mesh — Function
save_mesh(problem, topology, filename)Save the design topology as a VTK (.vtu) mesh file for visualization in ParaView or similar. topology is the density vector.
save_mesh(filename, problem, vars)Save the design vars (a density vector) as a VTK (.vtu) mesh file.
save_mesh(filename, problem::HeatTransferTopOptProblem, vars, temperature)Save the design topology and the nodal temperature field (e.g. from TemperatureFun) as a VTK (.vtu) mesh file.
Finite element backend
Currently, TopOpt uses Ferrite.jl for FEA-related modeling. This means that all the problems above are described in the language and types of Ferrite.
Matrices and vectors
TopOpt.TopOptProblems.assemble — Function
assemble(problem, elementinfo, vars, penalty, xmin)Assemble the global stiffness matrix and load vector of problem from the element information and design variables, returning a GlobalFEAInfo.
TopOpt.TopOptProblems.assemble_f! — Function
assemble_f!(f, problem, elementinfo, ρ, penalty, xmin)Assemble the global load vector f in place from the element load vectors and concentrated/distributed loads.
ElementFEAInfo
TopOpt.TopOptProblems.ElementFEAInfo — Type
struct ElementFEAInfo{dim, T}
Kes::AbstractVector{<:AbstractMatrix{T}}
fes::AbstractVector{<:AbstractVector{T}}
fixedload::AbstractVector{T}
cellvolumes::AbstractVector{T}
cellvalues::CellValues{dim, T}
facevalues::FacetValues{<:Any, T}
metadata::Metadata
cells
endAn instance of the ElementFEAInfo type stores element information such as:
Kes: the element stiffness matrices,fes: the element load vectors,cellvolumes: the element volumes,cellvaluesandfacevalues: twoFerritetypes that facilitate cell and face iteration and queries.metadata: that stores degree of freedom (dof) to node mapping, dof to cell mapping, etc.cells: the cell connectivities.
GlobalFEAInfo
TopOpt.TopOptProblems.GlobalFEAInfo — Type
struct GlobalFEAInfo{T, TK<:AbstractMatrix{T}, Tf<:AbstractVector{T}, Tchol, Tqr}
K::TK
f::Tf
cholK::Tchol
qrK::Tqr
endAn instance of GlobalFEAInfo hosts the global stiffness matrix K, the load vector f and the cholesky decomposition of the K, cholK.