TrussSim.js

September 2015

TrussSim.js is a full-fledged 2D truss stress simulator and optimizer that I wrote as part of one of my university courses. Its a Javascript based application that performs real-time calculations of the stresses in a struss structure.

The Problem

As part of my MTE119 Statics course, I was assigned a group project to design a 2D truss. Given a certain cost per node, and a cost per length of each member, we had to come up with a design capable of supporting a distributed load of about 8kN, whilst also being as cheap as possible.

Performing the hand calculation necessary for solving a single design could last somewhere between 15-30 minutes, and is far more difficult when dealing with non-standard member angles. Rather than spend my time doing that, I decided that whilst working on the project, I'd also spend some spare time writing a simulator to help me do this much faster.

The Solution

I used Javascript and Fabric.JS as my canvassing library to create an interactive app, where the user is able to put in some custom parameters on the structure, draw the truss, and instantly simulate the stresses at each member. There is also a cost calculation that takes into account the total number of nodes and length of each member, and for the purposes of the project a feature to display the coordinates of each drawn node. As the members reach their maximum compressive and tensile strength, their colors change into a darker red and blue respectively. When a member reaches yellow, it's exceeded its maximum forces. This helps in guiding you to where a node should be positioned.

The simulator in use

Internally the calculator worked by mapping all the nodes and members into a huge matrix and solving it (similar to finite element analysis, though I didn't know it back then).

The Optimizer

I had a little bit of time before the submission date to the project to actually create an optimizing feature in the simulator. It works by simply randomly positioning each non-floor node of the structure a certain radius away from its original position, and re-calculated the forces and cost of the bridge. By the end of the optimization after a certain specified interval of time, it'll return a bridge that met its constraints and had the lowest cost. That may sound inefficient, but my laptop can perform about 20,000 iterations of these possible different designs a second! Far better than me dragging nodes until I get what 'feels' right.

The optimizer

The Result

We finished the application 2 days before the final report was due, and came up with a very cheap design that met all the constraints within a few hours. Our design was one if not the most cheapest, and the simulator is expandable enough for me to use in some of my homework assignments. I forked another app from this one called CraneBoom.js that helped me simulate a Mechanics problem for my MTE219 course.

Overall I'm extremely proud of the outcome, and it was a great learning experience. I didn't actually know I could pull it off within the project deadline until I finally did.

Try it Here

Contributors

I would like to thank Chris Gravel who was in my group for helping me with the project. He implemented the import and export feature of the calculator, making it far easier for our group to share possible designs with each other. It was also from his insight that I could debug the calculation algorithm and solve for the final solution.

View on Github