Truss topology optimization finds the optimal layout of bar elements (trusses) that minimizes compliance (maximizes stiffness) subject to a volume constraint. Unlike continuum topology optimization which uses density-based methods, truss optimization works with discrete bar elements whose cross-sectional areas are the design variables.
This tutorial demonstrates truss optimization using a JSON input file. The truss optimization framework supports:
Precompiling packages...
2333.3 ms ✓ QuartoNotebookWorkerTablesExt (serial)
1 dependency successfully precompiled in 3 seconds
Precompiling packages...
1163.5 ms ✓ QuartoNotebookWorkerJSONExt (serial)
1 dependency successfully precompiled in 2 seconds
Precompiling packages...
1148.1 ms ✓ QuartoNotebookWorkerJSON3Ext (serial)
1 dependency successfully precompiled in 1 seconds
Precompiling packages...
1075.7 ms ✓ QuartoNotebookWorkerLaTeXStringsExt (serial)
1 dependency successfully precompiled in 1 seconds
Precompiling packages...
6581.7 ms ✓ QuartoNotebookWorkerMakieExt (serial)
1 dependency successfully precompiled in 7 seconds
display_app (generic function with 1 method)
WGLMakie.activate!(; resize_to=:parent) selects the browser renderer and fills the Quarto output column. Bonito.Page(exportable=true, offline=true) embeds the assets needed by visualize(...; static=true) in the Quarto output, so the visualization does not require a running Julia process.
Load the truss problem from JSON
Truss problems are defined by node coordinates, element connectivity, material properties, cross-sectional areas, boundary conditions, and load cases. These can be loaded from a JSON file:
ndim =2node_points, elements, mats, crosssecs, fixities, load_cases =load_truss_json("path/to/truss_problem.json")nnodes =length(node_points)ncells =length(elements)loads = load_cases["1"] # first load case
The JSON file contains:
node_points: coordinates of all nodes
elements: connectivity (node indices for each bar)
mats: Young’s modulus for each element
crosssecs: initial cross-sectional areas
fixities: fixed degrees of freedom at nodes
load_cases: named load vectors
Create the TrussProblem
problem =TrussProblem( node_points, elements, loads, fixities, mats, crosssecs)
The default celltype=:Linear specifies linear truss elements (axial deformation only). The problem object assembles the global stiffness matrix and applies boundary conditions.
Define design variables and constraints
xmin =0.0001# minimum cross-sectional area (prevents singularity)x0 =fill(1.0, ncells) # initial design (uniform bars)p =4.0# power-law penalty exponentV =0.5# maximum volume fraction (50% of initial material)
The penalty exponent p=4.0 drives the design toward discrete 0/1 solutions (void bars or full-size bars).
The visualization shows the optimized truss layout — bars with larger cross- sectional areas carry more load, while inefficient bars are removed (area → 0).