An earthquake hands the same SDOF oscillator the most violent right-hand side it will ever see: a jagged, broadband ground acceleration that lasts only tens of seconds. Yet the engine from Chapter 3 does not flinch, because a ground motion is just another . The new idea in this chapter is not how to solve one oscillator, but what to do with the answer. By solving many oscillators, one for each natural period, and keeping only the peak from each, we distill a whole record into a single curve: the response spectrum. It is the one plot a designer actually uses, and we are going to build it from the ground up by looping the solver.
1Recap: when the ground moves¶
The base-excitation equation of Chapter 1 is the starting point. The ground does not push the roof; it shakes the base by an acceleration . Writing for the displacement of the mass relative to the ground (the quantity that actually strains the columns), the spring and dashpot feel only that relative motion, while the inertia responds to the total acceleration. Balancing forces gives
Figure 1 reads this equation as a statement about two structures. On the left the base itself moves by , the mass moves by the total , and the columns bend by the relative . On the right the base is fixed and the mass is pushed instead by the force , which opposes the ground acceleration. Both structures obey (1), so they share the same relative motion , and the second picture is the one our engine already knows how to solve.
Figure 1:A structure on a moving base (left) and the equivalent fixed-base structure loaded by the effective force (right).
The right-hand side is therefore an effective force . The minus sign and the factor carry the physics: a heavier structure attracts a larger earthquake force from the same shaking. Dividing through by and using and , the response depends on the structure through only two numbers, its natural period and its damping ratio :
That is the whole reason a response spectrum is possible: feed the same ground
motion to oscillators that differ only in , and the peak response is
a function of those two numbers alone. Our solver already takes base excitation
directly: we pass the effective force p = -m * ag.
2A ground motion¶
We need a record. sd.demo_record() returns a reproducible synthetic
strong-motion accelerogram, filtered noise (Kanai, 1957; Tajimi, 1960) shaped by
a rise-and-decay intensity envelope and scaled to a target peak ground
acceleration (PGA). It stands in for
a real event so the chapter runs anywhere; a real record loads identically with
sd.load_record(path, dt) and every line below is unchanged. The record is in
, the unit the equation of motion needs, while peak accelerations
are also quoted in units of , as is customary in
earthquake engineering.
t, ag = sd.demo_record() # ag in m/s^2, sampled uniformly
dt = t[1] - t[0]
g = 9.81
pga = np.max(np.abs(ag))
print(f"record length {t[-1]:.1f} s ({t.size} samples at dt = {dt:.3f} s)")
print(f"PGA = {pga:.2f} m/s^2 = {pga/g:.2f} g")record length 30.0 s (1500 samples at dt = 0.020 s)
PGA = 2.94 m/s^2 = 0.30 g
fig, ax = plt.subplots(figsize=(7.6, 3.0))
ax.plot(t, ag, color=sd.PLT[0], lw=1.4)
ax.axhline(0, color="#9aa3ab", lw=1.0)
ax.axhline( pga, color=sd.PLT[1], lw=1.0, ls="--")
ax.axhline(-pga, color=sd.PLT[1], lw=1.0, ls="--")
ax.set_xlabel(r"time $t$ (s)")
ax.set_ylabel(r"ground accel. $\ddot u_g$ (m/s$^2$)")
ax.set_xlim(0, t[-1])
# twin axis in g
axg = ax.twinx()
axg.set_ylim(np.array(ax.get_ylim()) / g)
axg.set_ylabel(r"$\ddot u_g$ ($g$)")
axg.grid(False)
plt.show()

