# The Method of Joints: Part 2

See Part 1.

With the theory established, the python script was simple enough to write. Prior to this project I hadn’t used numpy before, but after seeing some examples online involving matrix operations, I figured numpy was the perfect tool.

The script is split into 9 major steps:

- Read data from the input files
- Construct the members table, filled with the coefficients and
- Construct the coefficient matrix and the vector of applied forces
- Solve the matrix equation!
- Find the maximum safe load for the truss
- Present the results

All the relevant data are kept in a few separate files, which are imported into some `ndarray`

s:

`joints.in`

: containing the (x,y) coordinates of each numbered joint, in mm`members.in`

: a list of members with their two associated joints`supports.in`

: the two supported joints and whether it is a pin or roller support`applied.in`

: the forces applied to the truss, and their locations`material.in`

: the physical properties of the material we’re using

The first four use `numpy.genfromtxt()`

to form their arrays, but `material.in`

is imported into a dictionary:

material = {} with open(inpath+'material.in', 'r') as fin: for line in fin: if (line[0] != '#'): spl = line.split() if len(spl)==2: (key, value) = spl material[key] = float(value)

This way the material properties can be accessed easily, for example the Young’s modulus is `material['E']`

The members table initially has three columns: the member number, the number of joint , and the number of joint . The table is extended with a few empty columns, which are filled in with the relevant geometric properties of the member (taken from the (x,y) coordinates of it’s two joints): , , , , .

Constructing is pretty much as described in Part 1: the and values for each member are inserted in the appropriate place, and then the coefficients for the reaction forces are added in to the final three columns. These coefficients are 1 as they’re aligned with the axes. The applied forces are inserted into a vector “”

Solving the matrix equation is the easy part and it’s why I chose numpy in the first place:

Q = numpy.linalg.solve(C,P)

I’ve been setting up the applied forces to sum to 1, so now contains the portion of the load which is carried by each member. For example if Q[3] = -0.707, this means member #3 is carrying a compressive force of 0.707*(Load).

The maximum load for the truss as a whole is found by iterating through the members and finding the maximum load for the bridge before that member fails, then taking the lowest of these failure limits. This isn’t a rigorous analysis and only yielding and Euler buckling are accounted for, but that’s good enough for a bridge made of plastic straws:

maxL_t = np.zeros([members.shape[0],3]) maxL = 1e6 for k in range(members.shape[0]): if Q[k] != 0: # yield: F/A <= (safety factor) * s_y maxL_t[k,0] = material['sf'] * material['s_y'] * material['A'] / abs(Q[k]) # buckling: F <= (safety factor) * pi^2 * E * I / l^2 if Q[k] < 0: maxL_t[k,1] = material['sf'] * numpy.pi**2 * material['E'] * material['I'] \ / (abs(Q[k]) * members[k,5]**2) # which is the smaller limit? maxL_t[k,2] = min(maxL_t[k,0], maxL_t[k,1]) else: maxL_t[k,2] = maxL_t[k,0] if maxL_t[k,2] < maxL: maxL = maxL_t[k,2]

And with that the analysis is complete. I’ve set up two modes of output: a plaintext mode, where the results are sent straight to a text file; and a presentation mode, where matplotlib is used to draw the bridge and the results are written to an .html page like this one!

## Recent Comments