OpenSees Cloud
OpenSees AMI
Valid Range of OpenSees Tags
Original Post - 29 Sep 2024 - Michael H. Scott
Visit Structural Analysis Is Simple on Substack.
A few draft blog posts are swirling around the abyss of approximately 80% complete. In need of a diversion, I found a question about tags, posted on the OpenSees Facebook group, to be perfectly timed.
The question was about strange behavior when using large integers for node and element tags. Not many other details were provided, but I knew what they were getting at.
With modern compilers, the tags of node, element, material, and
basically all tagged objects in OpenSees are represented internally as
signed, 32-bit long int
C++ data types.
The first bit is the algebraic
sign and the remaining 31 bits store the magnitude. So, the valid range
for a 32-bit int
is -231 to 231-1, or -2,147,483,648 to 2,147,483,647.
Ten digits, but not all ten digit numbers.
With OpenSeesPy, you can use a tag with more than ten digits and not see an error.
import openseespy.opensees as ops
ops.model('basic','-ndm',1)
tagI = 1234567890
tagJ = 123456789012
ops.node(tagI,0.0)
ops.node(tagJ,1.0)
print(ops.getNodeTags())
But after you print the node tags stored in the OpenSees domain, you will see a strange result.
[-1097262572, 1234567890]
The 12-digit tagJ
overflowed, and was stored as tagJ % -(2**32)
. In
fact, the OpenSeesPy interpreter will accept integers in the range -263
to 263-1 (the 64-bit long long int), but then overflow internally via
mod by -232.
With OpenSees.exe (Tcl), you won’t be able to use a tag outside the range -231 to 231-1. Executing the same commands as shown above, but with Tcl:
model basic -ndm 1
set tagI 1234567890
set tagJ 123456789012
node $tagI 0.0
node $tagJ 1.0
puts [getNodeTags]
You will get the following output:
WARNING invalid nodeTag
Want: node nodeTag? [ndm coordinates?] <-mass [ndf values?]>
integer value too large to represent as non-long integer
while executing
"node $tagJ 1.0"
The interpreter will stop you, saying the 12-digit tag is too large to represent internally.
There’s more details to the valid integer range that I don’t want to get in to because those details are compiler and operating system dependent.
But for practical purposes, whether using OpenSeesPy or OpenSees.exe, keep the tags of your tagged objects between -231 and 231-1.