Like learning another language, not everything in OpenSees, and programming in general, is a direct translation from textbooks. Your mother tongue could be $latex {\bf x} = {\bf A}^{-1}{\bf b}$, but you should never invert the matrix then multiply. Instead, call an equation solver. For small matrices in OpenSees, use A.Solve(b, x) from the Matrix … Continue reading Not Everything Should Be a Direct Translation
Tag: Python
Multi-Threaded SDF Analysis
A previous post showed that, when compared to a couple of brute force approaches, using the sdfResponse command is the most computationally efficient approach to generating an earthquake response spectrum. During an OpenSees Cafe, Dr. Silvia Mazzoni suggested taking a more intelligent approach by "batching" the brute force SDF analyses. Instead of analyzing one oscillator … Continue reading Multi-Threaded SDF Analysis
Single Quotes or Double?
Python, like many other languages, uses single (') and double quotes (") for multi-character strings. This was a bit for me to digest coming from the C++ world where single and double quotes have distinct uses: single quotes for a character and double quotes for strings. Functionally, there's no difference between single and double quotes … Continue reading Single Quotes or Double?
OpenSeesPy List Comprehensions
OpenSees was always meant to be an API and you can use various helper functions like ops.eleResponse() and ops.nodeDisp() to get selected response quantities. You will find, however, that the values returned by these commands are not always congruent with what you want. In many cases, Python list comprehensions give an easy one-liner for morphing … Continue reading OpenSeesPy List Comprehensions
OpenSees to JSON
The plain text JSON format is widely used for moving information to and from back end servers in web applications. So I've been learning how to work with JSON for OpenSees Cloud and a couple other projects. JSON is nothing new in the OpenSees universe. Some element and material classes write key-value pairs when the … Continue reading OpenSees to JSON
OpenSees 12345
In the early 2000s, when the Tcl interpreter was taking shape for OpenSees, Frank used a dummy tag 123456789 to determine if a load pattern had already been defined while parsing the load and sp commands. Here is the 2001 source code for TclModelBuilder.cpp--clearly written by Frank because he does not capitalize anything when he … Continue reading OpenSees 12345
OpenSees Tcl to Python Converter
Although Python is a more popular programming language than Tcl, I suspect Tcl remains the most used language for OpenSees. Python is gaining ground though as it appeals to newer users of OpenSees. I don't have data to back any of this up. To help the transition from Tcl to Python, OpenSeesPy was designed to … Continue reading OpenSees Tcl to Python Converter
Tcl as a Front End for Python
I know I'm not the only one who enjoys converting between scripting languages or between structural analysis programs. I've had fun writing bespoke Tcl middleware between OpenSees and MATLAB, but now OpenSeesPy makes all of that obsolete. But, let's say you have an OpenSees Tcl script that you'd like to run in OpenSeesPy. There's a … Continue reading Tcl as a Front End for Python
Wipe Out!
I am often reminded that what seems basic to me is not so obvious to others who use OpenSees. For example, the wipe command. What it does--and what it does not do--can be confusing. The wipe command clears out the entire OpenSees model domain (nodes, elements, materials, loads, etc.) and analysis options (algorithm, system, etc.). … Continue reading Wipe Out!
How Many Clicks Does It Take?
Coding single degree of freedom (SDF) response in order to generate earthquake response spectra is a rite of passage in earthquake engineering research and education. I wrote my first response spectrum in MATLAB. Nowadays, people are likely to use Python. To generate response spectra in OpenSees, you can create a simple one-dimensional model of SDF … Continue reading How Many Clicks Does It Take?