Figure 2:The ground-acceleration record used throughout this chapter, in m/s (left axis) and in units of (right axis), with the peak ground acceleration dashed.
The shaking builds over the first few seconds, peaks near 5 s, and then dies away, which is the classic non-stationary signature of a real earthquake. By about 20 s the ground is nearly still, so the strong motion lasts only some fifteen seconds. This single trace is the input for everything below.
3How different structures feel the same shaking¶
Before collapsing the record to a spectrum, let us build intuition by running a
few individual structures through it. We take four SDOFs with natural periods
, short and stiff through tall and
flexible, all at , and plot their relative-displacement histories.
Because the spectrum only ever needs the peak per structure, we work with a
unit mass: the period and damping fully determine the deformation, so
m = 1, , .
def sdof_to_record(Tn, ag, dt, zeta=0.05):
"""Relative response of a unit-mass SDOF (period Tn, damping zeta) to ag."""
m = 1.0
wn = 2 * np.pi / Tn
k = m * wn**2
c = 2 * zeta * m * wn
t, u, v, a = sd.sdof_response(m, c, k, -m * ag, dt) # effective force = -m*ag
return t, u
Tns = [0.3, 0.6, 1.0, 2.0]
hist = {Tn: sdof_to_record(Tn, ag, dt) for Tn in Tns}
for Tn in Tns:
_, u = hist[Tn]
print(f"Tn = {Tn:.1f} s peak deformation = {np.max(np.abs(u))*1000:6.1f} mm")Tn = 0.3 s peak deformation = 7.3 mm
Tn = 0.6 s peak deformation = 30.3 mm
Tn = 1.0 s peak deformation = 61.5 mm
Tn = 2.0 s peak deformation = 121.0 mm
fig, axes = plt.subplots(len(Tns), 1, figsize=(7.6, 6.4), sharex=True)
for ax, Tn in zip(axes, Tns):
tt, u = hist[Tn]
ax.plot(tt, u * 1000, color=sd.PLT[0], lw=1.5)
ax.axhline(0, color="#9aa3ab", lw=0.9)
# mark the peak that feeds the spectrum
ipk = np.argmax(np.abs(u))
ax.plot(tt[ipk], u[ipk] * 1000, "o", color=sd.PLT[1], ms=6, zorder=5)
ax.set_ylabel(r"$u$ (mm)")
ax.text(0.985, 0.86, rf"$T_n = {Tn:.1f}$ s", transform=ax.transAxes,
ha="right", va="top", fontsize=11,
bbox=dict(boxstyle="round,pad=0.25", fc="white", ec="#d6dbdf"))
axes[-1].set_xlabel(r"time $t$ (s)")
axes[0].set_xlim(0, t[-1])
plt.show()

