@@ -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+
206248def support_check (system : "SystemElements" , node_id : int ) -> None :
207249 """Check if the node is a hinge
208250
0 commit comments