File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -499,10 +499,14 @@ def remove_event(self, event):
499499 # system assembly -------------------------------------------------------------
500500
501501 def _assemble_graph (self ):
502- """Build the internal graph representation for fast system function
502+ """Build the internal graph representation for fast system function
503503 evaluation and algebraic loop resolution.
504504 """
505505
506+ #reset all block inputs to clear stale values from removed connections
507+ for block in self .blocks :
508+ block .inputs .reset ()
509+
506510 #time the graph construction
507511 with Timer (verbose = False ) as T :
508512 self .graph = Graph (self .blocks , self .connections )
Original file line number Diff line number Diff line change @@ -381,6 +381,11 @@ def _assemble_graph(self):
381381 """Assemble internal graph of subsystem for fast
382382 algebraic evaluation during simulation.
383383 """
384+
385+ #reset all block inputs to clear stale values from removed connections
386+ for block in self .blocks :
387+ block .inputs .reset ()
388+
384389 self .graph = Graph ({* self .blocks , self .interface }, self .connections )
385390 self ._graph_dirty = False
386391
Original file line number Diff line number Diff line change @@ -884,6 +884,23 @@ def test_remove_connection_error(self):
884884 with self .assertRaises (ValueError ):
885885 self .Sim .remove_connection (C )
886886
887+ def test_remove_connection_zeroes_inputs (self ):
888+ """Removing a connection zeroes target inputs on next graph rebuild"""
889+ # Run a step so the connection pushes data
890+ self .Src .function = lambda t : 5.0
891+ self .Sim .step (0.01 )
892+
893+ # Int should have received input from Src
894+ self .assertNotEqual (self .Int .inputs [0 ], 0.0 )
895+
896+ # Remove the connection — graph is dirty but not rebuilt yet
897+ self .Sim .remove_connection (self .C1 )
898+ self .assertTrue (self .Sim ._graph_dirty )
899+
900+ # Next step triggers graph rebuild which resets inputs
901+ self .Sim .step (0.01 )
902+ self .assertEqual (self .Int .inputs [0 ], 0.0 )
903+
887904 def test_remove_event (self ):
888905 """Adding and removing events works"""
889906 evt = Event (func_evt = lambda t : t - 1.0 , func_act = lambda t : None )
You can’t perform that action at this time.
0 commit comments