A package for binary and continuous, single and multi-material, truss and continuum, 2D and 3D topology optimization on unstructured meshes using automatic differentiation in Julia.
I was wondering if someone could help me out with this. I wish to obtain iteration wise samples of the 3D sample i am optimizing. Let;s say if it takes 100 iterations to converge to the optimized figure, i want all the 3D sample figures at every iteration.
I checked the github but i believe this functionality is not there. Below is my code, could you tell how do i do this?
using TopOpt
using Makie, GeometryBasics, GLMakie # For visualization
using Images
using FileIO
Material properties
E = 1.0 # Young's modulus
v = 0.3 # Poisson's ratio
Force applied
f = -1.0; # Downward force magnitude
Number of elements in each dimension
nels = (30, 10, 10) # Adjust based on desired resolution and computational resources
Define the problem, assuming a cantilever fixed at one end with a point load at the other
problem = PointLoadCantilever(Val{:Linear}, nels, (1.0, 1.0, 1.0), E, v, f)
Optimization settings
V = 0.3 # Volume fraction
xmin = 1e-6 # Minimum density
rmin = 2.0 # Density filter radius
function optimization_loop()
r = optimize(model, alg, x0; options)
push!(iteration_figures, GeometryBasics.Mesh(problem, r.minimizer))
println("Iteration $(length(iteration_figures)): Objective value = $(obj(r.minimizer))")
return r
end
Greetings,
I was wondering if someone could help me out with this. I wish to obtain iteration wise samples of the 3D sample i am optimizing. Let;s say if it takes 100 iterations to converge to the optimized figure, i want all the 3D sample figures at every iteration.
I checked the github but i believe this functionality is not there. Below is my code, could you tell how do i do this?
using TopOpt using Makie, GeometryBasics, GLMakie # For visualization using Images using FileIO
Material properties
E = 1.0 # Young's modulus v = 0.3 # Poisson's ratio
Force applied
f = -1.0; # Downward force magnitude
Number of elements in each dimension
nels = (30, 10, 10) # Adjust based on desired resolution and computational resources
Define the problem, assuming a cantilever fixed at one end with a point load at the other
problem = PointLoadCantilever(Val{:Linear}, nels, (1.0, 1.0, 1.0), E, v, f)
Optimization settings
V = 0.3 # Volume fraction xmin = 1e-6 # Minimum density rmin = 2.0 # Density filter radius
Penalty for intermediate density values
penalty = TopOpt.PowerPenalty(3.0)
Finite element solver setup
solver = FEASolver(Direct, problem; xmin=xmin, penalty=penalty)
Compliance objective
comp = TopOpt.Compliance(solver) filter = DensityFilter(solver; rmin=rmin) obj = x -> comp(filter(PseudoDensities(x)))
Volume constraint
volfrac = TopOpt.Volume(solver) constr = x -> volfrac(filter(PseudoDensities(x))) - V
Initial design (volume fraction as initial guess for all elements)
x0 = fill(V, length(solver.vars))
Define optimization model
model = Model(obj) addvar!(model, zeros(length(x0)), ones(length(x0))) add_ineq_constraint!(model, constr)
Optimization algorithm
alg = MMA87() convcriteria = Nonconvex.KKTCriteria() options = MMAOptions(; maxiter=3000, tol=Nonconvex.Tolerance(; x=1e-3, f=1e-3, kkt=0.001), convcriteria)
Create a list to store iteration figures
iteration_figures = []
Optimization loop to collect iteration figures
function optimization_loop() r = optimize(model, alg, x0; options) push!(iteration_figures, GeometryBasics.Mesh(problem, r.minimizer)) println("Iteration $(length(iteration_figures)): Objective value = $(obj(r.minimizer))") return r end