Figure 3:Relative-displacement response of four SDOF structures (all at 5% damping) to the same ground motion, with the peak of each trace marked (dot).
Two trends jump out of Figure 3 once the four structures sit side by side. First, the longer the period, the larger the deformation here: the flexible structures soak up more drift. Second, the longer-period traces oscillate visibly more slowly: each structure rings at its own . The orange dot on each trace is the one number the response spectrum keeps. Collect that dot for every conceivable period and we have the spectrum.
▶ Interactive: one record, five structures on a shake table
The four oscillators above and a nearly rigid fifth one ( s), all at 5 % damping and drawn taller the longer the period, stand on one shake table that moves with the first 20 s of the record. The table follows the baseline-corrected ground displacement: integrated twice from rest, the record itself drifts to -22.8 m by the end, so its content below 0.1 Hz is removed before the table is drawn. Each mass sits at , the table position plus the drift computed by the engine from the unfiltered record, so the correction moves the table and the masses together and every column bends by exactly the engine’s drift, as in Figure 3. Dashed lines mark the rest positions, fixed in space. Below, the table displacement and the five drifts play on one scale, with the largest value so far shaded and printed at the right, and the readout collects the five largest drifts.
The stiff structures ride with the table: as it swings past 100 mm, the 0.1 s mass stays within 0.8 mm of it and the 0.3 s mass within 7.3 mm, their columns nearly straight. The longer the period, the more the mass falls behind the table and swings past it, and the more the column bends, to 30.3 mm at 0.6 s, 61.5 mm at 1.0 s, and 121.0 mm at 2.0 s. The flexible 2.0 s mass does not stay still in space either: at s, when its drift peaks, the table is at -106 mm and the drift points the same way, so the mass swings farther than the ground. The table’s slow swings last several seconds, longer than any of these periods, and every mass is carried along by them. A mass that stays put while the ground moves beneath it, the flexible limit discussed with the spectra below, needs a period long compared with those swings.
4Building the elastic response spectrum¶
Figure 4 condenses the whole construction into one picture. Three oscillators of increasing period ride out the same record, each history is reduced to its largest swing, and each swing becomes one point on a plot of peak deformation against period. Repeating that for every period traces the continuous curve on the right, which is the deformation response spectrum defined next.
Figure 4:Three oscillators under the chapter’s record (left), their relative-displacement histories with the peaks marked (middle), and the deformation spectrum on which those peaks lie (right).
The deformation response spectrum is the peak relative displacement, , plotted against . It is all we need: is the peak drift, and the peak elastic spring force, what stresses the columns, is times that drift. But it is convenient to repackage into two companions with the units of velocity and acceleration, and the right powers of to use are not arbitrary: they fall out of the equivalent static force.
At the instant of peak drift, the elastic force the structure carries is the spring force , whose peak is . Using (from , Chapter 2) this peak force is
A static force of this size, applied to the mass, would produce the same peak drift: it is the equivalent static earthquake force. Writing it as , exactly as for a body under acceleration , forces the definition . The intermediate quantity, with units of velocity, is :
is the pseudo-velocity and the pseudo-acceleration. The prefix pseudo is a reminder that these are defined from by the relations above, not measured as the peaks of the actual relative velocity or total acceleration . For a lightly damped structure stays within about half a percent of the peak total acceleration. , by contrast, can miss the peak relative velocity by 20 % or more at very short and very long periods, as a check after the spectra below shows, yet both are the quantities a designer wants. Each successive multiplication by mirrors the harmonic response factors of Chapter 4, where differentiating a sinusoid brought down a factor of . Of the three, matters most, because the peak base shear, the total horizontal force the foundation must carry, is just the peak elastic force we started from:
Multiply the structure’s mass by the value the spectrum gives at its period and you have the design force. The pseudo-velocity, in turn, measures the peak energy stored in the structure: its peak strain energy is , the form of a kinetic energy at “velocity” , which is why all three spectra carry the same information, merely viewed through (4). Example 1 turns one peak from Figure 3 into a design force.
The next cell repeats Example 1 from the stored history of the 1.0 s oscillator.
# Spectral values and base shear at Tn = 1.0 s (ex-ch06-base-shear).
_, u_1 = hist[1.0]
Sd_1 = np.max(np.abs(u_1))
wn_1 = 2 * np.pi / 1.0
m_bldg = 500.0 # effective mass (t)
print(f"Sd = {Sd_1*1000:.2f} mm Sv = {wn_1*Sd_1:.3f} m/s Sa = {wn_1**2*Sd_1:.3f} m/s^2 = {wn_1**2*Sd_1/g:.3f} g")
print(f"V_base = m Sa = {m_bldg*wn_1**2*Sd_1:.0f} kN W = {m_bldg*g:.0f} kN V/W = {wn_1**2*Sd_1/g:.3f}")Sd = 61.47 mm Sv = 0.386 m/s Sa = 2.427 m/s^2 = 0.247 g
V_base = m Sa = 1213 kN W = 4905 kN V/W = 0.247
Building all three spectra is one loop over periods with one call to the solver
each. It is structurally the same loop that swept the pulse-duration ratio
to build the shock spectrum in Chapter 5,
except that here the load (the whole ground motion) is fixed and the
structure’s period sweeps. That is exactly what sd.response_spectrum
does: for each period it
builds a unit-mass SDOF, runs the record through the Chapter-3 solver
sd.sdof_response (the matrix-exponential step inside it), records the peak
deformation , and finally returns via
(4).
periods = np.linspace(0.05, 3.0, 150) # Tn grid, 0.05 s ... 3.0 s
Sd, Sv, Sa = sd.response_spectrum(ag, dt, periods, zeta=0.05)
# sanity: the four hand-run peaks must lie on the Sd curve
for Tn in Tns:
_, u = hist[Tn]
Sd_interp = np.interp(Tn, periods, Sd)
print(f"Tn = {Tn:.1f} s : hand-run peak {np.max(np.abs(u))*1000:6.1f} mm"
f" | spectrum {Sd_interp*1000:6.1f} mm")Tn = 0.3 s : hand-run peak 7.3 mm | spectrum 7.4 mm
Tn = 0.6 s : hand-run peak 30.3 mm | spectrum 30.2 mm
Tn = 1.0 s : hand-run peak 61.5 mm | spectrum 61.5 mm
Tn = 2.0 s : hand-run peak 121.0 mm | spectrum 121.0 mm
The hand-run peaks land on the spectrum, as they must, because the spectrum is made of those peaks (the 0.1 mm differences come from interpolating between grid periods), and the next cell plots all three spectra.
fig, axes = plt.subplots(1, 3, figsize=(9.4, 3.1))
axes[0].plot(periods, Sd * 1000, color=sd.PLT[0])
axes[0].set_ylabel(r"$S_d$ (mm)")
axes[0].set_title("deformation")
axes[1].plot(periods, Sv, color=sd.PLT[2])
axes[1].set_ylabel(r"$S_v$ (m/s)")
axes[1].set_title("pseudo-velocity")
axes[2].plot(periods, Sa / g, color=sd.PLT[1])
axes[2].set_ylabel(r"$S_a$ ($g$)")
axes[2].set_title("pseudo-acceleration")
for ax in axes:
ax.set_xlabel(r"period $T_n$ (s)")
ax.set_xlim(0, 3.0)
ax.set_ylim(bottom=0)
fig.tight_layout()
plt.show()

