diff --git a/matlab/AddCurvePort.m b/matlab/AddCurvePort.m index 8c627bd..1c4ad9d 100644 --- a/matlab/AddCurvePort.m +++ b/matlab/AddCurvePort.m @@ -1,5 +1,5 @@ -function [CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop, excitename ) -%[CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop [, excitename] ) +function [CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop, excite, varargin ) +%[CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop [, excite, varargin] ) % % Creates a curve port (1-dimensional). % The mesh must already be initialized. @@ -11,7 +11,9 @@ function [CSX,port] = AddCurvePort( CSX, prio, portnr, R, start, stop, excitenam % R: internal resistance of the port % start: 3D start rowvector for port definition % stop: 3D end rowvector for port definition -% excitename (optional): if specified, the port will be switched on (see AddExcitation()) +% 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 % % output: % CSX: @@ -137,12 +139,26 @@ port.drawingunit = unit; % port.idx1 = idx1; port.excite = 0; +if (nargin < 7) + excite = false; +end + +% legacy support, will be removed at some point +if ischar(excite) + warning('CSXCAD:AddCurvePort','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 + % create excitation -if (nargin >= 7) && ~isempty(excitename) +if (excite) % excitation of this port is enabled port.excite = 1; e_start = v_start; e_stop = v_stop; - CSX = AddExcitation( CSX, excitename, 0, start_idx ~= stop_idx ); - CSX = AddBox( CSX, excitename, prio, e_start, e_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 ); end diff --git a/matlab/AddLumpedPort.m b/matlab/AddLumpedPort.m index dfde128..7c3635a 100644 --- a/matlab/AddLumpedPort.m +++ b/matlab/AddLumpedPort.m @@ -1,5 +1,5 @@ -function [CSX] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excitename, varargin ) -% [CSX] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excitename, varargin ) +function [CSX] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excite, varargin ) +% [CSX] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excite, varargin ) % % Add a 3D lumped port as an excitation. % @@ -10,7 +10,8 @@ function [CSX] = AddLumpedPort( CSX, prio, portnr, R, start, stop, dir, excitena % start: 3D start rowvector for port definition % stop: 3D end rowvector for port definition % dir: direction/amplitude of port (e.g.: [1 0 0], [0 1 0] or [0 0 1]) -% excitename (optional): if specified, the port will be switched on (see AddExcitation()) +% 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 % % example: @@ -58,10 +59,25 @@ elseif (R<=0) CSX = AddBox(CSX,['port_resist_' int2str(portnr)], prio, start, stop); end +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 + + % create excitation -if (nargin >= 8) && ~isempty(excitename) - CSX = AddExcitation( CSX, excitename, 0, -dir*direction, varargin{:}); - CSX = AddBox( CSX, excitename, prio, start, stop ); +if (excite) + CSX = AddExcitation( CSX, ['port_excite_' num2str(portnr)], 0, -dir*direction, varargin{:}); + CSX = AddBox( CSX, ['port_excite_' num2str(portnr)], prio, start, stop ); end u_start = 0.5*(start + stop); diff --git a/matlab/AddMSLPort.m b/matlab/AddMSLPort.m index 6205ff3..0c0828d 100644 --- a/matlab/AddMSLPort.m +++ b/matlab/AddMSLPort.m @@ -11,7 +11,8 @@ 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: -% 'ExcitePort' necessary excitation name to make the port an active feeding port +% '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 % units. Default is 0. Only active if 'ExcitePort' is set! % 'Feed_R' Specifiy a lumped port resistance. Default is no lumped @@ -66,35 +67,41 @@ n_conv_arg = 8; % number of conventional arguments %set defaults feed_shift = 0; feed_R = 0; -excitename = ''; +excite = false; measplanepos = nan; -if (nargin>n_conv_arg) - for n=1:2:(nargin-n_conv_arg) - if (strcmp(varargin{n},'FeedShift')==1); - feed_shift = varargin{n+1}; - if (numel(feed_shift)>1) - error 'FeedShift must be a scalar value' +excite_args = {}; + +for n=1:2:numel(varargin) + if (strcmp(varargin{n},'FeedShift')==1); + feed_shift = varargin{n+1}; + if (numel(feed_shift)>1) + error 'FeedShift must be a scalar value' + end + elseif (strcmp(varargin{n},'Feed_R')==1); + feed_R = varargin{n+1}; + if (numel(feed_shift)>1) + error 'Feed_R must be a scalar value' + end + elseif (strcmp(varargin{n},'MeasPlaneShift')==1); + measplanepos = varargin{n+1}; + if (numel(feed_shift)>1) + error 'MeasPlaneShift must be a scalar value' + end + elseif (strcmp(varargin{n},'ExcitePort')==1); + if ischar(varargin{n+1}) + warning('CSXCAD:AddMSLPort','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 + else + excite = varargin{n+1}; end - - if (strcmp(varargin{n},'Feed_R')==1); - feed_R = varargin{n+1}; - if (numel(feed_shift)>1) - error 'Feed_R must be a scalar value' - end - end - - if (strcmp(varargin{n},'MeasPlaneShift')==1); - measplanepos = varargin{n+1}; - if (numel(feed_shift)>1) - error 'MeasPlaneShift must be a scalar value' - end - end - - if (strcmp(varargin{n},'ExcitePort')==1); - excitename = varargin{n+1}; - end + else + excite_args{end+1} = varargin{n}; + excite_args{end+1} = varargin{n+1}; end end @@ -227,9 +234,9 @@ ex_stop(idx_prop) = ex_start(idx_prop); ex_stop(idx_width) = nstop(idx_width); ex_stop(idx_height) = nstop(idx_height); -if ~isempty(excitename) - CSX = AddExcitation( CSX, excitename, 0, evec ); - CSX = AddBox( CSX, excitename, prio, ex_start, ex_stop ); +if excite + CSX = AddExcitation( CSX, ['port_excite_' num2str(portnr)], 0, evec, excite_args{:} ); + CSX = AddBox( CSX, ['port_excite_' num2str(portnr)], prio, ex_start, ex_stop ); end if feed_R > 0 CSX = AddLumpedElement( CSX, 'port_R', idx_height-1, 'R', feed_R ); diff --git a/matlab/Tutorials/MSL_NotchFilter.m b/matlab/Tutorials/MSL_NotchFilter.m index 45019e9..728f79f 100644 --- a/matlab/Tutorials/MSL_NotchFilter.m +++ b/matlab/Tutorials/MSL_NotchFilter.m @@ -51,7 +51,7 @@ CSX = AddBox( CSX, 'RO4350B', 0, start, stop ); CSX = AddMetal( CSX, 'PEC' ); portstart = [ mesh.x(1), -MSL_width/2, substrate_thickness]; portstop = [ 0, MSL_width/2, 0]; -[CSX,portstruct{1}] = AddMSLPort( CSX, 999, 1, 'PEC', portstart, portstop, 0, [0 0 -1], 'ExcitePort', 'excite', 'FeedShift', 10*resolution, 'MeasPlaneShift', MSL_length/3); +[CSX,portstruct{1}] = AddMSLPort( CSX, 999, 1, 'PEC', portstart, portstop, 0, [0 0 -1], 'ExcitePort', true, 'FeedShift', 10*resolution, 'MeasPlaneShift', MSL_length/3); portstart = [mesh.x(end), -MSL_width/2, substrate_thickness]; portstop = [0 , MSL_width/2, 0]; diff --git a/matlab/Tutorials/Simple_Patch_Antenna.m b/matlab/Tutorials/Simple_Patch_Antenna.m index 9a61493..37ab7cd 100644 --- a/matlab/Tutorials/Simple_Patch_Antenna.m +++ b/matlab/Tutorials/Simple_Patch_Antenna.m @@ -49,21 +49,15 @@ FDTD = SetBoundaryCond( FDTD, BC ); %% setup CSXCAD geometry & mesh % currently, openEMS cannot automatically generate a mesh -max_res = c0 / (f0+fc) / unit / 20; % cell size: lambda/20 CSX = InitCSX(); %create fixed lines for the simulation box, substrate and port -mesh.x = [-SimBox(1)/2 SimBox(1)/2 -substrate.width/2 substrate.width/2 -patch.width/2 patch.width/2 feed.pos+[-feed.width/2 feed.width/2]]; -mesh.x = SmoothMeshLines( mesh.x, max_res, 1.4); % create a smooth mesh between specified fixed mesh lines - -mesh.y = [-SimBox(2)/2 SimBox(2)/2 -substrate.length/2 substrate.length/2 -feed.width/2 feed.width/2 -patch.length/2 patch.length/2]; -mesh.y = SmoothMeshLines( mesh.y, max_res, 1.4 ); - -%create fixed lines for the simulation box and given number of lines inside the substrate -mesh.z = [-SimBox(3)/3 linspace(0,substrate.thickness,substrate.cells) SimBox(3)*2/3 ]; -mesh.z = SmoothMeshLines( mesh.z, max_res, 1.4 ); - -CSX = DefineRectGrid( CSX, unit, mesh ); +mesh.x = [-SimBox(1)/2 SimBox(1)/2 -substrate.width/2 substrate.width/2 -patch.width/2 patch.width/2 feed.pos+[-feed.width/2 feed.width/2]]; +mesh.y = [-SimBox(2)/2 SimBox(2)/2 -substrate.length/2 substrate.length/2 -feed.width/2 feed.width/2 -patch.length/2 patch.length/2]; +mesh.z = [-SimBox(3)/3 SimBox(3)*2/3 linspace(0,substrate.thickness,substrate.cells) ]; +% generate a smooth mesh with max. cell size: lambda_min / 20 +mesh = SmoothMesh(mesh, c0 / (f0+fc) / unit / 20); +CSX = DefineRectGrid(CSX, unit, mesh); %% create patch CSX = AddMetal( CSX, 'patch' ); % create a perfect electric conductor (PEC) @@ -87,7 +81,7 @@ CSX = AddBox(CSX,'gnd',10,start,stop); %% apply the excitation & resist as a current source start = [feed.pos-feed.width/2 -feed.width/2 0]; stop = [feed.pos+feed.width/2 +feed.width/2 substrate.thickness]; -[CSX] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 0 1], 'excite'); +[CSX] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 0 1], true); %%nf2ff calc start = [mesh.x(4) mesh.y(4) mesh.z(4)];