Skip to content

Commit

Permalink
Getting crazy with properties
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccomb committed Dec 15, 2023
1 parent 4b4cde9 commit 43e1202
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions trussme/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,36 @@ def __init__(self, joint_a: Joint, joint_b: Joint):
self.idx = -1

# Shape independent variables
self.shape: Shape = None
self.shape: Shape = Pipe(t=0.002, r=0.02)

# Material properties
self.material: Material = None
self.material: Material = MATERIALS[0]

# Variables to store information about truss state
self._force: float = 0

# Variable to store location in truss
self.joints = [joint_a, joint_b]

# Calculate properties
self.set_shape(Pipe(t=0.002, r=0.02))
self.set_material(MATERIALS[0])

def set_shape(self, new_shape: Shape):
self.shape = new_shape

def set_material(self, new_material: Material):
# Set material properties
self.material = new_material

@property
def yield_strength(self) -> float:
return self.material["yield_strength"]

@property
def density(self) -> float:
return self.material["density"]

@property
def elastic_modulus(self) -> float:
return self.material["elastic_modulus"]

@property
def moment_of_inertia(self) -> float:
return self.shape.moi()
Expand All @@ -159,7 +167,7 @@ def area(self) -> float:

@property
def linear_weight(self) -> float:
return self.area * self.material["density"]
return self.area * self.density

@property
def length(self) -> float:
Expand All @@ -179,9 +187,9 @@ def force(self, new_force):

@property
def fos_yielding(self) -> float:
return self.material["yield_strength"] / abs(self.force / self.area)
return self.yield_strength / abs(self.force / self.area)

@property
def fos_buckling(self) -> float:
return -((numpy.pi**2)*self.material["elastic_modulus"]*self.moment_of_inertia
return -((numpy.pi**2)*self.elastic_modulus*self.moment_of_inertia
/(self.length**2))/self.force
2 changes: 1 addition & 1 deletion trussme/truss.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def calc_fos(self):
area = []
connections = []
for m in self.members:
elastic_modulus.append(m.material["elastic_modulus"])
elastic_modulus.append(m.elastic_modulus)
area.append(m.area)
connections.append([j.idx for j in m.joints])

Expand Down

0 comments on commit 43e1202

Please sign in to comment.