Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions anastruct/fem/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def __init__(
self.supports_hinged: List[Node] = []
self.supports_rotational: List[Node] = []
self.internal_hinges: List[Node] = []
# node ids passed to add_internal_hinge()
self._explicit_internal_hinges: Set[int] = set()
self.supports_roll: List[Node] = []
self.supports_spring_x: List[Tuple[Node, bool]] = []
self.supports_spring_y: List[Tuple[Node, bool]] = []
Expand Down Expand Up @@ -493,6 +495,8 @@ def remove_element(self, element_id: int) -> None:
# Check if node is now orphaned, and remove it and its loads if so
if len(self.node_map[node_id].elements) == 0:
system_components.util.remove_node_id(self, node_id)
else:
system_components.util.check_internal_hinges(self, node_id)

# Remove element_id
self.element_map.pop(element_id)
Expand Down Expand Up @@ -891,13 +895,15 @@ def solve(
Raises:
FEMException: The eigenvalues of the stiffness matrix are non zero, which indicates an unstable structure.
Check your support conditions
FEMException: A moment load is applied to an internal hinge that no support restrains.

Returns:
np.ndarray: Displacements vector.
"""

for node_id in self.node_map:
system_components.util.check_internal_hinges(self, node_id)
system_components.util.check_internal_hinge_moment_loads(self)

if self.system_displacement_vector is None:
system_components.assembly.process_supports(self)
Expand Down Expand Up @@ -1049,7 +1055,8 @@ def add_support_rotational(self, node_id: Union[int, Sequence[int]]) -> None:

def add_internal_hinge(self, node_id: Union[int, Sequence[int]]) -> None:
"""Model a internal hinge at a given node.
This may alternatively be done by setting a spring restraint to zero (`{1: 0}` or `{2: 0}`).
This may alternatively be done by setting a spring restraint to zero (`{1: 0}` or `{2: 0}`)
at this node on every element connected to it.
The effect is the same, though this function may be easier to use.

Args:
Expand All @@ -1062,7 +1069,9 @@ def add_internal_hinge(self, node_id: Union[int, Sequence[int]]) -> None:
id_ = _negative_index_to_id(id_, self.node_map.keys())

# add the support to the support list for the plotter
self.internal_hinges.append(self.node_map[id_])
if not any(node.id == id_ for node in self.internal_hinges):
self.internal_hinges.append(self.node_map[id_])
self._explicit_internal_hinges.add(id_)

def add_support_roll(
self,
Expand Down Expand Up @@ -2260,6 +2269,8 @@ def discretize(self, n: int = 10) -> None:
ss.add_support_rotational((node.id - 1) * n + 1)
for args in self.supports_spring_args:
ss.add_support_spring((args[0] - 1) * n + 1, *args[1:])
for node_id in self._explicit_internal_hinges:
ss.add_internal_hinge((node_id - 1) * n + 1)

# loads
for node_id, forces in self.loads_point.items():
Expand Down
80 changes: 50 additions & 30 deletions anastruct/fem/system_components/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING, Optional, Sequence, Tuple, Union
from typing import TYPE_CHECKING, Literal, Optional, Sequence, Tuple, Union

import numpy as np

Expand All @@ -14,46 +14,66 @@
def check_internal_hinges(system: "SystemElements", node_id: int) -> None:
"""Identify internal hinges, set their hinge status

A node is an internal hinge if it was passed to `add_internal_hinge()`, or if every
element connected to it is released (k=0) at that node. Nothing then restrains the
rotation of the node, so it is restrained instead (see `process_supports()`), which
keeps the stiffness matrix non-singular without changing any element forces.

The springs of the elements are not modified, so the result only depends on the
elements currently connected to the node, not on the order in which they were added.

Args:
system (SystemElements): System in which the node is located
node_id (int): Id of the node in the system
"""

node = system.node_map[node_id]

hinges = []
released = []
for el_id in node.elements:
el = system.element_map[el_id]
assert el.springs is not None
if node_id == el.node_id1 and 1 in el.springs and el.springs[1] == 0:
hinges.append(1)
elif node_id == el.node_id2 and 2 in el.springs and el.springs[2] == 0:
hinges.append(1)
else:
hinges.append(0)
end: Literal[1, 2] = 1 if node_id == el.node_id1 else 2
released.append(el.springs.get(end) == 0)

# If at least one element is connected
# and no more than one element is rigidly connected
if (1 < len(hinges) <= 1 + sum(hinges)) or (len(hinges) == 1 and sum(hinges) == 1):
is_hinge = node_id in system._explicit_internal_hinges or (
len(released) > 0 and all(released)
)

# Match by id, as the post-processing replaces the node objects
system.internal_hinges[:] = [n for n in system.internal_hinges if n.id != node_id]
node.hinge = is_hinge
if is_hinge:
system.internal_hinges.append(node)

if node in system.internal_hinges:
node.hinge = True

# If the elements aren't already all hinged, then set them to be
if len(hinges) - sum(hinges) >= 1:
for el_id in node.elements:
el = system.element_map[el_id]
assert el.springs is not None
if node_id == el.node_id1 and not (
1 in el.springs and el.springs[1] == 0
):
el.springs.update({1: 0})
if node_id == el.node_id2 and not (
2 in el.springs and el.springs[2] == 0
):
el.springs.update({2: 0})
system.element_map[el_id].springs = el.springs

def check_internal_hinge_moment_loads(system: "SystemElements") -> None:
"""Check that no moment load is applied to an unsupported internal hinge

The rotation of an internal hinge is only restrained to keep the stiffness matrix
non-singular. No element resists a moment load on it, so unless a support restrains
the rotation, the load would otherwise be silently lost in that restraint.

Args:
system (SystemElements): System to check

Raises:
FEMException: Raised when a moment load is applied to an unsupported internal hinge
"""
supported = {n.id for n in system.supports_fixed + system.supports_rotational}
supported |= {n.id for n, _ in system.supports_spring_z}
supported |= {
n.id
for n, rotate in zip(system.supports_roll, system.supports_roll_rotate)
if not rotate
}
for node in system.internal_hinges:
if system.loads_moment.get(node.id, 0) != 0 and node.id not in supported:
raise FEMException(
"StabilityError",
f"A moment load is applied to node {node.id}, but every element is hinged "
"at this node, so nothing resists it.",
)


def append_node_id(
Expand Down Expand Up @@ -105,8 +125,8 @@ def remove_node_id(
system.supports_hinged.remove(node)
if node in system.supports_rotational:
system.supports_rotational.remove(node)
if node in system.internal_hinges:
system.internal_hinges.remove(node)
system.internal_hinges[:] = [n for n in system.internal_hinges if n.id != node_id]
system._explicit_internal_hinges.discard(node_id)
if node in system.supports_roll:
ind = system.supports_roll.index(node)
system.supports_roll.remove(node)
Expand Down
125 changes: 124 additions & 1 deletion tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pytest import approx, raises

from anastruct import LoadCase, LoadCombination, SystemElements
from anastruct.basic import FEMException

from .fixtures.e2e_fixtures import *
from .utils import pspec_context
Expand Down Expand Up @@ -109,7 +110,7 @@ def context_example_4():
def it_results_in_correct_solution():
sol = np.fromstring(
"""0.00000000e+00 0.00000000e+00 1.46957616e-25 2.00000000e-09
-7.34788079e-25 0.00000000e+00 0.00000000e+00 0.00000000e+00
-7.34788079e-25 -2.08333293e-03 0.00000000e+00 0.00000000e+00
4.16666667e-03""",
float,
sep=" ",
Expand Down Expand Up @@ -577,6 +578,128 @@ def it_results_in_symmetric_element_demands():
system.get_element_results(2)["Mmax"]
)

def context_internal_hinge_independent_of_element_order():
# Test bug fix for a joint with only one of three elements released being treated as
# an internal hinge, depending on the order in which the elements are added (#464)

elements = {
"left": ([[0, 4], [4, 4]], None),
"right": ([[4, 4], [8, 4]], {1: 0}),
"column": ([[4, 4], [4, 0]], None),
}

def _build(order):
system = SystemElements()
ids = {
name: system.add_element(elements[name][0], spring=elements[name][1])
for name in order
}
for location in ([0, 4], [8, 4], [4, 0]):
system.add_support_fixed(system.find_node_id(location))
system.q_load(q=-10, element_id=[ids["left"], ids["right"]])
system.solve()
return system, ids

systems = [
_build(order)
for order in (
["left", "column", "right"],
["left", "right", "column"],
["right", "left", "column"],
)
]

def it_does_not_create_an_internal_hinge():
for system, ids in systems:
assert system.internal_hinges == []
assert system.element_map[ids["left"]].springs == {}
assert system.element_map[ids["column"]].springs == {}

def it_does_not_create_an_internal_hinge_when_splitting_an_element_first():
system = SystemElements()
left = system.add_element(elements["left"][0])
system.add_element(elements["right"][0], spring=elements["right"][1])
system.insert_node(left, location=[2, 4])
column = system.add_element(elements["column"][0])
assert system.internal_hinges == []
assert system.element_map[column].springs == {}

def it_results_in_the_same_moments_for_any_element_order():
moments = []
for system, ids in systems:
node_id = system.find_node_id([4, 4])
m_left = system.element_map[ids["left"]].node_map[node_id].Tz
m_column = system.element_map[ids["column"]].node_map[node_id].Tz
assert m_left == approx(-m_column)
moments.append(m_left)
assert moments[0] != approx(0)
assert moments == approx([moments[0]] * len(moments))

def context_moment_load_on_a_joint_with_one_rigid_element():
# Test that a joint where all but one element is released isn't an internal hinge,
# so a moment load on it is carried by the rigid element

system = SystemElements()
system.add_element([[0, 0], [5, 0]])
system.add_element([[5, 0], [10, 0]], spring={1: 0})
system.add_support_fixed(1)
system.add_support_roll(3, direction="x")
system.moment_load(2, Tz=10)
system.solve()

def it_does_not_create_an_internal_hinge():
assert system.internal_hinges == []
assert system.element_map[1].springs == {}

def it_carries_the_moment_load_to_the_support():
assert system.get_node_results_system(1)["Tz"] == approx(10)

def context_moment_load_on_an_internal_hinge():
# Test that a moment load on a node where every element is released raises, instead of
# being lost in the restraint of the node's rotation

system = SystemElements()
system.add_element([[0, 0], [5, 0]], spring={2: 0})
system.add_element([[5, 0], [10, 0]], spring={1: 0})
system.add_support_fixed([1, 3])
system.moment_load(2, Tz=10)

def it_raises_a_stability_error():
with raises(FEMException, match="StabilityError"):
system.solve()

def context_add_internal_hinge():
# Test that add_internal_hinge() releases every element at the node without
# modifying their springs, also when the system is discretized

def _build(discretize):
system = SystemElements()
system.add_element([[0, 0], [5, 0]])
system.add_element([[5, 0], [10, 0]])
system.add_support_fixed([1, 3])
system.add_internal_hinge(2)
system.point_load(2, Fy=-10)
if discretize:
system.discretize(4)
system.solve()
return system

system = _build(discretize=False)
discretized = _build(discretize=True)

def it_does_not_modify_the_springs():
for s in (system, discretized):
assert all(el.springs == {} for el in s.element_map.values())

def it_keeps_the_internal_hinge_when_discretized():
assert [node.id for node in system.internal_hinges] == [2]
assert [node.id for node in discretized.internal_hinges] == [5]

def it_results_in_hinged_moments():
# two cantilevers that each carry half of the point load
assert system.get_node_results_system(1)["Tz"] == approx(-25)
assert discretized.get_node_results_system(1)["Tz"] == approx(-25)

def context_q_and_q_perp_loads():
# Test addition of simultaneous q and q_perp loads

Expand Down