### 29 releases (12 breaking)

0.13.0 | Oct 29, 2023 |
---|---|

0.11.0 | Oct 23, 2023 |

#**140** in Math

**207** downloads per month

**MIT**license

200KB

942 lines

# QTruss

A simple finite-element solver for 2D trusses.

# Getting Started

## Importing `maria-linalg`

`maria-linalg`

You must import the latest version of the Rust crate

in order to use this package.`maria-linalg`

## Creating a List of Nodes

First, you must construct a list of nodes. Each node must have a location and a constraint type. There are four types of constraints.

. 0 degrees of freedom. An immobile pin joint.`Constraint`Pin`::`

. 2 degrees of freedom. A free joint with an applied`Constraint`Free`::``(`force`)`

of type`force`

. Note that this applied force may be zero.`maria_linalg`Vector`::``<`2`>`

. 1 degree of freedom. A horizontal slider joint with an applied`Constraint`HorizontalSlide`::``(`force`)`

of type`force`

. Note that this applied force may be zero. This joint is free to move in the X direction but cannot move in the Y direction.`maria_linalg`Vector`::``<`2`>`

. 1 degree of freedom. A vertical slider joint with an applied`Constraint`VerticalSlide`::``(`force`)`

of type`force`

. Note that this applied force may be zero. This joint is free to move in the X direction but cannot move in the Y direction.`maria_linalg`Vector`::``<`2`>`

Construct nodes according to the following method.

`use` `maria_linalg``::`Vector`;`
`use` `qtruss``::``{`Constraint`,` Node`}``;`
`//` Note that From<[f64; N]> is implemented for Vector<N>
`let` n0 `=` `Node``::`new`(`
`[``0.``0``,` `1.``0``]``.``into``(``)``,`
`Constraint``::`Pin`,`
`)``;`
`//` Note that From<[f64; N]> is implemented for Vector<N>
`let` n1 `=` `Node``::`new`(`
`[``0.``0``,` `1.``0``]``.``into``(``)``,`
`Constraint``::`HorizontalSlide `(``[``-``1.``0``,` `0.``0``]``.``into``(``)``)``,`
`)``;`

## Constructing a Truss

Once nodes are constructed, place these in an array like so.

`let` nodes `=` `[`
n0`,`
n1`,`
`//` All the nodes
`]``;`

You are now ready to construct your truss. Note that the truss should be

able, as you will add elements later. Additionally, the `mut`

function stores its results inside of the `Truss ::`solve

`Truss`

structure.Note that there are *three generic constants* that must be defined.

. The number of nodes in this truss.`N``:``usize`

. The number of elements in this truss.`K``:``usize`

. The number of`F``:``usize`*degrees of freedom*in this truss. As of the latest version of

, you must compute this manually. Compute this by summing the number of degrees of freedom for each node (see above about`qopt`

).`enum``Constraint`

`let` `mut` truss `=` `Truss``::``<`N, K, F`>``::`new`(`nodes`)``;`

## Creating Elements

Create elements according to the following pattern.

`truss``.``add``(`n0`,` n1`)``;`

This function has two arguments.

. The index in`n0``:``usize`

of the first node to which this element connects.`nodes`

. The index in`n1``:``usize`

of the second node to which this element connects.`nodes`

Note that the area and material of this element will be passed at evaluation time. This allows improved run-time on specific optimization problems.

Call

for every element in your truss.`Truss ::`add

This function returns

. If the provided node numbers are valid, it returns variant `Option``<``usize``>`

with the index of this element. The first call to `Some`

will have index `Truss ::`add

`0`

, the second call index `1`

, and so on. If the provided node numbers are invalid (beyond the range of `nodes`

), this function returns variant `None`

.## Solving the Truss

`let` `(`forces`,` displacements`)` `=` truss`.``solve``(`areas`,` materials`)``.``unwrap``(``)``;`

This function has two arguments.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

. The materials of each element in the truss.`materials``:``[`Material`;`K`]`

## Determining Member Forces

`let` force`:` `Option``<``f64``>` `=` truss`.``internal_force``(`areas`,` materials`,` k`)``;`

This function has three arguments.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

. The materials of each element in the truss.`materials``:``[`Material`;`K`]`

. The index of the desired element. This is determined by the number of calls to`k``:``usize`

. The first call corresponds to`Truss`add`::`

, the second call`k``=``0`

, and so on.`k``=``1`

This function is positive when the element is in tension and negative when the element is in compression.

If

is of variant `force`

, there is something preventing `None`

from solving your truss. Check your `qtruss`

, `N`

, and `K`

values, and ensure that your truss is fully constrained.`F`

## Determining Node Displacements

`let` displacement`:` `Option``<`Vector`<`2`>``>` `=` truss`.``displacement``(`areas`,` materials`,` n`)``;`

This function has three arguments.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

. The materials of each element in the truss.`materials``:``[`Material`;`K`]`

. The index of the desired node in`n``:``usize`

.`nodes`

If

is of variant `displacement`

, there is something preventing `None`

from solving your truss. Check your `qtruss`

, `N`

, and `K`

values, and ensure that your truss is fully constrained.`F`

## Determining Total Truss Compliance

`let` compliance`:` `Option``<``f64``>` `=` truss`.``compliance``(`areas`,` materials`)``;`

This function has two arguments.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

. The materials of each element in the truss.`materials``:``[`Material`;`K`]`

If

is of variant `compliance`

, there is something preventing `None`

from solving your truss. Check your `qtruss`

, `N`

, and `K`

values, and ensure that your truss is fully constrained.`F`

## Determining Truss Volume

`let` volume`:` `f64` `=` truss`.``volume``(`areas`)``;`

This function has one argument.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

## Determining Truss Fabrication Complexity

`let` complexity`:` `f64` `=` truss`.``volume``(`areas`,` maxarea`,` beta`)``;`

This function has three arguments.

. The areas of each element in the truss.`areas``:``[``f64``;`K`]`

. An area standardization term of each element. This should be close to the maximum allowable area.`maxarea``:``f64`

. A term to adjust the regularized Heaviside distribution.`beta``:``f64`

#### Dependencies

~5–16MB

~202K SLoC