Figure 5:The three elastic response spectra of the record at 5% damping: deformation (left), pseudo-velocity (center), and pseudo-acceleration (right, in ).
The pseudo quantities can be checked against the true peaks directly, since the solver also returns the relative velocity and acceleration of each run.
# Pseudo-spectral values against the true peaks of relative velocity and total acceleration.
for Tn in (0.1, 1.0, 3.0):
wn_c = 2 * np.pi / Tn
_, u_c, v_c, a_c = sd.sdof_response(1.0, 2 * 0.05 * wn_c, wn_c**2, -ag, dt)
Sd_c = np.max(np.abs(u_c))
print(f"Tn = {Tn:.1f} s: Sv = {wn_c*Sd_c:.3f} vs max|v| = {np.max(np.abs(v_c)):.3f} m/s"
f" ({100*(np.max(np.abs(v_c))/(wn_c*Sd_c) - 1):+.0f} %) "
f"Sa = {wn_c**2*Sd_c/g:.3f} vs max|a_total| = {np.max(np.abs(a_c + ag))/g:.3f} g"
f" ({100*(np.max(np.abs(a_c + ag))/(wn_c**2*Sd_c) - 1):+.1f} %)")Tn = 0.1 s: Sv = 0.052 vs max|v| = 0.041 m/s (-21 %) Sa = 0.332 vs max|a_total| = 0.334 g (+0.4 %)
Tn = 1.0 s: Sv = 0.386 vs max|v| = 0.355 m/s (-8 %) Sa = 0.247 vs max|a_total| = 0.249 g (+0.5 %)
Tn = 3.0 s: Sv = 0.255 vs max|v| = 0.319 m/s (+25 %) Sa = 0.054 vs max|a_total| = 0.055 g (+0.2 %)
Read the three panels together, and the two limits explain themselves. In the rigid limit the structure is infinitely stiff, so the mass cannot move relative to the base and simply rides with the ground. The relative deformation therefore vanishes, , while the mass’s total acceleration equals the ground’s, so its peak is the peak ground acceleration (PGA), and because approaches that true total acceleration in this limit, PGA. A rigid block feels the full ground shaking. That limit sits to the left of the grid plotted here, which starts at . Within the figure the short-period end is already climbing into the resonant hump, where the structure’s period matches the dominant periods in the shaking and the response is amplified well above the PGA, just as a near-resonant harmonic drive was in Chapter 4. At the opposite, flexible limit of long periods the structure is so soft that the mass, by its inertia, stays nearly still in space while the ground shakes beneath it. The relative deformation then approaches the full sweep of the ground itself, the peak ground displacement (the largest excursion of the ground, obtained by integrating twice in time). So falls away while the deformation keeps growing toward that peak ground displacement.
▶ Interactive: the spectrum assembling itself, period by period
The spectrum is a loop: step the period, solve one SDOF, keep its peak, plot the point, and repeat. The animation runs that loop over 25 periods from 0.1 to 3.0 s. On the left the current oscillator, drawn taller the longer its period, sways under the effective force (green), with its largest swing so far held as a dashed orange outline. On the right the first 20 s of the ground acceleration and of the drift history play together, and the orange band and dot track the peak so far. Below, that peak, as , climbs at the current period and then joins the growing orange curve, drawn over the full spectrum of Figure 5 in gray. The step buttons move one period at a time, and the readout gives and for each oscillator.
The coarse animation grid traces the broad shape of the spectrum but steps over the narrow spike near 0.2 s that the 150-period grid of Figure 5 catches, a reminder that a spectrum is only as detailed as its period grid. The drift histories also show the trade-off read off Figure 5: short periods barely move and long periods drift a lot, while falls as the period grows.
5The effect of damping¶
Damping is the second knob of the spectrum, after the period. More damping bleeds off more energy each cycle, so every peak, and hence the whole spectrum, comes down. Rebuilding the spectra for shows how strongly, and where, damping bites.
zetas = [0.02, 0.05, 0.10]
cols = [sd.PLT[4], sd.PLT[0], sd.PLT[6]]
fig, (axA, axD) = plt.subplots(1, 2, figsize=(9.0, 3.3))
for z, col in zip(zetas, cols):
Sd_z, Sv_z, Sa_z = sd.response_spectrum(ag, dt, periods, zeta=z)
axA.plot(periods, Sa_z / g, color=col, label=rf"$\zeta={z*100:.0f}\%$")
axD.plot(periods, Sd_z * 1000, color=col, label=rf"$\zeta={z*100:.0f}\%$")
print(f"zeta = {z:.2f}: largest Sa = {Sa_z.max()/g:.2f} g at Tn = {periods[np.argmax(Sa_z)]:.2f} s,"
f" Sa at Tn = 0.05 s = {Sa_z[0]/g:.2f} g")
axA.set_ylabel(r"$S_a$ ($g$)"); axA.set_title("pseudo-acceleration")
axD.set_ylabel(r"$S_d$ (mm)"); axD.set_title("deformation")
for ax in (axA, axD):
ax.set_xlabel(r"period $T_n$ (s)")
ax.set_xlim(0, 3.0); ax.set_ylim(bottom=0)
ax.legend()
fig.tight_layout()
plt.show()zeta = 0.02: largest Sa = 0.96 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.48 g
zeta = 0.05: largest Sa = 0.68 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.43 g
zeta = 0.10: largest Sa = 0.50 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.39 g

