Skip to content

Commit

Permalink
Improve buckling example (#114)
Browse files Browse the repository at this point in the history
* improve buckling example

* fix typo

* bump version

* minor changes

* tighten tolerance
  • Loading branch information
mohamed82008 authored May 14, 2022
1 parent c34feef commit 5630f41
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TopOpt"
uuid = "53a1e1a5-51bb-58a9-8a02-02056cc81109"
authors = ["mohamed82008 <[email protected]>", "yijiangh <[email protected]>"]
version = "0.5.3"
version = "0.5.4"

[deps]
AbstractDifferentiation = "c29ec348-61ec-40c8-8164-b8c60e9d9f3d"
Expand Down Expand Up @@ -62,7 +62,7 @@ NearestNeighbors = "0.4"
Nonconvex = "1"
NonconvexMMA = "0.1"
NonconvexPercival = "0.1"
NonconvexSemidefinite = "0.1"
NonconvexSemidefinite = "0.1.7"
Parameters = "0.12"
Preconditioners = "0.3, 0.4, 0.5"
Reexport = "1"
Expand Down
45 changes: 34 additions & 11 deletions test/truss_topopt_problems/test_buckling_optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gm_ins_dir = joinpath(@__DIR__, "instances", "ground_meshes");
file_name = "tim_$(problem_dim).json"
problem_file = joinpath(gm_ins_dir, file_name)

mats = TrussFEAMaterial(10.0, 0.3)
mats = TrussFEAMaterial(1.0, 0.3)
crossecs = TrussFEACrossSec(800.0)

node_points, elements, _, _, fixities, load_cases = load_truss_json(problem_file)
Expand All @@ -101,9 +101,9 @@ gm_ins_dir = joinpath(@__DIR__, "instances", "ground_meshes");
)

xmin = 0.0001 # minimum density
p = 4.0 # penalty
p = 1.0 # penalty
V = 0.5 # maximum volume fraction
x0 = fill(V, ncells) # initial design
x0 = fill(1.0, ncells) # initial design

solver = FEASolver(Direct, problem)
ch = problem.ch
Expand Down Expand Up @@ -149,25 +149,48 @@ gm_ins_dir = joinpath(@__DIR__, "instances", "ground_meshes");

# * Before optimization, check initial design stability
@test isfinite(logdet(cholesky(buckling_matrix_constr(x0))))
@test vol_constr(x0) <= 0
@test vol_constr(x0) == 0.5

m = Model(obj)
addvar!(m, zeros(length(x0)), ones(length(x0)))
Nonconvex.add_ineq_constraint!(m, vol_constr)
Nonconvex.add_sd_constraint!(m, buckling_matrix_constr)

Nonconvex.NonconvexCore.show_residuals[] = false
alg = IpoptAlg()
options = IpoptOptions(; max_iter=200)
r1 = Nonconvex.optimize(m, alg, x0; options=options)
@test vol_constr(r1.minimizer) < 1e-7

Nonconvex.add_sd_constraint!(m, buckling_matrix_constr)
alg = SDPBarrierAlg(; sub_alg=IpoptAlg())
options = SDPBarrierOptions(; sub_options=IpoptOptions(; max_iter=200))
r = Nonconvex.optimize(m, alg, x0; options=options)
# println("$(r.convstate)")
options = SDPBarrierOptions(; sub_options=IpoptOptions(; max_iter=200), keep_all = true)
r2 = Nonconvex.optimize(m, alg, x0; options=options)
@test vol_constr(r2.minimizer) < 1e-7

# * check result stability
@test isfinite(logdet(cholesky(buckling_matrix_constr(r.minimizer))))
S0 = buckling_matrix_constr(x0)
S1 = buckling_matrix_constr(r1.minimizer)
S2 = buckling_matrix_constr(r2.minimizer)
ev0 = eigen(S0).values
ev1 = eigen(S1).values
ev2 = eigen(S2).values

@test isfinite(logdet(cholesky(S0)))
@test minimum(ev0) 0.34 rtol = 0.01
@test maximum(ev0) 4204 rtol = 0.01

@test_throws PosDefException cholesky(S1)

@test isfinite(logdet(cholesky(S2)))
@test minimum(ev2) 0.001 atol = 0.002
@test maximum(ev2) 3250 rtol = 0.001

# using Makie
# import GLMakie
# using TopOpt.TrussTopOptProblems.TrussVisualization: visualize
# fig = visualize(problem; topology=r.minimizer)

# fig = visualize(problem; topology=x0)
# Makie.display(fig)

# fig = visualize(problem; topology=r2.minimizer)
# Makie.display(fig)
end

2 comments on commit 5630f41

@mohamed82008
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60240

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.4 -m "<description of version>" 5630f41376b5797fb469e5f63246a79a29dd1c63
git push origin v0.5.4

Please sign in to comment.