OpenSees (Open System for Earthquake Engineering Simulation) is an open-source software framework for developing applications to simulate the performance of structural and geotechnical systems subjected to earthquakes. OpenSeesPy is a Python module that provides an interface to OpenSees. This article is a step-by-step guide to using OpenSeesPy on CalcTree, where CalcTree is used as a graphical user interface (GUI) in a cloud environment. Step 1: Set up Input Parameters in CalcTree
Determine the input parameters required for your structural analysis with OpenSeesPy. Common parameters include material properties, geometric dimensions and loads.
In CalcTree, navigate to your page and create the input parameters by typing "/" and selecting "Parameter field" or "Parameter inline". We call these "page parameters".
👉Note, these input parameters are functioning and referenced in our OpenSeesPy Python code. See end of page for results.
Step 2: Add Python Integration to CalcTree
In CalcTree, add a "Code" source using the Integrations panel on the right-hand side of your page.
Step 3: Write CalcTree-Compliant Python Code
Below takes you through an example of a model construction using OpenSees in Python. The code sets up and visualises a 2D frame structure with given input parameters for mass, height, length, moment of inertia and Young's modulus. The structure consists of vertical columns and horizontal beams with fixed base nodes. The model is then visualized using Matplotlib.
👉Note, you can write your code directly in CalcTree, or any programming interface and copy and paste it back into CalcTree.
Importing Libraries
Import the necessary modules into Python for your analysis.
- openseespy.opensees as ops: imports the OpenSeesPy module for structural analysis
- opsvis as opsv: imports the opsvis module for visualizing the OpenSees model
- matplotlib.pyplot as plt: imports Matplotlib for plotting
- numpy as np: imports NumPy for numerical operations
Initialising the Model
- ops.wipe(): clears any existing model data
- ops.model('basic', '-ndm', 2, '-ndf', 3): initializes a 2D model with 3 degrees of freedom per node (2 translations and 1 rotation)
Defining Input Parameters
Use the "_page_" prefix to match input parameters in Python with CalcTree’s page parameters. Assign these to new variables in your script for clarity.
👉Note, the input parameter definition is tailored to CalcTree's interface. All other parts of the model construction can be written in any programming interface.
- m, h, L: input parameters for mass, height and length using parameters defined on your CalcTree page (as per Step 1)
- A: cross-sectional area, assumed as 0.09
- Ic: moment of inertia for columns, converted from mm^4 to m^4
- Ib: moment of inertia for beams, set as 100 times the column inertia
- E: Young's modulus, converted from GPa to Pa
Defining Nodes
- ops.node: defines the coordinates and mass (if applicable) for each node
- Nodes 1 and 2 are the base nodes, with nodes 3 to 8 forming the structure at different heights
Fixing Nodes
- ops.fix: fixes the base nodes (nodes 1 and 2) in all degrees of freedom (x, y, and rotation)
Defining Transformation
- ops.geomTransf('Linear', geomLinear): defines a linear geometric transformation with the ID geomLinear.
Defining Elements
- ops.element('elasticBeamColumn', ...): Defines elastic beam-column elements with given properties and node connectivity.
- Elements 1 to 6 are vertical columns with varying moments of inertia
- Elements 7 to 9 are horizontal beams with moment of inertia Ib
Visualising the Model
- opsv.plot_model(): plots the defined structural model using opsvis
- plt.title: adds a title to the plot
- plt.show(): displays the plot
Step 4: Add Output Python Parameters to CalcTree Page
Your output parameters will appear in the Integrations panel on the right-hand side of your page, in the page parameter list under Code source. To add these to your page, you can simply click and drag them to the page.
This will display the results of your Python code on the page for the user to see.
Here is the output figure from our Python code defined above.
Can’t display the image because of an internal error. Our team is looking at the issue.
This app is now ready to be shared!
Related Resources
- OpenSeesPy vs ETABS: 2D Frame Modal Analysis Comparison