update/fixes in PlotHDF5FieldData and new examples

This commit is contained in:
Thorsten Liebig 2010-04-07 16:32:22 +02:00
parent cf9969b5dc
commit 6a0581d2fd
2 changed files with 168 additions and 30 deletions

View File

@ -1,6 +1,5 @@
function PlotHDF5FieldData(file, PlotArgs)
plane = PlotArgs.plane;
component = PlotArgs.component;
if (isfield(PlotArgs,'pauseTime'))
@ -12,49 +11,49 @@ end
mesh = ReadHDF5Mesh(file);
fields = ReadHDF5FieldData(file);
[X Y Z] = meshgrid(double(mesh.lines{1}),double(mesh.lines{2}),double(mesh.lines{3}));
max_amp = 0;
if (strcmp(plane,'zx'))
[X1 X2] = meshgrid(mesh.lines{3}, mesh.lines{1});
if (component>0)
for n=1:numel(fields.values)
Z{n} = squeeze(double(fields.values{n}(:,1,:,component)));
end
else
for n=1:numel(fields.values)
fx = squeeze(double(fields.values{n}(:,1,:,1)));
fy = squeeze(double(fields.values{n}(:,1,:,2)));
fz = squeeze(double(fields.values{n}(:,1,:,3)));
Z{n} = sqrt(fx.^2 + fy.^2 + fz.^2);
end
if (component>0)
for n=1:numel(fields.values)
Field{n} = double(fields.values{n}(:,:,:,component));
end
else
for n=1:numel(fields.values)
fx = double(fields.values{n}(:,:,:,1));
fy = double(fields.values{n}(:,:,:,2));
fz = double(fields.values{n}(:,:,:,3));
Field{n} = sqrt(fx.^2 + fy.^2 + fz.^2);
end
end
for n=1:numel(Z)
amp = max(max(abs(Z{n})));
for n=1:numel(Field)
amp = max(max(max(abs(Field{n}))));
if (amp>max_amp)
max_amp = amp;
end
end
if (max_amp==0)
disp('max found amplitude was 0 --> nothing to plot');
return
end
for n=1:numel(Z)
surf(X1,X2,Z{n})
for n=1:numel(Field)
hsurfaces = slice(X,Y,Z, Field{n} , PlotArgs.slice{:});
set(hsurfaces,'FaceColor','interp','EdgeColor','none');
title(fields.names{n});
if (isfield(PlotArgs,'zlim'))
if ~ischar(PlotArgs.zlim)
zlim(PlotArgs.zlim);
elseif strcmp(PlotArgs.zlim,'auto')
zlim([-max_amp*(component>0) max_amp]);
end
end
%view(3)
axis equal
% if (isfield(PlotArgs,'zlim'))
% if ~ischar(PlotArgs.zlim)
% zlim(PlotArgs.zlim);
% elseif strcmp(PlotArgs.zlim,'auto')
% zlim([-max_amp*(component>0) max_amp]);
% end
% end
%
drawnow
pause(pauseT)
end

View File

