Animation of dynamic analysis and mode shapes of a 2d Portal Frame
Example .py
file can be downloaded here
:
If you do not see the animation running, depending on Python environment, you will have to set a matplotlib backand which supports animation.
For example to see the matplotlib animations in the Spyder Python
editor (which should be installed with the Anaconda platform), in the
IPython console run %matplotlib qt
. Then comment/uncomment one of
the two animations.
1import openseespy.opensees as ops
2# import opensees as ops # local compilation
3import opsvis as opsv
4
5import numpy as np
6import matplotlib.pyplot as plt
7
8# input_parameters = (3.8, 50., 100.)
9# input_parameters = (53.5767, 50., 100.)
10input_parameters = (20.8, 300., 8.)
11# input_parameters = (70.0, 500., 2.)
12
13pf, sfac_a, tkt = input_parameters
14
15ops.wipe()
16ops.model('basic', '-ndm', 2, '-ndf', 3) # frame 2D
17
18colL, girL = 4., 6.
19
20Acol, Agir = 0.06, 0.06
21IzCol, IzGir = 0.0002, 0.0002
22
23E = 3.2e10
24rho = 2400.
25muCol = rho * Acol
26muGir = rho * Agir
27massCol = ['-mass', muCol, '-cMass']
28massGir = ['-mass', muGir, '-cMass']
29
30ops.node(0, 0.0, 0.0)
31ops.node(1, 0.0, 2.0)
32ops.node(2, 0.0, 4.0)
33ops.node(3, 3.0, 4.0)
34ops.node(4, 6.0, 4.0)
35ops.node(5, 6.0, 2.0)
36ops.node(6, 6.0, 0.0)
37
38ops.fix(0, 1, 1, 1)
39ops.fix(6, 1, 1, 0)
40
41gTTag = 1
42ops.geomTransf('Linear', gTTag)
43
44# 1st column
45ops.element('elasticBeamColumn', 1, 0, 1, Acol, E, IzCol, gTTag, *massCol)
46ops.element('elasticBeamColumn', 2, 1, 2, Acol, E, IzCol, gTTag, *massCol)
47# girder
48ops.element('elasticBeamColumn', 3, 2, 3, Agir, E, IzGir, gTTag, *massGir)
49ops.element('elasticBeamColumn', 4, 3, 4, Agir, E, IzGir, gTTag, *massGir)
50# 2nd column
51ops.element('elasticBeamColumn', 5, 4, 5, Acol, E, IzCol, gTTag, *massCol)
52ops.element('elasticBeamColumn', 6, 5, 6, Acol, E, IzCol, gTTag, *massCol)
53
54t0 = 0.
55tk = 1.
56Tp = 1/pf
57P0 = 15000.
58dt = 0.002
59n_steps = int((tk-t0)/dt)
60
61tsTag = 1
62ops.timeSeries('Trig', tsTag, t0, tk, Tp, '-factor', P0)
63
64patTag = 1
65ops.pattern('Plain', patTag, tsTag)
66ops.load(1, 1., 0., 0.)
67
68ops.constraints('Transformation')
69ops.numberer('RCM')
70ops.test('NormDispIncr', 1.0e-6, 10, 1)
71ops.algorithm('Linear')
72ops.system('ProfileSPD')
73ops.integrator('Newmark', 0.5, 0.25)
74ops.analysis('Transient')
75
76el_tags = ops.getEleTags()
77
78nels = len(el_tags)
79
80Eds = np.zeros((n_steps, nels, 6))
81timeV = np.zeros(n_steps)
82
83# transient analysis loop and collecting the data
84for step in range(n_steps):
85 ops.analyze(1, dt)
86 timeV[step] = ops.getTime()
87 # collect disp for element nodes
88 for el_i, ele_tag in enumerate(el_tags):
89 nd1, nd2 = ops.eleNodes(ele_tag)
90 Eds[step, el_i, :] = [ops.nodeDisp(nd1)[0],
91 ops.nodeDisp(nd1)[1],
92 ops.nodeDisp(nd1)[2],
93 ops.nodeDisp(nd2)[0],
94 ops.nodeDisp(nd2)[1],
95 ops.nodeDisp(nd2)[2]]
96
97# 1. animate the deformated shape
98anim = opsv.anim_defo(Eds, timeV, sfac_a, interpFlag=1, xlim=[-1, 7],
99 ylim=[-1, 5], fig_wi_he=(30., 22.))
100
101plt.show()
102
103# 2. after closing the window, animate the specified mode shape
104eigVals = ops.eigen(5)
105
106modeNo = 2 # specify which mode to animate
107f_modeNo = np.sqrt(eigVals[modeNo-1])/(2*np.pi) # i-th natural frequency
108
109anim = opsv.anim_mode(modeNo, interpFlag=1, xlim=[-1, 7], ylim=[-1, 5],
110 fig_wi_he=(30., 22.))
111plt.title(f'Mode {modeNo}, f_{modeNo}: {f_modeNo:.3f} Hz')
112
113plt.show()