PEER logo
  • Examples 
  •  

Linear Truss

4 min read • 684 words
Truss   Python   Tcl  
Truss   Python   Tcl  

A finite element model of a simple truss is created, and static analysis is performed.

On this page
Model   Loads   Analysis   Output  
Python Tcl
  • truss.py
  • truss.ipynb
  • Example1.tcl

This example is of a linear-elastic three bar truss, as shown in the figure above, subject to static loads.

The analysis consists of three steps:

  1. Build a representation of the structural model
  2. Define a set of loads
  3. Perform the analysis

Model  

We begin the simulation by creating a Model  , which will manage the nodes, materials, and elements. This is done through either Python or Tcl as follows:

Python Tcl
import xara

model = xara.Model(ndm=2, ndf=2)
model -ndm 2 -ndf 2

where we’ve specified 2 for the spatial dimension ndm, and 2 for the number of degrees of freedom ndf.

Next we define the four nodes of the structural model by specifying a tag which identifies the node, and coordinates in the x−yx-y plane. In general, the node constructor must be passed ndm coordinates.

Python Tcl
#         tag     X     Y
model.node(1, (  0.0,  0.0))
model.node(2, (144.0,  0.0))
model.node(3, (168.0,  0.0))
model.node(4, ( 72.0, 96.0))
#   tag  X    Y
node 1   0.0  0.0;
node 2 144.0  0.0;
node 3 168.0  0.0;
node 4  72.0 96.0;

The restraints are now defined at the nodes with reactions (ie, nodes 1, 2, and 3). The restraints at the nodes with reactions (ie, nodes 1, 2, and 3) are then defined. This is done with the fix  method, whose first argument is an integer node tag and second argument a tuple containing a 1 or 0 for degree of freedom at the node.

Python Tcl
# set the boundary conditions
#    nodeID   x  y
model.fix(1, (1, 1))
model.fix(2, (1, 1))
model.fix(3, (1, 1))
# Set the boundary conditions
#  tag  X  Y
fix 1   1  1;
fix 2   1  1;
fix 3   1  1;

Since the truss elements have the same elastic properties, a single Elastic material is defined. The first argument assigns the tag 1 to the material, and the second specifies a Young’s modulus of 3000.

Python Tcl
# Create Elastic material prototype
model.uniaxialMaterial("Elastic", 1, 3000)
# Create Elastic material prototype
uniaxialMaterial Elastic 1 3000;

Finally, define the elements. The syntax for creating the truss element requires the following arguments:

  1. the element name, in this case always "Truss",
  2. the element tag, in this case 1 through 3,
  3. the nodes that the element is connected to,
  4. the cross-sectional area, in this case 10.0 for element 1 and 5.0 for elements 2 and 3.
  5. the tag of the material assigned to the element, in this case always 1
Python Tcl
# Define materials
model.material("Elastic", 1, E=3000.0, nu=0.3)

# Define sections, referencing material 1
model.section("Truss", 1, A=10.0, material=1)
model.section("Truss", 2, A=5.0,  material=1)
material Elastic 1 -E 3000.0 -nu 0.3

section Truss 1 -A 10.0 -material 1
section Truss 2 -A  5.0 -material 1
Python Tcl
model.element("Truss", 1, (1, 4), section=1)
model.element("Truss", 2, (2, 4), section=2)
model.element("Truss", 3, (3, 4), section=2)
element Truss 1  1 4  -section 1;
element Truss 2  2 4  -section 2;
element Truss 3  3 4  -section 2;

Loads  

The final step before we can configure and run the analysis is to define some loading. In this case we have two point loads at the apex of the truss (node 4). In OpenSees, loads are assigned to load patterns, which define how loads are scaled with each load step.

In Python, the simplest way to represent a nodal load is by a dictionary with node numbers as keys, and corresponding load vector as values. For the problem at hand, we want to apply a load to node 4 with 100 units in the xx direction, and -50 units in the yy direction; the corresponding definition is:

Python Python(Legacy) Tcl
loads = xara.NodalLoad({4: [100, -50]})
loads = {4: [100, -50]}
model.pattern("Plain", 1, "Constant", load=loads)
set loads {4 100 -50}
pattern Plain 1 "Constant" "load $loads"

Analysis  

Python Python(Legacy) Tcl
xara.solve(model, loads)
model.integrator("LoadControl", 1.0)
model.analysis("Static")
model.analyze(1)
integrator LoadControl 1.0;
analysis Static;
analyze 1

Output  

When the analysis is complete the state of node 4 obtained using nodeDisp  and printed to the screen:

Python Tcl
u4 = model.nodeDisp(4)
print(u4)
print node 4
print ele

The output looks like:

u4 = [0.5300927771322836, -0.1778936384693177]
Orienting frames in 3D 
On this page:
Model   Loads   Analysis   Output  
Linear Truss
Linear Truss
A gallery of technical examples using OpenSees.
Code licensed BSD, docs CC BY-NC 4.0
 
Links
Home 
Examples
Working with solids 
Nonlinear dynamics 
Basic Statics 
Community
Issues   
Discussions   
Contribute 
PEER
Code copied to clipboard