Skip to content

Commit cff52ab

Browse files
authored
Merge pull request #142 from WenjieYao/topopt
add topology optimization tutorial
2 parents c85bb52 + b49ba73 commit cff52ab

9 files changed

Lines changed: 223881 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
${{ runner.os }}-test-
125125
${{ runner.os }}-
126126
- uses: julia-actions/julia-buildpkg@v1
127-
- run: cd test/; julia --project=.. --color=yes --check-bounds=yes runtests.jl isotropic_damage.jl validation_DrWatson.jl interpolation_fe.jl poisson_transient.jl
127+
- run: cd test/; julia --project=.. --color=yes --check-bounds=yes runtests.jl isotropic_damage.jl validation_DrWatson.jl interpolation_fe.jl poisson_transient.jl TopOptEMFocus.jl
128128
tutorials_mpi:
129129
name: TutorialsMPI ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
130130
runs-on: ${{ matrix.os }}

Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ authors = ["Santiago Badia <santiago.badia@monash.edu>", "Francesc Verdugo <fver
44
version = "0.17.0"
55

66
[deps]
7+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
8+
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
79
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
810
DrWatson = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1"
911
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
1012
Gridap = "56d4f2e9-7ea1-5844-9cf6-b9c51ca7ce8e"
1113
GridapDistributed = "f9701e48-63b3-45aa-9a63-9bc6c271f355"
1214
GridapGmsh = "3025c34a-b394-11e9-2a55-3fee550c04c8"
15+
GridapMakie = "41f30b06-6382-4b60-a5f7-79d86b35bf5d"
1316
GridapP4est = "c2c8e14b-f5fd-423d-9666-1dd9ad120af9"
1417
GridapPETSc = "bcdc36c2-0c3e-11ea-095a-c9dadae499f1"
1518
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
@@ -18,12 +21,15 @@ LineSearches = "d3d80556-e9d4-5f37-9878-2ab0fcc64255"
1821
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1922
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
2023
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
24+
NLopt = "76087f3c-5699-56af-9a33-bf431cd00edd"
2125
NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
2226
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
2327
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
2428
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
2529
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
30+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
2631
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
32+
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2733

2834
[compat]
2935
Gridap = "0.17.9"

assets/TopOptEMFocus/Field.png

134 KB
Loading
28.2 KB
Loading
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
using Gmsh
2+
import Gmsh: gmsh
3+
4+
struct RecCirGeometry
5+
L::Float64 # Length of the normal region
6+
h1::Float64 # Height of normal region
7+
h2::Float64 # Height of the region above source
8+
rt::Float64 # Radius of the target location
9+
rd::Float64 # Radius of design domain
10+
rs::Float64 # Radius of smallest distance circle
11+
dpml::Float64 # Thickness of the PML
12+
# Characteristic length (controls the resolution, smaller the finer)
13+
l1::Float64 # Normal region
14+
l2::Float64 # Design domain
15+
end
16+
17+
18+
function MeshGenerator(geo_param::RecCirGeometry, meshfile_name::String)
19+
gmsh.initialize()
20+
gmsh.option.setNumber("General.Terminal", 1)
21+
gmsh.option.setNumber("Mesh.Algorithm", 6)
22+
gmsh.clear()
23+
gmsh.model.add("geometry")
24+
25+
# Add points
26+
gmsh.model.geo.addPoint(-geo_param.L/2-geo_param.dpml, -geo_param.dpml, 0, geo_param.l1, 1)
27+
gmsh.model.geo.addPoint( geo_param.L/2+geo_param.dpml, -geo_param.dpml, 0, geo_param.l1, 2)
28+
gmsh.model.geo.addPoint( geo_param.L/2+geo_param.dpml, geo_param.h1, 0, geo_param.l1, 3)
29+
gmsh.model.geo.addPoint( geo_param.L/2+geo_param.dpml, geo_param.h1+geo_param.h2+geo_param.dpml, 0, geo_param.l1, 4)
30+
gmsh.model.geo.addPoint(-geo_param.L/2-geo_param.dpml, geo_param.h1+geo_param.h2+geo_param.dpml, 0, geo_param.l1, 5)
31+
gmsh.model.geo.addPoint(-geo_param.L/2-geo_param.dpml, geo_param.h1, 0, geo_param.l1, 6)
32+
gmsh.model.geo.addPoint(0, geo_param.h1/2, 0, geo_param.l2, 7)
33+
gmsh.model.geo.addPoint(-geo_param.rs, geo_param.h1/2, 0, geo_param.l2, 8)
34+
gmsh.model.geo.addPoint( geo_param.rs, geo_param.h1/2, 0, geo_param.l2, 9)
35+
gmsh.model.geo.addPoint(-geo_param.rd, geo_param.h1/2, 0, geo_param.l2, 10)
36+
gmsh.model.geo.addPoint( geo_param.rd, geo_param.h1/2, 0, geo_param.l2, 11)
37+
# Add lines
38+
gmsh.model.geo.addLine( 1, 2, 1)
39+
gmsh.model.geo.addLine( 2, 3, 2)
40+
gmsh.model.geo.addLine( 3, 4, 3)
41+
gmsh.model.geo.addLine( 4, 5, 4)
42+
gmsh.model.geo.addLine( 6, 5, 5)
43+
gmsh.model.geo.addLine( 1, 6, 6)
44+
gmsh.model.geo.addLine( 6, 3, 7)
45+
gmsh.model.geo.addCircleArc( 8, 7, 9, 8)
46+
gmsh.model.geo.addCircleArc( 9, 7, 8, 9)
47+
gmsh.model.geo.addCircleArc(10, 7,11,10)
48+
gmsh.model.geo.addCircleArc(11, 7,10,11)
49+
# Construct curve loops and surfaces
50+
gmsh.model.geo.addCurveLoop([8, 9], 1)
51+
gmsh.model.geo.addPlaneSurface([1], 1)
52+
gmsh.model.geo.addCurveLoop([10, 11], 2)
53+
gmsh.model.geo.addPlaneSurface([2, 1], 2)
54+
gmsh.model.geo.addCurveLoop([1, 2, -7,-6], 4)
55+
gmsh.model.geo.addPlaneSurface([4, 2], 4)
56+
gmsh.model.geo.addCurveLoop([3, 4,-5, 7], 5)
57+
gmsh.model.geo.addPlaneSurface([5], 5)
58+
# Physical groups
59+
gmsh.model.addPhysicalGroup(0, [1, 2, 4, 5], 1)
60+
gmsh.model.setPhysicalName(0, 1, "DirichletNodes")
61+
gmsh.model.addPhysicalGroup(1, [1, 4], 2)
62+
gmsh.model.setPhysicalName(1, 2, "DirichletEdges")
63+
gmsh.model.addPhysicalGroup(0, [8, 9, 10, 11], 3)
64+
gmsh.model.setPhysicalName(0, 3, "DesignNodes")
65+
gmsh.model.addPhysicalGroup(1, [8, 9, 10, 11], 4)
66+
gmsh.model.setPhysicalName(1, 4, "DesignEdges")
67+
gmsh.model.addPhysicalGroup(2, [2], 5)
68+
gmsh.model.setPhysicalName(2, 5, "Design")
69+
gmsh.model.addPhysicalGroup(2, [1], 6)
70+
gmsh.model.setPhysicalName(2, 6, "Center")
71+
gmsh.model.addPhysicalGroup(2, [3,4,5], 7)
72+
gmsh.model.setPhysicalName(2, 7, "Air")
73+
gmsh.model.addPhysicalGroup(1, [7], 9)
74+
gmsh.model.setPhysicalName(1, 9, "Source")
75+
gmsh.model.geo.synchronize()
76+
77+
# Set periodic mesh on the left and right side
78+
gmsh.model.mesh.setPeriodic(1, [2], [6],
79+
[1, 0, 0, geo_param.L+2*geo_param.dpml, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
80+
gmsh.model.mesh.setPeriodic(1, [3], [5],
81+
[1, 0, 0, geo_param.L+2*geo_param.dpml, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1])
82+
# We can then generate a 2D mesh...
83+
gmsh.model.mesh.generate(2)
84+
85+
86+
87+
# ... and save it to disk
88+
gmsh.write(meshfile_name)
89+
gmsh.finalize()
90+
end
91+
92+
L = 600
93+
h1 = 600
94+
h2 = 200
95+
rt = 150
96+
rd = 100
97+
rs = 10
98+
99+
dpml = 300
100+
101+
l1 = 20
102+
l2 = 1
103+
104+
meshfile = "RecCirGeometry.msh"
105+
geo_param = RecCirGeometry(L, h1, h2, rt, rd, rs, dpml, l1, l2)
106+
MeshGenerator(geo_param, meshfile)

assets/TopOptEMFocus/shape.png

45.8 KB
Loading

deps/build.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ files = [
2121
"On using DrWatson.jl"=>"validation_DrWatson.jl",
2222
"Interpolation of CellFields"=>"interpolation_fe.jl",
2323
"Poisson equation on parallel distributed-memory computers"=>"poisson_distributed.jl",
24-
"Transient Poisson equation"=>"poisson_transient.jl"]
24+
"Transient Poisson equation"=>"poisson_transient.jl",
25+
"Topology optimization"=>"TopOptEMFocus.jl"]
2526

2627
Sys.rm(notebooks_dir;recursive=true,force=true)
2728
for (i,(title,filename)) in enumerate(files)

0 commit comments

Comments
 (0)