Skip to content

Commit

Permalink
Merge pull request #179 from ritchie46/addErrorHandlingIntIds
Browse files Browse the repository at this point in the history
Add error-handling to node & element id data types
  • Loading branch information
smith120bh authored Aug 28, 2023
2 parents 6b785e2 + f6020cc commit 5c889cc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion anastruct/fem/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@ def insert_node(
ss = SystemElements(
EA=self.EA, EI=self.EI, load_factor=self.load_factor, mesh=self.plotter.mesh
)
element_id = _negative_index_to_id(element_id, self.element_map)

for element in self.element_map.values():
g = self.element_map[element.id].dead_load
Expand Down Expand Up @@ -1015,7 +1016,7 @@ def point_load(
node_id: Union[int, Sequence[int]],
Fx: Union[float, Sequence[float]] = 0.0,
Fy: Union[float, Sequence[float]] = 0.0,
rotation: Union[float, Sequence[float]] = 0,
rotation: Union[float, Sequence[float]] = 0.0,
) -> None:
"""
Apply a point load to a node.
Expand Down Expand Up @@ -1317,6 +1318,7 @@ def get_node_displacements(
"""
result_list = []
if node_id != 0:
node_id = _negative_index_to_id(node_id, self.node_map)
node = self.node_map[node_id]
return {
"id": node.id,
Expand Down Expand Up @@ -1668,6 +1670,11 @@ def __deepcopy__(self, _: str) -> "SystemElements":


def _negative_index_to_id(idx: int, collection: Collection[int]) -> int:
if not isinstance(idx, int):
if int(idx) == idx: # if it can be non-destructively cast to an integer
idx = int(idx)
else:
raise TypeError("Node or element id must be an integer")
if idx > 0:
return idx
else:
Expand Down

0 comments on commit 5c889cc

Please sign in to comment.