zeta = 0.02: largest Sa = 0.96 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.48 g
zeta = 0.05: largest Sa = 0.68 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.43 g
zeta = 0.10: largest Sa = 0.50 g at Tn = 0.19 s, Sa at Tn = 0.05 s = 0.39 g

Figure 6:Pseudo-acceleration (left) and deformation (right) spectra at three damping ratios.
The lesson is general: damping is most valuable near resonance, where it clips the tallest spikes. Raising from 2 % to 10 % cuts the tallest , at 0.19 s, from 0.96 g to 0.50 g, nearly in half. At the stiff end of the grid (0.05 s) the same change lowers only from 0.48 g to 0.39 g. In the rigid limit, where the structure rides with the ground, damping has no effect at all, so it helps most for structures whose periods fall on the spectral peaks.
6Toward a smooth design spectrum¶
The spectrum in Figure 5 is jagged because it is the fingerprint of one record. A different earthquake, even at the same site, would put the spikes in different places. You cannot design a building to the accidents of a single accelerogram. Practice instead smooths and idealizes the spectrum into a few straight-line regions, the idea introduced by Newmark and Hall (1982). The three regions are the three behaviors we just read off Figure 5, and their slopes follow from the powers of in (4) together with , which turns those powers of into powers of :
an acceleration-controlled region at short, stiff periods, where is roughly constant at an amplified multiple of the PGA (a flat plateau); only at the very shortest periods does the structure ride with the ground and fall back to the PGA itself;
a velocity-controlled region at intermediate periods, where the pseudo-velocity is roughly constant; since , a flat means ;
a displacement-controlled region at long, flexible periods, where approaches the peak ground displacement and is therefore roughly constant; since , a flat means .
A design spectrum replaces the jagged curve with a smooth envelope through these three regions. Below we sketch the idea: take the actual spectrum, anchor a flat plateau at its short-period level, and let it decay as and then past two corner periods and . The numbers here are illustrative (real codes calibrate the plateau and corners to the site hazard). The shape is the three-branch shape that building codes use, apart from the short ramp from the PGA up to the plateau that codes add at the shortest periods.
Sd5, Sv5, Sa5 = sd.response_spectrum(ag, dt, periods, zeta=0.05)
Sa5_g = Sa5 / g
# --- conceptual Newmark-Hall idealization (illustrative anchors) -----------
S_plateau = 1.15 * np.median(Sa5_g[periods < 0.5]) # acceleration plateau (g)
Tb, Tc = 0.45, 1.1 # corner periods (s)
Sa_design = np.where(
periods <= Tb, S_plateau,
np.where(periods <= Tc,
S_plateau * (Tb / periods), # velocity branch ~ 1/Tn
S_plateau * (Tb / Tc) * (Tc / periods)**2)) # disp branch ~ 1/Tn^2
fig, ax = plt.subplots(figsize=(7.4, 4.0))
ax.loglog(periods, Sa5_g, color="#9aa3ab", lw=1.6, label="single-record spectrum")
ax.loglog(periods, Sa_design, color=sd.PLT[1], lw=2.6, label="smooth design spectrum")
for Tcorner, name in [(Tb, r"$T_b$"), (Tc, r"$T_c$")]:
ax.axvline(Tcorner, color="#c7ccd1", lw=1.0, ls="--")
ax.text(Tcorner, S_plateau * 1.6, name, ha="center", fontsize=12)
# label the three control regions, clear of the curves
box = dict(facecolor="white", edgecolor="none", pad=1.5)
ax.text(0.15, S_plateau * 0.55, "acceleration\ncontrolled", fontsize=10.5, ha="center",
va="center", color=sd.PLT[1], bbox=box)
ax.text(0.62, S_plateau * 0.45, "velocity\ncontrolled", fontsize=10.5, ha="center",
va="center", color=sd.PLT[1], bbox=box)
ax.text(1.55, S_plateau * 0.11, "displacement\ncontrolled", fontsize=10.5, ha="center",
va="center", color=sd.PLT[1], bbox=box)
from matplotlib.ticker import FixedLocator, FixedFormatter, NullLocator
ax.xaxis.set_major_locator(FixedLocator([0.05, 0.1, 0.2, 0.5, 1, 2, 3]))
ax.xaxis.set_major_formatter(FixedFormatter(["0.05", "0.1", "0.2", "0.5", "1", "2", "3"]))
ax.xaxis.set_minor_locator(NullLocator())
ax.yaxis.set_major_locator(FixedLocator([0.03, 0.05, 0.1, 0.2, 0.5, 1.0]))
ax.yaxis.set_major_formatter(FixedFormatter(["0.03", "0.05", "0.1", "0.2", "0.5", "1"]))
ax.yaxis.set_minor_locator(NullLocator())
ax.set_xlabel(r"period $T_n$ (s)")
ax.set_ylabel(r"$S_a$ ($g$)")
ax.set_xlim(0.05, 3.0)
ax.set_ylim(0.025, 1.0)
ax.legend(loc="lower left")
plt.show()

