forked from 1iyiwei/topopt
-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.py
81 lines (63 loc) · 1.86 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
This is the main program code that sets up the topology optimisation problem.
This optimisation tries to maximize the displacement at a set location. A so-
called compliant design.
Bram Lagerweij
Aerospace Structures and Materials Department TU Delft
2018
"""
import time
import math
from loads import Inverter
from constraints import DensityConstraint
from fesolvers import FESolver, CvxFEA, CGFEA
from topopt import Topopt
from plotting import Plot
if __name__ == "__main__":
# material properties
young = 1
Emin = 1e-9
poisson = 0.3
ext_stiff = 0.005
# constraints
volfrac = 0.3
move = 0.5
# mesh dimensions
nelx = 80
nely = 40
# optimizer parameters
penal = 3.0
rmin = 1.5
filt = 'density'
loopy = 100 # math.inf
delta = 0.005
# plotting and printing options
verbose = True
plotting = True
save_plot = False
history = True
# constraints object created
den_con = DensityConstraint(nelx, nely, move, volume_frac=volfrac)
# loading case object, other classes can be selected and created
load = Inverter(nelx, nely, young, Emin, poisson, ext_stiff)
# FEA object is generated, other solvers can be selected and created
fesolver = CvxFEA(verbose=verbose)
# create optimizer object and initialise the problem
optimizer = Topopt(den_con, load, fesolver, verbose=verbose)
# compute
t = time.time()
x, x_history = optimizer.layout(penal, rmin, delta, loopy, filt, history)
print('Elapsed time is: ', time.time() - t, 'seconds.')
# plotting
pl = Plot(load, title='Inverter example')
pl.boundary(load)
pl.loading(load)
if history:
for i in x_history:
pl.add(i, animated=True)
pl.save('video')
pl.add(x, animated=False)
if save_plot:
pl.save('figure')
if plotting:
pl.show()