Skip to content

Commit

Permalink
WCSMO 14 demos and files (#90)
Browse files Browse the repository at this point in the history
* wcsmo files

* move files and add to tests

* fix and add examples

* comment out 3d benchmarks

* split CI

* matrix group name

* comment out some wcsmo demo

* comment out wcsmo demo
  • Loading branch information
mohamed82008 authored Dec 2, 2021
1 parent 8ba374b commit 1706bdd
Show file tree
Hide file tree
Showing 44 changed files with 1,711 additions and 55 deletions.
46 changes: 34 additions & 12 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,47 @@ on:
tags: '*'
jobs:
test:
name: Test julia ${{ matrix.julia-version }} - ${{ matrix.os }}
name: ${{matrix.group}} - Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ['1.6',]
os: ['ubuntu-latest',]
version:
- '1.7'
os:
- ubuntu-latest
arch:
- x64
group:
- Tests
- Examples
- WCSMO14
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
with:
coverage: false
env:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
if: ${{ matrix.julia-version == '1.6' && matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.version == '1.7' && matrix.os == 'ubuntu-latest' }}
- uses: codecov/codecov-action@v1
if: ${{ matrix.julia-version == '1.6' && matrix.os == 'ubuntu-latest' }}
if: ${{ matrix.version == '1.7' && matrix.os == 'ubuntu-latest' }}
with:
file: lcov.info
# example for Makie-involving docs build
Expand All @@ -39,13 +61,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ['1.6',]
version: ['1.7',]
os: ['ubuntu-latest',]
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
version: ${{ matrix.version }}
# - uses: actions/cache@v1
# env:
# cache-name: cache-artifacts
Expand Down
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ All the following features are available in TopOpt.jl but the documentation is c
- Concentrated and distributed loads
- SIMP, RAMP, continuation SIMP/RAMP and BESO
- Compliance, volume and stress functions
- Buckling constrained truss optimization
- End-to-end topology optimization from INP file to VTK file
- Interactive visualization of designs and deformation
- Automatic differentiation of arbitrary Julia functions
- Method of moving asymptotes, NLopt, Ipopt and augmented Lagrangian algorithm for optimization
- Density and sensitivity filters
- Heaviside projection
- Handling load uncertainty in compliance-based topology optimization
- Neural network representation of designs
- Integer nonlinear topology optimization for truss and continuum problems (design variables guaranteed to be integer)

![gif1](https://user-images.githubusercontent.com/19524993/138464511-2685f3fe-e7c5-482e-8b06-43ab0fb82990.gif)
![gif2](https://user-images.githubusercontent.com/19524993/138464828-88f0ffcb-01f7-43b7-8d17-f5d201e95aa3.gif)
Expand All @@ -67,23 +70,23 @@ To cite this package, you can cite the following 2 conference publications.
- TopOpt.jl: An efficient and high-performance package for topology optimization of continuum structures in the Julia programming language

```bibtex
@inproceedings{tarek2019topoptjl,
title={TopOpt.jl: An efficient and high-performance package for topology optimization of continuum structures in the Julia programming language},
author={Tarek, Mohamed},
booktitle={Proceedings of the 13th World Congress of Structural and Multidisciplinary Optimization},
year={2019}
}
@inproceedings{tarek2019topoptjl,
title={TopOpt.jl: An efficient and high-performance package for topology optimization of continuum structures in the Julia programming language},
author={Tarek, Mohamed},
booktitle={Proceedings of the 13th World Congress of Structural and Multidisciplinary Optimization},
year={2019}
}
```

- [TopOpt.jl: Truss and Continuum Topology Optimization, Interactive Visualization, Automatic Differentiation and More](https://web.mit.edu/yijiangh/www/papers/topopt_jl_WCSMO2021.pdf)

```bibtex
@inproceedings{huang2021topoptjl,
title={TopOpt.jl: Truss and Continuum Topology Optimization, Interactive Visualization, Automatic Differentiation and More},
author={Huang, Yijiang and Tarek, Mohamed},
booktitle={Proceedings of the 14th World Congress of Structural and Multidisciplinary Optimization},
year={2021}
}
@inproceedings{huang2021topoptjl,
title={TopOpt.jl: Truss and Continuum Topology Optimization, Interactive Visualization, Automatic Differentiation and More},
author={Huang, Yijiang and Tarek, Mohamed},
booktitle={Proceedings of the 14th World Congress of Structural and Multidisciplinary Optimization},
year={2021}
}
```

## Contribute
Expand Down
2 changes: 1 addition & 1 deletion docs/src/literate/simp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ obj = x -> comp(filter(x))
volfrac = TopOpt.Volume(problem, solver)
constr = x -> volfrac(filter(x)) - V

# You can enable the iteration printouts with `Nonconvex.show_residuals[] = true`
# You can enable the iteration printouts with `Nonconvex.NonconvexCore.show_residuals[] = true`

# ### Define subproblem optimizer
mma_options =
Expand Down
4 changes: 2 additions & 2 deletions src/TrussTopOptProblems/matrices_and_vectors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ function GenericCellScalarValues(
dMdξ = fill(zero(Vec{ξdim,T}) * T(NaN), n_geom_basefuncs, n_qpoints)
for (qp, ξ) in enumerate(quad_rule.points)
for i = 1:n_func_basefuncs
dNdξ[i, qp], N[i, qp] = gradient-> value(func_interpol, i, ξ), ξ, :all)
dNdξ[i, qp], N[i, qp] = Ferrite.gradient-> value(func_interpol, i, ξ), ξ, :all)
end
for i = 1:n_geom_basefuncs
dMdξ[i, qp], M[i, qp] = gradient-> value(geom_interpol, i, ξ), ξ, :all)
dMdξ[i, qp], M[i, qp] = Ferrite.gradient-> value(geom_interpol, i, ξ), ξ, :all)
end
end
detJdV = fill(T(NaN), n_qpoints)
Expand Down
7 changes: 7 additions & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
[deps]
Arpack = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
FromFile = "ff7dd447-1dcb-4ce3-b8ac-22a812192de7"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
Juniper = "2ddba703-00a4-53a7-87a5-e8b9971dde84"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Nonconvex = "01bcebdf-4d21-426d-b5c4-6132c1619978"
NonconvexIpopt = "bf347577-a06d-49ad-a669-8c0e005493b8"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1 change: 1 addition & 0 deletions test/examples/mixed_integer_truss/tim_2d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"unit": "meter", "materials": [{"G12": 80760000.0, "E": 1.0, "name": "DummyMaterial", "family": "DummyMaterial", "density": 78.5, "elem_tags": [], "E_unit": "kN/m2", "type_name": "ISO", "fy": 235000.0, "density_unit": "kN/m3", "fy_unit": "kN/m2", "G12_unit": "kN/m2"}], "dimension": 2, "generate_time": "05/21/2019 07:40:59", "elements": [{"end_node_inds": [0, 2], "elem_tag": ""}, {"end_node_inds": [0, 3], "elem_tag": ""}, {"end_node_inds": [2, 3], "elem_tag": ""}, {"end_node_inds": [2, 1], "elem_tag": ""}, {"end_node_inds": [2, 4], "elem_tag": ""}, {"end_node_inds": [2, 5], "elem_tag": ""}, {"end_node_inds": [4, 5], "elem_tag": ""}, {"end_node_inds": [4, 3], "elem_tag": ""}, {"end_node_inds": [4, 6], "elem_tag": ""}, {"end_node_inds": [4, 7], "elem_tag": ""}, {"end_node_inds": [6, 7], "elem_tag": ""}, {"end_node_inds": [6, 5], "elem_tag": ""}, {"end_node_inds": [6, 8], "elem_tag": ""}, {"end_node_inds": [6, 9], "elem_tag": ""}, {"end_node_inds": [8, 9], "elem_tag": ""}, {"end_node_inds": [8, 7], "elem_tag": ""}, {"end_node_inds": [8, 10], "elem_tag": ""}, {"end_node_inds": [8, 11], "elem_tag": ""}, {"end_node_inds": [10, 11], "elem_tag": ""}, {"end_node_inds": [10, 9], "elem_tag": ""}, {"end_node_inds": [10, 12], "elem_tag": ""}, {"end_node_inds": [10, 13], "elem_tag": ""}, {"end_node_inds": [12, 13], "elem_tag": ""}, {"end_node_inds": [12, 11], "elem_tag": ""}, {"end_node_inds": [12, 14], "elem_tag": ""}, {"end_node_inds": [12, 15], "elem_tag": ""}, {"end_node_inds": [14, 15], "elem_tag": ""}, {"end_node_inds": [14, 13], "elem_tag": ""}, {"end_node_inds": [14, 16], "elem_tag": ""}, {"end_node_inds": [14, 17], "elem_tag": ""}, {"end_node_inds": [16, 17], "elem_tag": ""}, {"end_node_inds": [16, 15], "elem_tag": ""}, {"end_node_inds": [16, 18], "elem_tag": ""}, {"end_node_inds": [18, 17], "elem_tag": ""}, {"end_node_inds": [1, 3], "elem_tag": ""}, {"end_node_inds": [3, 5], "elem_tag": ""}, {"end_node_inds": [5, 7], "elem_tag": ""}, {"end_node_inds": [7, 9], "elem_tag": ""}, {"end_node_inds": [9, 11], "elem_tag": ""}, {"end_node_inds": [11, 13], "elem_tag": ""}, {"end_node_inds": [13, 15], "elem_tag": ""}, {"end_node_inds": [15, 17], "elem_tag": ""}], "supports": [{"node_ind": 0, "condition": [1, 1]}, {"node_ind": 1, "condition": [1, 1]}], "node_num": 19, "TO_model_type": "ground_mesh", "_info": "TTObuckling example used in PENLAB.", "model_name": "tim", "element_num": 42, "model_type": "truss", "loadcases": {"1": {"ploads": [{"node_ind": 18, "force": [0, -1], "loadcase": 1, "force_unit": "kN"}], "lc_ind": 1}, "0": {"ploads": [{"node_ind": 18, "force": [-1, 0], "loadcase": 0, "force_unit": "kN"}], "lc_ind": 0}}, "cross_secs": [{"A": 1.0, "name": "", "family": "DummyCroSec", "elem_tags": [], "A_unit": "m2"}], "nodes": [{"node_ind": 0, "point": [0, 0]}, {"node_ind": 1, "point": [0, 1]}, {"node_ind": 2, "point": [1, 0]}, {"node_ind": 3, "point": [1, 1]}, {"node_ind": 4, "point": [2, 0]}, {"node_ind": 5, "point": [2, 1]}, {"node_ind": 6, "point": [3, 0]}, {"node_ind": 7, "point": [3, 1]}, {"node_ind": 8, "point": [4, 0]}, {"node_ind": 9, "point": [4, 1]}, {"node_ind": 10, "point": [5, 0]}, {"node_ind": 11, "point": [5, 1]}, {"node_ind": 12, "point": [6, 0]}, {"node_ind": 13, "point": [6, 1]}, {"node_ind": 14, "point": [7, 0]}, {"node_ind": 15, "point": [7, 1]}, {"node_ind": 16, "point": [8, 0]}, {"node_ind": 17, "point": [8, 1]}, {"node_ind": 18, "point": [8.5, 0.5]}]}
49 changes: 49 additions & 0 deletions test/examples/mixed_integer_truss/truss_compliance_2d1.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using TopOpt, LinearAlgebra, StatsFuns
# using Makie
# using TopOpt.TrussTopOptProblems.TrussVisualization: visualize

