@@ -820,14 +820,8 @@ def test_sys_naming_convention(self):
820820 self .assertEquals (sys .copy ().name , "copy of sys[0]" )
821821
822822 namedsys = ios .NonlinearIOSystem (
823- updfcn = lambda t , x , u , params : np .array (
824- np .dot (self .mimo_linsys1 .A , np .reshape (x , (- 1 , 1 ))) \
825- + np .dot (self .mimo_linsys1 .B , np .reshape (u , (- 1 , 1 )))
826- ).reshape (- 1 ,),
827- outfcn = lambda t , x , u , params : np .array (
828- self .mimo_linsys1 .C * np .reshape (x , (- 1 , 1 )) \
829- + self .mimo_linsys1 .D * np .reshape (u , (- 1 , 1 ))
830- ).reshape (- 1 ,),
823+ updfcn = lambda t , x , u , params : x ,
824+ outfcn = lambda t , x , u , params : u ,
831825 inputs = ('u[0]' , 'u[1]' ),
832826 outputs = ('y[0]' , 'y[1]' ),
833827 states = self .mimo_linsys1 .states ,
@@ -880,11 +874,59 @@ def test_signals_naming_convention(self):
880874 state: 'x[i]'
881875 output: 'y[i]'
882876 """
877+ ct .InputOutputSystem .idCounter = 0
883878 sys = ct .LinearIOSystem (self .mimo_linsys1 )
879+ for statename in ["x[0]" , "x[1]" ]:
880+ self .assertTrue (statename in sys .state_index )
881+ for inputname in ["u[0]" , "u[1]" ]:
882+ self .assertTrue (inputname in sys .input_index )
883+ for outputname in ["y[0]" , "y[1]" ]:
884+ self .assertTrue (outputname in sys .output_index )
884885 self .assertEqual (len (sys .state_index ), sys .nstates )
885886 self .assertEqual (len (sys .input_index ), sys .ninputs )
886887 self .assertEqual (len (sys .output_index ), sys .noutputs )
887-
888+
889+ namedsys = ios .NonlinearIOSystem (
890+ updfcn = lambda t , x , u , params : x ,
891+ outfcn = lambda t , x , u , params : u ,
892+ inputs = ('u0' ),
893+ outputs = ('y0' ),
894+ states = ('x0' ),
895+ name = 'namedsys' )
896+ unnamedsys = ct .NonlinearIOSystem (
897+ lambda t ,x ,u ,params : x , inputs = 1 , outputs = 1 , states = 1
898+ )
899+ self .assertTrue ('u0' in namedsys .input_index )
900+ self .assertTrue ('y0' in namedsys .output_index )
901+ self .assertTrue ('x0' in namedsys .state_index )
902+
903+ # Unnamed/named connections
904+ un_series = unnamedsys * namedsys
905+ un_parallel = unnamedsys + namedsys
906+ un_feedback = unnamedsys .feedback (namedsys )
907+ un_dup = unnamedsys * namedsys .copy ()
908+ un_hierarchical = un_series * unnamedsys
909+ u_neg = - unnamedsys
910+
911+ self .assertTrue ("sys[1].x[0]" in un_series .state_index )
912+ self .assertTrue ("namedsys.x0" in un_series .state_index )
913+ self .assertTrue ("sys[1].x[0]" in un_parallel .state_index )
914+ self .assertTrue ("namedsys.x0" in un_series .state_index )
915+ self .assertTrue ("sys[1].x[0]" in un_feedback .state_index )
916+ self .assertTrue ("namedsys.x0" in un_feedback .state_index )
917+ self .assertTrue ("sys[1].x[0]" in un_dup .state_index )
918+ self .assertTrue ("copy of namedsys.x0" in un_dup .state_index )
919+ self .assertTrue ("sys[1].x[0]" in un_hierarchical .state_index )
920+ self .assertTrue ("sys[2].sys[1].x[0]" in un_hierarchical .state_index )
921+ self .assertTrue ("sys[1].x[0]" in u_neg .state_index )
922+
923+ # Same system conflict
924+ with warnings .catch_warnings (record = True ) as warnval :
925+ same_name_series = unnamedsys * unnamedsys
926+ self .assertEquals (len (warnval ), 1 )
927+ self .assertTrue ("sys[1].x[0]" in same_name_series .state_index )
928+ self .assertTrue ("copy of sys[1].x[0]" in same_name_series .state_index )
929+
888930 def test_named_signals_linearize_inconsistent (self ):
889931 """Mare sure that providing inputs or outputs not consistent with
890932 updfcn or outfcn fail
0 commit comments