simplified nf2ff creation and example update

This commit is contained in:
Thorsten Liebig 2010-12-21 09:35:27 +01:00
parent d3f0b694e5
commit b7a9b8c605
4 changed files with 121 additions and 33 deletions

View File

@ -1,12 +1,11 @@
function [E_theta,E_phi,Prad,Dmax] = AnalyzeNFFF2( Sim_Path, filenames_E, filenames_H, f, theta, phi, r )
function [E_theta,E_phi,Prad,Dmax] = AnalyzeNFFF2( Sim_Path, nf2ff, f, theta, phi, r )
% [E_theta,E_phi,Prad,Dmax] = AnalyzeNFFF2( Sim_Path, filenames_E, filenames_H, f, theta, phi, r )
%
% calculates the farfield via a near field to far field transformation
%
% input:
% Sim_Path: simulation directory
% filenames_E: cell array of filenames for the time domain fields on the NFFF contour (6 E-planes; hdf5)
% filenames_H: cell array of filenames for the time domain fields on the NFFF contour (6 H-planes; hdf5)
% nf2ff: structure on filenames etc. as created by CreateNF2FFBox
% f: frequency (Hz) for far field calculation
% theta: (degrees) vector of discrete theta values to calculate the far field for
% phi: (degrees) vector of discrete phi values to calculate the far field for
@ -20,16 +19,19 @@ function [E_theta,E_phi,Prad,Dmax] = AnalyzeNFFF2( Sim_Path, filenames_E, filena
%
% example:
% see examples/NF2FF/infDipol.m
%
% See also CreateNF2FFBox
%
% (C) 2010 Sebastian Held <sebastian.held@gmx.de>
% check arguments
error( nargchk(7,7,nargin) );
error( nargchk(6,6,nargin) );
if ~isscalar(f)
error 'Currently only one frequency is supported. Call this function multiple times.'
end
filenames_E = nf2ff.filenames_E;
filenames_H = nf2ff.filenames_H;
% read time domain field data and transform into frequency domain
for n=1:numel(filenames_E)

32
matlab/CreateNF2FFBox.m Normal file
View File

@ -0,0 +1,32 @@
function [CSX nf2ff] = CreateNF2FFBox(CSX, name, start, stop)
% function [CSX nf2ff] = CreateNF2FFBox(CSX, name, start, stop)
%
% create the dump boxes needed for the near field to far field transformation
%
% input:
% name: name of this nf2ff box
% start/stop: start/stop coordinates for the nf2ff box (this box has to
% enclose all radiating structures!)
%
% example:
% see examples/NF2FF/infDipol.m
%
% See also AnalyzeNF2FF
%
% (C) 2010 Thoorsten Liebig <thorsten.liebig@gmx.de>
nf2ff.filenames_E = {[name '_Et_xn'],[name '_Et_xp'],[name '_Et_yn'],[name '_Et_yp'],[name '_Et_zn'],[name '_Et_zp']};
nf2ff.filenames_H = {[name '_Ht_xn'],[name '_Ht_xp'],[name '_Ht_yn'],[name '_Ht_yp'],[name '_Ht_zn'],[name '_Ht_zp']};
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{1},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{1}, 0, start, [start(1) stop(2) stop(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{2},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{2}, 0, [stop(1) start(2) start(3)], stop );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{3},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{3}, 0, start, [stop(1) start(2) stop(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{4},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{4}, 0, [start(1) stop(2) start(3)], stop );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{5},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{5}, 0, start, [stop(1) stop(2) start(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_E{6},'DumpType',0,'DumpMode',2,'FileType',1), nf2ff.filenames_E{6}, 0, [start(1) start(2) stop(3)], stop );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{1},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{1}, 0, start, [start(1) stop(2) stop(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{2},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{2}, 0, [stop(1) start(2) start(3)], stop );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{3},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{3}, 0, start, [stop(1) start(2) stop(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{4},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{4}, 0, [start(1) stop(2) start(3)], stop );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{5},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{5}, 0, start, [stop(1) stop(2) start(3)] );
CSX = AddBox( AddDump(CSX,nf2ff.filenames_H{6},'DumpType',1,'DumpMode',2,'FileType',1), nf2ff.filenames_H{6}, 0, [start(1) start(2) stop(3)], stop );

View File

@ -9,7 +9,7 @@ clc
drawnow
postprocessing_only = 0;
postprocessing_only = 1;
@ -72,18 +72,7 @@ CSX = AddBox( CSX, 'infDipole', 1, start, stop );
% NFFF contour
s1 = [-4.5, -4.5, -4.5] * g.dipole_length/2;
s2 = [ 4.5, 4.5, 4.5] * g.dipole_length/2;
CSX = AddBox( AddDump(CSX,'Et_xn','DumpType',0,'DumpMode',2,'FileType',1), 'Et_xn', 0, s1, [s1(1) s2(2) s2(3)] );
CSX = AddBox( AddDump(CSX,'Et_xp','DumpType',0,'DumpMode',2,'FileType',1), 'Et_xp', 0, [s2(1) s1(2) s1(3)], s2 );
CSX = AddBox( AddDump(CSX,'Et_yn','DumpType',0,'DumpMode',2,'FileType',1), 'Et_yn', 0, s1, [s2(1) s1(2) s2(3)] );
CSX = AddBox( AddDump(CSX,'Et_yp','DumpType',0,'DumpMode',2,'FileType',1), 'Et_yp', 0, [s1(1) s2(2) s1(3)], s2 );
CSX = AddBox( AddDump(CSX,'Et_zn','DumpType',0,'DumpMode',2,'FileType',1), 'Et_zn', 0, s1, [s2(1) s2(2) s1(3)] );
CSX = AddBox( AddDump(CSX,'Et_zp','DumpType',0,'DumpMode',2,'FileType',1), 'Et_zp', 0, [s1(1) s1(2) s2(3)], s2 );
CSX = AddBox( AddDump(CSX,'Ht_xn','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_xn', 0, s1, [s1(1) s2(2) s2(3)] );
CSX = AddBox( AddDump(CSX,'Ht_xp','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_xp', 0, [s2(1) s1(2) s1(3)], s2 );
CSX = AddBox( AddDump(CSX,'Ht_yn','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_yn', 0, s1, [s2(1) s1(2) s2(3)] );
CSX = AddBox( AddDump(CSX,'Ht_yp','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_yp', 0, [s1(1) s2(2) s1(3)], s2 );
CSX = AddBox( AddDump(CSX,'Ht_zn','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_zn', 0, s1, [s2(1) s2(2) s1(3)] );
CSX = AddBox( AddDump(CSX,'Ht_zp','DumpType',1,'DumpMode',2,'FileType',1), 'Ht_zp', 0, [s1(1) s1(2) s2(3)], s2 );
[CSX g.nf2ff] = CreateNF2FFBox(CSX, 'nf2ff', s1, s2);
@ -125,15 +114,11 @@ disp( ' ' );
disp( ' ********************************************************** ' );
disp( ' ' );
% NFFF contour
filenames_E = {'Et_xn.h5','Et_xp.h5','Et_yn.h5','Et_yp.h5','Et_zn.h5','Et_zp.h5'};
filenames_H = {'Ht_xn.h5','Ht_xp.h5','Ht_yn.h5','Ht_yp.h5','Ht_zn.h5','Ht_zp.h5'};
% calculate the far field at phi=0 degrees and at phi=90 degrees
thetaRange = 0:2:359;
r = 1; % evaluate fields at radius r
disp( 'calculating far field at phi=[0 90] deg...' );
[E_far_theta,E_far_phi,Prad,Dmax] = AnalyzeNFFF2( g.Sim_Path, filenames_E, filenames_H, g.f_max, thetaRange, [0 90], r );
[E_far_theta,E_far_phi,Prad,Dmax] = AnalyzeNF2FF( g.Sim_Path, g.nf2ff, g.f_max, thetaRange, [0 90], r );
% display power and directivity
@ -175,7 +160,7 @@ legend( 'e-field magnitude', 'Location', 'BestOutside' );
phiRange = 0:2:359;
r = 1; % evaluate fields at radius r
disp( 'calculating far field at theta=90 deg...' );
[E_far_theta,E_far_phi] = AnalyzeNFFF2( g.Sim_Path, filenames_E, filenames_H, g.f_max, 90, phiRange, r );
[E_far_theta,E_far_phi] = AnalyzeNF2FF( g.Sim_Path, g.nf2ff, g.f_max, 90, phiRange, r );
E_theta90_far = zeros(1,numel(phiRange));
for n=1:numel(phiRange)
@ -197,7 +182,7 @@ phiRange = 0:15:360;
thetaRange = 0:10:180;
r = 1; % evaluate fields at radius r
disp( 'calculating 3D far field...' );
[E_far_theta,E_far_phi] = AnalyzeNFFF2( g.Sim_Path, filenames_E, filenames_H, g.f_max, thetaRange, phiRange, r );
[E_far_theta,E_far_phi] = AnalyzeNF2FF( g.Sim_Path, g.nf2ff, g.f_max, thetaRange, phiRange, r );
E_far = sqrt( abs(E_far_theta).^2 + abs(E_far_phi).^2 );
E_far_normalized = E_far / max(E_far(:));
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);

View File

@ -37,7 +37,7 @@ feed.width = 0.5;
feed.R = 50; % feed resistance
% size of the simulation box
SimBox = [120 120 32];
SimBox = [200 200 50];
%% prepare simulation folder
Sim_Path = 'tmp';
@ -62,15 +62,15 @@ max_res = c0 / (f0+fc) / unit / 20; % cell size: lambda/20
CSX = InitCSX();
mesh.x = [-SimBox(1)/2 SimBox(1)/2 -substrate.width/2 substrate.width/2 feed.pos-feed.width/2 feed.pos+feed.width/2];
% add patch mesh with 2/3 - 1/3 rule
mesh.x = [mesh.x -patch.width/2-max_res*0.66 -patch.width/2+max_res*0.33 patch.width/2+max_res*0.66 patch.width/2-max_res*0.33];
mesh.x = SmoothMeshLines( mesh.x, max_res ); % create a smooth mesh between specified mesh lines
mesh.x = [mesh.x -patch.width/2-max_res/2*0.66 -patch.width/2+max_res/2*0.33 patch.width/2+max_res/2*0.66 patch.width/2-max_res/2*0.33];
mesh.x = SmoothMeshLines( mesh.x, max_res, 1.4); % create a smooth mesh between specified mesh lines
mesh.y = [-SimBox(2)/2 SimBox(2)/2 -substrate.length/2 substrate.length/2 -feed.width/2 feed.width/2];
% add patch mesh with 2/3 - 1/3 rule
mesh.y = [mesh.y -patch.length/2-max_res*0.66 -patch.length/2+max_res*0.33 patch.length/2+max_res*0.66 patch.length/2-max_res*0.33];
mesh.y = SmoothMeshLines( mesh.y, max_res );
mesh.z = [linspace(0,substrate.thickness,substrate.cells) SimBox(3) SimBox(3)];
mesh.z = SmoothMeshLines( mesh.z, max_res );
mesh = AddPML( mesh, [8 8 8 8 0 8] ); % add equidistant cells (air around the structure)
mesh.y = [mesh.y -patch.length/2-max_res/2*0.66 -patch.length/2+max_res/2*0.33 patch.length/2+max_res/2*0.66 patch.length/2-max_res/2*0.33];
mesh.y = SmoothMeshLines( mesh.y, max_res, 1.4 );
mesh.z = [-SimBox(3)/2 linspace(0,substrate.thickness,substrate.cells) SimBox(3) ];
mesh.z = SmoothMeshLines( mesh.z, max_res, 1.4 );
mesh = AddPML( mesh, [8 8 8 8 8 8] ); % add equidistant cells (air around the structure)
CSX = DefineRectGrid( CSX, unit, mesh );
%% create patch
@ -86,6 +86,12 @@ start = [-substrate.width/2 -substrate.length/2 0];
stop = [ substrate.width/2 substrate.length/2 substrate.thickness];
CSX = AddBox( CSX, 'substrate', 0, start, stop );
%% create ground (same size as substrate)
CSX = AddMetal( CSX, 'gnd' ); % create a perfect electric conductor (PEC)
start(3)=0;
stop(3) =0;
CSX = AddBox(CSX,'gnd',10,start,stop);
%% apply the excitation & resist as a current source
% this creates a "port"
CSX = AddMaterial( CSX, 'resist' );
@ -116,6 +122,9 @@ start = [-patch.width -patch.length substrate.thickness+1];
stop = [ patch.width patch.length substrate.thickness+1];
CSX = AddBox( CSX, 'Ht_', 0, start, stop );
%%nf2ff calc
[CSX nf2ff] = CreateNF2FFBox(CSX, 'nf2ff', -SimBox/2, SimBox/2);
%% write openEMS compatible xml-file
WriteOpenEMS( [Sim_Path '/' Sim_CSX], FDTD, CSX );
@ -175,6 +184,66 @@ title( 'reflection coefficient S_{11}' );
xlabel( 'frequency f / MHz' );
ylabel( 'reflection coefficient |S_{11}|' );
%% NFFF contour plots %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f0 = freq(find(s11==min(s11)));
% calculate the far field at phi=0 degrees and at phi=90 degrees
thetaRange = 0:2:359;
r = 1; % evaluate fields at radius r
disp( 'calculating far field at phi=[0 90] deg...' );
[E_far_theta,E_far_phi,Prad,Dmax] = AnalyzeNF2FF( Sim_Path, nf2ff, f0, thetaRange, [0 90], r );
% display power and directivity
disp( ['radiated power: Prad = ' num2str(Prad)] );
disp( ['directivity: Dmax = ' num2str(Dmax)] );
% calculate the e-field magnitude for phi = 0 deg
E_phi0_far = zeros(1,numel(thetaRange));
for n=1:numel(thetaRange)
E_phi0_far(n) = norm( [E_far_theta(n,1) E_far_phi(n,1)] );
end
% display polar plot
figure
polar( thetaRange/180*pi, E_phi0_far );
ylabel( 'theta / deg' );
title( ['electrical far field (V/m) @r=' num2str(r) ' m phi=0 deg'] );
legend( 'e-field magnitude', 'Location', 'BestOutside' );
% calculate the e-field magnitude for phi = 90 deg
E_phi90_far = zeros(1,numel(thetaRange));
for n=1:numel(thetaRange)
E_phi90_far(n) = norm([E_far_theta(n,2) E_far_phi(n,2)]);
end
% display polar plot
figure
polar( thetaRange/180*pi, E_phi90_far );
ylabel( 'theta / deg' );
title( ['electrical far field (V/m) @r=' num2str(r) ' m phi=90 deg'] );
legend( 'e-field magnitude', 'Location', 'BestOutside' );
%% calculate 3D pattern
phiRange = 0:15:360;
thetaRange = 0:10:180;
r = 1; % evaluate fields at radius r
disp( 'calculating 3D far field...' );
[E_far_theta,E_far_phi] = AnalyzeNF2FF( Sim_Path, nf2ff, f0, thetaRange, phiRange, r );
E_far = sqrt( abs(E_far_theta).^2 + abs(E_far_phi).^2 );
E_far_normalized = E_far / max(E_far(:));
[theta,phi] = ndgrid(thetaRange/180*pi,phiRange/180*pi);
x = E_far_normalized .* sin(theta) .* cos(phi);
y = E_far_normalized .* sin(theta) .* sin(phi);
z = E_far_normalized .* cos(theta);
figure
surf( x,y,z, E_far_normalized );
axis equal
xlabel( 'x' );
ylabel( 'y' );
zlabel( 'z' );
%% visualize magnetic fields
% you will find vtk dump files in the simulation folder (tmp/)
% use paraview to visulaize them