Nonconvex.@load Juniper

# 2D
ndim = 2
node_points, elements, mats, crosssecs, fixities, load_cases =
load_truss_json(joinpath(@__DIR__, "tim_$(ndim)d.json"));
ndim, nnodes, ncells = length(node_points[1]), length(node_points), length(elements)
loads = load_cases["0"]
problem = TrussProblem(
Val{:Linear}, node_points, elements,
loads, fixities, mats, crosssecs,
);

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

solver = FEASolver(Direct, problem, xmin = xmin)
comp = TopOpt.Compliance(problem, solver)

function obj(x)
# minimize compliance
return comp(x)
end
function constr(x)
# volume fraction constraint
return sum(x) / length(x) - V
end

m = Model(obj)
addvar!(m, zeros(length(x0)), ones(length(x0)), integer = trues(length(x0)))
Nonconvex.add_ineq_constraint!(m, constr)

options = JuniperIpoptOptions()
TopOpt.setpenalty!(solver, p)
@time r = Nonconvex.optimize(m, JuniperIpoptAlg(), x0, options = options);

@show obj(r.minimizer)
@show constr(r.minimizer)
# fig = visualize(
# problem, solver.u; topology = r.minimizer,
# default_exagg_scale=0.0
# )
# Makie.display(fig)
9 changes: 5 additions & 4 deletions test/examples/neural.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using TopOpt, Zygote
using TopOpt, Zygote, ChainRulesCore
# using Makie
Nonconvex.@load Ipopt

