thliebig / openEMS

openEMS is a free and open-source electromagnetic field solver using the EC-FDTD method.
http://openEMS.de
GNU General Public License v3.0
427 stars 150 forks source link

Meshing issue #90

Closed Dianebonk closed 2 years ago

Dianebonk commented 2 years ago

Hello, I am new on using openems. I want to make a PCB trace antenna simulate it and have s11, impedance and radiation pattern curve. Here my code. I took IFA example to adapt to my antenna shape. I have meshing problems:

Meshing issues

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 = 3; % height of short circuit stub ifa.l = 8; % length of radiating element over2 ifa.w1 = 0.9; % width of short circuit stub ifa.w2 = 0.3; % width of radiating element ifa.wf = 0.4; % width of feed element ifa.fp = 4; % position of feed element relative to short % circuit stub ifa.e = 3.3; % distance to edge

ifa.b = 6; ifa.a = 1.2; ifa.c = 0.3; ifa.d = 0.3;

% substrate setup substrate.epsR = 4.29; substrate.kappa = 1e-3 2pi2.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.width2 substrate.length2 150];

%% setup FDTD parameter & excitation function f0 = 2.5e9; % center frequency fc = 1e9; % 20 dB corner frequency

FDTD = InitFDTD('NrTS', 60000 ); 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 substrate.thickness]; CSX = AddBox(CSX, 'groundplane', 10, start,stop);

%% create ifa CSX = AddMetal( CSX, 'ifa' ); % create a perfect electric conductor (PEC) tl = [0,substrate.length/2-ifa.e,substrate.thickness]; % translate

start = [-ifa.fp+ifa.c+ifa.c 0.5 0] + tl; stop = start + [ifa.wf ifa.h-0.5 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % feed element

start = [-ifa.fp 0 0] + tl; stop = start + [-ifa.w1 ifa.h 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % short circuit stub

start = [(-ifa.fp-ifa.w1) ifa.h 0] + tl; stop = start + [ifa.l -ifa.w2 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element1

start = [(-ifa.fp-ifa.w1+ifa.l) ifa.h 0] + tl; stop = start + [-ifa.w2 -ifa.a 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element2

start = [(-ifa.fp-ifa.w1+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 = [(-ifa.fp-ifa.w1+ifa.l-ifa.b+ifa.w2) ifa.h-ifa.a 0] + tl; stop = start + [-ifa.w2 -ifa.a 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element4

start = [(-ifa.fp-ifa.w1+ifa.l) (ifa.h-ifa.a+0.6) 0] + tl; stop = start + [-ifa.b ifa.w2 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element5

start = [(-ifa.fp-ifa.w1+ifa.l-ifa.b+ifa.w2+ifa.b) ifa.h-ifa.a 0] + tl; stop = start + [-ifa.w2 -ifa.a 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element6

start = [(-ifa.fp-ifa.w1+ifa.l) (ifa.h-ifa.a+2*0.6) 0] + tl; stop = start + [-ifa.b ifa.w2 0]; CSX = AddBox( CSX, 'ifa', 10, start, stop); % radiating element7

ifa_mesh = DetectEdges(CSX, [], 'SetProperty','ifa'); mesh.x = [mesh.x SmoothMeshLines(ifa_mesh.x, 0.6)]; mesh.y = [mesh.y SmoothMeshLines(ifa_mesh.y, 0.6)];

%% apply the excitation & resist as a current source start = [-ifa.fp+ifa.c+ifa.c 0 0] + tl; stop = start + [ifa.wf 0.5 0]; [CSX port] = AddLumpedPort(CSX, 5 ,1 ,feed.R, start, stop, [0 1 0], true);

%% finalize the mesh % generate a smooth mesh with max. cell size: lambda_min / 20 mesh = DetectEdges(CSX, mesh); mesh = SmoothMesh(mesh, c0 / (f0+fc) / unit / 10); CSX = DefineRectGrid(CSX, unit, mesh);

%% add a nf2ff calc box; size is 3 cells away from MUR boundary condition start = [mesh.x(4) mesh.y(4) mesh.z(4)]; stop = [mesh.x(end-3) mesh.y(end-3) mesh.z(end-3)]; [CSX nf2ff] = CreateNF2FFBox(CSX, 'nf2ff', start, stop);

%% prepare simulation folder Sim_Path = 'tmp_IFA'; 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

thliebig commented 2 years ago

Please use the openEMS forum for usage issues, This tracker is for development issues...