Figure 7:A conceptual smooth design spectrum (orange) over the jagged single-record spectrum (gray) on log-log axes, with its corner periods and .
The smooth curve is what a designer reads: enter at the structure’s period, read , multiply by the mass to get the design base shear via (5). The single-record spectrum was a stepping stone: the method (loop the engine over periods, keep the peaks) is what carries over, and the smoothing turns one record’s accidents into a robust design demand. Codes then add one more step, reducing that elastic demand for structures allowed to yield, which Chapter 7 and Chapter 9 take up.
7The same shaking, the easy way: OpenSeesPy¶
Everything above drove the structure through the effective force p = -m * ag, the Chapter 1 trick of turning base shaking into an
equivalent applied load. That is exactly right, and it is all our NumPy engine
needs. A full finite-element program does the same earthquake analysis in a few
lines, and it is worth seeing now because the very same pattern scales up to a
whole building in Chapter 8.
OpenSeesPy has a load pattern made for base motion: UniformExcitation. You
hand it the ground-acceleration record as a time series and say which direction
shakes; OpenSees then applies the inertial to every mass for you
and reports the relative response directly: there is no -m*ag to assemble
by hand. The model itself is the one-mass-on-a-spring from
Chapter 2; only the loading is new.
import openseespy.opensees as ops
# A 1 s, 5%-damped SDOF: the structure is nothing but mass, spring, dashpot.
m, zeta = 1.0, 0.05
wn = 2 * np.pi / 1.0 # Tn = 1 s
k = m * wn**2
c = 2 * zeta * m * wn
ops.wipe()
ops.model('basic', '-ndm', 1, '-ndf', 1)
ops.node(1, 0.0); ops.fix(1, 1) # fixed base
ops.node(2, 0.0); ops.mass(2, m) # the floor mass
ops.uniaxialMaterial('Elastic', 1, k) # linear spring of stiffness k
ops.element('zeroLength', 1, 1, 2, '-mat', 1, '-dir', 1)
ops.rayleigh(c / m, 0.0, 0.0, 0.0) # mass-proportional damping = c
# --- the base motion: hand OpenSees the record itself, not -m*ag ------------
ops.timeSeries('Path', 1, '-dt', dt, '-values', *map(float, ag))
ops.pattern('UniformExcitation', 1, 1, '-accel', 1) # shake DOF 1 by ag(t)
ops.constraints('Plain'); ops.numberer('Plain'); ops.system('BandGeneral')
ops.test('NormDispIncr', 1e-10, 10); ops.algorithm('Linear')
ops.integrator('Newmark', 0.5, 0.25); ops.analysis('Transient')
u_ops = np.zeros(t.size)
for i in range(t.size - 1):
ops.analyze(1, dt)
u_ops[i + 1] = ops.nodeDisp(2, 1) # relative drift, read out directly
print(f"OpenSees peak drift = {np.max(np.abs(u_ops))*1000:.1f} mm")OpenSees peak drift = 61.4 mm
That is the whole earthquake analysis: build the oscillator, attach a
UniformExcitation, march it with Newmark. To check it, lay it over our NumPy
engine driven by the same record. We solve the NumPy side with the same Newmark
rule (method="newmark") so the only thing that differs between the two is how
the earthquake got in, an assembled -m*ag versus a UniformExcitation pattern.
_, u_np, _, _ = sd.sdof_response(m, c, k, -m * ag, dt, method="newmark")
fig, ax = plt.subplots(figsize=(7.6, 3.0))
ax.plot(t, u_np * 1000, color=sd.PLT[0], lw=2.4, label=r"sd.sdof_response ($-m\,\ddot u_g$)")
ax.plot(t, u_ops * 1000, "--", color=sd.PLT[1], lw=1.6, label="OpenSees UniformExcitation")
ax.axhline(0, color="#9aa3ab", lw=1.0)
ax.set_xlabel(r"time $t$ (s)"); ax.set_ylabel(r"relative drift $u$ (mm)")
ax.set_xlim(0, t[-1]); ax.legend(loc="upper right")
plt.show()
gap = np.max(np.abs(u_ops - u_np)) / np.max(np.abs(u_np)) * 100
print(f"max difference between the two = {gap:.2e} % of the peak")
max difference between the two = 2.46e-11 % of the peak

