From 36e11152b162e57bf3ce7e17b364f6eefd90e638 Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Wed, 24 Mar 2010 21:27:48 +0100 Subject: [PATCH] new matlab examples --- matlab/examples/Coax.m | 95 +++++++++++++++++++++++++++++++++++++ matlab/examples/MSL.m | 90 +++++++++++++++++++++++++++++++++++ matlab/examples/PlaneWave.m | 74 +++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100644 matlab/examples/Coax.m create mode 100644 matlab/examples/MSL.m create mode 100644 matlab/examples/PlaneWave.m diff --git a/matlab/examples/Coax.m b/matlab/examples/Coax.m new file mode 100644 index 0000000..43b8629 --- /dev/null +++ b/matlab/examples/Coax.m @@ -0,0 +1,95 @@ +close all; +clear all; +clc + +abs_length = 250; +length = 1000; +coax_rad_i = 100; +coax_rad_ai = 230; +coax_rad_aa = 240; +mesh_res = [5 5 5]; + +EPS0 = 8.85418781762e-12; +MUE0 = 1.256637062e-6; + +openEMS_Path = [pwd() '/../../'] +openEMS_opts = ''; +% openEMS_opts = [openEMS_opts ' --disable-dumps']; +% openEMS_opts = [openEMS_opts ' --debug-material']; + +Sim_Path = 'tmp'; +Sim_CSX = 'coax.xml'; + +mkdir(Sim_Path); + +%setup FDTD parameter +FDTD = InitFDTD(5e5,1e-6); +FDTD = SetGaussExcite(FDTD,0.5e9,0.5e9); +BC = [1 1 1 1 1 1] * 0; +FDTD = SetBoundaryCond(FDTD,BC); + +%setup CSXCAD geometry +CSX = InitCSX(); +mesh.x = -2.5*mesh_res(1)-coax_rad_aa : mesh_res(1) : coax_rad_aa+2.5*mesh_res(1); +mesh.y = mesh.x; +mesh.z = 0 : mesh_res(3) : length; +CSX = DefineRectGrid(CSX, 1e-3,mesh); + +%create copper helix and feed lines... +CSX = AddMaterial(CSX,'copper'); +CSX = SetMaterialProperty(CSX,'copper','Kappa',56e6); + +%%%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)']); + +%%% coax +start = [0, 0 , 0];stop = [0, 0 , length]; +CSX = AddCylinder(CSX,'copper',0 ,start,stop,coax_rad_i); +CSX = AddCylindricalShell(CSX,'copper',0 ,start,stop,0.5*(coax_rad_aa+coax_rad_ai),(coax_rad_aa-coax_rad_ai)); +start(3) = length-abs_length; +CSX = AddCylindricalShell(CSX,'pml',0 ,start,stop,0.5*(coax_rad_i+coax_rad_ai),(coax_rad_ai-coax_rad_i)); +start(3) = 0; stop(3)=mesh_res(1)/2; +CSX = AddExcitation(CSX,'excite',0,[1 1 0]); +weight{1} = '(x)/(x*x+y*y)'; +weight{2} = 'y/pow(rho,2)'; +weight{3} = 0; +CSX = SetExcitationWeight(CSX, 'excite', weight ); +CSX = AddCylindricalShell(CSX,'excite',0 ,start,stop,0.5*(coax_rad_i+coax_rad_ai),(coax_rad_ai-coax_rad_i)); + +%dump +CSX = AddDump(CSX,'Et_',0,2); +start = [mesh.x(1) , 0 , mesh.z(1)]; +stop = [mesh.x(end) , 0 , mesh.z(end)]; +CSX = AddBox(CSX,'Et_',0 , start,stop); + +CSX = AddDump(CSX,'Ht_',1,2); +CSX = AddBox(CSX,'Ht_',0,start,stop); + +%voltage calc +CSX = AddProbe(CSX,'ut1',0); +start = [ coax_rad_i 0 length/2 ];stop = [ coax_rad_ai 0 length/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); + diff --git a/matlab/examples/MSL.m b/matlab/examples/MSL.m new file mode 100644 index 0000000..754b105 --- /dev/null +++ b/matlab/examples/MSL.m @@ -0,0 +1,90 @@ +close all; +clear all; +clc + +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; + +openEMS_Path = [pwd() '/../../'] +openEMS_opts = ''; +% openEMS_opts = [openEMS_opts ' --disable-dumps']; +openEMS_opts = [openEMS_opts ' --debug-material']; + +Sim_Path = 'tmp'; +Sim_CSX = 'msl.xml'; + +mkdir(Sim_Path); + +%setup FDTD parameter +FDTD = InitFDTD(5e5,1e-6); +FDTD = SetGaussExcite(FDTD,0.5e9,0.5e9); +BC = [1 1 0 1 0 0]; +FDTD = SetBoundaryCond(FDTD,BC); + +%setup CSXCAD geometry +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); + +%%%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)']); +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); + +%dump +CSX = AddDump(CSX,'Et_',0,2); +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); + +CSX = AddDump(CSX,'Ht_',1,2); +CSX = AddBox(CSX,'Ht_',0,start,stop); + +%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); + +%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); + diff --git a/matlab/examples/PlaneWave.m b/matlab/examples/PlaneWave.m new file mode 100644 index 0000000..25e531e --- /dev/null +++ b/matlab/examples/PlaneWave.m @@ -0,0 +1,74 @@ +close all; +clear all; +clc + +abs_length = 250; +length = 4000; +width = 1000; +height = 1000; +mesh_res = 25; + +EPS0 = 8.85418781762e-12; +MUE0 = 1.256637062e-6; + +openEMS_Path = [pwd() '/../../'] +openEMS_opts = ''; +% openEMS_opts = [openEMS_opts ' --disable-dumps']; +% openEMS_opts = [openEMS_opts ' --debug-material']; + +Sim_Path = 'tmp'; +Sim_CSX = 'plane_wave.xml'; + +mkdir(Sim_Path); + +%setup FDTD parameter +FDTD = InitFDTD(5e5,1e-6); +FDTD = SetGaussExcite(FDTD,0.5e9,0.5e9); +BC = [1 1 0 0 0 0]; +FDTD = SetBoundaryCond(FDTD,BC); + +%setup CSXCAD geometry +CSX = InitCSX(); +mesh.x = -width/2 : mesh_res : width/2; +mesh.y = -height/2 : mesh_res : height/2; +mesh.z = 0 : mesh_res : length; +CSX = DefineRectGrid(CSX, 1e-3,mesh); + + +%%%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)']); +start=[-width/2 -height/2 length-abs_length]; +stop=[width/2 height/2 length]; +CSX = AddBox(CSX,'pml',0 ,start,stop); + +start=[-width/2 -height/2 0]; +stop=[width/2 height/2 0]; +CSX = AddExcitation(CSX,'excite',0,[0 1 0]); +CSX = AddBox(CSX,'excite',0 ,start,stop); + +%dump +CSX = AddDump(CSX,'Et_',0,0); +start = [mesh.x(1) , 0 , mesh.z(1)]; +stop = [mesh.x(end) , 0 , mesh.z(end)]; +CSX = AddBox(CSX,'Et_',0 , start,stop); + +CSX = AddDump(CSX,'Ht_',1,0); +CSX = AddBox(CSX,'Ht_',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); +