Skip to content

Commit

Permalink
Reasonable shape solution achieved!
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccomb committed Dec 15, 2023
1 parent 804a731 commit 0655f12
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 51 deletions.
2 changes: 1 addition & 1 deletion trussme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .truss import Truss, read_trs
from .member import MATERIALS
from .member import MATERIALS, Shape, Material, Box, Pipe, Bar, Square
4 changes: 2 additions & 2 deletions trussme/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"connections": numpy.ndarray,
"loads": numpy.ndarray,
"reactions": numpy.ndarray,
"area": float,
"elastic_modulus": float
"area": numpy.ndarray,
"elastic_modulus": numpy.ndarray
})


Expand Down
42 changes: 19 additions & 23 deletions trussme/member.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,42 @@
import numpy
import warnings
from trussme.joint import Joint
from typing import Literal, Union, TypedDict
from typing import Union, TypedDict


# Gravitational constant for computing weight from mass
g: float = 9.80665


Material = TypedDict("Material", {
Material = Union[
TypedDict("Material", {
"name": str,
"density": float,
"E": float,
"Fy": float,
})
"elastic_modulus": float,
"yield_strength": float,
}),
None
]


# Material properties
MATERIALS: list[Material] = [
{
"name": "A36_Steel",
"density": 7800.0,
"E": 200*pow(10, 9),
"Fy": 250*pow(10, 6)
"elastic_modulus": 200*pow(10, 9),
"yield_strength": 250*pow(10, 6)
},
{
"name": "A992_Steel",
"density": 7800.0,
"E": 200*pow(10, 9),
"Fy": 345*pow(10, 6)
"elastic_modulus": 200*pow(10, 9),
"yield_strength": 345*pow(10, 6)
},
{
"name": "6061_T6_Aluminum",
"density": 2700.0,
"E": 68.9*pow(10, 9),
"Fy": 276*pow(10, 6)
"elastic_modulus": 68.9*pow(10, 9),
"yield_strength": 276*pow(10, 6)
}
]

Expand Down Expand Up @@ -128,10 +130,7 @@ def __init__(self, joint_a: Joint, joint_b: Joint):
self.shape: Shape = None

# Material properties
self.material: str = '' # string specifying material
self.elastic_modulus: float = 0.0 # Elastic modulus
self.Fy: float = 0.0 # yield strength
self.density: float = 0.0 # material density
self.material: Material = None

# Dependent variables
self.area: float = 0.0 # Cross-sectional area
Expand Down Expand Up @@ -165,10 +164,7 @@ def set_shape(self, new_shape: Shape, update_props: bool = True):

def set_material(self, new_material: Material, update_props: bool = True):
# Set material properties
self.material = new_material["name"]
self.density = new_material["density"]
self.elastic_modulus = new_material["E"]
self.Fy = new_material["Fy"]
self.material = new_material

# If required, update properties
if update_props:
Expand All @@ -194,7 +190,7 @@ def calc_area(self):
self.area = self.shape.area()

def calc_lw(self):
self.LW = self.area * self.density
self.LW = self.area * self.material["density"]

def calc_geometry(self):
self.end_a = self.joints[0].coordinates
Expand All @@ -204,8 +200,8 @@ def calc_geometry(self):

def set_force(self, the_force):
self.force = the_force
self.fos_yielding = self.Fy/abs(self.force/self.area)
self.fos_buckling = -((numpy.pi**2)*self.elastic_modulus*self.I
self.fos_yielding = self.material["yield_strength"]/abs(self.force/self.area)
self.fos_buckling = -((numpy.pi**2)*self.material["elastic_modulus"]*self.I
/(self.length**2))/self.force

def update_joints(self, joint_a, joint_b):
Expand Down
4 changes: 2 additions & 2 deletions trussme/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def print_instantiation_information(f, the_truss, verbose=False):
rows.append(mat["name"])
data.append([
str(mat["density"]),
str(mat["E"]/pow(10, 9)),
str(mat["Fy"]/pow(10, 6))])
str(mat["elastic_modulus"]/pow(10, 9)),
str(mat["yield_strength"]/pow(10, 6))])

