Skip to content

Commit

Permalink
Remove Requires and implement a Makie extension instead (#181)
Browse files Browse the repository at this point in the history
* remove Requires and add a Makie extension

* test the plotting code in scripts using CairoMakie as a backend

* fix deps

* result.topology -> result.minimizer

* savefig -> save

* fix typo

* add GeometryBasics to docs Project.toml

* throw a more informative error in the default visualize method
  • Loading branch information
mohamed82008 authored Oct 8, 2024
1 parent 33180ca commit 7a67ded
Show file tree
Hide file tree
Showing 43 changed files with 477 additions and 457 deletions.
10 changes: 7 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Preconditioners = "af69fa37-3177-5a40-98ee-561f696e4fcd"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down Expand Up @@ -70,7 +69,6 @@ NonconvexSemidefinite = "0.1.7"
Parameters = "0.12"
Preconditioners = "0.3, 0.4, 0.5, 0.6"
Reexport = "1"
Requires = "1.1"
Revise = "3"
Setfield = "0.7, 0.8, 1"
StaticArrays = "1"
Expand All @@ -81,4 +79,10 @@ TimerOutputs = "0.5"
VTKDataTypes = "0.1"
WriteVTK = "1.9"
Zygote = "0.6"
julia = "1.5, 1.6"
julia = "1.9"

[weakdeps]
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"

[extensions]
TopOptMakieExt = "Makie"
3 changes: 3 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DocumenterCitations = "daee34ce-89f3-4625-b898-19384cb65244"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Nonconvex = "01bcebdf-4d21-426d-b5c4-6132c1619978"
NonconvexTOBS = "6c0b5230-d4c9-466e-bfd4-b31e6272ab65"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Expand Down
13 changes: 6 additions & 7 deletions docs/src/literate/beso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ x0 = ones(length(solver.vars))
result = beso(x0)

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(problem; topology = result.topology)
# Makie.display(fig)
# ```
# 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)

#md # ## [Plain Program](@id beso-plain-program)
#md #
Expand Down
22 changes: 13 additions & 9 deletions docs/src/literate/csimp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,19 @@ end
@show constr(x)

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(problem; topology = x, default_exagg_scale = 0.07,
# scale_range = 10.0, vector_linewidth = 3, vector_arrowsize = 0.5,
# )
# Makie.display(fig)
# ```
# 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=x,
default_exagg_scale=0.07,
scale_range=10.0,
vector_linewidth=3,
vector_arrowsize=0.5,
)
Makie.display(fig)

#md # ## [Plain Program](@id csimp-plain-program)
#md #
Expand Down
13 changes: 6 additions & 7 deletions docs/src/literate/geso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ x0 = ones(length(solver.vars))
result = geso(x0)

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(problem; topology = result.topology)
# Makie.display(fig)
# ```
# 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)

#md # ## [Plain Program](@id geso-plain-program)
#md #
Expand Down
13 changes: 6 additions & 7 deletions docs/src/literate/global_stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@ r = optimize(model, alg, x0; options)
@show constr(r.minimizer)

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(problem; topology = r.minimizer)
# Makie.display(fig)
# ```
# 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=r.minimizer)
Makie.display(fig)

#md # ## [Plain Program](@id global-stress-plain-program)
#md #
Expand Down
23 changes: 13 additions & 10 deletions docs/src/literate/local_stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ maximum(stress(filter(PseudoDensities(x0))))
maximum(stress(filter(PseudoDensities(x))))

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(
# problem; topology = r.minimizer, default_exagg_scale = 0.07,
# scale_range = 10.0, vector_linewidth = 3, vector_arrowsize = 0.5,
# )
# Makie.display(fig)
# ```
# 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=r.minimizer,
default_exagg_scale=0.07,
scale_range=10.0,
vector_linewidth=3,
vector_arrowsize=0.5,
)
Makie.display(fig)

#md # ## [Plain Program](@id local-stress-plain-program)
#md #
Expand Down
32 changes: 16 additions & 16 deletions docs/src/literate/simp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ r = optimize(model, alg, x0; options)
@show obj(r.minimizer)

# ### (Optional) Visualize the result using Makie.jl
# Need to run `using Pkg; Pkg.add(["Makie", "GLMakie"])` first
# ```julia
# using Makie, GLMakie
# using TopOpt.TopOptProblems.Visualization: visualize
# fig = visualize(
# problem; topology = r.minimizer,
# default_exagg_scale = 0.07, scale_range = 10.0,
# vector_linewidth = 3, vector_arrowsize = 0.5,
# )
# Makie.display(fig)
# ```
# 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=r.minimizer,
default_exagg_scale=0.07,
scale_range=10.0,
vector_linewidth=3,
vector_arrowsize=0.5,
)
Makie.display(fig)

# or convert it to a Mesh
# Need to run `using Pkg; Pkg.add(GeometryBasics)` first
# ```julia
# import Makie, GeometryBasics
# result_mesh = GeometryBasics.Mesh(problem, r.minimizer);
# Makie.mesh(result_mesh)
# ```
using Makie, GeometryBasics
result_mesh = GeometryBasics.Mesh(problem, r.minimizer);
Makie.mesh(result_mesh)

#md # ## [Plain Program](@id simp-plain-program)
#md #
Expand Down
Loading

0 comments on commit 7a67ded

Please sign in to comment.