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
413 stars 146 forks source link

Different far field results using TD and FD dump data #119

Open qiank10 opened 1 year ago

qiank10 commented 1 year ago

Hello,

I tried to use OpenEMS to simulate the far-field radiation of a metal plate. Following the RCS_Sphere tutorial, I invoked CreateNF2FFBox to define the dump planes and CalcNF2FF to calculate the far-field RCS.

However, specifying "frequency" in CreateNF2FFBox or not yields different RCS patterns, as shown in the figures below. fd td

By stepping in CreateNF2FFBox, I find that it dumps FD data when "frequency" is specified. Otherwise, it dumps TD data. Then, in CalcNF2FF, if only TD data is provided, it conducts an additional step to calculate the DFT of the TD data and obtain the steady-state frequency data. Then, the dumped FD data seems incorrect since its imagery components are almost zero. So I guess I made some mistakes in configuring the dump boxes. I have attached the code below (in MATLAB). Could you please help me debug the code? Thank you!


clear
clc

%% setup the simulation
physical_constants;
unit = 1e-3; % all length in mm

f0 = 60e9;
lambda = c0 ./ f0 / unit;
eps_r = 2.6;
lambda_eff = lambda ./ sqrt(eps_r);

ele.num = 21;
ele.length = lambda / 2;
gp.thick = 0.5;
gp.length = ele.length * ele.num;

theta_inc = 45;
phi_inc = 0;
k_inc = -[sind(theta_inc) * cosd(phi_inc), sind(theta_inc) * sind(phi_inc), cosd(theta_inc)];
e_inc = [-sind(phi_inc), cosd(phi_inc), 0]; % TE
% e_inc = [-cosd(phi_inc) * sind(theta_inc), -sind(phi_inc) * sind(theta_inc), cosd(theta_inc)] % TM

% size of simulation box
gap_sp_xy = lambda / 2;
gap_pb_xy = lambda / 2;
gap_sp_z = lambda / 2;
gap_pb_z = lambda / 2;
sim_xy = gp.length + gap_sp_xy * 2 + gap_pb_xy * 2;
sim_z = gp.thick + 2 * lambda_eff + gap_sp_z * 2 + gap_pb_z * 2;
offset_z = (2 * lambda_eff - gp.thick) / 2;

%% setup FDTD parameter & excitation function
fdtd = InitFDTD();
fdtd = SetSinusExcite(fdtd, f0);
bc = [3 3 3 3 3 3];
fdtd = SetBoundaryCond(fdtd, bc);

%% setup CSXCAD geometry & mesh
max_res = lambda / 10;
csx = InitCSX();

% create mesh
sm_xy = SmoothMeshLines([-sim_xy / 2, sim_xy / 2], max_res);
sm_z = SmoothMeshLines([offset_z - sim_z / 2, offset_z + sim_z / 2], max_res);
sim_mesh.x = sm_xy;
sim_mesh.y = sm_xy;
sim_mesh.z = sm_z;

%% create plate
csx = AddMetal(csx, 'groundplane');
gp_start = [-gp.length / 2, -gp.length / 2, -gp.thick];
gp_stop = [gp.length / 2, gp.length / 2, 0];
csx = AddBox(csx, 'groundplane', 10, gp_start, gp_stop);

%% plane wave excitation
csx = AddPlaneWaveExcite(csx, 'plane_wave', k_inc, e_inc, f0);
pw_start = [sim_mesh.x(1) + gap_pb_xy, sim_mesh.y(1) + gap_pb_xy, sim_mesh.z(1) + gap_pb_z];
pw_stop = [sim_mesh.x(end) - gap_pb_xy, sim_mesh.y(end) - gap_pb_xy, sim_mesh.z(end) - gap_pb_z];
csx = AddBox(csx, 'plane_wave', 0, pw_start, pw_stop);

%% dump boxes
start = [sim_mesh.x(1), sim_mesh.y(1), sim_mesh.z(1)];
stop  = [sim_mesh.x(end), sim_mesh.y(end), sim_mesh.z(end)];
[csx nf2ff] = CreateNF2FFBox(csx, 'nf2ff', start, stop);

% add 10 lines in all direction as pml spacing
sim_mesh = AddPML(sim_mesh, 10);

csx = DefineRectGrid(csx, unit, sim_mesh);

%% prepare simulation folder
sim_path = 'Plate';
sim_csx = 'Plate.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);

%%
disp('Use Paraview to display the elctric fields dumped by openEMS');

%%
EF = ReadUI('et', sim_path, f0); % time domain/freq domain voltage
Pin = 0.5*norm(e_inc)^2/Z0 .* abs(EF.FD{1}.val).^2;

%%
nf2ff = CalcNF2FF(nf2ff, sim_path, f0, (0:2:90)*pi/180, (0:2:359)*pi/180, 'Mode',1);
RCS = 4*pi./Pin(1).*nf2ff.P_rad{1};
surf(0:2:359, 0:2:90, RCS);
hold on
grid on```
qiank10 commented 1 year ago

It seems that the TD dump uses an oversampling ratio of 4 by default, while the FD dump samples every Nyquist number of steps. Is there any shortcut to make the FD dump oversample fields?