SAWP20 / code /20.py
Certifiedloverboy
Add SAWP-20 benchmark dataset with ground truth code solutions, schematics, and problem descriptions
be06037
# Parameters configuration
import openseespy.opensees as ops # Import OpenSeesPy for structural analysis
import opsvis as opsv # Import opsvis for visualization
import matplotlib.pyplot as plt # Import Matplotlib for plotting
ops.wipe() # Clear any existing model
ops.model('basic', '-ndm', 2, '-ndf', 3) # Define a 2D model with 3 degrees of freedom per node (DOF)
# Column and girder lengths
colL, girL = 4.0, 6.0
# Section properties: cross-sectional area (A) and moment of inertia (Iz)
Acol, Agir = 2.0e-3, 6.0e-3
IzCol, IzGir = 1.6e-5, 5.4e-5
# Young's modulus (E)
E = 2.0e11
# Define the material property dictionary for columns, girders, and cantilever beams
Ep = {
1: [E, Acol, IzCol], # Column element 1
2: [E, Acol, IzCol], # Column element 2
3: [E, Agir, IzGir], # Girder element
4: [E, Agir, IzGir], # Left cantilever beam
5: [E, Agir, IzGir] # Right cantilever beam
}
# Define the node coordinates
ops.node(1, 0, 0) # Node 1 at (0, 0)
ops.node(2, 0, colL) # Node 2 at (0, colL)
ops.node(3, girL, 0) # Node 3 at (girL, 0)
ops.node(4, girL, colL) # Node 4 at (girL, colL)
ops.node(5, -colL, colL) # Node 5 at (-colL, colL) for left cantilever
ops.node(6, girL + colL, colL) # Node 6 at (girL + colL, colL) for right cantilever
# Define boundary conditions (supports)
ops.fix(1, 1, 1, 1) # Fix all 3 DOFs (x, y, rotation) for node 1
ops.fix(3, 1, 1, 1) # Fix all 3 DOFs (x, y, rotation) for node 3
# Plot the model before defining elements
opsv.plot_model()
# Add title
plt.title('plot_model before defining elements')
# Define transformation type for elements (Linear)
ops.geomTransf('Linear', 1) # Transformation ID 1 for linear transformation
# Define column and girder elements (elastic beam-column elements)
ops.element('elasticBeamColumn', 1, 1, 2, Acol, E, IzCol, 1) # Column element 1 between nodes 1 and 2
ops.element('elasticBeamColumn', 2, 3, 4, Acol, E, IzCol, 1) # Column element 2 between nodes 3 and 4
ops.element('elasticBeamColumn', 3, 2, 4, Agir, E, IzGir, 1) # Girder element between nodes 2 and 4
ops.element('elasticBeamColumn', 4, 5, 2, Agir, E, IzGir, 1) # Left cantilever beam between nodes 5 and 2
ops.element('elasticBeamColumn', 5, 4, 6, Agir, E, IzGir, 1) # Right cantilever beam between nodes 4 and 6
# Define external loads
Wy = -10e3 # Uniformly distributed load in the y-direction
# Create a dictionary to store element loads
Ew = {
3: ['-beamUniform', Wy, 0], # Girder element has a uniform distributed load
4: ['-beamUniform', Wy, 0], # Left cantilever beam has a uniform distributed load
5: ['-beamUniform', Wy, 0] # Right cantilever beam has a uniform distributed load
}
# Define time series for constant loads
ops.timeSeries('Constant', 1)
# Define load pattern using the constant time series
ops.pattern('Plain', 1, 1)
# Applying distributed loads
for etag in Ew:
ops.eleLoad('-ele', etag, '-type', Ew[etag][0], Ew[etag][1], Ew[etag][2])
# Analysis settings
ops.constraints('Transformation') # Apply transformation constraints
ops.numberer('RCM') # Renumber the nodes using Reverse Cuthill-McKee (RCM)
ops.system('BandGeneral') # Define the solution algorithm
ops.test('NormDispIncr', 1.0e-6, 6, 2) # Convergence test criteria
ops.algorithm('Linear') # Use linear algorithm for solving
ops.integrator('LoadControl', 1) # Control load increments
ops.analysis('Static') # Define a static analysis
ops.analyze(1) # Perform the analysis
# Print the model data
ops.printModel()
# Plot the model after defining elements
opsv.plot_model()
plt.title('plot_model after defining elements')
# Plot the applied loads on the model in 2D
opsv.plot_loads_2d(nep=10, # Number of points along each element
sfac=1, # Scale factor for loads
fig_wi_he=(10, 5), # Width and height of the figure
fig_lbrt=(0.1, 0.1, 0.9, 0.9), # Left, bottom, right, top margins
fmt_model_loads={'color': 'red', 'linewidth': 1.5}, # Formatting for load arrows
node_supports=True, # Display node supports
truss_node_offset=0.05, # Offset for truss elements
ax=None) # Matplotlib axis, None to use current axis
# Plot deformations (scaled) after analysis
opsv.plot_defo()
# Plot internal force diagrams: N (axial), V (shear), M (moment)
sfacN, sfacV, sfacM = 5.e-5, 5.e-5, 5.e-5 # Scale factors for internal force diagrams
# Plot axial force distribution
opsv.section_force_diagram_2d('N', sfacN)
plt.title('Axial force distribution')
# Plot shear force distribution
opsv.section_force_diagram_2d('T', sfacV)
plt.title('Shear force distribution')
# Plot bending moment distribution
opsv.section_force_diagram_2d('M', sfacM)
plt.title('Bending moment distribution')
# Show all plots
plt.show()
# Exit the program
exit()