fixed interconnect

parent b752cd3e
Subproject commit 4b657176dfd48b6ec6ef32d4d6fbb3bec9e6fb08
Subproject commit fc99cc735d6e56f67b140a19adeba3cc4a00e876
......@@ -140,6 +140,7 @@ for nn=1:length(netlist)
componentStruct.(['c' num2str(nn)]) = res;
% replace the name of the component by the name of the field in the struct
netlist{nn}{1} = ['c' num2str(nn)];
% SI LE DERIVE EST CALCULE, AJOUTE ZEROS
end
end
end
......@@ -155,7 +156,7 @@ if args.useTerminations
termStatements = netlist(termLines);
componentStatements = netlist(~termLines);
componentNames = componentNames(~termLines);
clear termLines netlist
% clear termLines netlist
else
componentStatements = netlist;
end
......@@ -210,23 +211,25 @@ if args.layout
o = plot(g,'layout','layered','Direction','right');
end
%% Add junction if necessary
componentStruct.junction = MultiPort([-1 2 2;2 -1 2;2 2 -1]/3);
componentNames{end+1} = 'junction';
%% Add junction if necessary
% Find number of ocurrences of each node
Nodeshash = cellfun(@hash,nodeList);
occur = Nodeshash == Nodeshash.';
% Add junction to componentStruct
componentStruct.junction = MultiPort([-1 2 2;2 -1 2;2 2 -1]/3);
% if any node appears more than 2 times add junction
for i=find(sum(triu(occur),1)>2)
% find occurences
p = find(Nodeshash == Nodeshash(i));
% replace first 2 matches
% replace first 2 matches (this should be unique)
nodeList{p(1)}= [nodeList{p(1)},'1'];
nodeList{p(2)}= [nodeList{p(2)},'2'];
% Add new nodes for the junction
nodeList = [nodeList,nodeList{p(1)},nodeList{p(2)},nodeList{p(3)}];
% Add junction to component struct
componentStruct.(['junction',num2str(i)]) = MultiPort([-1 2 2;2 -1 2;2 2 -1]/3);
% Add junction name
componentNames{end+1} = ['junction',num2str(i)];
% SI LE DERIVE EST CALCULE, AJOUTE ZEROS
end
%% Construct the interconnection matrix GAMMA
......@@ -268,8 +271,10 @@ for pp=1:length(componentNames)
end
end
components = components(c);
% MEME CHOSE
% gather all the MultiMatrices in a large block-diagonal matrix
Shuge = MultiMatrix.blkdiag(components{:});
% MEME CHOSE AVEC LES DERIVÉES
% Q is the total amount of ports in the circuit
Q = size(Shuge,1);
......@@ -328,6 +333,7 @@ T = 1:Q;
reshuffle = [c T(all(c.'~=T,1))];
Shuge = Shuge(reshuffle,reshuffle,:);
GAMMA = GAMMA(reshuffle,reshuffle);
% MEME CHOSE AVEC LE DERIVE
% subplot(122)
% spy(GAMMA,'r');
......@@ -341,12 +347,14 @@ Spc = Shuge( ind,~ind,:);
Scp = Shuge(~ind, ind,:);
Scc = Shuge(~ind,~ind,:);
Gcc = GAMMA(~ind,~ind);
% MEME CHOSE AVEC LE DERIVE
% calculate the connection scattering matrix
W = (Gcc-Scc);
% calculate Spc*W\Scp
DATA = MultiMatrix.run(@(A,B,C) A*(B\C),Spc,W,Scp);
% calculate Spp+Spc*W\Scp
DATA = Spp + DATA;
% AJOUTE CALCUL POUR LE DERIVE
%% cast it to a MultiPort
% find a good candidate MultiPort in the componentStruct to overwrite
......
......@@ -8,10 +8,10 @@ clc
netlist = { 'SeriesR a b R=50',...
'ShuntR b c R=100'};
% and call the interconnect function
RES = interconnect(struct(),netlist,'frequency',1:100,'useterminations',false);
RES = interconnect(struct(),netlist,'frequency',1:100,'useterminations',false,'layout',false);
%% netlist which uses a mix of components and MultiPorts
% figure
% generate a random system
componentStruct.AMP = TwoPort(rand(2,2,100),'Freq',reshape(linspace(0.1,1,100),1,1,[]));
% connect two resistors to the AMP
......@@ -20,10 +20,11 @@ netlist = { 'SeriesR a b R=50',...
'AMP c gnd',...
'ShuntR c d R=100'};
% and call the interconnect function
RES = interconnect(componentStruct,netlist,'useterminations',false,'layout',true);
RES = interconnect(componentStruct,netlist,'useterminations',false,'layout',false);
%% netlist which uses Terminations
% use terminations to indicate the ports
% figure
netlist = { 'Term a',...
'SeriesL a b L=50e-9',...
'AMP b c',...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment