openEMS/matlab/examples/MSL.m

92 lines
3.0 KiB
Matlab
Raw Normal View History

2010-04-30 12:56:46 +00:00
close all
clear
2010-03-24 20:27:48 +00:00
clc
2010-04-24 14:47:40 +00:00
%% setup the simulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
abs_length = 250;
length = 1000;
width = 500;
height = 250;
MSL_width = 50;
MSL_height = 10;
mesh_res = [5 5 10];
EPS0 = 8.85418781762e-12;
MUE0 = 1.256637062e-6;
2010-04-30 12:56:46 +00:00
%% define openEMS options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
openEMS_opts = '';
% openEMS_opts = [openEMS_opts ' --disable-dumps'];
2010-04-24 14:47:40 +00:00
% openEMS_opts = [openEMS_opts ' --debug-material'];
2010-03-24 20:27:48 +00:00
Sim_Path = 'tmp';
Sim_CSX = 'msl.xml';
mkdir(Sim_Path);
2010-04-24 14:47:40 +00:00
%% setup FDTD parameter & excitation function %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
FDTD = InitFDTD(5e5,1e-6);
FDTD = SetGaussExcite(FDTD,0.5e9,0.5e9);
BC = [1 1 0 1 0 0];
FDTD = SetBoundaryCond(FDTD,BC);
2010-04-24 14:47:40 +00:00
%% setup CSXCAD geometry & mesh %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
CSX = InitCSX();
mesh.x = -width/2 : mesh_res(1) : width/2;
mesh.y = [linspace(0,MSL_height,11) MSL_height+1 MSL_height+3 MSL_height+mesh_res(2):mesh_res(2):height];
mesh.z = 0 : mesh_res(3) : length;
CSX = DefineRectGrid(CSX, 1e-3,mesh);
%%% MSL
CSX = AddMaterial(CSX,'copper');
CSX = SetMaterialProperty(CSX,'copper','Kappa',56e6);
start = [-0.5*MSL_width, MSL_height , 0];stop = [0.5*MSL_width, MSL_height+1 , length];
CSX = AddBox(CSX,'copper',0 ,start,stop);
start = [-0.5*MSL_width, 0 , 0];stop = [0.5*MSL_width, MSL_height , mesh_res(1)/2];
CSX = AddExcitation(CSX,'excite',0,[0 -1 0]);
CSX = AddBox(CSX,'excite',0 ,start,stop);
2010-04-24 14:47:40 +00:00
%% fake pml %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
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)']);
start = [mesh.x(1) mesh.y(1) length-abs_length];
stop = [mesh.x(end) mesh.y(end) length];
CSX = AddBox(CSX,'pml',0 ,start,stop);
2010-04-24 14:47:40 +00:00
%% define dump boxes... %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-04-07 10:57:45 +00:00
CSX = AddDump(CSX,'Et_','DumpMode',2);
2010-03-24 20:27:48 +00:00
start = [mesh.x(1) , MSL_height/2 , mesh.z(1)];
stop = [mesh.x(end) , MSL_height/2 , mesh.z(end)];
CSX = AddBox(CSX,'Et_',0 , start,stop);
2010-04-07 10:57:45 +00:00
CSX = AddDump(CSX,'Ht_','DumpType',1,'DumpMode',2);
2010-03-24 20:27:48 +00:00
CSX = AddBox(CSX,'Ht_',0,start,stop);
2010-04-24 14:47:40 +00:00
%% define voltage calc boxes %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
%voltage calc
CSX = AddProbe(CSX,'ut1',0);
start = [ 0 MSL_height length/2 ];stop = [ 0 0 length/2 ];
CSX = AddBox(CSX,'ut1', 0 ,start,stop);
%current calc
CSX = AddProbe(CSX,'it1',1);
start = [ -MSL_width MSL_height/2 length/2 ];stop = [ MSL_width MSL_height*1.5 length/2 ];
CSX = AddBox(CSX,'it1', 0 ,start,stop);
2010-04-24 14:47:40 +00:00
%% Write openEMS compatoble xml-file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
WriteOpenEMS([Sim_Path '/' Sim_CSX],FDTD,CSX);
2010-04-24 14:47:40 +00:00
%% cd to working dir and run openEMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2010-03-24 20:27:48 +00:00
savePath = pwd();
cd(Sim_Path); %cd to working dir
2010-04-30 12:56:46 +00:00
args = [Sim_CSX ' ' openEMS_opts];
invoke_openEMS(args);
2010-03-24 20:27:48 +00:00
cd(savePath);