Skip to content

Commit

Permalink
Format .jl files
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed82008 authored Nov 18, 2021
1 parent 0359cb5 commit b3ec468
Show file tree
Hide file tree
Showing 107 changed files with 3,500 additions and 1,953 deletions.
1 change: 1 addition & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions docs/generate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for example in readdir(EXAMPLE_DIR)
Literate.markdown(input, GENERATED_DIR, postprocess = mdpost)
Literate.notebook(input, GENERATED_DIR, execute = true)
elseif any(endswith.(example, [".png", ".jpg", ".gif"]))
cp(joinpath(EXAMPLE_DIR, example), joinpath(GENERATED_DIR, example); force=true)
cp(joinpath(EXAMPLE_DIR, example), joinpath(GENERATED_DIR, example); force = true)
else
@warn "ignoring $example"
end
Expand All @@ -22,4 +22,4 @@ end
# remove any .vtu files in the generated dir (should not be deployed)
cd(GENERATED_DIR) do
foreach(file -> endswith(file, ".vtu") && rm(file), readdir())
end
end
27 changes: 8 additions & 19 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,22 @@ using DocumenterCitations
# Generate examples
include("generate.jl")

GENERATED_EXAMPLES = [joinpath("examples", f) for f in (
"simp.md",
"beso.md",
"geso.md",
"csimp.md",
"global_stress.md",
)]
GENERATED_EXAMPLES = [
joinpath("examples", f) for
f in ("simp.md", "beso.md", "geso.md", "csimp.md", "global_stress.md")
]

bib = CitationBibliography(joinpath(@__DIR__, "biblio", "ref.bib"))
makedocs(
bib,
sitename = "TopOpt.jl",
format = Documenter.HTML(
prettyurls = get(ENV, "CI", nothing) == "true"
),
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
# doctest = false,
pages = [
"Home" => "index.md",
"Examples" => GENERATED_EXAMPLES,
"API Reference" => [
"reference/TopOptProblems.md",
"reference/Algorithms.md",
],
"Bibliography" => "bibliography.md"
"API Reference" => ["reference/TopOptProblems.md", "reference/Algorithms.md"],
"Bibliography" => "bibliography.md",
],
)

