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
  2import opsvis as opsv
  3
  4import numpy as np
  5import matplotlib.pyplot as plt
  6
  7# input_parameters = (3.8, 50., 100.)
  8# input_parameters = (53.5767, 50., 100.)
  9input_parameters = (20.8, 300., 8.)
 10# input_parameters = (70.0, 500., 2.)
 11
 12pf, sfac_a, tkt = input_parameters
 13
 14ops.wipe()
 15ops.model('basic', '-ndm', 2, '-ndf', 3)  # frame 2D
 16
 17colL, girL = 4., 6.
 18
 19Acol, Agir = 0.06, 0.06
 20IzCol, IzGir = 0.0002, 0.0002
 21
 22E = 3.2e10
 23rho = 2400.
 24muCol = rho * Acol
 25muGir = rho * Agir
 26massCol = ['-mass', muCol, '-cMass']
 27massGir = ['-mass', muGir, '-cMass']
 28
 29ops.node(0, 0.0, 0.0)
 30ops.node(1, 0.0, 2.0)
 31ops.node(2, 0.0, 4.0)
 32ops.node(3, 3.0, 4.0)
 33ops.node(4, 6.0, 4.0)
 34ops.node(5, 6.0, 2.0)
 35ops.node(6, 6.0, 0.0)
 36
 37ops.fix(0, 1, 1, 1)
 38ops.fix(6, 1, 1, 0)
 39
 40gTTag = 1
 41ops.geomTransf('Linear', gTTag)
 42
 43# 1st column
 44ops.element('elasticBeamColumn', 1, 0, 1, Acol, E, IzCol, gTTag, *massCol)
 45ops.element('elasticBeamColumn', 2, 1, 2, Acol, E, IzCol, gTTag, *massCol)
 46# girder
 47ops.element('elasticBeamColumn', 3, 2, 3, Agir, E, IzGir, gTTag, *massGir)
 48ops.element('elasticBeamColumn', 4, 3, 4, Agir, E, IzGir, gTTag, *massGir)
 49# 2nd column
 50ops.element('elasticBeamColumn', 5, 4, 5, Acol, E, IzCol, gTTag, *massCol)
 51ops.element('elasticBeamColumn', 6, 5, 6, Acol, E, IzCol, gTTag, *massCol)
 52
 53t0 = 0.
 54tk = 1.
 55Tp = 1/pf
 56P0 = 15000.
 57dt = 0.002
 58n_steps = int((tk-t0)/dt)
 59
 60tsTag = 1
 61ops.timeSeries('Trig', tsTag, t0, tk, Tp, '-factor', P0)
 62
 63patTag = 1
 64ops.pattern('Plain', patTag, tsTag)
 65ops.load(1, 1., 0., 0.)
 66
 67ops.constraints('Transformation')
 68ops.numberer('RCM')
 69ops.test('NormDispIncr', 1.0e-6, 10, 1)
 70ops.algorithm('Linear')
 71ops.system('ProfileSPD')
 72ops.integrator('Newmark', 0.5, 0.25)
 73ops.analysis('Transient')
 74
 75el_tags = ops.getEleTags()
 76
 77nels = len(el_tags)
 78
 79Eds = np.zeros((n_steps, nels, 6))
 80timeV = np.zeros(n_steps)
 81
 82# transient analysis loop and collecting the data
 83for step in range(n_steps):
 84    ops.analyze(1, dt)
 85    timeV[step] = ops.getTime()
 86    # collect disp for element nodes
 87    for el_i, ele_tag in enumerate(el_tags):
 88        nd1, nd2 = ops.eleNodes(ele_tag)
 89        Eds[step, el_i, :] = [ops.nodeDisp(nd1)[0],
 90                              ops.nodeDisp(nd1)[1],
 91                              ops.nodeDisp(nd1)[2],
 92                              ops.nodeDisp(nd2)[0],
 93                              ops.nodeDisp(nd2)[1],
 94                              ops.nodeDisp(nd2)[2]]
 95
 96fmt_defo = {'color': 'blue', 'linestyle': 'solid', 'linewidth': 3.0,
 97            'marker': '', 'markersize': 6}
 98
 99# 1. animate the deformated shape
100anim = opsv.anim_defo(Eds, timeV, sfac_a, fmt_defo=fmt_defo,
101                      xlim=[-1, 7], ylim=[-1, 5], fig_wi_he=(30., 22.))
102
103plt.show()
104
105# 2. after closing the window, animate the specified mode shape
106eigVals = ops.eigen(5)
107
108modeNo = 2  # specify which mode to animate
109f_modeNo = np.sqrt(eigVals[modeNo-1])/(2*np.pi)  # i-th natural frequency
110
111anim = opsv.anim_mode(modeNo, fmt_defo=fmt_defo,
112                      xlim=[-1, 7], ylim=[-1, 5], fig_wi_he=(30., 22.))
113plt.title(f'Mode {modeNo}, f_{modeNo}: {f_modeNo:.3f} Hz')
114
115plt.show()