I am a beginner in the use of OpenEMS. I am using it for my internship to simulate a PCB antenna of 2.45GHz for bluetooth low energy. I used the inverted F antenna and modified the code to have the shape of my antenna on an FR4 substrate. And I have a mesh problem.
-When I run the simulation, I get an error that tells me that the time step is small and that I need to check my mesh and also I get an error with the excitation length I tried to increase the length of my simulation box but it doesn't correct anything.
If I make a coarse mesh, the result is not good. I understand that the mesh in the metal part of the structure is where we have the simulation, so the mesh must be coarse.
I have tried automatic meshing with edge detection but it does not work for me, so I do the meshing by hand.
-At the end of the simulation, I get this error: "RunFDTD: Warning: Max. number of timesteps was reached before the end-criteria of -50dB was". I know that this is because the energy does not decay to zero before the simulation is stopped. I want to know if I could have good result if I have this problem?
Attached is the images of CSX image of my antenna and the results I get.


Could anyone help me to correct these errors?
How do I know that my meshing is good and I get good results?
Thanks,
This is the error I've got. I put the code just after this.
##########################################################
Create FDTD operator (compressed SSE + multi-threading)
FDTD simulation size: 78x58x37 --> 167388 FDTD cells
FDTD timestep is: 2.74965e-14 s; Nyquist rate: 5270 timesteps @3.4505e+09 Hz
openEMS::SetupFDTD: Warning, the timestep seems to be very small --> long simulation. Check your mesh!?
Excitation signal length is: 104188 timesteps (2.8648e-09s)
Max. number of timesteps: 300000 ( --> 2.87941 * Excitation signal length)
openEMS::SetupFDTD: Warning, max. number of timesteps is smaller than three times the excitation.
You may want to choose a higher number of max. timesteps...
Create FDTD engine (compressed SSE + multi-threading)
Running FDTD engine... this may take a while... grab a cup of coffee?!?
####################################################################
Code: Select all
% EXAMPLE / antennas / ) 2.4GHz
%
% This example demonstrates how to:
% - calculate the reflection coefficient of an antenna
% - calculate farfield of an antenna
%
close all
clear
clc
%% setup the simulation
physical_constants;
unit = 1e-3; % all length in mm
substrate.width = 10; % width of substrate
substrate.length = 10; % length of substrate
substrate.thickness = 0.8; % thickness of substrate
substrate.cells = 4; % use 4 cells for meshing substrate
ifa.h = 2.1; % height of short circuit stub
ifa.l = 7.625; % length of radiating element1
ifa.w1 = 0.9; % width of short circuit stub
ifa.w2 = 0.3; % width of radiating element
ifa.wf = 0.3; % width of feed element
ifa.fp = 4; % position of feed element relative to short
% circuit stub
ifa.e = 2.4; % distance to edge
ifa.b = 5.525; %Radiating element3_5_7 length
ifa.a = 0.9; %Radiating element 2_4_6 length
ifa.c = 0.3; % distance between feeding elementand circuit stub
ifa.d = 0.3; %distance between feeding element and radiating element 2...
ifa.gnd = 0.3; %distance antenna to the ground plane
ifa.Ledge = 1; % distance to the left edge
ifa.cut = 0 ; %Cutting element
% substrate setup
substrate.epsR = 4.29;
substrate.kappa = 1e-3 * 2*pi*2.45e9 * EPS0*substrate.epsR;
%setup feeding
feed.R = 50; %feed resistance
%open AppCSXCAD and show ifa
show = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% size of the simulation box
SimBox = [substrate.width*6 substrate.length*6 200];
%% setup FDTD parameter & excitation function
f0 = 2.45e9; % center frequency
fc = 1e9; % 20 dB corner frequency
c0 = 3e8; %Speed of light
%FDTD = InitFDTD(80000, 1e-3, 'TimeStep', 5e-13);
%FDTD = InitFDTD('OverSampling', 100) %highly discourage you to change the timestep.
%we either make the simulation slower or unstable.
%openEMS chooses the fastest possible and stable timestep. So change the oversampling
%FDTD = InitFDTD('NrTS', 80000, 'EndCriteria', 1e-3);
FDTD = InitFDTD('NrTS', 300000 );
FDTD = SetGaussExcite( FDTD, f0, fc );
BC = {'MUR' 'MUR' 'MUR' 'MUR' 'MUR' 'MUR'}; % boundary conditions
FDTD = SetBoundaryCond( FDTD, BC );
%% setup CSXCAD geometry & mesh
CSX = InitCSX();
%initialize the mesh with the "air-box" dimensions
mesh.x = [-SimBox(1)/2 SimBox(1)/2];
mesh.y = [-SimBox(2)/2 SimBox(2)/2];
mesh.z = [-SimBox(3)/2 SimBox(3)/2];
%% create substrate
CSX = AddMaterial( CSX, 'substrate');
CSX = SetMaterialProperty( CSX, 'substrate', 'Epsilon',substrate.epsR, 'Kappa', substrate.kappa);
start = [-substrate.width/2 -substrate.length/2 0];
stop = [ substrate.width/2 substrate.length/2 substrate.thickness];
CSX = AddBox( CSX, 'substrate', 1, start, stop );
% add extra cells to discretize the substrate thickness
mesh.z = [linspace(0,substrate.thickness,substrate.cells+1) mesh.z];
%% create ground plane
CSX = AddMetal( CSX, 'groundplane' ); % create a perfect electric conductor (PEC)
start = [-substrate.width/2 -substrate.length/2 substrate.thickness];
stop = [ substrate.width/2 substrate.length/2-ifa.e-0.1 substrate.thickness];
CSX = AddBox(CSX, 'groundplane', 10, start,stop);
%% create ifa
CSX = AddMetal( CSX, 'ifa' ); % create a perfect electric conductor (PEC)
tl = [ifa.Ledge,substrate.length/2-ifa.e,substrate.thickness]; % translate
start = [(-substrate.width/2)+ifa.w1+ifa.c 0.5-0.1 0] + tl;
stop = start + [ifa.wf ifa.h-0.5 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % feed element
start = [-substrate.width/2 -0.1 0] + tl;
stop = start + [ifa.w1 ifa.h 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % short circuit stub
start = [(-substrate.width/2) ifa.h 0] + tl;
stop = start + [ifa.l -ifa.w2 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element1
start = [(-substrate.width/2+ifa.l) ifa.h 0] + tl;
stop = start + [-ifa.w2 -ifa.a 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element2
start = [(-substrate.width/2+ifa.l) ifa.h-ifa.a 0] + tl;
stop = start + [-ifa.b ifa.w2 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element3
start = [(-substrate.width/2+ifa.l-ifa.b+ifa.w2) ifa.h-ifa.a+ifa.w2 0] + tl;
stop = start + [-ifa.w2 -ifa.a 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element4
start = [(-substrate.width/2+ifa.l) (ifa.h-2*ifa.a+ifa.w2) 0] + tl;
stop = start + [-ifa.b ifa.w2 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element5
start = [(-substrate.width/2+ifa.l) ifa.h-2*ifa.a+2*ifa.w2 0] + tl;
stop = start + [-ifa.w2 -ifa.a 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element6
start = [(-substrate.width/2+ifa.l) (ifa.h-3*ifa.a+2*ifa.w2) 0] + tl;
stop = start + [-ifa.b+ifa.cut ifa.w2 0];
CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element7
%% apply the excitation & resist as a current source
start = [ (-substrate.width/2)+ifa.w1+ifa.c -0.1 0] + tl;
stop = start + [ifa.wf 0.5 0];
[CSX port] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 1 0], true); %
% MESH left
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mesh.x = [mesh.x linspace(-substrate.width,(-substrate.width/2)+ifa.Ledge-0.2,8.0)]; %tab 15 elements step of 0.4
mesh.y = [mesh.y linspace(-substrate.length,(substrate.length/2)-ifa.e-0.1,18.0)];%mesh.z = [mesh.z linspace(-10.0,5,40.0) + 0];
CSX = DefineRectGrid(CSX, 0.001, mesh);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MESH right
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mesh.x = [mesh.x linspace((-substrate.width/2)+ifa.l+ifa.Ledge+0.5,substrate.width,8.0)];
mesh.y = [mesh.y linspace(substrate.length/2+0.1,substrate.length,8.0) ];
CSX = DefineRectGrid(CSX, 0.001, mesh);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%MESH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mesh.x = [mesh.x linspace(-4,4,1.0)];
mesh.x = [mesh.x linspace(-substrate.width/2+ifa.Ledge,-substrate.width/2+ifa.Ledge+ifa.l,60.0) ];
mesh.y = [mesh.y linspace((substrate.length/2)-ifa.e,substrate.width/2-ifa.e+ifa.h,30.0) ];
mesh.z = [mesh.z linspace(-substrate.width,substrate.width,30.0) ];
CSX = DefineRectGrid(CSX, 0.001, mesh);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% finalize the mesh DOESN'T WORK Hand meshing is better.
%ifa_mesh = DetectEdges(CSX, [], 'SetProperty','ifa');
%mesh.x = [mesh.x SmoothMeshLines(ifa_mesh.x, 0.5)];
%mesh.y = [mesh.y SmoothMeshLines(ifa_mesh.y, 10)];
% generate a smooth mesh with max. cell size: lambda_min / 20
%mesh = DetectEdges(CSX, mesh);
%mesh = SmoothMesh(mesh, c0 / (f0+fc) / unit / 20);
% Always problem to put smoothmeshing problem error: max_recursion_depth exceeded
%CSX = DefineRectGrid(CSX, unit , mesh); % define the mesh with a drawing unit of 1mm (1e-3)
%% add a nf2ff calc box; size is 3 cells away from MUR boundary condition
%%%%%%%It's implements a near field to far field transformation for near field antenna measurement setups
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
[CSX nf2ff] = CreateNF2FFBox(CSX, 'nf2ff', start, stop);
%For H-fields
CSX = AddDump(CSX,'Et');
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
CSX = AddBox(CSX, 'Et',0, start, stop);
%For E-fields
CSX= AddDump(CSX,'Ht', 'DumpType',1);
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
CSX = AddBox(CSX, 'Ht',0, start, stop);
%For current
CSX = AddDump(CSX,'Jt', 'Dumptype', 3);
start = [mesh.x(1) mesh.y(1) mesh.z(1)];
stop = [mesh.x(end) mesh.y(end) mesh.z(end)];
CSX = AddBox(CSX, 'Jt',0, start, stop);
%% prepare simulation folder
Sim_Path = 'tmp_LIGHT';
Sim_CSX = 'IFA.xml';
try confirm_recursive_rmdir(false,'local'); end
[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
if (show == 1)
CSXGeomPlot( [Sim_Path '/' Sim_CSX] );
end
%% run openEMS
RunOpenEMS( Sim_Path, Sim_CSX); %RunOpenEMS( Sim_Path, Sim_CSX, '--debug-PEC -v');
%% postprocessing & do the plots
freq = linspace( max([1e9,f0-fc]), f0+fc, 501 );
port = calcPort(port, Sim_Path, freq);
Zin = port.uf.tot ./ port.if.tot;
s11 = port.uf.ref ./ port.uf.inc;
P_in = real(0.5 * port.uf.tot .* conj( port.if.tot )); % antenna feed power
% plot feed point impedance
figure
plot( freq/1e6, real(Zin), 'k-', 'Linewidth', 2 );
hold on
grid on
plot( freq/1e6, imag(Zin), 'r--', 'Linewidth', 2 );
title( 'feed point impedance' );
xlabel( 'frequency f / MHz' );
ylabel( 'impedance Z_{in} / Ohm' );
legend( 'real', 'imag' );
% plot reflection coefficient S11
figure
plot( freq/1e6, 20*log10(abs(s11)), 'k-', 'Linewidth', 2 );
grid on
title( 'reflection coefficient S_{11}' );
xlabel( 'frequency f / MHz' );
ylabel( 'reflection coefficient |S_{11}|' );
drawnow
%% NFFF contour plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%find resonance frequncy from s11
f_res_ind = find(s11==min(s11));
f_res = freq(f_res_ind);
%%
disp( 'calculating 3D far field pattern and dumping to vtk (use Paraview to visualize)...' );
thetaRange = (0:2:180);
phiRange = (0:2:360) - 180;
nf2ff = CalcNF2FF(nf2ff, Sim_Path, f_res, thetaRange*pi/180, phiRange*pi/180,'Verbose',1,'Outfile','3D_Pattern.h5');
figure
plotFF3D(nf2ff)
% display power and directivity
disp( ['radiated power: Prad = ' num2str(nf2ff.Prad) ' Watt']);
disp( ['directivity: Dmax = ' num2str(nf2ff.Dmax) ' (' num2str(10*log10(nf2ff.Dmax)) ' dBi)'] );
disp( ['efficiency: nu_rad = ' num2str(100*nf2ff.Prad./real(P_in(f_res_ind))) ' %']);
E_far_normalized = nf2ff.E_norm{1} / max(nf2ff.E_norm{1}(:)) * nf2ff.Dmax;
DumpFF2VTK([Sim_Path '/3D_Pattern.vtk'],E_far_normalized,thetaRange,phiRange,1e-3);