Expand Down Expand Up @@ -103,16 +103,17 @@ end

μ = 1.0
res2 = res1
for _ = 1:10
# Increase the number of iterations to get a good design
for _ = 1:3
global μ *= 2
global res2
model2 = Model()
addvar!(model2, fill(-100.0, nparams), fill(100.0, nparams))
noise = randn(nparams)
# set_objective!(model2, obj)
set_objective!(model2, p -> μ * obj(p) - log(max(0, -constr(p))))
# add_ineq_constraint!(model2, p -> 10*constr(p))
options = IpoptOptions(max_iter = 100)
# Increase the following number e.g. to 100 for a better design
options = IpoptOptions(max_iter = 20)
res2 = optimize(model2, alg, res2.minimizer; options)
@show extrema(tf(res2.minimizer))
@show obj(res2.minimizer)
Expand Down
79 changes: 55 additions & 24 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,71 @@
using Test, SafeTestsets

@safetestset "InpParser Tests" begin
include("inp_parser/parser.jl")
end
@safetestset "TopOptProblems Tests" begin
include("topopt_problems/problems.jl")
include("topopt_problems/metadata.jl")
end
@safetestset "Functions" begin
include("Functions/test_common_fns.jl")
include("Functions/test_buckling_fns.jl")
end
@safetestset "Solver" begin
include("fea/solvers.jl")
end
@safetestset "Truss Problem Tests" begin
include("truss_topopt_problems/test_problem.jl")
include("truss_topopt_problems/test_fea.jl")
include("truss_topopt_problems/test_buckling.jl")
include("truss_topopt_problems/test_buckling_optimize.jl")
const GROUP = get(ENV, "GROUP", "All")