pw(f, pandas.DataFrame(data,
index=rows,
Expand Down
47 changes: 24 additions & 23 deletions trussme/truss.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import time
import warnings

import numpy
from numpy.typing import NDArray
from trussme.joint import Joint
from trussme.member import Member, Pipe, Box, Square, Bar, g, Material, MATERIALS
from trussme import report

from trussme import evaluate
import time
import os
import warnings
from trussme import report
from trussme.joint import Joint
from trussme.member import Member, g, Material, MATERIALS, Pipe, Box, Square, Bar


class Truss(object):
Expand All @@ -30,16 +32,16 @@ def __init__(self):
self.fos_yielding: float = 0.0
self.fos_buckling: float = 0.0
self.fos_total: float = 0.0
self.limit_state = ''
self.condition = 0
self.limit_state: str = ''
self.condition: float = 0.0

# Design goals
self.goals = {"min_fos_total": -1,
"min_fos_buckling": -1,
"min_fos_yielding": -1,
"max_mass": -1,
"max_deflection": -1}
self.THERE_ARE_GOALS = False
self.THERE_ARE_GOALS: bool = False

def set_goal(self, **kwargs):
self.THERE_ARE_GOALS = True
Expand All @@ -56,11 +58,11 @@ def set_goal(self, **kwargs):
self.goals["max_deflection"] = kwargs["max_deflection"]
else:
self.THERE_ARE_GOALS = False
raise ValueError(key+' is not a valid defined design goal. '
'Try min_fos_total, '
'min_fos_yielding, '
'min_fos_buckling, '
'max_mass, or max_deflection.')
raise ValueError(key + ' is not a valid defined design goal. '
'Try min_fos_total, '
'min_fos_yielding, '
'min_fos_buckling, '
'max_mass, or max_deflection.')

def add_support(self, coordinates: NDArray[float], d: int = 3):
# Make the joint
Expand All @@ -79,7 +81,7 @@ def add_joint(self, coordinates: NDArray[float], d: int = 3):
def add_member(self, joint_index_a: int, joint_index_b: int):
# Make a member
self.members.append(Member(self.joints[joint_index_a],
self.joints[joint_index_b]))
self.joints[joint_index_b]))

self.members[-1].idx = self.number_of_members

Expand Down Expand Up @@ -114,16 +116,16 @@ def calc_fos(self):
reactions[1, i] = self.joints[i].translation[1]
reactions[2, i] = self.joints[i].translation[2]
loads[0, i] = self.joints[i].loads[0]
loads[1, i] = self.joints[i].loads[1]\
- sum([m.mass/2.0*g for m in self.joints[i].members])
loads[1, i] = self.joints[i].loads[1] \
- sum([m.mass / 2.0 * g for m in self.joints[i].members])
loads[2, i] = self.joints[i].loads[2]

# Pull out E and A
elastic_modulus = []
area = []
connections = []
for m in self.members:
elastic_modulus.append(m.elastic_modulus)
elastic_modulus.append(m.material["elastic_modulus"])
area.append(m.area)
connections.append([j.idx for j in m.joints])

Expand Down Expand Up @@ -237,7 +239,7 @@ def save_truss(self, file_name: str = ""):
f.write("M" + "\t"
+ str(m.joints[0].idx) + "\t"
+ str(m.joints[1].idx) + "\t"
+ m.material + "\t"
+ m.material["name"] + "\t"
+ m.shape.to_str() + "\t")
if str(m.shape.t) != "N/A":
f.write("t=" + str(m.shape.t) + "\t")
Expand All @@ -263,8 +265,8 @@ def read_trs(file_name: str) -> Truss:
truss.materials.append({
"name": info[0],
"density": float(info[1]),
"E": float(info[2]),
"Fy": float(info[3]),
"elastic_modulus": float(info[2]),
"yield_strength": float(info[3]),
})

elif line[0] is "J":
Expand Down Expand Up @@ -295,7 +297,6 @@ def read_trs(file_name: str) -> Truss:
truss.joints[int(info[0])].loads[1] = float(info[2])
truss.joints[int(info[0])].loads[2] = float(info[3])
elif line[0] is not "#" and not line.isspace():
raise ValueError("'" + line[0] +
"' is not a valid line beginner.")
raise ValueError("'" + line[0] + "' is not a valid line initializer.")

return truss

0 comments on commit 0655f12

Please sign in to comment.