BESO example: HalfMBB Beam

Tip

This example is also available as a Jupyter notebook: beso.ipynb

Commented Program

What follows is a program spliced with comments. The full program, without comments, can be found in the next section.

using TopOpt

Define the problem

E = 1.0 # Young’s modulus
v = 0.3 # Poisson’s ratio
f = 1.0; # downward force

nels = (160, 40)
problem = HalfMBB(Val{:Linear}, nels, (1.0, 1.0), E, v, f)

Define the FEA Solver and penalty functions

solver = FEASolver(Direct, problem; xmin=0.01, penalty=TopOpt.PowerPenalty(3.0))

Define the compliance objective function and volume fraction constraint

comp = Compliance(solver)
volfrac = Volume(solver)
sensfilter = SensFilter(solver; rmin=4.0)
beso = BESO(comp, volfrac, 0.5, sensfilter)

Run optimization

x0 = ones(length(solver.vars))
result = beso(x0)
TopOpt.Algorithms.BESOResult{Float64, Vector{Float64}}([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 347.57452308620924, 9.602487566045443e-5, true, 117)

(Optional) Visualize the result using Makie.jl

Need to run using Pkg; Pkg.add("Makie") first and either Pkg.add("CairoMakie") or Pkg.add("GLMakie")

using Makie
using CairoMakie

alternatively, using GLMakie

fig = visualize(problem; topology=result.topology)
Makie.display(fig)
CairoMakie.Screen{IMAGE}

Plain Program

Below follows a version of the program without any comments. The file is also available here: beso.jl

using TopOpt

E = 1.0 # Young’s modulus
v = 0.3 # Poisson’s ratio
f = 1.0; # downward force

nels = (160, 40)
problem = HalfMBB(Val{:Linear}, nels, (1.0, 1.0), E, v, f)

solver = FEASolver(Direct, problem; xmin=0.01, penalty=TopOpt.PowerPenalty(3.0))

comp = Compliance(solver)
volfrac = Volume(solver)
sensfilter = SensFilter(solver; rmin=4.0)
beso = BESO(comp, volfrac, 0.5, sensfilter)

x0 = ones(length(solver.vars))
result = beso(x0)

using Makie
using CairoMakie

fig = visualize(problem; topology=result.topology)
Makie.display(fig)

# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl

This page was generated using Literate.jl.