Skip to content

Commit 1c51cdb

Browse files
authored
Merge pull request #422 from ritchie46/trussGenerator
Truss generator preprocessor
2 parents be480dc + f49f494 commit 1c51cdb

10 files changed

Lines changed: 2797 additions & 3 deletions

File tree

.coverage

-236 KB
Binary file not shown.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,5 @@ MANIFEST
8989
build/
9090
.ipynb_checkpoints/
9191

92-
dev/
92+
dev/
93+
.coverage

anastruct/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from anastruct.fem.system import SystemElements
22
from anastruct.fem.util.load import LoadCase, LoadCombination
3+
from anastruct.preprocess import truss
34
from anastruct.vertex import Vertex

anastruct/fem/system.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,6 +2363,6 @@ def _negative_index_to_id(idx: int, collection: Collection[int]) -> int:
23632363
idx = int(idx)
23642364
else:
23652365
raise TypeError("Node or element id must be an integer")
2366-
if idx > 0:
2366+
if idx >= 0:
23672367
return idx
23682368
return max(collection) + (idx + 1)

anastruct/fem/system_components/util.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,48 @@ def det_node_ids(
203203
return node_ids[0], node_ids[1]
204204

205205

206+
def add_node(
207+
system: "SystemElements", point: Vertex, node_id: Optional[int] = None
208+
) -> int:
209+
"""Add a node, optionally with a specific ID, without adding an element
210+
211+
Args:
212+
system (SystemElements): System in which the nodes are located
213+
point (Vertex): Location of the node
214+
node_id (Optional[int], optional): node_id to assign to the node. Defaults to None,
215+
which means to use the first available node_id automatically.
216+
217+
Raises:
218+
FEMException: Raised when the location is already assigned to a different node id.
219+
FEMException: Raised when the node id is already assigned to a different location.
220+
221+
Returns:
222+
int: The node id of the added (or existing) node
223+
"""
224+
if point in system._vertices:
225+
if node_id is not None:
226+
existing_node_id = system._vertices[point]
227+
if existing_node_id != node_id:
228+
raise FEMException(
229+
"Flawed inputs",
230+
f"Location {point} is already assigned to node id {existing_node_id}, "
231+
f"cannot assign to node id {node_id}.",
232+
)
233+
return existing_node_id
234+
235+
if node_id is None:
236+
node_id = max(system.node_map.keys(), default=0) + 1
237+
elif node_id in system.node_map and system.node_map[node_id].vertex != point:
238+
raise FEMException(
239+
"Flawed inputs",
240+
f"Node id {node_id} is already assigned to a different location.",
241+
)
242+
243+
system._vertices[point] = node_id
244+
system.node_map[node_id] = Node(node_id, vertex=point)
245+
return node_id
246+
247+
206248
def support_check(system: "SystemElements", node_id: int) -> None:
207249
"""Check if the node is a hinge
208250

anastruct/preprocess/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)