-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathexample.py
More file actions
70 lines (56 loc) · 1.51 KB
/
example.py
File metadata and controls
70 lines (56 loc) · 1.51 KB
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
'''
tester for topology optimization code
'''
import numpy as np
import math
import matplotlib.pyplot as plt
from loads import HalfBeam
from constraints import DensityConstraint
from fesolvers import LilFESolver, CooFESolver
from topopt import Topopt
if __name__ == "__main__":
# material properties
young = 1
poisson = 0.3
# constraints
volfrac = 0.4
xmin = 0.001
xmax = 1.0
# input parameters
nelx = 180
nely = 60
penal = 3.0
rmin = 5.4
delta = 0.02
loopy = math.inf
# loading/problem
load = HalfBeam(nelx, nely)
# constraints
density_constraint = DensityConstraint(volume_frac = volfrac, density_min = xmin, density_max = xmax)
# optimizer
verbose = True
fesolver = CooFESolver(verbose = verbose)
optimizer = Topopt(fesolver, young, poisson, verbose = verbose)
# compute
history = False
x = optimizer.init(load, density_constraint)
x, x_more = optimizer.layout(load, density_constraint, x, penal, rmin, delta, loopy, history)
if history:
x_history = x_more
loop = len(x_history)
else:
loop = x_more
x_history = None
# save
if x_history:
# import scipy.misc
# sequence = [scipy.misc.toimage(x, cmin=0, cmax=1) for x in x_history]
import imageio
imageio.mimsave('topopt.gif', x_history)
# plot
plt.figure()
plt.imshow(x, cmap=plt.cm.gray)
plt.title(str(loop) + ' loops')
plt.xticks([])
plt.yticks([])
plt.show()