3131
3232__all__ = ['NonlinearIOSystem' , 'InterconnectedSystem' , 'nlsys' ,
3333 'input_output_response' , 'find_eqpt' , 'linearize' ,
34- 'interconnect' , 'signal_table ' ]
34+ 'interconnect' , 'connection_table ' ]
3535
3636
3737class NonlinearIOSystem (InputOutputSystem ):
@@ -1001,11 +1001,11 @@ def unused_signals(self):
10011001 return ({inputs [i ][:2 ]: inputs [i ][2 ] for i in unused_sysinp },
10021002 {outputs [i ][:2 ]: outputs [i ][2 ] for i in unused_sysout })
10031003
1004- def signal_table (self , show_names = False ):
1005- """Print table of signal names, sources, and destinations .
1004+ def connection_table (self , show_names = False , column_width = 32 ):
1005+ """Print table of connections inside an interconnected system model .
10061006
1007- Intended primarily for systems that have been connected implicitly
1008- using signal names.
1007+ Intended primarily for :class:`InterconnectedSystems` that have been
1008+ connected implicitly using signal names.
10091009
10101010 Parameters
10111011 ----------
@@ -1014,23 +1014,28 @@ def signal_table(self, show_names=False):
10141014 each system. Default is False because system name is not usually
10151015 specified when performing implicit interconnection using
10161016 :func:`interconnect`.
1017+ column_width : int (optional)
1018+ Character width of printed columns
10171019
10181020 Examples
10191021 --------
10201022 >>> P = ct.ss(1,1,1,0, inputs='u', outputs='y', name='P')
10211023 >>> C = ct.tf(10, [.1, 1], inputs='e', outputs='u', name='C')
10221024 >>> L = ct.interconnect([C, P], inputs='e', outputs='y')
1023- >>> L.signal_table (show_names=True) # doctest: +SKIP
1025+ >>> L.connection_table (show_names=True) # doctest: +SKIP
10241026 signal | source | destination
10251027 --------------------------------------------------------------------
10261028 e | input | C
10271029 u | C | P
10281030 y | P | output
10291031 """
10301032
1031- spacing = 32
1032- print ('signal' .ljust (10 ) + '| source' .ljust (spacing ) + '| destination' )
1033- print ('-' * (10 + spacing * 2 ))
1033+ print ('signal' .ljust (10 ) + '| source' .ljust (column_width ) + \
1034+ '| destination' )
1035+ print ('-' * (10 + column_width * 2 ))
1036+
1037+ # TODO: version of this method that is better suited
1038+ # to explicitly-connected systems
10341039
10351040 # collect signal labels
10361041 signal_labels = []
@@ -1061,8 +1066,12 @@ def signal_table(self, show_names=False):
10611066 if not dests .endswith (' ' ):
10621067 dests += ', '
10631068 dests += sys .name if show_names else 'system ' + str (idx )
1064- print (sources .ljust (spacing ), end = '' )
1065- print (dests .ljust (spacing ), end = '\n ' )
1069+ if len (sources ) >= column_width :
1070+ sources = sources [:column_width - 3 ] + '.. '
1071+ print (sources .ljust (column_width ), end = '' )
1072+ if len (dests ) > column_width :
1073+ dests = dests [:column_width - 3 ] + '.. '
1074+ print (dests .ljust (column_width ), end = '\n ' )
10661075
10671076 def _find_inputs_by_basename (self , basename ):
10681077 """Find all subsystem inputs matching basename
@@ -2018,7 +2027,7 @@ def interconnect(
20182027 signals are given names, then the forms 'sys.sig' or ('sys', 'sig')
20192028 are also recognized. Finally, for multivariable systems the signal
20202029 index can be given as a list, for example '(subsys_i, [inp_j1, ...,
2021- inp_jn])'; as a slice, for example, 'sys.sig[i:j]'; or as a base
2030+ inp_jn])'; or as a slice, for example, 'sys.sig[i:j]'; or as a base
20222031 name `sys.sig` (which matches `sys.sig[i]`).
20232032
20242033 Similarly, each output-spec should describe an output signal from
@@ -2235,8 +2244,7 @@ def interconnect(
22352244 raise ValueError ('check_unused is False, but either '
22362245 + 'ignore_inputs or ignore_outputs non-empty' )
22372246
2238- if connections is False and not inplist and not outlist \
2239- and not inputs and not outputs :
2247+ if connections is False and not any ((inplist , outlist , inputs , outputs )):
22402248 # user has disabled auto-connect, and supplied neither input
22412249 # nor output mappings; assume they know what they're doing
22422250 check_unused = False
@@ -2564,11 +2572,11 @@ def _convert_static_iosystem(sys):
25642572 None , lambda t , x , u , params : sys @ u ,
25652573 outputs = sys .shape [0 ], inputs = sys .shape [1 ])
25662574
2567- def signal_table (sys , show_names = False ):
2568- """Print table of signal names, sources, and destinations .
2575+ def connection_table (sys , show_names = False , column_width = 32 ):
2576+ """Print table of connections inside an interconnected system model .
25692577
2570- Intended primarily for systems that have been connected implicitly
2571- using signal names.
2578+ Intended primarily for :class:`InterconnectedSystems` that have been
2579+ connected implicitly using signal names.
25722580
25732581 Parameters
25742582 ----------
@@ -2579,13 +2587,16 @@ def signal_table(sys, show_names=False):
25792587 each system. Default is False because system name is not usually
25802588 specified when performing implicit interconnection using
25812589 :func:`interconnect`.
2590+ column_width : int (optional)
2591+ Character width of printed columns
2592+
25822593
25832594 Examples
25842595 --------
25852596 >>> P = ct.ss(1,1,1,0, inputs='u', outputs='y', name='P')
25862597 >>> C = ct.tf(10, [.1, 1], inputs='e', outputs='u', name='C')
25872598 >>> L = ct.interconnect([C, P], inputs='e', outputs='y')
2588- >>> L.signal_table (show_names=True) # doctest: +SKIP
2599+ >>> L.connection_table (show_names=True) # doctest: +SKIP
25892600 signal | source | destination
25902601 --------------------------------------------------------------
25912602 e | input | C
@@ -2595,4 +2606,4 @@ def signal_table(sys, show_names=False):
25952606 assert isinstance (sys , InterconnectedSystem ), "system must be" \
25962607 "an InterconnectedSystem."
25972608
2598- sys .signal_table (show_names = show_names )
2609+ sys .connection_table (show_names = show_names )
0 commit comments