GESO example: HalfMBB Beam
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}}([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], 383.3165772954196, 0.0008937683346101372, true, 126)
(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: 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)
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.