gsapy¶
gsapy is a lightweight GSA COM wrapper to allow python programmers to interact with GSA without needing to think about the details of COM programming. It provides python versions of all the COM functions available in GSA, in addition to a few useful additions. It also provides a set of classes for representing, reading and writing GSA modules such as Node, Element, etc…
The full documentation is available at https://docs.oasys-software.com/structural/gsapy/.
Installation¶
gsapy currently is available to Arup staff. You can install as follows:
pip install https://packages.arup.com/gsapy.tar.gz
This will install the latest stable release of gsapy. If a new version is released, running the command again will upgrade your version of gsapy.
Brief Tour / How to use gsapy¶
Start your python code by importing the module
from gsapy import GSA
Open a GSA file. If the file does not exist, it will create a new file when you save.
model = GSA(r'c:\full\path\to\GSA_file.gwb')
Access the model data by calling the appropriate methods.
model.get_nodes() # a dict of the nodes
model.get_members() # a dict of the members
A second, optional parameter allows you to specify what version of GSA to use. You can either specify both parameters in order, or specify the version by name. The version number needs to be a string in the format “Major.Minor”, as below:
model = GSA(r'c:\full\path\to\GSA_101_file.gwb',version="10.2")
You can analyse all the analysis tasks that are not analysed. This will fail silently if an analysis task cannot run.
If you specify a task number, it will analyse just that task (task #2 in this case…). If the task is already analysed, it will return silently
model.analyse()
model.analyse(2)
To update the model, create classes for the data you want to create (Nodes, Elements, etc…) and then call the set() function. You can call set() with either a single object, or an iterable (e.g. list) of objects.
For a list of all the gsapy objects that you can create and add, see the gsapy module reference in the sidebar.
from gsapy import Node
model.set(Node(index=1,coords=[0,0,0],restraints=[1,1,1,0,0,0])
model.set(list_of_nodes)
Warning: if your model has analysis results, the set command will fail silently!
Getting element forces¶
Beams: returns list of tuples of resultant forces
(Fx, Fy, Fz, Mxx, Myy, Mzz
)
2D elements: returns of a list of lists of forces
[NX, NY, NXY, QX, QY]
or a list of tuples of moments
(MX, MY, MXY, |MX + MXY|, |MY + MXY|)
. There is one set of forces or
moments for each position on the element. The GSA API documentation does
not guarantee the order in which the forces are reported, it’s probably
the order of the nodes in the element definition, followed by the centre
values.
Assemblies: returns of list of lists of forces
[position, Fx, Fy, Fz, Mxx, Myy, Mzz]
. The first element in each ‘row’
is the position along the assembly
model.get_1D_elem_resultants(134, # the element number
"C1", # analysis case or combination number
axis="local", # output axis - if omitted, it uses the default axis
addl_pts=10) # additional number of points along the element to output forces, if ommited it defaults to 0
model.get_2D_elem_forces(134, # element number
"A1", # analysis case or combination number
axis="local") # output axis - if omitted, it uses the default axis
model.get_2D_elem_moments(134, # element number
"A1", # analysis case or combination number
axis="local") # output axis - if omitted, it uses the default axis
model.get_assembly_forces(1, # assembly reference
"A1") # output case
Save your changes (including analysis results)
model.save()
Close the model
del model
Getting under the hood¶
All the functions in the GSA COM interface are available through gsapy. The only change is that instead of passing arrays to the functions to be filled up the COM interface, the functions will return those values to you, as you would expect in Python. For example:
model.gsa.IsItemIncluded("ELEMENT",30,"1 to 50")
However, when functions do return values, the data structures are a bit weird (though the GSA API documentation does explain it). If you are going to dig into these functions, please wrap the code that calls it in a python function that cleans up the output, and submit a PR!
Note¶
gsapy is not an official Oasys product: there is an ongoing process to achieve this but in the meantime, the Oasys team may not be able to provide support or quality guarantees.