Model#

The Model class is an alternative to the model command in Python that creates an isolated model that is safe from global state corruption. An instance of Model has all of the standard OpenSees modeling commands exposed as methods.

class Model(ndm, ndf=None, group=None, space=None, echo_file=None)#

Create an isolated model for given number of dimensions and number of DOFs.

Parameters:
  • ndm (integer) – number of dimensions

  • ndf (integer) – number of dofs (optional, default ndm*(ndm+1)/2)

  • echo_file (FileLike) – Optional file handle to write command history to. This allows OpenSeesPy scripts to be converted exactly to Tcl. See <serialization> below.

ndm: int#

The number of dimensions in the model.

ndf: int#

The number of degrees-of-freedom at each node.

The Model class prevents inadvertent corruption of global state that may be caused when using the model command that was implemented by older finite element interpreters. Each instance of a Model owns a unique instance of an interpreter which can only be manipulated through the instance itself. This interpreter can be be used from Python to invoke either Tcl or Python commands. These additional commands are described in the subsequent sections.

Examples#

The following examples demonstrate the creation of a Basic model builder that will create nodes with in 2D space (ndm of 2) and with ndf=3 degrees-of-freedom at each node.

import xara
model = xara.Model(ndm=2, ndf=3)

model.node(1, 2.0, 3.0)
...

Serializing OpenSeesPy#

This example demonstrates how run OpenSeesPy scripts with xara, and optionally serialize them to faster Tcl files. Consider the following OpenSeesPy script which builds a truss model:

import openseespy.opensees as ops
# remove existing model
ops.wipe()

# set modelbuilder
ops.model('basic', '-ndm', 2, '-ndf', 2)

# create nodes
ops.node(1,   0.0,  0.0)
ops.node(2, 144.0,  0.0)
ops.node(3, 168.0,  0.0)
ops.node(4,  72.0, 96.0)

# set boundary condition
ops.fix(1, 1, 1)
ops.fix(2, 1, 1)
ops.fix(3, 1, 1)

All that is required to run this with πœ’ara is to change the import on the first line to:

import opensees.openseespy as ops

For more examples, visit the STAIRlab example gallery.

Code Developed by: Claudio M. Perez