From 50467e029debe35659a11f842436b045259bbcff Mon Sep 17 00:00:00 2001 From: Sebastian Held Date: Tue, 30 Mar 2010 13:14:00 +0200 Subject: [PATCH] new testsuite --- TESTSUITE/combinedtests/Coax.m | 152 +++++++++++++++++++ TESTSUITE/combinedtests/README | 3 + TESTSUITE/helperscripts/check_limits.m | 22 +++ TESTSUITE/helperscripts/invoke_openEMS.m | 15 ++ TESTSUITE/helperscripts/physical_constants.m | 8 + 5 files changed, 200 insertions(+) create mode 100644 TESTSUITE/combinedtests/Coax.m create mode 100644 TESTSUITE/combinedtests/README create mode 100644 TESTSUITE/helperscripts/check_limits.m create mode 100644 TESTSUITE/helperscripts/invoke_openEMS.m create mode 100644 TESTSUITE/helperscripts/physical_constants.m diff --git a/TESTSUITE/combinedtests/Coax.m b/TESTSUITE/combinedtests/Coax.m new file mode 100644 index 0000000..1ea2009 --- /dev/null +++ b/TESTSUITE/combinedtests/Coax.m @@ -0,0 +1,152 @@ +function pass = Coax + +physical_constants; + + +ENABLE_PLOTS = 1; +CLEANUP = 0; % if enabled and result is PASS, remove simulation folder +STOP_IF_FAILED = 1; % if enabled and result is FAILED, stop with error + +% LIMITS +upper_error = 0.036; % max +3.6% +lower_error = 0; % max -0.0% + +% structure +abs_length = 250; +length = 1000; +coax_rad_i = 100; +coax_rad_ai = 230; +coax_rad_aa = 240; +mesh_res = [5 5 5]; +f_start = 0; +f_stop = 1e9; + +Sim_Path = 'tmp'; +Sim_CSX = 'coax.xml'; + +[status,message,messageid]=mkdir(Sim_Path); + +%setup FDTD parameter +FDTD = InitFDTD(5e5,1e-6); +FDTD = SetGaussExcite(FDTD,(f_stop-f_start)/2,(f_stop-f_start)/2); +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 +CSX = AddMetal(CSX,'PEC'); + +%%%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,'PEC',0 ,start,stop,coax_rad_i); % inner conductor +CSX = AddCylindricalShell(CSX,'PEC',0 ,start,stop,0.5*(coax_rad_aa+coax_rad_ai),(coax_rad_aa-coax_rad_ai)); % outer conductor + +%%% add PML +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 compatible 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 +invoke_openEMS( Sim_CSX ); +UI = ReadUI( {'ut1','it1'} ); +cd(savePath); + + + +% +% analysis +% + +f = UI.FD{2}.f; +u = UI.FD{1}.val; +i = UI.FD{2}.val; + +f_idx_start = interp1( f, 1:numel(f), f_start, 'nearest' ); +f_idx_stop = interp1( f, 1:numel(f), f_stop, 'nearest' ); +f = f(f_idx_start:f_idx_stop); +u = u(f_idx_start:f_idx_stop); +i = i(f_idx_start:f_idx_stop); + +Z = abs(u./i); + +% analytic formular for characteristic impedance +Z0 = sqrt(MUE0/EPS0) * log(coax_rad_ai/coax_rad_i) / (2*pi); +upper_limit = Z0 * (1+upper_error); +lower_limit = Z0 * (1-lower_error); + +if ENABLE_PLOTS + upper = upper_limit * ones(1,size(Z,2)); + lower = lower_limit * ones(1,size(Z,2)); + Z0_plot = Z0 * ones(1,size(Z,2)); + figure + plot(f/1e9,[Z;upper;lower]) + hold on + plot(f/1e9,Z0_plot,'m-.','LineWidth',2) + hold off + xlabel('Frequency (GHz)') + ylabel('Impedance (Ohm)') + legend( {'sim', 'upper limit', 'lower limit', 'theoretical'} ); +end + +pass = check_limits( Z, upper_limit, lower_limit ); +if pass + disp( 'combinedtests/Coax.m (characteristic impedance): pass' ); +else + disp( 'combinedtests/Coax.m (characteristic impedance): * FAILED *' ); +end + + + + +if pass && CLEANUP + rmdir( [Sim_Path '/' Sim_CSX], 's' ); +end +if ~pass && STOP_IF_FAILED + error 'test failed'; +end diff --git a/TESTSUITE/combinedtests/README b/TESTSUITE/combinedtests/README new file mode 100644 index 0000000..cc29c5b --- /dev/null +++ b/TESTSUITE/combinedtests/README @@ -0,0 +1,3 @@ +# +# These scripts test the full simulator (not single features) +# \ No newline at end of file diff --git a/TESTSUITE/helperscripts/check_limits.m b/TESTSUITE/helperscripts/check_limits.m new file mode 100644 index 0000000..c1cba3d --- /dev/null +++ b/TESTSUITE/helperscripts/check_limits.m @@ -0,0 +1,22 @@ +function pass = check_limits( Z, upper_limit, lower_limit ) + +% make row vector +if size(Z,1) ~= 1 + Z = Z.'; +end + +if numel(upper_limit) == 1 + upper_limit = upper_limit * ones(1,size(Z,2)); +end +if numel(lower_limit) == 1 + lower_limit = lower_limit * ones(1,size(Z,2)); +end + + +pass = 1; +if any( Z > upper_limit ) + pass = 0; +end +if any( Z < lower_limit ) + pass = 0; +end diff --git a/TESTSUITE/helperscripts/invoke_openEMS.m b/TESTSUITE/helperscripts/invoke_openEMS.m new file mode 100644 index 0000000..57f05f1 --- /dev/null +++ b/TESTSUITE/helperscripts/invoke_openEMS.m @@ -0,0 +1,15 @@ +function invoke_openEMS( opts ) + +if nargin < 1 + opts = ''; +end +% openEMS_opts = [openEMS_opts ' --disable-dumps']; +% openEMS_opts = [openEMS_opts ' --debug-material']; + +filename = mfilename('fullpath'); +dir = fileparts( filename ); +openEMS_Path = [dir '/../../']; + +command = [openEMS_Path 'openEMS.sh ' opts]; +disp(command); +system(command) diff --git a/TESTSUITE/helperscripts/physical_constants.m b/TESTSUITE/helperscripts/physical_constants.m new file mode 100644 index 0000000..082efda --- /dev/null +++ b/TESTSUITE/helperscripts/physical_constants.m @@ -0,0 +1,8 @@ +% +% physical constants +% + +% Bronstein 3rd ed., 1997, pp. 945-946 +c0 = 299792458; % m/s +MUE0 = 4e-7*pi; % N/A^2 +EPS0 = 1/(MUE0*c0^2); % F/m