2010-12-09 11:59:10 +00:00
|
|
|
%
|
|
|
|
% 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>
|
|
|
|
|
2010-04-30 12:56:46 +00:00
|
|
|
close all
|
|
|
|
clear
|
2010-04-06 14:56:41 +00:00
|
|
|
clc
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%% switches
|
|
|
|
postproc_only = 1;
|
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
physical_constants;
|
|
|
|
unit = 1e-3; %drawing unit in mm
|
|
|
|
numTS = 50000; %max. number of timesteps
|
|
|
|
|
|
|
|
% waveguide dimensions
|
2010-10-26 06:30:35 +00:00
|
|
|
length = 2000;
|
2010-12-09 11:59:10 +00:00
|
|
|
a = 1000; %waveguide width
|
|
|
|
b = 600; %waveguide heigth
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%waveguide TE-mode definition
|
2010-04-06 14:56:41 +00:00
|
|
|
m = 1;
|
|
|
|
n = 0;
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
mesh_res = [10 10 10];
|
|
|
|
|
|
|
|
%% setup FDTD parameters & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
f_start = 175e6;
|
|
|
|
f_stop = 500e6;
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
% dump special frequencies to vtk, use paraview (www.paraview.org) to
|
|
|
|
% animate this dumps over phase
|
|
|
|
vtk_dump_freq = [200e6 300e6 500e6];
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
freq = linspace(f_start,f_stop,201);
|
|
|
|
|
|
|
|
k = 2*pi*freq/c0;
|
2010-04-06 14:56:41 +00:00
|
|
|
kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2);
|
2010-12-09 11:59:10 +00:00
|
|
|
fc = c0*kc/2/pi; %cut-off frequency
|
|
|
|
beta = sqrt(k.^2 - kc^2); %waveguide phase-constant
|
|
|
|
ZL_a = k * Z0 ./ beta; %analytic waveguide impedance
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
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
|
2010-10-26 06:30:35 +00:00
|
|
|
|
|
|
|
%% mode functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
% by David M. Pozar, Microwave Engineering, third edition, page 113
|
2010-10-26 06:30:35 +00:00
|
|
|
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_Hx = [num2str(m/a/unit) '*sin(' num2str(m*pi/a) '*x)*cos(' num2str(n*pi/b) '*y)'];
|
|
|
|
func_Hy = [num2str(n/b/unit) '*cos(' num2str(m*pi/a) '*x)*sin(' num2str(n*pi/b) '*y)'];
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-04-30 12:56:46 +00:00
|
|
|
%% define and openEMS options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-04-06 14:56:41 +00:00
|
|
|
openEMS_opts = '';
|
|
|
|
% openEMS_opts = [openEMS_opts ' --disable-dumps'];
|
|
|
|
% openEMS_opts = [openEMS_opts ' --debug-material'];
|
2010-12-09 11:59:10 +00:00
|
|
|
% openEMS_opts = [openEMS_opts ' --engine=basic'];
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-10-26 06:30:35 +00:00
|
|
|
Settings = [];
|
|
|
|
Settings.LogFile = 'openEMS.log';
|
|
|
|
|
2010-04-06 14:56:41 +00:00
|
|
|
Sim_Path = 'tmp';
|
|
|
|
Sim_CSX = 'rect_wg.xml';
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
if (postproc_only==0)
|
|
|
|
if (exist(Sim_Path,'dir'))
|
|
|
|
rmdir(Sim_Path,'s');
|
|
|
|
end
|
|
|
|
mkdir(Sim_Path);
|
2010-05-25 10:17:09 +00:00
|
|
|
end
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% setup FDTD parameter & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
FDTD = InitFDTD(numTS,1e-5,'OverSampling',6);
|
|
|
|
FDTD = SetGaussExcite(FDTD,0.5*(f_start+f_stop),0.5*(f_stop-f_start));
|
2010-10-26 06:30:35 +00:00
|
|
|
BC = [0 0 0 0 0 3];
|
2010-04-06 14:56:41 +00:00
|
|
|
FDTD = SetBoundaryCond(FDTD,BC);
|
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-04-06 14:56:41 +00:00
|
|
|
CSX = InitCSX();
|
2010-12-09 11:59:10 +00:00
|
|
|
mesh.x = SmoothMeshLines([0 a], mesh_res(1));
|
|
|
|
mesh.y = SmoothMeshLines([0 b], mesh_res(2));
|
|
|
|
mesh.z = SmoothMeshLines([0 length], mesh_res(3));
|
2010-04-06 14:56:41 +00:00
|
|
|
CSX = DefineRectGrid(CSX, unit,mesh);
|
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% apply the excitation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
start=[mesh.x(1) mesh.y(1) mesh.z(1) ];
|
|
|
|
stop =[mesh.x(end) mesh.y(end) mesh.z(1) ];
|
2010-04-06 14:56:41 +00:00
|
|
|
CSX = AddExcitation(CSX,'excite',0,[1 1 0]);
|
|
|
|
weight{1} = func_Ex;
|
|
|
|
weight{2} = func_Ey;
|
|
|
|
weight{3} = 0;
|
|
|
|
CSX = SetExcitationWeight(CSX,'excite',weight);
|
|
|
|
CSX = AddBox(CSX,'excite',0 ,start,stop);
|
2010-10-26 06:30:35 +00:00
|
|
|
|
|
|
|
%% voltage and current definitions using the mode matching probes %%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
%port 1
|
2010-10-26 06:30:35 +00:00
|
|
|
start = [mesh.x(1) mesh.y(1) 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 = AddBox(CSX, 'ut1', 0 ,start,stop);
|
|
|
|
CSX = AddProbe(CSX,'it1', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0});
|
|
|
|
CSX = AddBox(CSX,'it1', 0 ,start,stop);
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%port 2
|
2010-10-26 06:30:35 +00:00
|
|
|
start = [mesh.x(1) mesh.y(1) 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 = AddBox(CSX, 'ut2', 0 ,start,stop);
|
|
|
|
CSX = AddProbe(CSX,'it2', 11, 1, [], 'ModeFunction',{func_Hx,func_Hy,0});
|
|
|
|
CSX = AddBox(CSX,'it2', 0 ,start,stop);
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% define dump boxes... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-10-26 06:30:35 +00:00
|
|
|
CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,2');
|
2010-12-09 11:59:10 +00:00
|
|
|
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
|
|
|
|
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
|
2010-04-06 14:56:41 +00:00
|
|
|
CSX = AddBox(CSX,'Et',0 , start,stop);
|
|
|
|
|
2010-10-26 06:30:35 +00:00
|
|
|
CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1,'SubSampling','4,4,2');
|
|
|
|
CSX = AddBox(CSX,'Ht',0,start,stop);
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-04-24 14:47:40 +00:00
|
|
|
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-12-09 11:59:10 +00:00
|
|
|
if (postproc_only==0)
|
|
|
|
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
|
2010-10-26 06:30:35 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts, Settings)
|
|
|
|
end
|
2010-10-26 06:30:35 +00:00
|
|
|
|
|
|
|
%% postproc %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
U = ReadUI({'ut1','ut2'},[Sim_Path '/'],freq);
|
|
|
|
I = ReadUI({'it1','it2'},[Sim_Path '/'],freq);
|
|
|
|
Exc = ReadUI('et',Sim_Path,freq);
|
|
|
|
|
|
|
|
uf1 = U.FD{1}.val./Exc.FD{1}.val;
|
|
|
|
uf2 = U.FD{2}.val./Exc.FD{1}.val;
|
|
|
|
if1 = I.FD{1}.val./Exc.FD{1}.val;
|
|
|
|
if2 = I.FD{2}.val./Exc.FD{1}.val;
|
|
|
|
|
|
|
|
uf1_inc = 0.5 * ( uf1 + if1 .* ZL_a );
|
|
|
|
if1_inc = 0.5 * ( if1 + uf1 ./ ZL_a );
|
|
|
|
uf2_inc = 0.5 * ( uf2 + if2 .* ZL_a );
|
|
|
|
if2_inc = 0.5 * ( if2 + uf2 ./ ZL_a );
|
|
|
|
|
|
|
|
uf1_ref = uf1 - uf1_inc;
|
|
|
|
if1_ref = if1 - if1_inc;
|
|
|
|
uf2_ref = uf2 - uf2_inc;
|
|
|
|
if2_ref = if2 - if2_inc;
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%% plot s-parameter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-10-26 06:30:35 +00:00
|
|
|
figure
|
|
|
|
s11 = uf1_ref./uf1_inc;
|
|
|
|
s21 = uf2_inc./uf1_inc;
|
|
|
|
plot(freq,20*log10(abs(s11)),'Linewidth',2);
|
|
|
|
xlim([freq(1) freq(end)]);
|
|
|
|
% ylim([-40 5]);
|
|
|
|
grid on;
|
|
|
|
hold on;
|
|
|
|
plot(freq,20*log10(abs(s21)),'r','Linewidth',2);
|
|
|
|
legend('s11','s21','Location','SouthEast');
|
|
|
|
ylabel('s-para (dB)');
|
|
|
|
xlabel('freq (Hz)');
|
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%% compare analytic and numerical wave-impedance %%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-10-26 06:30:35 +00:00
|
|
|
ZL = uf1./if1;
|
|
|
|
figure()
|
|
|
|
plot(freq,real(ZL),'Linewidth',2);
|
|
|
|
hold on;
|
|
|
|
grid on;
|
|
|
|
plot(freq,imag(ZL),'r--','Linewidth',2);
|
|
|
|
plot(freq,ZL_a,'g-.','Linewidth',2);
|
|
|
|
ylabel('ZL (\Omega)');
|
|
|
|
xlabel('freq (Hz)');
|
|
|
|
xlim([freq(1) freq(end)]);
|
|
|
|
legend('\Re(Z_L)','\Im(Z_L)','Z_L analytic','Location','Best');
|
2010-04-06 14:56:41 +00:00
|
|
|
|
2010-12-09 11:59:10 +00:00
|
|
|
%% 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)!')
|