Skip to content

Commit

Permalink
Merge pull request #219 from ritchie46/cleanUpYvsZ
Browse files Browse the repository at this point in the history
Clean up all y and z coordinates
  • Loading branch information
smith120bh authored Oct 30, 2023
2 parents d50c5d4 + be8fb17 commit 66931c4
Show file tree
Hide file tree
Showing 21 changed files with 284 additions and 262 deletions.
12 changes: 6 additions & 6 deletions anastruct/cython/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def converge(lhs: float, rhs: float) -> float:
return (rhs / lhs - 1) / div + 1


def angle_x_axis(delta_x: float, delta_z: float) -> float:
def angle_x_axis(delta_x: float, delta_y: float) -> float:
"""Determine the angle of the element with the global x-axis
Args:
delta_x (float): Element length in the x-direction
delta_z (float): Element length in the z-direction
delta_y (float): Element length in the y-direction
Returns:
float: Angle of the element with the global x-axis
"""
# dot product v_x = [1, 0] ; v = [delta_x, delta_z]
# dot product = 1 * delta_x + 0 * delta_z -> delta_x
ai = math.acos(delta_x / math.sqrt(delta_x**2 + delta_z**2))
if delta_z < 0:
# dot product v_x = [1, 0] ; v = [delta_x, delta_y]
# dot product = 1 * delta_x + 0 * delta_y -> delta_x
ai = math.acos(delta_x / math.sqrt(delta_x**2 + delta_y**2))
if delta_y < 0:
ai = 2 * math.pi - ai

return ai
10 changes: 5 additions & 5 deletions anastruct/cython/cbasic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ cpdef converge(double lhs, double rhs):
div = max(lhs, rhs) / min(lhs, rhs) * 2.0
return (abs(rhs) / abs(lhs) - 1.0) / div + 1.0

cpdef angle_x_axis(double delta_x, double delta_z):
cpdef angle_x_axis(double delta_x, double delta_y):
cdef double ai
# dot product v_x = [1, 0] ; v = [delta_x, delta_z]
# dot product = 1 * delta_x + 0 * delta_z -> delta_x
ai = acos(delta_x / sqrt(delta_x**2 + delta_z**2))
if delta_z < 0:
# dot product v_x = [1, 0] ; v = [delta_x, delta_y]
# dot product = 1 * delta_x + 0 * delta_y -> delta_x
ai = acos(delta_x / sqrt(delta_x**2 + delta_y**2))
if delta_y < 0:
ai = 2 * pi - ai

return ai
8 changes: 4 additions & 4 deletions anastruct/fem/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ def __add__(self, other: Element) -> Element:
el.node_map[self.node_id1] = el.node_1 + other.node_1
el.node_map[self.node_id2] = el.node_2 + other.node_2
el.node_map[self.node_id1].ux = el.node_1.ux + other.node_1.ux
el.node_map[self.node_id1].uz = el.node_1.uz + other.node_1.uz
el.node_map[self.node_id1].phi_y = el.node_1.phi_y + other.node_1.phi_y
el.node_map[self.node_id1].uy = el.node_1.uy + other.node_1.uy
el.node_map[self.node_id1].phi_z = el.node_1.phi_z + other.node_1.phi_z
el.node_map[self.node_id2].ux = el.node_2.ux + other.node_2.ux
el.node_map[self.node_id2].uz = el.node_2.uz + other.node_2.uz
el.node_map[self.node_id2].phi_y = el.node_2.phi_y + other.node_2.phi_y
el.node_map[self.node_id2].uy = el.node_2.uy + other.node_2.uy
el.node_map[self.node_id2].phi_z = el.node_2.phi_z + other.node_2.phi_z
return el


Expand Down
2 changes: 1 addition & 1 deletion anastruct/fem/examples/ex_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ss = SystemElements()
ss.add_element(location=[[0, 0], [5, 0]], EA=5e9, EI=8000, spring={2: 0})
ss.add_element(location=[[5, 0], [5, 5]], EA=5e9, EI=4000)
ss.moment_load(Ty=10, node_id=3)
ss.moment_load(Tz=10, node_id=3)
ss.add_support_hinged(node_id=1)
ss.add_support_hinged(node_id=3)