if GROUP == "All" || GROUP == "Tests"
@safetestset "InpParser Tests" begin
include("inp_parser/parser.jl")
end
@safetestset "TopOptProblems Tests" begin
include("topopt_problems/problems.jl")
include("topopt_problems/metadata.jl")
end
@safetestset "Functions" begin
include("Functions/test_common_fns.jl")
include("Functions/test_buckling_fns.jl")
end
@safetestset "Solver" begin
include("fea/solvers.jl")
end
@safetestset "Truss Problem Tests" begin
include("truss_topopt_problems/test_problem.jl")
include("truss_topopt_problems/test_fea.jl")
include("truss_topopt_problems/test_buckling.jl")
include("truss_topopt_problems/test_buckling_optimize.jl")
end
end

@safetestset "Examples" begin
@safetestset "CSIMP" begin
if GROUP == "All" || GROUP == "Examples"
@safetestset "CSIMP example" begin
include("examples/csimp.jl")
end
@safetestset "Global Stress" begin
@safetestset "Global stress example" begin
include("examples/global_stress.jl")
end
@safetestset "Local Stress" begin
@safetestset "Local stress example" begin
include("examples/local_stress.jl")
end
@safetestset "More examples" begin
include("examples/test_examples.jl")
end
@safetestset "Neural networks" begin
@safetestset "Neural network example" begin
include("examples/neural.jl")
end
@safetestset "Integer nonlinear programming for truss optimization example" begin
include("examples/mixed_integer_truss/truss_compliance_2d1.jl")
end
end

if GROUP == "All" || GROUP == "WCSMO14"
# This was originlly part of https://github.com/JuliaTopOpt/TopOpt.jl_WCSMO21
@safetestset "Continuum demos" begin
include("wcsmo14/demos/continuum/cont_compliance1.jl")
include("wcsmo14/demos/continuum/cont_compliance2.jl")
include("wcsmo14/demos/continuum/cont_stress.jl")
end
@safetestset "Truss 2d demos" begin
include("wcsmo14/demos/truss/truss_compliance_2d1.jl")
include("wcsmo14/demos/truss/truss_compliance_2d2.jl")
end
@safetestset "Truss 3d demos" begin
include("wcsmo14/demos/truss/truss_compliance_3d1.jl")
include("wcsmo14/demos/truss/truss_compliance_3d2.jl")
end
@safetestset "WCSMO Benchmarks" begin
include("wcsmo14/jl_benchmarks/compare_neo99_2D.jl")
#include("wcsmo14/jl_benchmarks/compare_polytop.jl")
#include("wcsmo14/jl_benchmarks/compare_top3d.jl")
#include("wcsmo14/jl_benchmarks/compare_top3d125.jl")
#include("wcsmo14/jl_benchmarks/new_problems.jl")
end
end
Binary file added test/wcsmo14/benchmarks.xlsx
Binary file not shown.
9 changes: 9 additions & 0 deletions test/wcsmo14/demos/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[deps]
Ferrite = "c061ca5d-56c9-439f-9c0e-210fe06d3992"
GLFW = "f7f18e0c-5ee9-5ccd-a5bf-e8befd85ed98"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Nonconvex = "01bcebdf-4d21-426d-b5c4-6132c1619978"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
TopOpt = "53a1e1a5-51bb-58a9-8a02-02056cc81109"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/wcsmo14/demos/_demo_covers/5_truss.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 1706bdd

Please sign in to comment.