This is my script:
Code: Select all
close all
clear
clc
physical_constants;
unit=1; %drawing unit in m
numTS=10000; %max number of timesteps
f0=5; %nyquist rate
% compute frequency
f_start=1e-5;
f_stop=1;
%% define compute area
a=500; %block length
b=500; %block width
c=500; %block heigth
% TE_mode='TE11';
mesh_res=[10,10,10]; %homogeneous mesh
%% setup FDTD parameter & excitation function
FDTD=InitFDTD();
FDTD=SetCustomExcite(FDTD,f0,'(t<5)*1');
%% boundary conditions
BC=[3 3 3 3 3 3]; %set PML condition
FDTD=SetBoundaryCond(FDTD,BC);
%% setup CSXCAD mesh
CSX=InitCSX();
mesh.x=SmoothMeshLines([0 a],mesh_res(1));
mesh.y=SmoothMeshLines([0 b],mesh_res(2));
mesh.z=SmoothMeshLines([0 c],mesh_res(3));
CSX=DefineRectGrid(CSX,unit,mesh);
%% apply
%define loop source material:metal
CSX=AddMetal(CSX,'loop');
%define the source loop
Spoints(1,1)=350;Spoints(2,1)=350;Spoints(3,1)=250;
Spoints(1,2)=350;Spoints(2,2)=150;Spoints(3,2)=250;
Spoints(1,3)=150;Spoints(2,3)=150;Spoints(3,3)=250;
Spoints(1,4)=150;Spoints(2,4)=350;Spoints(3,4)=250;
Spoints(1,5)=350;Spoints(2,5)=350;Spoints(3,5)=250;
CSX=AddCurve(CSX,'loop',1,Spoints);
start=Spoints(:,1);
stop=Spoints(:,2);
[CSX,port{1}]=AddLumpedPort(CSX,2,1,0,start,stop,[0 1 0],true);
start=Spoints(:,2);
stop=Spoints(:,3);
[CSX,port{2}]=AddLumpedPort(CSX,2,2,0,start,stop,[1 0 0],true);
start=Spoints(:,3);
stop=Spoints(:,4);
[CSX,port{2}]=AddLumpedPort(CSX,2,3,0,start,stop,[0 1 0],true);
start=Spoints(:,4);
stop=Spoints(:,5);
[CSX,port{4}]=AddLumpedPort(CSX,2,4,0,start,stop,[1 0 0],true);
%% creat box
% define air material
CSX=AddMaterial(CSX,'air');
CSX=SetMaterialProperty(CSX,'air','Epsilon',1,'Mue',1, 'Kappa',0);
% define earth material
CSX=AddMaterial(CSX,'earth');
CSX=SetMaterialProperty(CSX,'earth','Epsilon',5,'mu',1,'Kappa',0.01);
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) mesh.y(end) mesh.z(25)];
CSX=AddBox(CSX,'air',0,start,stop);
start = [mesh.x(1) mesh.y(1) mesh.z(25)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
CSX=AddBox(CSX,'earth',0,start,stop);
%% prepare simulation folder
Sim_Path = 'tmp';
Sim_CSX = 'box.xml';
[status, message, messageid] = rmdir( Sim_Path, 's' ); % clear previous directory
[status, message, messageid] = mkdir( Sim_Path ); % create empty simulation folder
%% write openEMS compatible xml-file
WriteOpenEMS([Sim_Path '/' Sim_CSX], FDTD, CSX);
%% show the structure
CSXGeomPlot([Sim_Path '/' Sim_CSX]);
%% run openEMS
RunOpenEMS(Sim_Path, Sim_CSX);
%% post processing
freq=linspace(f_start,f_stop,200);
port= calcPort(port, Sim_Path, freq);
U=port{1}.uf.tot;
II=port{1}.if.tot;
% plot
figure
loglog(freq,U,'k-','LineWidth',2);
grid on;
hold on
loglog(freq,II,'k--','LineWidth',2);
l = legend('U','II','Location','Best');
set(l,'FontSize',12);
% ylabel('S-Parameter (dB)','FontSize',12);
xlabel('frequency (MHz) \rightarrow','FontSize',12);
regards
LEM