Skip to content

Commit

Permalink
Translation is now logical
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccomb committed Dec 16, 2023
1 parent a67b248 commit 5d11a63
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
4 changes: 4 additions & 0 deletions trussme/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def the_forces(truss_info: TrussInfo) -> tuple[NDArray[float], NDArray[float], N
[numpy.size(truss_info["reactions"], axis=0), numpy.size(truss_info["reactions"], axis=1)])
dof: numpy.ndarray = numpy.zeros([3 * w[1], 3 * w[1]])
deflections: numpy.ndarray = numpy.ones(w)
print("deflections")
print(deflections)
print("reactions")
print(truss_info["reactions"])
deflections -= truss_info["reactions"]

# This identifies joints that can be loaded
Expand Down
16 changes: 8 additions & 8 deletions trussme/joint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class Joint(object):

def __init__(self, coordinates: list[float]):
# Save the joint id
self.idx = -1
self.idx: int = -1

# Coordinates of the joint
self.coordinates = coordinates

# Allowed translation in x, y, and z
self.translation = numpy.ones([3, 1])
self.translation = [True, True, True]

# Loads
self.loads: list[float] = [0.0, 0.0, 0.0]
Expand All @@ -28,20 +28,20 @@ def __init__(self, coordinates: list[float]):
self.deflections = numpy.zeros([3, 1])

def free(self, d: int = 3):
self.translation = numpy.zeros([3, 1])
self.translation = [False, False, False]
# If 2d, add out of plane support
if d is 2:
self.translation[2] = 1
self.translation[2] = True

def pinned(self, d: int = 3):
# Restrict all translation
self.translation = numpy.ones([3, 1])
self.translation = [True, True, True]

def roller(self, axis: Literal["x", "y"] = 'y', d: int = 3):
# Only support reaction along denoted axis
self.translation = numpy.zeros([3, 1])
self.translation[ord(axis)-120] = 1
self.translation = [False, False, False]
self.translation[ord(axis)-120] = True

# If 2d, add out of plane support
if d is 2:
self.translation[2] = 1
self.translation[2] = True
24 changes: 12 additions & 12 deletions trussme/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
class Shape(abc.ABC):
@abc.abstractmethod
def __init__(self):
self.w = "N/A"
self.h = "N/A"
self.t = "N/A"
self.r = "N/A"
self.w = None
self.h = None
self.t = None
self.r = None

@abc.abstractmethod
def moi(self) -> float:
Expand All @@ -66,8 +66,8 @@ class Pipe(Shape):
def __init__(self, r: float = 0.0, t: float = 0.0):
self.r: float = r
self.t: float = t
self.w = "N/A"
self.h = "N/A"
self.w = None
self.h = None

def moi(self) -> float:
return (numpy.pi / 4.) * (self.r ** 4 - (self.r - 2 * self.t) ** 4)
Expand All @@ -82,9 +82,9 @@ def name(self) -> str:
class Bar(Shape):
def __init__(self, r: float = 0.0):
self.r: float = r
self.w = "N/A"
self.h = "N/A"
self.t = "N/A"
self.w = None
self.h = None
self.t = None

def moi(self) -> float:
return (numpy.pi / 4.) * self.r ** 4
Expand All @@ -100,8 +100,8 @@ class Square(Shape):
def __init__(self, w: float = 0.0, h: float = 0.0):
self.w: float = w
self.h: float = h
self.t = "N/A"
self.r = "N/A"
self.t = None
self.r = None

def moi(self) -> float:
if self.h > self.w:
Expand All @@ -121,7 +121,7 @@ def __init__(self, w: float = 0.0, h: float = 0.0, t: float = 0.0):
self.w: float = w
self.h: float = h
self.t: float = t
self.r = "N/A"
self.r = None

def moi(self) -> float:
if self.h > self.w:
Expand Down
18 changes: 9 additions & 9 deletions trussme/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def print_instantiation_information(f, the_truss, verbose=False):
data.append([str(j.coordinates[0]),
str(j.coordinates[1]),
str(j.coordinates[2]),
str(bool(j.translation[0][0])),
str(bool(j.translation[1][0])),
str(bool(j.translation[2][0]))])
str(j.translation[0]),
str(j.translation[1]),
str(j.translation[2])])

