Skip to content

Commit

Permalink
Added example
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccomb committed Dec 31, 2023
1 parent 6d3e96d commit 3e0b071
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
31 changes: 30 additions & 1 deletion trussme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
"""
Trussme: A library for truss analysis and design
This library includes some utilities and tools for analyzing and designing truss structures
This library includes some utilities and tools for analyzing and designing truss structures.
Examples
--------
```
import trussme
# Build a small, simple truss
truss = trussme.Truss()
pin = truss.add_pinned_joint([0.0, 0.0, 0.0])
free = truss.add_free_joint([2.5, 2.5, 0.0])
roller = truss.add_roller_joint([5.0, 0.0, 0.0])
truss.add_member(pin, free)
truss.add_member(pin, roller)
truss.add_member(roller, free)
# Add out of plane support and a load
truss.add_out_of_plane_support("z")
truss.joints[1].loads[1] = -10000
# Define goals
goals = trussme.Goals(
minimum_fos_buckling=1.5,
minimum_fos_yielding=1.5,
maximum_mass=5.0,
maximum_deflection=6e-3,
)
# Print results
trussme.print_report(truss, goals)
```
"""

from .components import material_library, Shape, Material, Pipe, Box, Pipe, Bar, Square
Expand Down
20 changes: 19 additions & 1 deletion trussme/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def report_to_str(truss: Truss, goals: Goals) -> str:
str
A full report on the truss
"""
truss.calc_fos()
truss.analyze()

report_string = generate_summary(truss, goals) + "\n"
report_string += generate_instantiation_information(truss) + "\n"
Expand All @@ -34,6 +34,24 @@ def report_to_str(truss: Truss, goals: Goals) -> str:
return report_string


def print_report(truss: Truss, goals: Goals) -> None:
"""
Prints a report on the truss
Parameters
----------
truss: Truss
The truss to be reported on
goals: Goals
The goals against which to evaluate the truss
Returns
-------
None
"""
print(report_to_str(truss, goals))


def report_to_md(file_name: str, truss: Truss, goals: Goals) -> None:
"""
Writes a report in Markdown format
Expand Down
2 changes: 1 addition & 1 deletion trussme/truss.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def set_load(self, joint_index: int, load: list[float]):

self.joints[joint_index].loads = load

def calc_fos(self):
def analyze(self):
loads = numpy.zeros([3, self.number_of_joints])
for i in range(self.number_of_joints):
loads[0, i] = self.joints[i].loads[0]
Expand Down

0 comments on commit 3e0b071

Please sign in to comment.