One of the best examples of “offline” calculations you can easily avoid in OpenSees is Rayleigh damping coefficients. I’ve seen people hard code the mass and stiffness proportional damping coefficients in their OpenSees scripts, after computing said coefficients in another software, e.g., MATLAB, or on paper.
Inevitably, it becomes difficult to keep your OpenSees model and offline calculations synced up. But with just a few lines of code, you can compute the Rayleigh damping coefficients directly in your Python script and keep Rayleigh damping in sync with your model.
After defining your model, compute its eigenvalues (natural frequencies), then set up a 2×2 matrix and right-hand side vector according to Equation (11.4.9) in Chopra, 5th edition.
# # Define your model # Nmodes = 4 # or whatever w2 = ops.eigen(Nmodes) # Pick your modes and damping ratios wi = w2**0.5; zetai = 0.05 # 5% in mode 1 wj = w2**0.5; zetaj = 0.02 # 2% in mode 3 A = np.array([[1/wi, wi],[1/wj, wj]]) b = np.array([zetai,zetaj]) x = np.linalg.solve(A,2*b) # M KT KI Kn ops.rayleigh(x,0.0,0.0,x)
I put the stiffness proportional damping coefficient on the last committed stiffness. The OpenSees wiki page on Rayleigh damping has a couple references explaining the pros and cons of current, initial, or last committed stiffness proportional damping.
At any rate, using
np.linalg.solve is overkill for two simultaneous equations. A 2×2 matrix is easy enough to invert in closed form using the determinant and the adjoint.