max difference between the two = 2.46e-11 % of the peak
Figure 8:The relative drift of a 1 s SDOF under the chapter’s ground motion, computed two ways: our NumPy engine fed the effective force (solid), and OpenSeesPy handed the raw record through a UniformExcitation pattern (dashed).
The two traces lie exactly on top of one another, differing by about
10-11 % of the peak: the effective-force route and the UniformExcitation
pattern are solving the identical equation. We have packaged these few lines as
osdof.opensees_sdof_ground(m, c, k, ag, dt), documented in
Appendix A, so that the whole analysis is a
single call. The pattern is more than a tidy convenience, because
UniformExcitation does not care how many degrees of freedom the model carries: attach it to a three-story
frame or a forty-story tower and it shakes every mass by the same ground record,
with no extra bookkeeping. That is exactly how Chapter 8
drives a whole building: the earthquake input you just wrote is already the
MDOF earthquake input.
8Summary¶
A ground motion enters the SDOF equation only through the effective force , (1) and Figure 1; after normalizing, the response depends on the structure through just and , (2).
Running the engine for a few periods (Figure 3) shows flexible structures drifting further and ringing more slowly; the peak of each history is one point on the spectrum.
The response spectrum is built by looping
sd.sdof_responseover a grid of periods and keeping each peak: , with pseudo-velocity and pseudo-acceleration (Figure 4, Figure 5). The base shear is , (5), a quarter of the weight for the 1.0 s building of Example 1.More damping lowers the whole spectrum, most of all at the resonant peaks (Figure 6).
A single-record spectrum is jagged; smoothing it into acceleration-, velocity-, and displacement-controlled regions yields the design spectrum (Figure 7) that codes are built on.
The same earthquake analysis takes only a few lines in OpenSeesPy: a
UniformExcitationpattern feeds the ground record straight to the model and returns the relative drift, matching the NumPy engine to machine precision (Figure 8), and the identical pattern drives a whole building in Chapter 8.
Every spectrum in this chapter assumed the structure stays elastic, that it returns to plumb once the shaking stops. Strong earthquakes rarely grant that luxury: structures yield, and many survive precisely because they do, trading strength for ductility. Chapter 7 lets the spring break that linear promise and watches what happens.