@ -0,0 +1,139 @@
close all;
clear all;
clc
abs_length = 500;
length = 5000;
unit = 1e-3;
rad = 300;
mesh_res = [15 15 30];
EPS0 = 8.85418781762e-12;
MUE0 = 1.256637062e-6;
C0 = 1/sqrt(EPS0*MUE0);
f0 = 400e6;
p11 = 1.841;
kc = p11 / rad /unit;
k = 2*pi*f0/C0;
fc = C0*kc/2/pi
beta = sqrt(k^2 - kc^2);
kc = kc*unit;
func_Er = [ num2str(-1/kc^2) '/rho*cos(a)*j1(' num2str(kc) '*rho)'];
func_Ea = [ num2str(1/kc) '*sin(a)*0.5*(j0(' num2str(kc) '*rho)-jn(2,' num2str(kc) '*rho))'];
func_Ex = [func_Er '*cos(a) - ' func_Ea '*sin(a)'];
func_Ey = [func_Er '*sin(a) + ' func_Ea '*cos(a)'];
openEMS_Path = [pwd() '/../../']
openEMS_opts = '';
% openEMS_opts = [openEMS_opts ' --disable-dumps'];
% openEMS_opts = [openEMS_opts ' --debug-material'];
% openEMS_opts = [openEMS_opts ' --debug-operator'];
% openEMS_opts = [openEMS_opts ' --engine=multithreaded'];
Sim_Path = 'tmp';
Sim_CSX = 'Circ_WG.xml';
mkdir(Sim_Path);
%setup FDTD parameter
FDTD = InitFDTD(1000,1e-6,'OverSampling',5);
T = 1/f0;
FDTD = SetCustomExcite(FDTD,f0,[ '(1-exp(-1*(t/' num2str(T) ')^2) ) * sin(2*pi*' num2str(f0) '*t)' ]);
BC = [1 1 1 1 1 1] * 0;
FDTD = SetBoundaryCond(FDTD,BC);
%setup CSXCAD geometry
CSX = InitCSX();
mesh.x = -mesh_res(1)/2-rad:mesh_res(1):rad+mesh_res(1)/2;
mesh.y = -mesh_res(2)/2-rad:mesh_res(2):rad+mesh_res(2)/2;
mesh.z = 0 : mesh_res(3) : length;
CSX = DefineRectGrid(CSX, 1e-3,mesh);
start = [0,0,0];
stop = [0,0,length];
%%fake pml
finalKappa = 0.3/abs_length^4;
finalSigma = finalKappa*MUE0/EPS0;
CSX = AddMaterial(CSX,'pml');
CSX = SetMaterialProperty(CSX,'pml','Kappa',finalKappa);
CSX = SetMaterialProperty(CSX,'pml','Sigma',finalSigma);
CSX = SetMaterialWeight(CSX,'pml','Kappa',['pow(abs(z)-' num2str(length-abs_length) ',4)']);
CSX = SetMaterialWeight(CSX,'pml','Sigma',['pow(abs(z)-' num2str(length-abs_length) ',4)']);
CSX = AddCylinder(CSX,'pml',10 ,[0 0 length-abs_length],stop,rad);
%%% fill everything with copper, priority 0
CSX = AddMaterial(CSX,'copper');
CSX = SetMaterialProperty(CSX,'copper','Kappa',56e6);
CSX = AddBox(CSX,'copper',0,[mesh.x(1) mesh.y(1) mesh.z(1)],[mesh.x(end) mesh.y(end) mesh.z(end)]);
%%% cut out an air cylinder as circular waveguide... priority 5
CSX = AddMaterial(CSX,'air');
CSX = SetMaterialProperty(CSX,'air','Epsilon',1);
CSX = AddCylinder(CSX,'air', 5 ,start,stop,rad);
CSX = AddExcitation(CSX,'excite',0,[1 1 0]);
weight{1} = func_Ex;
weight{2} = func_Ey;
weight{3} = 0;
CSX = SetExcitationWeight(CSX, 'excite', weight );
CSX = AddCylinder(CSX,'excite', 5 ,[0 0 -0.1],[0 0 0.1],rad);
%dump
CSX = AddDump(CSX,'Et','SubSampling','2,2,4','FileType',1,'DumpMode',2);
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);
% CSX = AddDump(CSX,'Ht','SubSampling','2,2,4','DumpType',1,'FileType',1,'DumpMode',2);
% CSX = AddBox(CSX,'Ht',0,start,stop);
% CSX = AddDump(CSX,'Excite_');
% start = [mesh.x(1) , mesh.y(1) , 0];
% stop = [mesh.x(end) , mesh.y(end) ,0];
% CSX = AddBox(CSX,'Excite_',0 , start,stop);
%
% CSX = AddDump(CSX,'Exy');
% start = [mesh.x(1) , mesh.y(1) , length/2];
% stop = [mesh.x(end) , mesh.y(end) , length/2];
% CSX = AddBox(CSX,'Exy',0 , start,stop);
%voltage calc
CSX = AddProbe(CSX,'ut1',0);
start = [ -rad 0 0/2 ];stop = [ rad 0 0/2 ];
CSX = AddBox(CSX,'ut1', 0 ,start,stop);
%
% %current calc
% CSX = AddProbe(CSX,'it1',1);
% mid = 0.5*(coax_rad_i+coax_rad_ai);
% start = [ -mid -mid length/2 ];stop = [ mid mid length/2 ];
% CSX = AddBox(CSX,'it1', 0 ,start,stop);
%Write openEMS compatoble xml-file
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
%cd to working dir and run openEMS
savePath = pwd();
cd(Sim_Path); %cd to working dir
command = [openEMS_Path 'openEMS.sh ' Sim_CSX ' ' openEMS_opts];
disp(command);
system(command)
cd(savePath);
UI = ReadUI('ut1','tmp/');
plot(UI.TD{1}.t,UI.TD{1}.val);
grid on;
% plotting
if exist('tmp/Et.h5','file')
PlotArgs.slice = {mesh.x(round(end/2)) mesh.y(round(end/2)) mesh.z(round(end/2))};
PlotArgs.pauseTime=0.1;
PlotArgs.component=0;
PlotArgs.zlim='auto';
PlotHDF5FieldData('tmp/Et.h5',PlotArgs)
end