@@ -246,23 +246,54 @@ def test_string_inputoutput():
246246 assert P_s2 .output_index == {'y2' : 0 }
247247
248248def test_linear_interconnect ():
249- tf_ctrl = ct .tf (1 , (10.1 , 1 ), inputs = 'e' , outputs = 'u' )
250- tf_plant = ct .tf (1 , (10.1 , 1 ), inputs = 'u' , outputs = 'y' )
251- ss_ctrl = ct .ss (1 , 2 , 1 , 2 , inputs = 'e' , outputs = 'u' )
252- ss_plant = ct .ss (1 , 2 , 1 , 2 , inputs = 'u' , outputs = 'y' )
249+ tf_ctrl = ct .tf (1 , (10.1 , 1 ), inputs = 'e' , outputs = 'u' , name = 'ctrl' )
250+ tf_plant = ct .tf (1 , (10.1 , 1 ), inputs = 'u' , outputs = 'y' , name = 'plant' )
251+ ss_ctrl = ct .ss (1 , 2 , 1 , 0 , inputs = 'e' , outputs = 'u' , name = 'ctrl ' )
252+ ss_plant = ct .ss (1 , 2 , 1 , 0 , inputs = 'u' , outputs = 'y' , name = 'plant ' )
253253 nl_ctrl = ct .NonlinearIOSystem (
254- lambda t , x , u , params : x * x ,
255- lambda t , x , u , params : u * x , states = 1 , inputs = 'e' , outputs = 'u' )
254+ lambda t , x , u , params : x * x , lambda t , x , u , params : u * x ,
255+ states = 1 , inputs = 'e' , outputs = 'u' , name = 'ctrl ' )
256256 nl_plant = ct .NonlinearIOSystem (
257- lambda t , x , u , params : x * x ,
258- lambda t , x , u , params : u * x , states = 1 , inputs = 'u' , outputs = 'y' )
259-
260- assert isinstance (ct .interconnect ((tf_ctrl , tf_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
261- assert isinstance (ct .interconnect ((ss_ctrl , ss_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
262- assert isinstance (ct .interconnect ((tf_ctrl , ss_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
263- assert isinstance (ct .interconnect ((ss_ctrl , tf_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
264-
265- assert ~ isinstance (ct .interconnect ((nl_ctrl , ss_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
266- assert ~ isinstance (ct .interconnect ((nl_ctrl , tf_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
267- assert ~ isinstance (ct .interconnect ((ss_ctrl , nl_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
268- assert ~ isinstance (ct .interconnect ((tf_ctrl , nl_plant ), inputs = 'e' , outputs = 'y' ), ct .LinearIOSystem )
257+ lambda t , x , u , params : x * x , lambda t , x , u , params : u * x ,
258+ states = 1 , inputs = 'u' , outputs = 'y' , name = 'plant' )
259+ sumblk = ct .summing_junction (inputs = ['r' , '-y' ], outputs = ['e' ], name = 'sum' )
260+
261+ # Interconnections of linear I/O systems should be linear I/O system
262+ assert isinstance (
263+ ct .interconnect ([tf_ctrl , tf_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
264+ ct .LinearIOSystem )
265+ assert isinstance (
266+ ct .interconnect ([ss_ctrl , ss_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
267+ ct .LinearIOSystem )
268+ assert isinstance (
269+ ct .interconnect ([tf_ctrl , ss_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
270+ ct .LinearIOSystem )
271+ assert isinstance (
272+ ct .interconnect ([ss_ctrl , tf_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
273+ ct .LinearIOSystem )
274+
275+ # Interconnections with nonliner I/O systems should not be linear
276+ assert ~ isinstance (
277+ ct .interconnect ([nl_ctrl , ss_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
278+ ct .LinearIOSystem )
279+ assert ~ isinstance (
280+ ct .interconnect ([nl_ctrl , tf_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
281+ ct .LinearIOSystem )
282+ assert ~ isinstance (
283+ ct .interconnect ([ss_ctrl , nl_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
284+ ct .LinearIOSystem )
285+ assert ~ isinstance (
286+ ct .interconnect ([tf_ctrl , nl_plant , sumblk ], inputs = 'r' , outputs = 'y' ),
287+ ct .LinearIOSystem )
288+
289+ # Implicit converstion of transfer function should retain name
290+ clsys = ct .interconnect (
291+ [tf_ctrl , ss_plant , sumblk ],
292+ connections = [
293+ ['plant.u' , 'ctrl.u' ],
294+ ['ctrl.e' , 'sum.e' ],
295+ ['sum.y' , 'plant.y' ]
296+ ],
297+ inplist = ['sum.r' ], inputs = 'r' ,
298+ outlist = ['plant.y' ], outputs = 'y' )
299+ assert clsys .syslist [0 ].name == 'ctrl'
0 commit comments