Skip to content

Commit

Permalink
Approaching a reasonable shape solution
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccomb committed Dec 15, 2023
1 parent a158d63 commit 85e10e5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
4 changes: 2 additions & 2 deletions trussme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from trussme.truss import Truss, read_trs
from trussme.physical_properties import MATERIALS
from .truss import Truss, read_trs
from .physical_properties import MATERIALS
64 changes: 61 additions & 3 deletions trussme/member.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
import numpy
import typing
import warnings
from trussme.physical_properties import Material, MATERIALS
from trussme.joint import Joint
from typing import Literal, Union


class Pipe(object):
def __init__(self, r: float, t: float):
self.r: float = r
self.t: float = t

def moi(self) -> float:
return (numpy.pi / 4.) * (self.r ** 4 - (self.r - 2 * self.t) ** 4)

def area(self) -> float:
return numpy.pi * (self.r ** 2 - (self.r - self.t) ** 2)


class Bar(object):
def __init__(self, r: float):
self.r: float = r

def moi(self) -> float:
return (numpy.pi / 4.) * self.r ** 4

def area(self) -> float:
return numpy.pi*self.r**2


class Square(object):
def __init__(self, w: float, h: float):
self.w: float = w
self.h: float = h

def moi(self) -> float:
if self.h > self.w:
return (1./12.)*self.w*self.h**3
else:
return (1./12.)*self.h*self.w**3

def area(self) -> float:
return self.w * self.h

class Box(object):
def __init__(self, w: float, h: float, t: float):
self.w: float = w
self.h: float = h
self.t: float = t

def moi(self) -> float:
if self.h > self.w:
return (1./12.)*(self.w*self.h**3)\
- (1./12.)*(self.w - 2*self.t)*(self.h - 2*self.t)**3
else:
return (1./12.)*(self.h*self.w**3)\
- (1./12.)*(self.h - 2*self.t)*(self.w - 2*self.t)**3

def area(self) -> float:
return self.w*self.h - (self.h - 2*self.t)*(self.w - 2*self.t)


Shape = Union[Pipe, Bar, Square, Box, None]


class Member(object):
Expand All @@ -15,7 +73,7 @@ def __init__(self, joint_a: Joint, joint_b: Joint):
self.idx = -1

# Shape independent variables
self.shape: str = ''
self.shape: Shape = None
self.t: float = 0.0 # thickness
self.w: float = 0.0 # outer width
self.h: float = 0.0 # outer height
Expand Down Expand Up @@ -49,7 +107,7 @@ def __init__(self, joint_a: Joint, joint_b: Joint):
self.set_material(MATERIALS[0], update_props=False)
self.set_parameters(t=0.002, r=0.02, update_props=True)

def set_shape(self, new_shape: typing.Literal["pipe", "bar", "square", "box"], update_props: bool = True):
def set_shape(self, new_shape: Literal["pipe", "bar", "square", "box"], update_props: bool = True):
# Read and save hte shape name
if self.shape_name_is_ok(new_shape):
self.shape = new_shape
Expand Down

0 comments on commit 85e10e5

Please sign in to comment.