2016-08-28 19:42:00 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2016-09-10 21:53:20 +00:00
|
|
|
Rectangular Waveguide Tutorial
|
2016-08-28 19:42:00 +00:00
|
|
|
|
2022-03-11 21:17:27 +00:00
|
|
|
Description at:
|
2016-09-10 21:53:20 +00:00
|
|
|
http://openems.de/doc/openEMS/Tutorials.html#rectangular-waveguide
|
2016-08-28 19:42:00 +00:00
|
|
|
|
|
|
|
Tested with
|
|
|
|
- python 3.4
|
2016-09-10 21:53:20 +00:00
|
|
|
- openEMS v0.0.34+
|
2016-08-28 19:42:00 +00:00
|
|
|
|
|
|
|
(C) 2015-2016 Thorsten Liebig <thorsten.liebig@gmx.de>
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Import Libraries
|
2016-08-28 19:42:00 +00:00
|
|
|
import os, tempfile
|
|
|
|
from pylab import *
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
from CSXCAD import ContinuousStructure
|
|
|
|
from openEMS import openEMS
|
2016-08-28 19:42:00 +00:00
|
|
|
from openEMS.physical_constants import *
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Setup the simulation
|
2016-08-28 19:42:00 +00:00
|
|
|
Sim_Path = os.path.join(tempfile.gettempdir(), 'Rect_WG')
|
|
|
|
|
|
|
|
post_proc_only = False
|
|
|
|
unit = 1e-6; #drawing unit in um
|
|
|
|
|
|
|
|
# waveguide dimensions
|
|
|
|
# WR42
|
|
|
|
a = 10700; #waveguide width
|
2022-03-11 21:17:27 +00:00
|
|
|
b = 4300; #waveguide height
|
2016-08-28 19:42:00 +00:00
|
|
|
length = 50000;
|
|
|
|
|
|
|
|
# frequency range of interest
|
|
|
|
f_start = 20e9;
|
|
|
|
f_0 = 24e9;
|
|
|
|
f_stop = 26e9;
|
|
|
|
lambda0 = C0/f_0/unit;
|
|
|
|
|
|
|
|
#waveguide TE-mode definition
|
|
|
|
TE_mode = 'TE10';
|
|
|
|
|
|
|
|
#targeted mesh resolution
|
|
|
|
mesh_res = lambda0/30
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Setup FDTD parameter & excitation function
|
2016-08-28 19:42:00 +00:00
|
|
|
FDTD = openEMS(NrTS=1e4);
|
|
|
|
FDTD.SetGaussExcite(0.5*(f_start+f_stop),0.5*(f_stop-f_start));
|
|
|
|
|
|
|
|
# boundary conditions
|
|
|
|
FDTD.SetBoundaryCond([0, 0, 0, 0, 3, 3]);
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Setup geometry & mesh
|
|
|
|
CSX = ContinuousStructure()
|
2016-08-28 19:42:00 +00:00
|
|
|
FDTD.SetCSX(CSX)
|
|
|
|
mesh = CSX.GetGrid()
|
|
|
|
mesh.SetDeltaUnit(unit)
|
|
|
|
|
|
|
|
mesh.AddLine('x', [0, a])
|
|
|
|
mesh.AddLine('y', [0, b])
|
|
|
|
mesh.AddLine('z', [0, length])
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
## Apply the waveguide port
|
2016-08-28 19:42:00 +00:00
|
|
|
ports = []
|
|
|
|
start=[0, 0, 10*mesh_res];
|
|
|
|
stop =[a, b, 15*mesh_res];
|
|
|
|
mesh.AddLine('z', [start[2], stop[2]])
|
|
|
|
ports.append(FDTD.AddRectWaveGuidePort( 0, start, stop, 'z', a*unit, b*unit, TE_mode, 1))
|
|
|
|
|
|
|
|
start=[0, 0, length-10*mesh_res];
|
|
|
|
stop =[a, b, length-15*mesh_res];
|
|
|
|
mesh.AddLine('z', [start[2], stop[2]])
|
|
|
|
ports.append(FDTD.AddRectWaveGuidePort( 1, start, stop, 'z', a*unit, b*unit, TE_mode))
|
|
|
|
|
|
|
|
mesh.SmoothMeshLines('all', mesh_res, ratio=1.4)
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Define dump box...
|
2016-08-28 19:42:00 +00:00
|
|
|
Et = CSX.AddDump('Et', file_type=0, sub_sampling=[2,2,2])
|
|
|
|
start = [0, 0, 0];
|
|
|
|
stop = [a, b, length];
|
2016-09-20 20:08:57 +00:00
|
|
|
Et.AddBox(start, stop);
|
2016-08-28 19:42:00 +00:00
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Run the simulation
|
2016-08-28 19:42:00 +00:00
|
|
|
if 0: # debugging only
|
|
|
|
CSX_file = os.path.join(Sim_Path, 'rect_wg.xml')
|
2016-09-06 21:12:59 +00:00
|
|
|
if not os.path.exists(Sim_Path):
|
|
|
|
os.mkdir(Sim_Path)
|
2016-08-28 19:42:00 +00:00
|
|
|
CSX.Write2XML(CSX_file)
|
|
|
|
os.system(r'AppCSXCAD "{}"'.format(CSX_file))
|
|
|
|
|
|
|
|
if not post_proc_only:
|
|
|
|
FDTD.Run(Sim_Path, verbose=3, cleanup=True)
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
### Postprocessing & plotting
|
2016-08-28 19:42:00 +00:00
|
|
|
freq = linspace(f_start,f_stop,201)
|
|
|
|
for port in ports:
|
|
|
|
port.CalcPort(Sim_Path, freq)
|
|
|
|
|
|
|
|
s11 = ports[0].uf_ref / ports[0].uf_inc
|
|
|
|
s21 = ports[1].uf_ref / ports[0].uf_inc
|
|
|
|
ZL = ports[0].uf_tot / ports[0].if_tot
|
|
|
|
ZL_a = ports[0].ZL # analytic waveguide impedance
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
## Plot s-parameter
|
2016-08-28 19:42:00 +00:00
|
|
|
figure()
|
|
|
|
plot(freq*1e-6,20*log10(abs(s11)),'k-',linewidth=2, label='$S_{11}$')
|
|
|
|
grid()
|
|
|
|
plot(freq*1e-6,20*log10(abs(s21)),'r--',linewidth=2, label='$S_{21}$')
|
|
|
|
legend();
|
|
|
|
ylabel('S-Parameter (dB)')
|
|
|
|
xlabel(r'frequency (MHz) $\rightarrow$')
|
|
|
|
|
2016-09-10 21:53:20 +00:00
|
|
|
## Compare analytic and numerical wave-impedance
|
2016-08-28 19:42:00 +00:00
|
|
|
figure()
|
|
|
|
plot(freq*1e-6,real(ZL), linewidth=2, label='$\Re\{Z_L\}$')
|
|
|
|
grid()
|
|
|
|
plot(freq*1e-6,imag(ZL),'r--', linewidth=2, label='$\Im\{Z_L\}$')
|
|
|
|
plot(freq*1e-6,ZL_a,'g-.',linewidth=2, label='$Z_{L, analytic}$')
|
|
|
|
ylabel('ZL $(\Omega)$')
|
|
|
|
xlabel(r'frequency (MHz) $\rightarrow$')
|
|
|
|
legend()
|
|
|
|
|
|
|
|
show()
|