Expand Down
2 changes: 1 addition & 1 deletion anastruct/fem/examples/ex_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ss = SystemElements()
ss.add_element(location=[[0, 0], [5, 0]], EA=5e9, EI=8000)
ss.add_element(location=[[5, 0], [5, 5]], EA=5e9, EI=4000)
ss.moment_load(Ty=10, node_id=3)
ss.moment_load(Tz=10, node_id=3)
ss.add_support_hinged(node_id=1)
ss.add_support_hinged(node_id=3)

Expand Down
10 changes: 6 additions & 4 deletions anastruct/fem/examples/water_acc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
" deflection = np.zeros(len(ss.node_map))\n",
"\n",
" # Height of the nodes\n",
" y = np.array(ss.nodes_range(\"y\"))\n",
" y = np.array(ss.nodes_range(\"y_neg\"))\n",
"\n",
" # An array with point loads.\n",
" # cubic meters * weight water\n",
Expand All @@ -210,7 +210,7 @@
" point_load = force_water[k - 1]\n",
"\n",
" if point_load > 0:\n",
" ss.point_load(k, Fx=0, Fz=-point_load)\n",
" ss.point_load(k, Fx=0, Fy=-point_load)\n",
" cubics += point_load / q_water\n",
"\n",
" return cubics"
Expand Down Expand Up @@ -397,12 +397,14 @@
"source": [
"plt.figure(figsize=(10, 6))\n",
"\n",
"plt.plot(ss.nodes_range(\"x\")[:-2], ss.nodes_range(\"y\")[:-2])\n",
"plt.plot(ss.nodes_range(\"x\")[:-2], ss.nodes_range(\"y_neg\")[:-2])\n",
"plt.plot(\n",
" ss.nodes_range(\"x\")[:-2],\n",
" [\n",
" a + b\n",
" for a, b in zip(ss.nodes_range(\"y\")[:-2], ss.get_node_result_range(\"uy\")[:-2])\n",
" for a, b in zip(\n",
" ss.nodes_range(\"y_neg\")[:-2], ss.get_node_result_range(\"uy\")[:-2]\n",
" )\n",
" ],\n",
")\n",
"\n",
Expand Down
82 changes: 41 additions & 41 deletions anastruct/fem/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def __init__(
self,
id: int, # pylint: disable=redefined-builtin
Fx: float = 0.0,
Fz: float = 0.0,
Ty: float = 0.0,
Fy: float = 0.0,
Tz: float = 0.0,
ux: float = 0.0,
uz: float = 0.0,
phi_y: float = 0.0,
uy: float = 0.0,
phi_z: float = 0.0,
vertex: Vertex = Vertex(0, 0),
hinge: bool = False,
):
Expand All @@ -26,35 +26,35 @@ def __init__(
Args:
id (int): ID of the node
Fx (float, optional): Value of Fx force. Defaults to 0.0.
Fz (float, optional): Value of Fz force. Defaults to 0.0.
Ty (float, optional): Value of Ty moment. Defaults to 0.0.
Fy (float, optional): Value of Fy force. Defaults to 0.0.
Tz (float, optional): Value of Tz moment. Defaults to 0.0.
ux (float, optional): Value of ux displacement. Defaults to 0.0.
uz (float, optional): Value of uz displacement. Defaults to 0.0.
phi_y (float, optional): Value of phi_y rotation. Defaults to 0.0.
uy (float, optional): Value of uy displacement. Defaults to 0.0.
phi_z (float, optional): Value of phi_z rotation. Defaults to 0.0.
vertex (Vertex, optional): Point object coordinate. Defaults to Vertex(0, 0).
hinge (bool, optional): Is this node a hinge. Defaults to False.
"""
self.id = id
# forces
self.Fx = Fx
self.Fz = Fz
self.Ty = Ty
self.Fy = Fy
self.Tz = Tz
# displacements
self.ux = ux
self.uz = uz
self.phi_y = phi_y
self.uy = uy
self.phi_z = phi_z
self.vertex = vertex
self.hinge = hinge
self.elements: Dict[int, Element] = {}

@property
def Fy(self) -> float:
"""Fy is the vertical force, and the negative of Fz
def Fy_neg(self) -> float:
"""Fy is the vertical force, and the negative of Fy
Returns:
float: negative of Fz
float: negative of Fy
"""
return -self.Fz
return -self.Fy

def __str__(self) -> str:
"""String representation of the node
Expand All @@ -64,12 +64,12 @@ def __str__(self) -> str:
"""
if self.vertex:
return (
f"[id = {self.id}, Fx = {self.Fx}, Fz = {self.Fz}, Ty = {self.Ty}, ux = {self.ux}, "
f"uz = {self.uz}, phi_y = {self.phi_y}, x = {self.vertex.x}, y = {self.vertex.y}]"
f"[id = {self.id}, Fx = {self.Fx}, Fy = {self.Fy}, Tz = {self.Tz}, ux = {self.ux}, "
f"uy = {self.uy}, phi_z = {self.phi_z}, x = {self.vertex.x}, y = {self.vertex.y}]"
)
return (
f"[id = {self.id}, Fx = {self.Fx}, Fz = {self.Fz}, Ty = {self.Ty}, ux = {self.ux}, "
f"uz = {self.uz}, phi_y = {self.phi_y}]"
f"[id = {self.id}, Fx = {self.Fx}, Fy = {self.Fy}, Tz = {self.Tz}, ux = {self.ux}, "
f"uy = {self.uy}, phi_z = {self.phi_z}]"
)

def __add__(self, other: Node) -> Node:
Expand All @@ -85,17 +85,17 @@ def __add__(self, other: Node) -> Node:
self.id == other.id
), "Cannot add nodes as the ID's don't match. The nodes positions don't match."
Fx = self.Fx + other.Fx
Fz = self.Fz + other.Fz
Ty = self.Ty + other.Ty
Fy = self.Fy + other.Fy
Tz = self.Tz + other.Tz

return Node(
id=self.id,
Fx=Fx,
Fz=Fz,
Ty=Ty,
Fy=Fy,
Tz=Tz,
ux=self.ux,
uz=self.uz,
phi_y=self.phi_y,
uy=self.uy,
phi_z=self.phi_z,
vertex=self.vertex,
hinge=self.hinge,
)
Expand All @@ -113,24 +113,24 @@ def __sub__(self, other: Node) -> Node:
self.id == other.id
), "Cannot subtract nodes as the ID's don't match. The nodes positions don't match."
Fx = self.Fx - other.Fx
Fz = self.Fz - other.Fz
Ty = self.Ty - other.Ty
Fy = self.Fy - other.Fy
Tz = self.Tz - other.Tz

