GESO example: HalfMBB Beam

Tip

This example is also available as a Jupyter notebook: geso.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)
geso = GESO(comp, volfrac, 0.5, sensfilter)

Run optimization

x0 = ones(length(solver.vars))
result = geso(x0)
TopOpt.Algorithms.GESOResult{Float64, Vector{Float64}, Float64, Float64, Bool, Int64}([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], 643.8435206612245, 0.0007198221999027014, true, 29)

(Optional) Visualize the result using Makie.jl

Need to run using Pkg; Pkg.add(["Makie", "GLMakie"]) first

using Makie, GLMakie
using TopOpt.TopOptProblems.Visualization: visualize
fig = visualize(problem; topology = result.topology)
Makie.display(fig)

Plain Program

Below follows a version of the program without any comments. The file is also available here: geso.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)
geso = GESO(comp, volfrac, 0.5, sensfilter)

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

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

This page was generated using Literate.jl.