Expand All @@ -40,8 +32,5 @@ makedocs(
# end

if get(ENV, "CI", nothing) == "true"
deploydocs(
repo = "github.com/JuliaTopOpt/TopOpt.jl.git",
push_preview=true,
)
deploydocs(repo = "github.com/JuliaTopOpt/TopOpt.jl.git", push_preview = true)
end
2 changes: 1 addition & 1 deletion docs/src/literate/beso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ result = beso(x0)
#md #
#md # ```julia
#md # @__CODE__
#md # ```
#md # ```
39 changes: 16 additions & 23 deletions docs/src/literate/csimp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ v = 0.3 # Poisson’s ratio
f = 1.0 # downward force

problems = Any[
PointLoadCantilever(Val{:Linear}, (60, 20, 20), (1.0, 1.0, 1.0), E, v, f),
PointLoadCantilever(Val{:Linear}, (160, 40), (1.0, 1.0), E, v, f),
HalfMBB(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
LBeam(Val{:Linear}, Float64, force = f),
TieBeam(Val{:Quadratic}, Float64)
]
problem_names = [
"3d cantilever beam",
"cantilever beam",
"half MBB beam",
"L-beam",
"tie-beam",
]
PointLoadCantilever(Val{:Linear}, (60, 20, 20), (1.0, 1.0, 1.0), E, v, f),
PointLoadCantilever(Val{:Linear}, (160, 40), (1.0, 1.0), E, v, f),
HalfMBB(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
LBeam(Val{:Linear}, Float64, force = f),
TieBeam(Val{:Quadratic}, Float64),
]
problem_names =
["3d cantilever beam", "cantilever beam", "half MBB beam", "L-beam", "tie-beam"]

i = 2
println(problem_names[i])
Expand All @@ -47,7 +42,7 @@ penalty = TopOpt.PowerPenalty(1.0)
pcont = Continuation(penalty, steps = steps, xmin = xmin, pmax = 5.0)

# NOTE: non-convexity + computational error lead to different solutions that satisfy the KKT tolerance
mma_options = options = MMAOptions(maxiter=1000)
mma_options = options = MMAOptions(maxiter = 1000)
maxtol = 0.01 # maximum tolerance
mintol = 0.0001 # minimum tolerance
b = log(mintol / maxtol) / steps
Expand All @@ -58,9 +53,9 @@ mma_options_gen = TopOpt.MMAOptionsGen(
ftol_gen = ExponentialContinuation(a, b, 0.0, steps + 1, mintol),
)
csimp_options = TopOpt.CSIMPOptions(
steps = steps,
options_gen = mma_options_gen,
p_gen = pcont,
steps = steps,
options_gen = mma_options_gen,
p_gen = pcont,
reuse = reuse,
)

Expand All @@ -82,14 +77,12 @@ constr = x -> volfrac(filter(x)) - V

# ### Define subproblem optimizer
x0 = fill(V, length(solver.vars))
optimizer = Optimizer(
obj, constr, x0, MMA87(),
options = mma_options, convcriteria = convcriteria,
)
optimizer =
Optimizer(obj, constr, x0, MMA87(), options = mma_options, convcriteria = convcriteria)

# ### Define continuation SIMP optimizer
simp = SIMP(optimizer, solver, penalty.p)
cont_simp = ContinuationSIMP(simp, steps, csimp_options)
cont_simp = ContinuationSIMP(simp, steps, csimp_options)

# ### Solve
result = cont_simp(x0)
Expand All @@ -116,4 +109,4 @@ result = cont_simp(x0)
#md #
#md # ```julia
#md # @__CODE__
#md # ```
#md # ```
2 changes: 1 addition & 1 deletion docs/src/literate/geso.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ result = geso(x0)
#md #
#md # ```julia
#md # @__CODE__
#md # ```
#md # ```
27 changes: 8 additions & 19 deletions docs/src/literate/global_stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ f = 1.0 # downward force
rmin = 3.0 # filter radius

problems = Any[
PointLoadCantilever(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
HalfMBB(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
]
problem_names = [
"Cantilever beam",
"Half MBB beam",
"L-beam",
"Tie-beam",
PointLoadCantilever(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
HalfMBB(Val{:Linear}, (60, 20), (1.0, 1.0), E, v, f),
]
problem_names = ["Cantilever beam", "Half MBB beam", "L-beam", "Tie-beam"]

i = 1
println(problem_names[i])
Expand All @@ -40,9 +35,7 @@ convcriteria = Nonconvex.KKTCriteria()
penalty = TopOpt.PowerPenalty(1.0)

# ### Define a finite element solver
solver = FEASolver(
Direct, problem, xmin = xmin, penalty = penalty,
)
solver = FEASolver(Direct, problem, xmin = xmin, penalty = penalty)

# ### Define **stress** objective
# Notice that gradient is derived automatically by automatic differentiation (Zygote.jl)!
Expand All @@ -56,16 +49,12 @@ volfrac = TopOpt.Volume(problem, solver)

obj = x -> volfrac(filter(x))
constr = x -> norm(stress(filter(x)), 5) - 1.0
options = MMAOptions(
maxiter=2000, tol = Nonconvex.Tolerance(kkt = 1e-4),
)
options = MMAOptions(maxiter = 2000, tol = Nonconvex.Tolerance(kkt = 1e-4))

# ### Define subproblem optimizer
x0 = fill(1.0, length(solver.vars))
optimizer = Optimizer(
obj, constr, x0, MMA87(),
options = options, convcriteria = convcriteria,
)
optimizer =
Optimizer(obj, constr, x0, MMA87(), options = options, convcriteria = convcriteria)

# ### Define continuation SIMP optimizer
simp = SIMP(optimizer, solver, 3.0)
Expand All @@ -92,4 +81,4 @@ result = simp(x0)
#md #
#md # ```julia
#md # @__CODE__
#md # ```
#md # ```
16 changes: 4 additions & 12 deletions docs/src/literate/local_stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ xmin = 0.0001 # minimum density
steps = 40 # maximum number of penalty steps, delta_p0 = 0.1

# ### Continuation SIMP
x0 = fill(1.0, 160*40) # initial design
x0 = fill(1.0, 160 * 40) # initial design
x = copy(x0)
for p in [1.0, 2.0, 3.0]
global penalty, stress, filter, result, stress, x
penalty = TopOpt.PowerPenalty(p)
solver = FEASolver(
Direct, problem, xmin = xmin, penalty = penalty,
)
solver = FEASolver(Direct, problem, xmin = xmin, penalty = penalty)
stress = TopOpt.MicroVonMisesStress(solver)
filter = DensityFilter(solver, rmin = rmin)
volfrac = TopOpt.Volume(problem, solver)
Expand All @@ -31,17 +29,11 @@ for p in [1.0, 2.0, 3.0]
thr = 10 # stress threshold
constr = x -> begin
s = stress(filter(x))
vcat(
(s .- thr) / 100,
logsumexp(s) - log(length(s)) - thr,
)
vcat((s .- thr) / 100, logsumexp(s) - log(length(s)) - thr)
end
alg = PercivalAlg()
options = PercivalOptions()
optimizer = Optimizer(
obj, constr, x, alg,
options = options,
)
optimizer = Optimizer(obj, constr, x, alg, options = options)
simp = SIMP(optimizer, solver, p)
result = simp(x)
x = result.topology
Expand Down
22 changes: 10 additions & 12 deletions docs/src/literate/simp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ E = 1.0 # Young’s modulus
v = 0.3 # Poisson’s ratio
f = 1.0; # downward force

nels = (30, 10, 10)
nels = (30, 10, 10)
problem = PointLoadCantilever(Val{:Linear}, nels, (1.0, 1.0, 1.0), E, v, f);

# See also the detailed API of `PointLoadCantilever`:
Expand All @@ -31,9 +31,7 @@ rmin = 2.0; # density filter radius

# ### Define a finite element solver
penalty = TopOpt.PowerPenalty(3.0)
solver = FEASolver(
Direct, problem, xmin = xmin, penalty = penalty,
)
solver = FEASolver(Direct, problem, xmin = xmin, penalty = penalty)

# ### Define compliance objective
comp = TopOpt.Compliance(problem, solver)
Expand All @@ -47,15 +45,15 @@ constr = x -> volfrac(filter(x)) - V
# You can enable the iteration printouts with `Nonconvex.show_residuals[] = true`

# ### Define subproblem optimizer
mma_options = options = MMAOptions(
maxiter = 3000, tol = Nonconvex.Tolerance(x = 1e-3, f = 1e-3, kkt = 0.001),
)
mma_options =
options = MMAOptions(
maxiter = 3000,
tol = Nonconvex.Tolerance(x = 1e-3, f = 1e-3, kkt = 0.001),
)
convcriteria = Nonconvex.KKTCriteria()
x0 = fill(V, length(solver.vars))
optimizer = Optimizer(
obj, constr, x0, MMA87(),
options = mma_options, convcriteria = convcriteria,
)
optimizer =
Optimizer(obj, constr, x0, MMA87(), options = mma_options, convcriteria = convcriteria)

# ### Define SIMP optimizer
simp = SIMP(optimizer, solver, penalty.p);
Expand Down Expand Up @@ -93,4 +91,4 @@ result = simp(x0);
#md #
#md # ```julia
#md # @__CODE__
#md # ```
#md # ```
22 changes: 11 additions & 11 deletions src/Algorithms/Algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ using Parameters: @unpack, @pack!
using ..Utilities, Ferrite
using LinearAlgebra, Zygote

export Optimizer,
SIMP,
ExponentialContinuation,
ContinuationSIMP,
AdaptiveSIMP,
MMAOptionsGen,
CSIMPOptions,
BESO,
GESO,
Continuation,
PowerContinuation
export Optimizer,
SIMP,
ExponentialContinuation,
ContinuationSIMP,
AdaptiveSIMP,
MMAOptionsGen,
CSIMPOptions,
BESO,
GESO,
Continuation,
PowerContinuation

const to = TimerOutput()

Expand Down
Loading

0 comments on commit b3ec468

Please sign in to comment.