Most native C++ operations are binary, taking two arguments, e.g., a + b, or unary, taking one argument, e.g., a++. But C++ (and many other languages) has a native "conditional operator", which is ternary, taking three arguments. Known simply as ?:, the conditional operator has the following syntax (condition) ? true_outcome : false_outcome; The conditional … Continue reading My Favorite Ternary Operation
Category: Programming
Not Everything Should Be a Direct Translation
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
Pruning OpenSees
Most OpenSees pull requests add to the code base. Often incremental and sometimes innovative, the new additions keep OpenSees moving forward, offering something for everyone. But it's rare that we remove code. Although it would be great to purge OpenSees of Concrete23 and all its unused variations, to prune code in frequently used OpenSees classes … Continue reading Pruning OpenSees
Sometimes Tags Don’t Matter
When building a model in OpenSees, you have to ensure that you have unique tags for your domain components (nodes, elements, patterns, time series, parameters, etc.), reliability components (random variables, limit state functions, etc.), and model building components (materials, sections, beam integrations, etc.). If you define a duplicate tag, you will get an error message. … Continue reading Sometimes Tags Don’t Matter
How to Profile OpenSees
Where does the time in a nonlinear finite element analysis go? For large models, solving equations dominates the analysis time, while for small to moderate models, constitutive models (state determination) dominate. It is impossible to know the relative cost of state determination and solving equations prior to an analysis. Profiling tools can tell you after … Continue reading How to Profile OpenSees
Don’t Invert the Matrix
A common issue with linear algebra textbooks is the depiction of $latex {\bf x}={\bf A}^{-1}{\bf b}$ as the solution to the linear system of equations $latex {\bf A}{\bf x}={\bf b}$. Find the inverse of the matrix $latex {\bf A}$, then multiply that inverse with the right-hand side vector, $latex {\bf b}$. Theoretically correct? Yes. Practical? … Continue reading Don’t Invert the Matrix
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?
Stop Hogging All the RAM
While writing a previous post on elastic shear beams available in OpenSees, I noticed that the ElasticTimoshenkoBeam3d class stores the element stiffness matrix, along with several other matrices, as private data. As a result, each instance of this class keeps its own copy of several 12x12 matrices for the element response instead of writing to … Continue reading Stop Hogging All the RAM
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