2012-11-09 14:41:18 +00:00
function [CSX, port] = AddLumpedPort ( CSX, prio, portnr, R, start, stop, dir, excite, varargin )
% [CSX, port] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excite, varargin )
2011-07-13 07:38:31 +00:00
%
2013-01-23 08:11:36 +00:00
% Add a lumped port as an excitation.
2010-06-09 07:53:49 +00:00
%
2012-12-12 21:27:47 +00:00
% A lumped port consists of an excitation, a lumped resistor, a voltage and
% current probe.
%
2011-02-08 09:33:17 +00:00
% CSX: CSX-object created by InitCSX()
% prio: priority for substrate and probe boxes
% portnr: (integer) number of the port
2012-12-12 21:27:47 +00:00
% R: internal resistance of the port (lumped element)
2011-02-08 09:33:17 +00:00
% start: 3D start rowvector for port definition
% stop: 3D end rowvector for port definition
2011-07-13 07:38:31 +00:00
% dir: direction/amplitude of port (e.g.: [1 0 0], [0 1 0] or [0 0 1])
2012-10-29 14:34:21 +00:00
% excite (optional): if true, the port will be switched on (see AddExcitation())
% Note: for legacy support a string will be accepted
2013-04-04 12:54:26 +00:00
% optional (key/values):
% 'PortNamePrefix': an prefix to the port name
2011-07-13 07:38:31 +00:00
% varargin (optional): additional excitations options, see also AddExcitation
2010-06-09 07:53:49 +00:00
%
% example:
2013-01-23 08:11:36 +00:00
% start = [0 -width/2 0];
% stop = [0 width/2 height];
% [CSX] = AddLumpedPort(CSX, 5 ,1 , 50, start, stop, [0 0 1], true);
% %this defines an active lumped port in z-direction with a 50 Ohm port impedence
2010-06-09 07:53:49 +00:00
%
2011-07-13 07:38:31 +00:00
% openEMS matlab interface
% -----------------------
2010-06-09 07:53:49 +00:00
% Sebastian Held <sebastian.held@gmx.de>
% Jun 1 2010
2011-07-13 07:38:31 +00:00
% Thorsten Liebig
% Jul 13 2011
2010-06-09 07:53:49 +00:00
%
% See also InitCSX AddExcitation
% check dir
2012-11-09 14:41:18 +00:00
port . type = ' Lumped' ;
port . nr = portnr ;
2011-07-13 07:38:31 +00:00
if ( dir ( 1 ) ~= 0 ) && ( dir ( 2 ) == 0 ) && ( dir ( 3 ) == 0 )
n_dir = 1 ;
elseif ( dir ( 1 ) == 0 ) && ( dir ( 2 ) ~= 0 ) && ( dir ( 3 ) == 0 )
n_dir = 2 ;
elseif ( dir ( 1 ) == 0 ) && ( dir ( 2 ) == 0 ) && ( dir ( 3 ) ~= 0 )
n_dir = 3 ;
else
error ' dir must have exactly one component ~= 0'
2010-06-09 07:53:49 +00:00
end
2013-04-04 12:54:26 +00:00
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
2013-01-22 08:22:01 +00:00
if ( stop ( n_dir ) == start ( n_dir ) )
error ' start/stop in excitation direction in must not be equal'
2010-06-09 07:53:49 +00:00
end
2011-07-13 07:38:31 +00:00
if ( stop ( n_dir ) - start ( n_dir ) ) > 0
2010-06-09 07:53:49 +00:00
direction = + 1 ;
else
direction = - 1 ;
end
2012-11-09 14:41:18 +00:00
port . direction = direction ;
2010-06-09 07:53:49 +00:00
2012-11-09 14:41:18 +00:00
port . Feed_R = R ;
2012-07-23 10:12:16 +00:00
if ( R > 0 && ( ~ isinf ( R ) ) )
2013-04-04 12:54:26 +00:00
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 ) ;
2012-07-23 10:12:16 +00:00
elseif ( R < = 0 )
2013-04-04 12:54:26 +00:00
CSX = AddMetal ( CSX , [ PortNamePrefix ' port_resist_' int2str ( portnr ) ] ) ;
CSX = AddBox ( CSX , [ PortNamePrefix ' port_resist_' int2str ( portnr ) ] , prio , start , stop ) ;
2012-02-10 10:50:31 +00:00
end
2010-06-09 07:53:49 +00:00
2012-10-29 14:34:21 +00:00
if ( nargin < 8 )
excite = false ;
end
% legacy support, will be removed at some point
if ischar ( excite )
warning ( ' CSXCAD:AddLumpedPort' , ' depreceated: a string as excite option is no longer supported and will be removed in the future, please use true or false' ) ;
if ~ isempty ( excite )
excite = true ;
else
excite = false ;
end
end
2012-11-09 14:41:18 +00:00
port . excite = excite ;
2011-07-13 07:38:31 +00:00
% create excitation
2012-10-29 14:34:21 +00:00
if ( excite )
2013-04-04 12:54:26 +00:00
CSX = AddExcitation ( CSX , [ PortNamePrefix ' port_excite_' num2str ( portnr ) ] , 0 , - dir * direction , varargin { : } ) ;
CSX = AddBox ( CSX , [ PortNamePrefix ' port_excite_' num2str ( portnr ) ] , prio , start , stop ) ;
2011-07-13 07:38:31 +00:00
end
2010-06-09 07:53:49 +00:00
2011-07-13 07:38:31 +00:00
u_start = 0.5 * ( start + stop ) ;
u_stop = 0.5 * ( start + stop ) ;
u_start ( n_dir ) = start ( n_dir ) ;
u_stop ( n_dir ) = stop ( n_dir ) ;
2010-06-09 07:53:49 +00:00
2013-04-04 12:54:26 +00:00
port . U_filename = [ PortNamePrefix ' port_ut' int2str ( portnr ) ] ;
2013-03-22 12:52:27 +00:00
CSX = AddProbe ( CSX , port . U_filename , 0 , ' weight' , - direction ) ;
CSX = AddBox ( CSX , port . U_filename , prio , u_start , u_stop ) ;
2010-06-09 07:53:49 +00:00
2011-07-13 07:38:31 +00:00
i_start = start ;
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 ) ) ;
2010-06-09 07:53:49 +00:00
2013-04-04 12:54:26 +00:00
port . I_filename = [ PortNamePrefix ' port_it' int2str ( portnr ) ] ;
2013-03-22 12:52:27 +00:00
CSX = AddProbe ( CSX , port . I_filename , 1 , ' weight' , direction , ' NormDir' , n_dir - 1 ) ;
CSX = AddBox ( CSX , port . I_filename , prio , i_start , i_stop ) ;
2010-06-09 07:53:49 +00:00