update example: Rect_Waveguide

This commit is contained in:
Thorsten Liebig 2010-12-09 12:59:10 +01:00
parent 3104335dce
commit b324296e23

View File

@ -1,36 +1,65 @@
%
% EXAMPLE / waveguide / Rect_Waveguide
%
% This example demonstrates:
% - waveguide mode excitation
% - waveguide mode matching
% - pml absorbing boundaries
%
%
% Tested with
% - Matlab 2009b
% - openEMS v0.0.17
%
% (C) 2010 Thorsten Liebig <thorsten.liebig@gmx.de>
close all close all
clear clear
clc clc
%% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% switches
length = 2000; postproc_only = 1;
unit = 1e-3;
a = 1000;
width = a;
b = 500;
height = b;
mesh_res = [10 10 10];
%define mode %% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
physical_constants;
unit = 1e-3; %drawing unit in mm
numTS = 50000; %max. number of timesteps
% waveguide dimensions
length = 2000;
a = 1000; %waveguide width
b = 600; %waveguide heigth
%waveguide TE-mode definition
m = 1; m = 1;
n = 0; n = 0;
EPS0 = 8.85418781762e-12; mesh_res = [10 10 10];
MUE0 = 1.256637062e-6;
C0 = 1/sqrt(EPS0*MUE0);
Z0 = sqrt(MUE0/EPS0);
f0 = 1e9; %% setup FDTD parameters & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%
freq = linspace(f0-f0/3,f0+f0/3,201); f_start = 175e6;
f_stop = 500e6;
k = 2*pi*freq/C0; % dump special frequencies to vtk, use paraview (www.paraview.org) to
% animate this dumps over phase
vtk_dump_freq = [200e6 300e6 500e6];
freq = linspace(f_start,f_stop,201);
k = 2*pi*freq/c0;
kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2); kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2);
fc = C0*kc/2/pi; fc = c0*kc/2/pi; %cut-off frequency
beta = sqrt(k.^2 - kc^2); beta = sqrt(k.^2 - kc^2); %waveguide phase-constant
ZL_a = k * Z0 ./ beta; %analytic waveguide impedance
ZL_a = k * Z0 ./ beta; disp([' Cutoff frequencies for this mode and wavguide is: ' num2str(fc/1e6) ' MHz']);
if (f_start<fc)
warning('openEMS:example','f_start is smaller than the cutoff-frequency, this may result in a long simulation... ');
end
%% mode functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% mode functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% by David M. Pozar, Microwave Engineering, third edition, page 113
func_Ex = [num2str( n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)']; func_Ex = [num2str( n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)'];
func_Ey = [num2str(-m/a/unit) '*sin(' num2str(m*pi/a) '*x)*cos(' num2str(n*pi/b) '*y)']; func_Ey = [num2str(-m/a/unit) '*sin(' num2str(m*pi/a) '*x)*cos(' num2str(n*pi/b) '*y)'];
@ -41,7 +70,7 @@ func_Hy = [num2str(n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b)
openEMS_opts = ''; openEMS_opts = '';
% openEMS_opts = [openEMS_opts ' --disable-dumps']; % openEMS_opts = [openEMS_opts ' --disable-dumps'];
% openEMS_opts = [openEMS_opts ' --debug-material']; % openEMS_opts = [openEMS_opts ' --debug-material'];
openEMS_opts = [openEMS_opts ' --engine=fastest']; % openEMS_opts = [openEMS_opts ' --engine=basic'];
Settings = []; Settings = [];
Settings.LogFile = 'openEMS.log'; Settings.LogFile = 'openEMS.log';
@ -49,27 +78,29 @@ Settings.LogFile = 'openEMS.log';
Sim_Path = 'tmp'; Sim_Path = 'tmp';
Sim_CSX = 'rect_wg.xml'; Sim_CSX = 'rect_wg.xml';
if (exist(Sim_Path,'dir')) if (postproc_only==0)
rmdir(Sim_Path,'s'); if (exist(Sim_Path,'dir'))
rmdir(Sim_Path,'s');
end
mkdir(Sim_Path);
end end
mkdir(Sim_Path);
%% setup FDTD parameter & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% setup FDTD parameter & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FDTD = InitFDTD(50000,1e-5,'OverSampling',6); FDTD = InitFDTD(numTS,1e-5,'OverSampling',6);
FDTD = SetGaussExcite(FDTD,f0,f0/3); FDTD = SetGaussExcite(FDTD,0.5*(f_start+f_stop),0.5*(f_stop-f_start));
BC = [0 0 0 0 0 3]; BC = [0 0 0 0 0 3];
FDTD = SetBoundaryCond(FDTD,BC); FDTD = SetBoundaryCond(FDTD,BC);
%% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSX = InitCSX(); CSX = InitCSX();
mesh.x = 0 : mesh_res(1) : width; mesh.x = SmoothMeshLines([0 a], mesh_res(1));
mesh.y = 0 : mesh_res(2) : height; mesh.y = SmoothMeshLines([0 b], mesh_res(2));
mesh.z = 0 : mesh_res(3) : length; mesh.z = SmoothMeshLines([0 length], mesh_res(3));
CSX = DefineRectGrid(CSX, unit,mesh); CSX = DefineRectGrid(CSX, unit,mesh);
%% apply the excitation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% apply the excitation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start=[0 0 mesh.z(1) ]; start=[mesh.x(1) mesh.y(1) mesh.z(1) ];
stop =[width height mesh.z(1) ]; stop =[mesh.x(end) mesh.y(end) mesh.z(1) ];
CSX = AddExcitation(CSX,'excite',0,[1 1 0]); CSX = AddExcitation(CSX,'excite',0,[1 1 0]);
weight{1} = func_Ex; weight{1} = func_Ex;
weight{2} = func_Ey; weight{2} = func_Ey;
@ -78,6 +109,7 @@ CSX = SetExcitationWeight(CSX,'excite',weight);
CSX = AddBox(CSX,'excite',0 ,start,stop); CSX = AddBox(CSX,'excite',0 ,start,stop);
%% voltage and current definitions using the mode matching probes %%%%%%%%% %% voltage and current definitions using the mode matching probes %%%%%%%%%
%port 1
start = [mesh.x(1) mesh.y(1) mesh.z(15)]; start = [mesh.x(1) mesh.y(1) mesh.z(15)];
stop = [mesh.x(end) mesh.y(end) mesh.z(15)]; stop = [mesh.x(end) mesh.y(end) mesh.z(15)];
CSX = AddProbe(CSX, 'ut1', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0}); CSX = AddProbe(CSX, 'ut1', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0});
@ -85,6 +117,7 @@ CSX = AddBox(CSX, 'ut1', 0 ,start,stop);
CSX = AddProbe(CSX,'it1', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0}); CSX = AddProbe(CSX,'it1', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0});
CSX = AddBox(CSX,'it1', 0 ,start,stop); CSX = AddBox(CSX,'it1', 0 ,start,stop);
%port 2
start = [mesh.x(1) mesh.y(1) mesh.z(end-15)]; start = [mesh.x(1) mesh.y(1) mesh.z(end-15)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end-15)]; stop = [mesh.x(end) mesh.y(end) mesh.z(end-15)];
CSX = AddProbe(CSX, 'ut2', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0}); CSX = AddProbe(CSX, 'ut2', 10, 1, [], 'ModeFunction',{func_Ex,func_Ey,0});
@ -94,18 +127,19 @@ CSX = AddBox(CSX,'it2', 0 ,start,stop);
%% define dump boxes... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% define dump boxes... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,2'); CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,2');
start = [mesh.x(1) , height/2 , mesh.z(1)]; start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) , height/2 , mesh.z(end)]; stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
CSX = AddBox(CSX,'Et',0 , start,stop); CSX = AddBox(CSX,'Et',0 , start,stop);
CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1,'SubSampling','4,4,2'); CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1,'SubSampling','4,4,2');
CSX = AddBox(CSX,'Ht',0,start,stop); CSX = AddBox(CSX,'Ht',0,start,stop);
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX); if (postproc_only==0)
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts, Settings)
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts, Settings)
end
%% postproc %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% postproc %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
U = ReadUI({'ut1','ut2'},[Sim_Path '/'],freq); U = ReadUI({'ut1','ut2'},[Sim_Path '/'],freq);
@ -127,7 +161,7 @@ if1_ref = if1 - if1_inc;
uf2_ref = uf2 - uf2_inc; uf2_ref = uf2 - uf2_inc;
if2_ref = if2 - if2_inc; if2_ref = if2 - if2_inc;
%% plot s-parameter %% plot s-parameter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure figure
s11 = uf1_ref./uf1_inc; s11 = uf1_ref./uf1_inc;
s21 = uf2_inc./uf1_inc; s21 = uf2_inc./uf1_inc;
@ -141,7 +175,7 @@ legend('s11','s21','Location','SouthEast');
ylabel('s-para (dB)'); ylabel('s-para (dB)');
xlabel('freq (Hz)'); xlabel('freq (Hz)');
%% compare analytic and numerical wave-impedance %% compare analytic and numerical wave-impedance %%%%%%%%%%%%%%%%%%%%%%%%%%
ZL = uf1./if1; ZL = uf1./if1;
figure() figure()
plot(freq,real(ZL),'Linewidth',2); plot(freq,real(ZL),'Linewidth',2);
@ -154,3 +188,41 @@ xlabel('freq (Hz)');
xlim([freq(1) freq(end)]); xlim([freq(1) freq(end)]);
legend('\Re(Z_L)','\Im(Z_L)','Z_L analytic','Location','Best'); legend('\Re(Z_L)','\Im(Z_L)','Z_L analytic','Location','Best');
%% Plot the field dumps %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dump_file = [Sim_Path '/Et.h5'];
figure()
PlotArgs.slice = {a/2*unit b/2*unit 0};
PlotArgs.pauseTime=0.01;
PlotArgs.component=0;
PlotArgs.Limit = 'auto';
PlotHDF5FieldData(dump_file, PlotArgs)
%% dump frequency to vtk %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% cleanup and create dump folder
vtk_path = [Sim_Path '/vtk'];
if exist(vtk_path,'dir')
rmdir(vtk_path,'s');
end
mkdir(vtk_path);
disp('Dumping to vtk files... this may take a minute...')
% define interpolation mesh
mesh_interp{1}=mesh.x * unit;
mesh_interp{2}=b/2 * unit;
mesh_interp{3}=mesh.z * unit;
[field_FD mesh_FD] = ReadHDF5Dump(dump_file,'Interpolation',mesh_interp,'Frequency',vtk_dump_freq);
% dump animated phase to vtk
for n=1:numel(vtk_dump_freq)
phase = linspace(0,360,21);
phase = phase(1:end-1);
for ph = phase
filename = [vtk_path '/E_xz_f=' num2str(vtk_dump_freq(n)) '_p' num2str(ph) '.vtk'];
Dump2VTK(filename,real(field_FD.values{n}.*exp(1j*ph/180*pi)),mesh_FD,'E-Field');
end
filename = [vtk_path '/E_xz_f=' num2str(vtk_dump_freq(n)) '_mag.vtk'];
Dump2VTK(filename,abs(field_FD.values{n}),mesh_FD,'E-Field');
end
disp('done... you can open and visualize the vtk-files using Paraview (www.paraview.org)!')