return Node(
self.id,
Fx,
Fz,
Ty,
Fy,
Tz,
self.ux,
self.uz,
self.phi_y,
self.uy,
self.phi_z,
self.vertex,
hinge=self.hinge,
)

def reset(self) -> None:
"""Reset the node to zero forces and displacements"""
self.Fx = self.Fz = self.Ty = self.ux = self.uz = self.phi_y = 0
self.Fx = self.Fy = self.Tz = self.ux = self.uy = self.phi_z = 0
self.hinge = False

def add_results(self, other: Node) -> None:
Expand All @@ -142,15 +142,15 @@ def add_results(self, other: Node) -> None:
assert (
self.id == other.id
), "Cannot add nodes as the ID's don't match. The nodes positions don't match."
assert self.phi_y is not None
assert self.phi_z is not None
assert self.ux is not None
assert self.uz is not None
assert other.phi_y is not None
assert self.uy is not None
assert other.phi_z is not None
assert other.ux is not None
assert other.uz is not None
assert other.uy is not None
self.Fx = self.Fx + other.Fx
self.Fz = self.Fz + other.Fz
self.Ty = self.Ty + other.Ty
self.Fy = self.Fy + other.Fy
self.Tz = self.Tz + other.Tz
self.ux = self.ux + other.ux
self.uz = self.uz + other.uz
self.phi_y = self.phi_y + other.phi_y
self.uy = self.uy + other.uy
self.phi_z = self.phi_z + other.phi_z
38 changes: 19 additions & 19 deletions anastruct/fem/plotter/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def plot_values_deflection(
Tuple[np.ndarray, np.ndarray]: x and y values
"""
ux1 = element.node_1.ux * factor
uz1 = -element.node_1.uz * factor
uy1 = -element.node_1.uy * factor
ux2 = element.node_2.ux * factor
uz2 = -element.node_2.uz * factor
uy2 = -element.node_2.uy * factor

x1 = element.vertex_1.x + ux1
y1 = -element.vertex_1.z + uz1
y1 = element.vertex_1.y + uy1
x2 = element.vertex_2.x + ux2
y2 = -element.vertex_2.z + uz2
y2 = element.vertex_2.y + uy2

if element.type == "general" and not linear:
assert element.deflection is not None
Expand Down Expand Up @@ -61,17 +61,17 @@ def plot_values_bending_moment(
"""

# Determine forces for horizontal element.angle = 0
T_left = element.node_1.Ty
T_right = -element.node_2.Ty
T_left = element.node_1.Tz
T_right = -element.node_2.Tz

sin = math.sin(-element.angle)
cos = math.cos(-element.angle)

# apply angle ai
x1 = element.vertex_1.x + T_left * sin * factor
y1 = -element.vertex_1.z + T_left * cos * factor
y1 = element.vertex_1.y + T_left * cos * factor
x2 = element.vertex_2.x + T_right * sin * factor
y2 = -element.vertex_2.z + T_right * cos * factor
y2 = element.vertex_2.y + T_right * cos * factor

interpolate = np.linspace(0, 1, n)
dx = x2 - x1
Expand All @@ -94,9 +94,9 @@ def plot_values_bending_moment(
y_val += cos * q_part * factor

x_val = np.append(x_val, element.vertex_2.x)
y_val = np.append(y_val, -element.vertex_2.z)
y_val = np.append(y_val, element.vertex_2.y)
x_val = np.insert(x_val, 0, element.vertex_1.x)
y_val = np.insert(y_val, 0, -element.vertex_1.z)
y_val = np.insert(y_val, 0, element.vertex_1.y)

return x_val, y_val

Expand Down Expand Up @@ -126,9 +126,9 @@ def plot_values_axial_force(

# apply angle ai
x1 = element.vertex_1.x + N1 * cos * factor
y1 = -element.vertex_1.z + N1 * sin * factor
y1 = element.vertex_1.y + N1 * sin * factor
x2 = element.vertex_2.x + N2 * cos * factor
y2 = -element.vertex_2.z + N2 * sin * factor
y2 = element.vertex_2.y + N2 * sin * factor

interpolate = np.linspace(0, 1, n)
dx = x2 - x1
Expand All @@ -147,9 +147,9 @@ def plot_values_axial_force(
y_val += sin * qn_part * factor

x_val = np.append(x_val, element.vertex_2.x)
y_val = np.append(y_val, -element.vertex_2.z)
y_val = np.append(y_val, element.vertex_2.y)
x_val = np.insert(x_val, 0, element.vertex_1.x)
y_val = np.insert(y_val, 0, -element.vertex_1.z)
y_val = np.insert(y_val, 0, element.vertex_1.y)

return x_val, y_val

Expand All @@ -167,9 +167,9 @@ def plot_values_shear_force(
Tuple[np.ndarray, np.ndarray]: x and y values
"""
x1 = element.vertex_1.x
y1 = -element.vertex_1.z
y1 = element.vertex_1.y
x2 = element.vertex_2.x
y2 = -element.vertex_2.z
y2 = element.vertex_2.y

assert element.shear_force is not None
n = len(element.shear_force)
Expand All @@ -189,9 +189,9 @@ def plot_values_shear_force(
y_val += cos * element.shear_force * factor

x_val = np.append(x_val, element.vertex_2.x)
y_val = np.append(y_val, -element.vertex_2.z)
y_val = np.append(y_val, element.vertex_2.y)
x_val = np.insert(x_val, 0, element.vertex_1.x)
y_val = np.insert(y_val, 0, -element.vertex_1.z)
y_val = np.insert(y_val, 0, element.vertex_1.y)

return x_val, y_val

Expand All @@ -206,5 +206,5 @@ def plot_values_element(element: "Element") -> Tuple[np.ndarray, np.ndarray]:
Tuple[np.ndarray, np.ndarray]: x and y values
"""
x_val = np.array([element.vertex_1.x, element.vertex_2.x])
y_val = np.array([-element.vertex_1.z, -element.vertex_2.z])
y_val = np.array([element.vertex_1.y, element.vertex_2.y])
return x_val, y_val
Loading

0 comments on commit 66931c4

Please sign in to comment.