matlab: port names support a prefix string

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
This commit is contained in:
Thorsten Liebig 2013-04-04 14:54:26 +02:00
parent 7bbd70a951
commit 5f0261b3c5
6 changed files with 77 additions and 29 deletions

View File

@ -15,7 +15,10 @@ function [CSX,port] = AddCircWaveGuidePort( CSX, prio, portnr, start, stop, radi
% mode_name: mode name, e.g. 'TE11' or 'TM21'
% pol_ang: polarization angle (e.g. 0 = horizontal, pi/2 = vertical)
% exc_amp: excitation amplitude (set 0 to be passive)
%
% optional (key/values):
% varargin: optional additional excitations options, see also AddExcitation
% 'PortNamePrefix': a prefix to the port name
%
% output:
% CSX: modified CSX structure

View File

@ -13,7 +13,9 @@ function [CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop, excite, v
% stop: 3D end rowvector for port definition
% excite (optional): if true, the port will be switched on (see AddExcitation())
% Note: for legacy support a string will be accepted
% varargin (optional): additional excitations options, see also AddExcitation
% optional (key/values):
% varargin: optional additional excitations options, see also AddExcitation
% 'PortNamePrefix': a prefix to the port name
%
% output:
% CSX:
@ -30,6 +32,16 @@ function [CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop, excite, v
port.type='Lumped';
port.nr=portnr;
PortNamePrefix = '';
varargin_tmp = varargin;
for n=1:2:numel(varargin_tmp)
if strcmpi('PortNamePrefix',varargin_tmp{n})
PortNamePrefix = varargin_tmp{n+1};
varargin([n n+1]) = [];
end
end
% make row vector
start = reshape( start, 1, [] );
stop = reshape( stop , 1, [] );
@ -79,7 +91,7 @@ if abs(start_idx(dir) - stop_idx(dir)) ~= 1
port_stop_idx(dir) = idx+1;
port_stop_idx(dir1) = idx1;
port_stop_idx(dir2) = idx2;
metalname = ['port' num2str(portnr) '_PEC'];
metalname = [PortNamePrefix 'port' num2str(portnr) '_PEC'];
CSX = AddMetal( CSX, metalname );
CSX = AddCurve( CSX, metalname, prio, [nstart.' [mesh{1}(port_start_idx(1));mesh{2}(port_start_idx(2));mesh{3}(port_start_idx(3))]] );
CSX = AddCurve( CSX, metalname, prio, [nstop.' [mesh{1}(port_stop_idx(1));mesh{2}(port_stop_idx(2));mesh{3}(port_stop_idx(3))]] );
@ -112,11 +124,11 @@ i_start(dir) = (i_start(dir)+i_stop(dir))/2;
i_stop(dir) = i_start(dir);
% create the probes
name = ['port_ut' num2str(portnr)];
name = [PortNamePrefix 'port_ut' num2str(portnr)];
weight = -1;
CSX = AddProbe( CSX, name, 0, 'weight', weight );
CSX = AddBox( CSX, name, prio, v_start, v_stop );
name = ['port_it' num2str(portnr)];
name = [PortNamePrefix 'port_it' num2str(portnr)];
weight = 1;
CSX = AddProbe( CSX, name, 1, 'weight', weight );
CSX = AddBox( CSX, name, prio, i_start, i_stop );
@ -157,14 +169,14 @@ if (excite)
port.excite = 1;
e_start = v_start;
e_stop = v_stop;
CSX = AddExcitation( CSX, ['port_excite_' num2str(portnr)], 0, start_idx ~= stop_idx, varargin{:});
CSX = AddBox( CSX, ['port_excite_' num2str(portnr)], prio, e_start, e_stop );
CSX = AddExcitation( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], 0, start_idx ~= stop_idx, varargin{:});
CSX = AddBox( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], prio, e_start, e_stop );
end
port.Feed_R = R;
if (R>0 && (~isinf(R)))
CSX = AddLumpedElement( CSX, ['port_resist_' int2str(portnr)], dir-1, 'R', R);
CSX = AddBox( CSX, ['port_resist_' int2str(portnr)], prio, v_start, v_stop );
CSX = AddLumpedElement( CSX, [PortNamePrefix 'port_resist_' int2str(portnr)], dir-1, 'R', R);
CSX = AddBox( CSX, [PortNamePrefix 'port_resist_' int2str(portnr)], prio, v_start, v_stop );
elseif (R==0)
CSX = AddBox(CSX,metalname, prio, v_start, v_stop);
end

View File

@ -15,6 +15,8 @@ function [CSX, port] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, ex
% dir: direction/amplitude of port (e.g.: [1 0 0], [0 1 0] or [0 0 1])
% excite (optional): if true, the port will be switched on (see AddExcitation())
% Note: for legacy support a string will be accepted
% optional (key/values):
% 'PortNamePrefix': an prefix to the port name
% varargin (optional): additional excitations options, see also AddExcitation
%
% example:
@ -47,6 +49,16 @@ else
error 'dir must have exactly one component ~= 0'
end
PortNamePrefix = '';
varargin_tmp = varargin;
for n=1:2:numel(varargin_tmp)
if strcmpi('PortNamePrefix',varargin_tmp{n})
PortNamePrefix = varargin_tmp{n+1};
varargin([n n+1]) = [];
end
end
if (stop(n_dir)==start(n_dir))
error 'start/stop in excitation direction in must not be equal'
end
@ -60,11 +72,11 @@ port.direction = direction;
port.Feed_R = R;
if (R>0 && (~isinf(R)))
CSX = AddLumpedElement(CSX,['port_resist_' int2str(portnr)], n_dir-1, 'Caps', 1, 'R', R);
CSX = AddBox(CSX,['port_resist_' int2str(portnr)], prio, start, stop);
CSX = AddLumpedElement(CSX,[PortNamePrefix 'port_resist_' int2str(portnr)], n_dir-1, 'Caps', 1, 'R', R);
CSX = AddBox(CSX,[PortNamePrefix 'port_resist_' int2str(portnr)], prio, start, stop);
elseif (R<=0)
CSX = AddMetal(CSX,['port_resist_' int2str(portnr)]);
CSX = AddBox(CSX,['port_resist_' int2str(portnr)], prio, start, stop);
CSX = AddMetal(CSX,[PortNamePrefix 'port_resist_' int2str(portnr)]);
CSX = AddBox(CSX,[PortNamePrefix 'port_resist_' int2str(portnr)], prio, start, stop);
end
if (nargin < 8)
@ -84,8 +96,8 @@ end
port.excite = excite;
% create excitation
if (excite)
CSX = AddExcitation( CSX, ['port_excite_' num2str(portnr)], 0, -dir*direction, varargin{:});
CSX = AddBox( CSX, ['port_excite_' num2str(portnr)], prio, start, stop );
CSX = AddExcitation( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], 0, -dir*direction, varargin{:});
CSX = AddBox( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], prio, start, stop );
end
u_start = 0.5*(start + stop);
@ -93,7 +105,7 @@ u_stop = 0.5*(start + stop);
u_start(n_dir) = start(n_dir);
u_stop(n_dir) = stop(n_dir);
port.U_filename = ['port_ut' int2str(portnr)];
port.U_filename = [PortNamePrefix 'port_ut' int2str(portnr)];
CSX = AddProbe(CSX, port.U_filename, 0, 'weight', -direction);
CSX = AddBox(CSX, port.U_filename, prio, u_start, u_stop);
@ -102,7 +114,7 @@ i_stop = stop;
i_start(n_dir) = 0.5*(start(n_dir)+stop(n_dir));
i_stop(n_dir) = 0.5*(start(n_dir)+stop(n_dir));
port.I_filename = ['port_it' int2str(portnr)];
port.I_filename = [PortNamePrefix 'port_it' int2str(portnr)];
CSX = AddProbe(CSX, port.I_filename, 1, 'weight', direction, 'NormDir', n_dir-1);
CSX = AddBox(CSX, port.I_filename, prio, i_start, i_stop);

View File

@ -11,6 +11,7 @@ function [CSX,port] = AddMSLPort( CSX, prio, portnr, materialname, start, stop,
% evec: excitation vector, which defines the direction of the e-field (must be the same as used in AddExcitation())
%
% variable input:
% varargin: optional additional excitations options, see also AddExcitation
% 'ExcitePort' true/false to make the port an active feeding port (default
% is false)
% 'FeedShift' shift to port from start by a given distance in drawing
@ -21,6 +22,7 @@ function [CSX,port] = AddMSLPort( CSX, prio, portnr, materialname, start, stop,
% 'MeasPlaneShift' Shift the measurement plane from start t a given distance
% in drawing units. Default is the middle of start/stop.
% Only active if 'ExcitePort' is set!
% 'PortNamePrefix' a prefix to the port name
%
% the mesh must be already initialized
%
@ -69,6 +71,7 @@ feed_shift = 0;
feed_R = inf; %(default is open, no resitance)
excite = false;
measplanepos = nan;
PortNamePrefix = '';
excite_args = {};
@ -99,6 +102,8 @@ for n=1:2:numel(varargin)
else
excite = varargin{n+1};
end
elseif (strcmpi(varargin{n},'PortNamePrefix'))
PortNamePrefix = varargin{n+1};
else
excite_args{end+1} = varargin{n};
excite_args{end+1} = varargin{n+1};
@ -189,23 +194,23 @@ i2_start(idx_prop) = sum(meshlines(2:3))/2;
i2_stop(idx_prop) = i2_start(idx_prop);
% create the probes
port.U_filename{1} = ['port_ut' num2str(portnr) 'A'];
port.U_filename{1} = [PortNamePrefix 'port_ut' num2str(portnr) 'A'];
% weight = sign(stop(idx_height)-start(idx_height))
weight = upsidedown;
CSX = AddProbe( CSX, port.U_filename{1}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{1}, prio, v1_start, v1_stop );
port.U_filename{2} = ['port_ut' num2str(portnr) 'B'];
port.U_filename{2} = [PortNamePrefix 'port_ut' num2str(portnr) 'B'];
CSX = AddProbe( CSX, port.U_filename{2}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{2}, prio, v2_start, v2_stop );
port.U_filename{3} = ['port_ut' num2str(portnr) 'C'];
port.U_filename{3} = [PortNamePrefix 'port_ut' num2str(portnr) 'C'];
CSX = AddProbe( CSX, port.U_filename{3}, 0, 'weight', weight );
CSX = AddBox( CSX, port.U_filename{3}, prio, v3_start, v3_stop );
weight = direction;
port.I_filename{1} = ['port_it' num2str(portnr) 'A'];
port.I_filename{1} = [PortNamePrefix 'port_it' num2str(portnr) 'A'];
CSX = AddProbe( CSX, port.I_filename{1}, 1, 'weight', weight );
CSX = AddBox( CSX, port.I_filename{1}, prio, i1_start, i1_stop );
port.I_filename{2} = ['port_it' num2str(portnr) 'B'];
port.I_filename{2} = [PortNamePrefix 'port_it' num2str(portnr) 'B'];
CSX = AddProbe( CSX, port.I_filename{2}, 1,'weight', weight );
CSX = AddBox( CSX, port.I_filename{2}, prio, i2_start, i2_stop );
@ -236,8 +241,8 @@ ex_stop(idx_height) = nstop(idx_height);
port.excite = 0;
if excite
port.excite = 1;
CSX = AddExcitation( CSX, ['port_excite_' num2str(portnr)], 0, evec, excite_args{:} );
CSX = AddBox( CSX, ['port_excite_' num2str(portnr)], prio, ex_start, ex_stop );
CSX = AddExcitation( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], 0, evec, excite_args{:} );
CSX = AddBox( CSX, [PortNamePrefix 'port_excite_' num2str(portnr)], prio, ex_start, ex_stop );
end
%% MSL resitance at start of MSL line
@ -245,8 +250,8 @@ ex_start(idx_prop) = start(idx_prop);
ex_stop(idx_prop) = ex_start(idx_prop);
if (feed_R > 0) && ~isinf(feed_R)
CSX = AddLumpedElement( CSX, 'port_R', idx_height-1, 'R', feed_R );
CSX = AddBox( CSX, 'port_R', prio, ex_start, ex_stop );
CSX = AddLumpedElement( CSX, [PortNamePrefix 'port_resist_' int2str(portnr)], idx_height-1, 'R', feed_R );
CSX = AddBox( CSX, [PortNamePrefix 'port_resist_' int2str(portnr)], prio, ex_start, ex_stop );
elseif isinf(feed_R)
% do nothing --> open port
elseif feed_R == 0

View File

@ -15,7 +15,10 @@ function [CSX,port] = AddRectWaveGuidePort( CSX, prio, portnr, start, stop, dir,
% a,b: rectangular waveguide width and height (in meter)
% mode_name: mode name, e.g. 'TE11' or 'TM21'
% exc_amp: excitation amplitude (set 0 to be passive)
%
% optional (key/values):
% varargin: optional additional excitations options, see also AddExcitation
% 'PortNamePrefix': a prefix to the port name
%
% output:
% CSX: modified CSX structure

View File

@ -6,7 +6,7 @@ function [CSX,port] = AddWaveGuidePort( CSX, prio, portnr, start, stop, dir, E_W
% Note: - The excitation will be located at the start position in the given direction
% - The voltage and current probes at the stop position in the given direction
%
% input:
% parameter:
% CSX: complete CSX structure (must contain a mesh)
% prio: priority of primitives
% start: start coordinates of waveguide port box
@ -16,7 +16,10 @@ function [CSX,port] = AddWaveGuidePort( CSX, prio, portnr, start, stop, dir, E_W
% H_WG_func: magnetic field mode profile function as a string
% kc: cutoff wavenumber (defined by the waveguide dimensions)
% exc_amp: excitation amplitude (set 0 to be passive)
%
% optional (key/values):
% varargin: optional additional excitations options, see also AddExcitation
% 'PortNamePrefix': a prefix to the port name
%
% output:
% CSX: modified CSX structure
@ -63,6 +66,16 @@ if ~( (dir==0) || (dir==1) || (dir==2) )
error 'dir must be 0, 1 or 2'
end
PortNamePrefix = '';
varargin_tmp = varargin;
for n=1:2:numel(varargin_tmp)
if strcmpi('PortNamePrefix',varargin_tmp{n})
PortNamePrefix = varargin_tmp{n+1};
varargin([n n+1]) = [];
end
end
% matlab adressing
dir = dir + 1;
dir_sign = sign(stop(dir) - start(dir));
@ -87,7 +100,7 @@ if (exc_amp~=0)
port.excitepos = e_start(dir);
e_vec = [1 1 1]*exc_amp;
e_vec(dir) = 0;
exc_name = ['port_excite_' num2str(portnr)];
exc_name = [PortNamePrefix 'port_excite_' num2str(portnr)];
CSX = AddExcitation( CSX, exc_name, 0, e_vec, varargin{:});
CSX = SetExcitationWeight(CSX, exc_name, E_WG_func );
CSX = AddBox( CSX, exc_name, prio, e_start, e_stop);
@ -99,10 +112,10 @@ m_stop = stop;
m_start(dir) = stop(dir);
port.measplanepos = m_start(dir);
port.U_filename = ['port_ut' int2str(portnr)];
port.U_filename = [PortNamePrefix 'port_ut' int2str(portnr)];
CSX = AddProbe(CSX, port.U_filename, 10, 'ModeFunction', E_WG_func);
CSX = AddBox(CSX, port.U_filename, 0 ,m_start, m_stop);
port.I_filename = ['port_it' int2str(portnr)];
port.I_filename = [PortNamePrefix 'port_it' int2str(portnr)];
CSX = AddProbe(CSX, port.I_filename, 11, 'ModeFunction', H_WG_func, 'weight', dir_sign);
CSX = AddBox(CSX, port.I_filename, 0 ,m_start, m_stop);