Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Throughout the book we used sd.sdof_response, the pure-NumPy engine of Chapter 3, for the forward solve, and we kept an independent OpenSeesPy run nearby as a cross-check (Chapter 2, Chapter 5, Chapter 6). Chapters 7 and 8 build their own OpenSees models on the same pattern. That OpenSees run lives in the tiny helper osdof.py, called as from osdof import opensees_sdof. This appendix opens that helper up and walks through it line by line, then collects the handful of variants you reach for most often. It is a copy-paste reference, not a tutorial: every block below is short, commented, and runs on its own.

OpenSees is a finite-element framework, so even a single mass on a spring is assembled from the same primitives a full building uses: a model, nodes, a material, an element, a pattern of loads, an integrator, and an analysis that marches in time. Building the SDOF by hand is the cleanest way to meet those primitives, because nothing is hidden. The sections below take them in that order, one primitive at a time.

Everything in this appendix needs only NumPy and OpenSeesPy:

11. The model: one fixed node, one mass node

Every analysis starts by wiping any previous state and declaring the model domain. We work in one spatial dimension (-ndm 1) with one degree of freedom per node (-ndf 1): the only motion is translation along the single axis. Node 1 sits at the origin and is fully fixed (the ground); node 2 sits at the same point and carries the mass m. They are coincident because a zeroLength spring will connect them, and its deformation is the difference of their displacements.

mass on node 2 = 2.0 t

The lone DOF lives on node 2, and its displacement is the relative displacement uu of the oscillator, because node 1 never moves. For base excitation we keep node 1 fixed and inject the shaking as an effective force (Section 4); the DOF then reads the response relative to the ground, exactly the quantity that strains the columns.

22. Stiffness: an elastic material on a zeroLength element

The spring is two objects, a material and an element. The uniaxial material defines a force-deformation law, here Elastic, so force is simply kk times deformation. The zeroLength element then ties node 1 to node 2 and assigns that material to act along direction 1 (-dir 1), the only direction there is.

That is the entire structure: a mass on a linear spring to the ground.

33. Damping: Rayleigh, tuned to hit c exactly

OpenSees forms a damping matrix as a Rayleigh combination C=αM M+βK KC = \alpha_M\,M + \beta_K\,K. For a single DOF, M=mM = m and K=kK = k, so a purely mass-proportional choice βK=0\beta_K = 0 gives C=αM mC = \alpha_M\,m. Setting αM=c/m\alpha_M = c/m therefore reproduces our target cc exactly, no approximation:

c = 1.000 kN*s/m  ->  alpha_M = 0.500

The four arguments of rayleigh are αM\alpha_M (mass-proportional), βK\beta_K (current-stiffness-proportional), and two more for initial- and committed-stiffness terms, which we leave at zero.

44. Loading: a force history through a Path time series

A load in OpenSees is a pattern of nodal loads scaled in time by a time series. For an arbitrary force history p(t)p(t) sampled at spacing dt, the Path series carries the values and a Plain pattern applies them to the DOF. The load(2, 1.0) says the spatial load on node 2 is 1.0, scaled by the series, so the series values are the force in kN directly.

Ground motion, the effective-force trick: an earthquake shakes the base, not the roof. The relative-displacement equation of motion (see Chapter 1) is

m u¨+c u˙+k u=− m u¨g(t),m\,\ddot u + c\,\dot u + k\,u = -\,m\,\ddot u_g(t),

so a base acceleration record u¨g\ddot u_g is identical to an effective force peff(t)=−m u¨g(t)p_\text{eff}(t) = -m\,\ddot u_g(t) applied to the fixed-base model. We never move node 1; we just feed −m u¨g-m\,\ddot u_g into the same Path series and the DOF reports the relative response:

peak ground accel = 2.94 m/s^2  ->  peak effective force = 5.89 kN

55. The analysis: build the solver, then march in time

With the model loaded, we assemble the analysis from one object of each kind. Each line below picks how a piece of the solve is done; for a linear SDOF the choices are the standard, robust defaults:

The heart is integrator('Newmark', 0.5, 0.25): Newmark’s average-acceleration rule (γ=12\gamma=\tfrac12, β=14\beta=\tfrac14), which is unconditionally stable and second-order accurate (the workhorse of nonlinear time-history analysis) and the same scheme sd.newmark implements in NumPy. The algorithm('Linear') does one solve per step because the system is linear; the nonlinear model of Chapter 7 swaps in algorithm('Newton') to iterate.

We then march: call analyze(1, dt) to advance one step of size dt, and read the state off the DOF with nodeDisp / nodeVel / nodeAccel after each step; analyze returns 0 on success.

analyze flag: 0  u after one step: 0.0

66. Initial conditions: a nudge for free vibration

For free vibration we impose an initial displacement and/or velocity on the DOF before the time march, with setNodeDisp / setNodeVel. The -commit flag writes the value into the committed state so the integrator starts from it. We also commit the dynamically consistent initial acceleration a0=(p0−c v0−k u0)/ma_0=(p_0-c\,v_0-k\,u_0)/m: without it Newmark begins from a0=0a_0=0 and injects a spurious first-step transient, an O(Δt)O(\Delta t) error that would otherwise swamp the true (much smaller) period-elongation error:

ops.setNodeDisp(2, 1, u0, '-commit')              # initial displacement u0 on node 2
ops.setNodeVel(2, 1, v0, '-commit')               # initial velocity v0
ops.setNodeAccel(2, 1, -(c*v0 + k*u0)/m, '-commit')   # consistent a0 (here p0 = 0)

That is the last primitive, and Sections 1 to 6 together are the whole of the basic opensees_sdof helper: model, mass, spring, Rayleigh damping, a (zero) load pattern, the Newmark analysis, and the initial nudge. (osdof.py builds three more on the same skeleton: opensees_sdof_ground for base motion via UniformExcitation, and opensees_mdof_eigen / opensees_mdof_ground for the multi-story building of Chapter 8.)

7A complete, verified example: free-vibration decay

Let us assemble all six pieces into one runnable script and check it against theory. We release a 2 t / 50 kN/m frame with 5 % damping from a 20 mm nudge and let it ring. Free vibration with u0u_0 and u˙0=0\dot u_0 = 0 has the closed-form solution (from Chapter 2)

u(t)=e−ζωnt(u0cos⁡ωdt+ζωnωd u0sin⁡ωdt),u(t) = e^{-\zeta\omega_n t}\Big(u_0\cos\omega_d t + \tfrac{\zeta\omega_n}{\omega_d}\,u_0\sin\omega_d t\Big),

where ωd=ωn1−ζ2\omega_d=\omega_n\sqrt{1-\zeta^2} is the damped natural frequency (returned as p["wd"] by sd.natural below). The peaks of the response lie on the exponential envelope ±u0 e−ζωnt\pm u_0\,e^{-\zeta\omega_n t}, so the OpenSees peaks should touch it.

Tn = 1.257 s,  built 1200 steps at dt = 5 ms

Now overlay the analytic solution and its envelope, and report the error.

<Figure size 988x416 with 1 Axes>
max OpenSees-vs-analytic error = 0.04 % of the initial nudge
<Figure size 988x416 with 1 Axes>
max OpenSees-vs-analytic error = 0.04 % of the initial nudge

Figure 1:OpenSeesPy free-vibration decay (solid) of the 2 t / 50 kN/m / 5 %-damped frame, released from a 20 mm nudge, against the analytic damped solution (dashed) and its ±u0e−ζωnt\pm u_0 e^{-\zeta\omega_n t} envelope (dotted).

The trace hugs the analytic curve and touches the envelope at every peak. The small gap that remains, 0.04 % of the nudge at most, is not a modeling error: OpenSees marches with Newmark, which elongates the period slightly at finite Δt\Delta t, while the analytic solution is exact. That period error is O(Δt2)O(\Delta t^2) and accumulates as a growing phase lag, so the gap shrinks quadratically, and halving Δt\Delta t should cut it to a quarter, as the last cell of this section confirms. This is the very gap Chapter 2 and Chapter 3 discuss when comparing the exact matrix-exponential stepper of sd.sdof_response to a Newmark march. (Committing the consistent initial acceleration in Section 6 is what keeps this residual at the genuine O(Δt2)O(\Delta t^2) period-elongation floor rather than an O(Δt)O(\Delta t) start-up transient.)

Finally, confirm that this hand-built script and the packaged opensees_sdof helper are the same thing; they should agree to machine precision:

hand-built vs osdof.opensees_sdof : 0.00e+00 % of u0

With the helper in hand, halving the time step takes one more call:

error at dt = 5.0 ms: 0.0384 % of u0;   at dt = 2.50 ms: 0.0096 % of u0   (ratio 4.00)

The error falls from 0.038 % to 0.0096 % of the nudge, a ratio of 4.0, the signature of a second-order method. An error left over from a wrong starting acceleration would only have halved. The same factor of four appeared in Chapter 2, where the OpenSees march was compared with the exact NumPy stepper.

8Quick reference

The whole linear 1-D dynamics workflow, in the order you build it:

StepCallPurpose
Domainmodel('basic','-ndm',1,'-ndf',1)1-D, 1 DOF/node
Nodesnode(1,0.); fix(1,1) / node(2,0.); mass(2,m)ground + mass
SpringuniaxialMaterial('Elastic',1,k) + element('zeroLength',...,'-dir',1)stiffness k (or Steel01 for yielding)
Dampingrayleigh(c/m, 0., 0., 0.)exact c for the SDOF
LoadtimeSeries('Path',...,'-dt',dt,'-values',*p) + pattern('Plain',...) + load(2,1.)force history p(t) (use -m*ag for quakes)
Solverconstraints/numberer/system/test/algorithm + integrator('Newmark',0.5,0.25) + analysis('Transient')assemble the time-stepper
InitialsetNodeDisp(2,1,u0,'-commit') / setNodeVel(2,1,v0,'-commit')free-vibration nudge
Marchanalyze(1,dt) then nodeDisp/nodeVel/nodeAccel(2,1)step and read response

For everyday cross-checks you do not need to retype any of this: just from osdof import opensees_sdof and call opensees_sdof(m, c, k, p, dt, u0=0, v0=0), which returns t, u, v, a and is documented above line by line. For base motion, opensees_sdof_ground(m, c, k, ag, dt) takes the acceleration record directly. Appendix B lists all four helpers with their arguments.