Skip to content

Commit

Permalink
fixed bug in connect for multiport connections
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenovic committed Jul 8, 2015
1 parent 427bcaf commit 45fddf4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
17 changes: 15 additions & 2 deletions skrf/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,6 +2678,11 @@ def connect(ntwkA, k, ntwkB, l, num=1):
# some checking
check_frequency_equal(ntwkA,ntwkB)

if (k+num-1> ntwkA.nports-1):
raise IndexError('Port `k` out of range')
if (l+num-1> ntwkB.nports-1):
raise IndexError('Port `l` out of range')

# create output Network, from copy of input
ntwkC = ntwkA.copy()

Expand All @@ -2703,7 +2708,8 @@ def connect(ntwkA, k, ntwkB, l, num=1):
ntwkC.z0 = npy.hstack(
(npy.delete(ntwkA.z0, range(k,k+1), 1), npy.delete(ntwkB.z0, range(l,l+1), 1)))

# if we're connecting more than one port, call innerconnect to finish the job
# if we're connecting more than one port, call innerconnect recursively
# untill all connections are made to finish the job
if num>1:
ntwkC = innerconnect(ntwkC, k, ntwkA.nports-1+l, num-1)

Expand Down Expand Up @@ -2839,6 +2845,13 @@ def innerconnect(ntwkA, k, l, num=1):
>>> ntwkC = rf.innerconnect(ntwkA, 0,1)
'''

if (k+num-1> ntwkA.nports-1):
raise IndexError('Port `k` out of range')
if (l+num-1> ntwkA.nports-1):
raise IndexError('Port `l` out of range')


# create output Network, from copy of input
ntwkC = ntwkA.copy()

Expand All @@ -2859,7 +2872,7 @@ def innerconnect(ntwkA, k, l, num=1):
ntwkC.s = innerconnect_s(ntwkC.s,k,l)

# update the characteristic impedance matrix
ntwkC.z0 = npy.delete(ntwkC.z0, list(range(k,k+num)) + list(range(l,l+num)),1)
ntwkC.z0 = npy.delete(ntwkC.z0, list(range(k,k+1)) + list(range(l,l+1)),1)

# recur if we're connecting more than one port
if num>1:
Expand Down
5 changes: 4 additions & 1 deletion skrf/taper.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ def __init__(self, med, param, start, stop, n_sections, length,f,kw={}):
self.length =length
self.n_sections= n_sections
self.kw = kw


def __str__(self):
return 'Taper: {classname}: {param} from {start}-{stop}'


@property
def section_length(self):
Expand Down
6 changes: 6 additions & 0 deletions skrf/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,14 @@ def test_connect_multiports(self):
b.frequency=(1,)
b.s = npy.arange(16).reshape(4,4)
b.z0 = npy.arange(4)+10

c=rf.connect(a,2,b,0,2)
self.assertTrue((c.z0==[0,1,12,13]).all())

d=rf.connect(a,0,b,0,3)
self.assertTrue((d.z0==[3,13]).all())



def test_connect_fast(self):
raise SkipTest('not supporting this function currently ')
Expand Down

0 comments on commit 45fddf4

Please sign in to comment.