Mode matching probe: fixed an error in HField interpolation

Now also excluding the boundaries from the MM.
Updated waveguide example: Rect_Waveguide.m

Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>
pull/1/head
Thorsten Liebig 2010-10-26 08:30:35 +02:00
parent 1586c76af6
commit f204bc2723
3 changed files with 105 additions and 25 deletions

View File

@ -61,6 +61,12 @@ void ProcessModeMatch::InitProcess()
stop[n]=help;
}
//exclude boundaries from mode-matching
if (start[n]==0)
++start[n];
if (stop[n]==Op->GetNumberOfLines(n)-1)
--stop[n];
if (stop[n]>start[n])
++Dump_Dim;
@ -185,7 +191,7 @@ void ProcessModeMatch::SetFieldType(int type)
cerr << "ProcessModeMatch::SetFieldType: Warning, unknown field type..." << endl;
}
double ProcessModeMatch::GetField(int ny, unsigned int pos[3])
double ProcessModeMatch::GetField(int ny, const unsigned int pos[3])
{
if (m_ModeFieldType==0)
return GetEField(ny,pos);
@ -194,7 +200,7 @@ double ProcessModeMatch::GetField(int ny, unsigned int pos[3])
return 0;
}
double ProcessModeMatch::GetEField(int ny, unsigned int pos[3])
double ProcessModeMatch::GetEField(int ny, const unsigned int pos[3])
{
if ((pos[ny]==0) || (pos[ny]==Op->GetNumberOfLines(ny)-1))
return 0.0;
@ -210,7 +216,7 @@ double ProcessModeMatch::GetEField(int ny, unsigned int pos[3])
return 0.0;
}
double ProcessModeMatch::GetHField(int ny, unsigned int pos[3])
double ProcessModeMatch::GetHField(int ny, const unsigned int pos[3])
{
if ((pos[ny]==0) || (pos[ny]>=Op->GetNumberOfLines(ny)-1))
return 0.0;
@ -218,19 +224,19 @@ double ProcessModeMatch::GetHField(int ny, unsigned int pos[3])
unsigned int EngPos[] = {pos[0],pos[1],pos[2]};
int nyP = (ny+1)%3;
if (pos[nyP] >= Op->GetNumberOfLines(nyP)-1)
if (pos[nyP] == 0)
return 0.0;
int nyPP = (ny+2)%3;
if (pos[nyPP] >= Op->GetNumberOfLines(nyPP)-1)
if (pos[nyPP] == 0)
return 0.0;
double hfield = Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
EngPos[nyP]++;
hfield += Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
EngPos[nyPP]++;
hfield += Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
EngPos[nyP]--;
hfield += Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
EngPos[nyPP]--;
hfield += Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
EngPos[nyP]++;
hfield += Eng->GetCurr(ny,EngPos) / Op->GetMeshDelta(ny,EngPos,true);
return hfield/4.0;
}

View File

@ -43,9 +43,9 @@ protected:
int m_ModeFieldType;
double GetField(int ny, unsigned int pos[3]);
double GetEField(int ny, unsigned int pos[3]);
double GetHField(int ny, unsigned int pos[3]);
double GetField(int ny, const unsigned int pos[3]);
double GetEField(int ny, const unsigned int pos[3]);
double GetHField(int ny, const unsigned int pos[3]);
string m_ModeFunction[3];
CSFunctionParser* m_ModeParser[2];

View File

@ -3,13 +3,13 @@ clear
clc
%% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
length = 8000;
length = 2000;
unit = 1e-3;
a = 1000;
width = a;
b = 500;
height = b;
mesh_res = [10 10 20];
mesh_res = [10 10 10];
%define mode
m = 1;
@ -18,16 +18,24 @@ n = 0;
EPS0 = 8.85418781762e-12;
MUE0 = 1.256637062e-6;
C0 = 1/sqrt(EPS0*MUE0);
Z0 = sqrt(MUE0/EPS0);
f0 = 1e9;
freq = linspace(f0-f0/3,f0+f0/3,201);
k = 2*pi*f0/C0;
k = 2*pi*freq/C0;
kc = sqrt((m*pi/a/unit)^2 + (n*pi/b/unit)^2);
fc = C0*kc/2/pi;
beta = sqrt(k^2 - kc^2);
beta = sqrt(k.^2 - kc^2);
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)'];
ZL_a = k * Z0 ./ beta;
%% mode functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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)'];
%% define and openEMS options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
openEMS_opts = '';
@ -35,6 +43,9 @@ openEMS_opts = '';
% openEMS_opts = [openEMS_opts ' --debug-material'];
openEMS_opts = [openEMS_opts ' --engine=fastest'];
Settings = [];
Settings.LogFile = 'openEMS.log';
Sim_Path = 'tmp';
Sim_CSX = 'rect_wg.xml';
@ -46,7 +57,7 @@ mkdir(Sim_Path);
%% setup FDTD parameter & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FDTD = InitFDTD(50000,1e-5,'OverSampling',6);
FDTD = SetGaussExcite(FDTD,f0,f0/3);
BC = [0 0 0 0 2 2];
BC = [0 0 0 0 0 3];
FDTD = SetBoundaryCond(FDTD,BC);
%% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -57,8 +68,8 @@ mesh.z = 0 : mesh_res(3) : length;
CSX = DefineRectGrid(CSX, unit,mesh);
%% apply the excitation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
start=[0 0 mesh.z(3) ];
stop =[width height mesh.z(3) ];
start=[0 0 mesh.z(1) ];
stop =[width height mesh.z(1) ];
CSX = AddExcitation(CSX,'excite',0,[1 1 0]);
weight{1} = func_Ex;
weight{2} = func_Ey;
@ -66,17 +77,80 @@ weight{3} = 0;
CSX = SetExcitationWeight(CSX,'excite',weight);
CSX = AddBox(CSX,'excite',0 ,start,stop);
%% voltage and current definitions using the mode matching probes %%%%%%%%%
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);
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);
%% define dump boxes... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
CSX = AddDump(CSX,'Et','FileType',0,'SubSampling','4,4,1');
CSX = AddDump(CSX,'Et','FileType',1,'SubSampling','4,4,2');
start = [mesh.x(1) , height/2 , mesh.z(1)];
stop = [mesh.x(end) , height/2 , mesh.z(end)];
CSX = AddBox(CSX,'Et',0 , start,stop);
% CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1,'SubSampling','4,4,4');
% CSX = AddBox(CSX,'Ht',0,start,stop);
CSX = AddDump(CSX,'Ht','DumpType',1,'FileType',1,'SubSampling','4,4,2');
CSX = AddBox(CSX,'Ht',0,start,stop);
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts)
RunOpenEMS(Sim_Path, Sim_CSX, openEMS_opts, Settings)
%% 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;
%% plot s-parameter
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)');
%% compare analytic and numerical wave-impedance
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');