pw(f, pandas.DataFrame(data,
index=rows,
Expand Down Expand Up @@ -182,11 +182,11 @@ def print_stress_analysis(f, the_truss, verbose=False):
for j in the_truss.joints:
rows.append("Joint_"+"{0:02d}".format(j.idx))
data.append([format(j.reactions[0][0]/pow(10, 3), '.2f')
if j.translation[0][0] != 0.0 else "N/A",
if j.translation[0] != 0.0 else "N/A",
format(j.reactions[1][0]/pow(10, 3), '.2f')
if j.translation[1][0] != 0.0 else "N/A",
if j.translation[1] != 0.0 else "N/A",
format(j.reactions[2][0]/pow(10, 3), '.2f')
if j.translation[2][0] != 0.0 else "N/A"])
if j.translation[2] != 0.0 else "N/A"])

pw(f, pandas.DataFrame(data,
index=rows,
Expand Down Expand Up @@ -223,11 +223,11 @@ def print_stress_analysis(f, the_truss, verbose=False):
for j in the_truss.joints:
rows.append("Joint_"+"{0:02d}".format(j.idx))
data.append([format(j.deflections[0][0]*pow(10, 3), '.5f')
if j.translation[0][0] == 0.0 else "N/A",
if j.translation[0] == 0.0 else "N/A",
format(j.deflections[1][0]*pow(10, 3), '.5f')
if j.translation[1][0] == 0.0 else "N/A",
if j.translation[1] == 0.0 else "N/A",
format(j.deflections[2][0]*pow(10, 3), '.5f')
if j.translation[2][0] == 0.0 else "N/A"])
if j.translation[2] == 0.0 else "N/A"])

pw(f, pandas.DataFrame(data,
index=rows,
Expand Down
19 changes: 9 additions & 10 deletions trussme/truss.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def calc_fos(self):
"elastic_modulus": numpy.array([member.elastic_modulus for member in self.members]),
"coordinates": numpy.array([joint.coordinates for joint in self.joints]).T,
"connections": numpy.array([[j.idx for j in member.joints] for member in self.members]).T,
"reactions": numpy.array([list(joint.translation.flatten()) for joint in self.joints]).T,
"reactions": numpy.array([joint.translation for joint in self.joints]).T,
"loads": loads,
"area": numpy.array([member.area for member in self.members])
}
Expand Down Expand Up @@ -206,9 +206,9 @@ def save_truss(self, file_name: str):
+ str(j.coordinates[0]) + "\t"
+ str(j.coordinates[1]) + "\t"
+ str(j.coordinates[2]) + "\t"
+ str(j.translation[0, 0]) + "\t"
+ str(j.translation[1, 0]) + "\t"
+ str(j.translation[2, 0]) + "\n")
+ str(int(j.translation[0])) + "\t"
+ str(int(j.translation[1])) + "\t"
+ str(int(j.translation[2])) + "\n")
if numpy.sum(j.loads) != 0:
load_string += "L" + "\t"
load_string += str(j.idx) + "\t"
Expand All @@ -224,13 +224,13 @@ def save_truss(self, file_name: str):
+ str(m.joints[1].idx) + "\t"
+ m.material["name"] + "\t"
+ m.shape.name() + "\t")
if str(m.shape.t) != "N/A":
if m.shape.t:
f.write("t=" + str(m.shape.t) + "\t")
if str(m.shape.r) != "N/A":
if m.shape.r:
f.write("r=" + str(m.shape.r) + "\t")
if str(m.shape.w) != "N/A":
if m.shape.w:
f.write("w=" + str(m.shape.w) + "\t")
if str(m.shape.h) != "N/A":
if m.shape.h:
f.write("h=" + str(m.shape.h) + "\t")
f.write("\n")

Expand All @@ -256,8 +256,7 @@ def read_trs(file_name: str) -> Truss:
elif line[0] == "J":
info = line.split()[1:]
truss.add_joint([float(x) for x in info[:3]])
truss.joints[-1].translation = numpy.array(
[[int(x)] for x in info[3:]])
truss.joints[-1].translation = [bool(int(x)) for x in info[3:]]
elif line[0] == "M":
info = line.split()[1:]
truss.add_member(int(info[0]), int(info[1]))
Expand Down

0 comments on commit 5d11a63

Please sign in to comment.