From a6f6baff2ed0f430ec9cd368a048606d20ba49b2 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Mon, 22 Jul 2013 15:06:52 +0200 Subject: [PATCH] matlab: enable 'x', 'y' or 'z' as port direction char Signed-off-by: Thorsten Liebig --- matlab/AddMSLPort.m | 18 ++++++------------ matlab/AddRectWaveGuidePort.m | 4 ++-- matlab/AddWaveGuidePort.m | 8 +++----- matlab/Tutorials/Rect_Waveguide.m | 4 ++-- 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/matlab/AddMSLPort.m b/matlab/AddMSLPort.m index a1d893e..1a79203 100644 --- a/matlab/AddMSLPort.m +++ b/matlab/AddMSLPort.m @@ -7,7 +7,7 @@ function [CSX,port] = AddMSLPort( CSX, prio, portnr, materialname, start, stop, % materialname: property for the MSL (created by AddMetal()) % start: 3D start rowvector for port definition % stop: 3D end rowvector for port definition -% dir: direction of wave propagation (choices: 0 1 2) +% dir: direction of wave propagation (choices: 0, 1, 2 or 'x','y','z') % evec: excitation vector, which defines the direction of the e-field (must be the same as used in AddExcitation()) % % variable input: @@ -18,10 +18,8 @@ function [CSX,port] = AddMSLPort( CSX, prio, portnr, materialname, start, stop, % units. Default is 0. Only active if 'ExcitePort' is set! % 'Feed_R' Specifiy a lumped port resistance. Default is no lumped % port resistance --> port has to end in an ABC. -% Only active if 'ExcitePort' is set! % '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 @@ -47,15 +45,13 @@ function [CSX,port] = AddMSLPort( CSX, prio, portnr, materialname, start, stop, %check mesh if ~isfield(CSX,'RectilinearGrid') error 'mesh needs to be defined! Use DefineRectGrid() first!'; - if (~isfield(CSX.RectilinearGrid,'XLines') || ~isfield(CSX.RectilinearGrid,'YLines') || ~isfield(CSX.RectilinearGrid,'ZLines')) - error 'mesh needs to be defined! Use DefineRectGrid() first!'; - end +end +if (~isfield(CSX.RectilinearGrid,'XLines') || ~isfield(CSX.RectilinearGrid,'YLines') || ~isfield(CSX.RectilinearGrid,'ZLines')) + error 'mesh needs to be defined! Use DefineRectGrid() first!'; end % check dir -if ~( (dir >= 0) && (dir <= 2) ) - error 'dir must have exactly one component ~= 0' -end +dir = DirChar2Int(dir); % check evec if ~(evec(1) == evec(2) == 0) && ~(evec(1) == evec(3) == 0) && ~(evec(2) == evec(3) == 0) || (sum(evec) == 0) @@ -63,9 +59,6 @@ if ~(evec(1) == evec(2) == 0) && ~(evec(1) == evec(3) == 0) && ~(evec(2) == evec end evec0 = evec ./ sum(evec); % evec0 is a unit vector -%% read optional arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -n_conv_arg = 8; % number of conventional arguments - %set defaults feed_shift = 0; feed_R = inf; %(default is open, no resitance) @@ -75,6 +68,7 @@ PortNamePrefix = ''; excite_args = {}; +%% read optional arguments %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for n=1:2:numel(varargin) if (strcmp(varargin{n},'FeedShift')==1); feed_shift = varargin{n+1}; diff --git a/matlab/AddRectWaveGuidePort.m b/matlab/AddRectWaveGuidePort.m index 491a994..8233f77 100644 --- a/matlab/AddRectWaveGuidePort.m +++ b/matlab/AddRectWaveGuidePort.m @@ -11,7 +11,7 @@ function [CSX,port] = AddRectWaveGuidePort( CSX, prio, portnr, start, stop, dir, % prio: priority of primitives % start: start coordinates of waveguide port box % stop: stop coordinates of waveguide port box -% dir: direction of port (0/1/2 for x/y/z-direction) +% dir: direction of port (0/1/2 or 'x'/'y'/'z'-direction) % 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) @@ -58,8 +58,8 @@ if ~isfield(CSX,'RectilinearGrid') end unit = CSX.RectilinearGrid.ATTRIBUTE.DeltaUnit; -kc_draw = kc*unit; +dir = DirChar2Int(dir); dir_names={'x','y','z'}; dirP = mod((dir+1),3)+1; diff --git a/matlab/AddWaveGuidePort.m b/matlab/AddWaveGuidePort.m index 8c4eb0b..1a17db2 100644 --- a/matlab/AddWaveGuidePort.m +++ b/matlab/AddWaveGuidePort.m @@ -11,7 +11,7 @@ function [CSX,port] = AddWaveGuidePort( CSX, prio, portnr, start, stop, dir, E_W % prio: priority of primitives % start: start coordinates of waveguide port box % stop: stop coordinates of waveguide port box -% dir: direction of port (0/1/2 for x/y/z-direction) +% dir: direction of port (0/1/2 or 'x'/'y'/'z'-direction) % E_WG_func: electric field mode profile function as a string % H_WG_func: magnetic field mode profile function as a string % kc: cutoff wavenumber (defined by the waveguide dimensions) @@ -56,16 +56,14 @@ if ~isfield(CSX,'RectilinearGrid') error 'mesh needs to be defined! Use DefineRectGrid() first!'; end +dir = DirChar2Int(dir); + port.type='WaveGuide'; port.nr=portnr; port.kc = kc; port.dir = dir; port.drawingunit = CSX.RectilinearGrid.ATTRIBUTE.DeltaUnit; -if ~( (dir==0) || (dir==1) || (dir==2) ) - error 'dir must be 0, 1 or 2' -end - PortNamePrefix = ''; varargin_tmp = varargin; diff --git a/matlab/Tutorials/Rect_Waveguide.m b/matlab/Tutorials/Rect_Waveguide.m index 3cbfea0..e47ea36 100644 --- a/matlab/Tutorials/Rect_Waveguide.m +++ b/matlab/Tutorials/Rect_Waveguide.m @@ -50,11 +50,11 @@ CSX = DefineRectGrid(CSX, unit,mesh); %% apply the waveguide port %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% start=[mesh.x(1) mesh.y(1) mesh.z(8)]; stop =[mesh.x(end) mesh.y(end) mesh.z(15)]; -[CSX, port{1}] = AddRectWaveGuidePort( CSX, 0, 1, start, stop, 2, a*unit, b*unit, TE_mode, 1); +[CSX, port{1}] = AddRectWaveGuidePort( CSX, 0, 1, start, stop, 'z', a*unit, b*unit, TE_mode, 1); start=[mesh.x(1) mesh.y(1) mesh.z(end-13)]; stop =[mesh.x(end) mesh.y(end) mesh.z(end-14)]; -[CSX, port{2}] = AddRectWaveGuidePort( CSX, 0, 2, start, stop, 2, a*unit, b*unit, TE_mode); +[CSX, port{2}] = AddRectWaveGuidePort( CSX, 0, 2, start, stop, 'z', a*unit, b*unit, TE_mode); %% define dump box... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,4');