path(pathdef); % clear previous path changes
addpath(genpath('~/Documents/nano-optics/smarties/'));
addpath(genpath('~/Documents/nano-optics/easyh5/'));
;
clearvars
%% example
% requested precision (OA Cext)
= 1e-10;
accuracy
% prolate Au spheroid in water
% semi-axes a=b=20nm, c=40nm
= 600:50:800; wavelength = wavelength(:);
wavelength = length(wavelength);
Nl =epsAu(wavelength);
epsilon=1.33;
medium
% constant simulation parameters
=20;
stParams.a=40;
stParams.c
% internal options
= false;
stOptions.bGetR = 0;
stOptions.Delta = 0; % NB will be estimated automatically
stOptions.NB = false;
stOptions.bGetSymmetricT = false; % verbosity stOptions.bOutput
Exporting SMARTIES T-matrices
Below is an example script to run many SMARTIES simulations and export the T-matrices in HDF5. The script is available as standalone script smarties.m.
SMARTIES provides some functions to estimate the maximum multipolar order and number of quadrature points required to reach a desired accuracy. We choose here to fix the relative accuracy to \(10^{-10}\) for the orientation-averaged extinction cross-section, which results in higher \(lmax\) values for larger and/or more elongated spheroids.
We first figure out the maximum convergence parameters required
= 1;
globalN = 1;
globalnNbTheta
for i=1:Nl
=medium*2*pi/wavelength(i);
stParams.k1=sqrt(epsilon(i)) / medium;
stParams.s% Estimated convergence params
, nNbTheta] = sphEstimateNandNT(stParams, stOptions, accuracy);
[N=N; stParams.nNbTheta=nNbTheta;
stParams.N% Increase params to test accuracy
=stParams;
stParams2=stParams2.N+5;
stParams2.N=stParams2.nNbTheta+5;
stParams2.nNbTheta
, stT] = slvForT(stParams,stOptions);
[stCoa, stT2] = slvForT(stParams2,stOptions);
[stCoa2
if(stOptions.bOutput)
fprintf('Convergence testing... lambda = %.5g\n', wavelength(i));
fprintf('<Cext> = %.10g, relative error: %.2g\n', stCoa.Cext, abs(stCoa.Cext./stCoa2.Cext-1));
fprintf('<Csca> = %.10g, relative error: %.2g\n', stCoa.Csca, abs(stCoa.Csca./stCoa2.Csca-1));
fprintf('<Cabs> = %.10g, relative error: %.2g\n', stCoa.Cabs, abs(stCoa.Cabs./stCoa2.Cabs-1));
end
if(abs(stCoa.Cext./stCoa2.Cext-1) > 1.1*accuracy)
warning('requested precision was not achieved')
end
= max(globalN, stParams.N);
globalN = max(globalnNbTheta, stParams.nNbTheta);
globalnNbTheta end
Next, we redo the calculations for all wavelengths with these fixed parameters.
% allocate 3D array for all results
= 2*(globalN*(globalN + 1) + globalN );
qmax = zeros(qmax, qmax, Nl);
tmatrix
for i=1:Nl
=medium*2*pi/wavelength(i);
stParams.k1=sqrt(epsilon(i)) / medium;
stParams.s
=globalN; stParams.nNbTheta=globalnNbTheta;
stParams.N
, stT] = slvForT(stParams,stOptions);
[stCoa
, q, qp] = exportTmatrix( stT, true, [], [] );
[T= sub2ind(size(tmatrix),q,qp,q*0+i);
ind = T(:,7) + 1i*T(:,8);
tmatrix(ind)
end
Finally, we export the data into HDF5.
= 1:qmax;
vecq = [repmat(1,1, qmax/2), repmat(2,1, qmax/2)];
vecs = vecq - (vecs - 1) * qmax/2;
vecp = floor(sqrt(vecp));
vecl = vecp - vecl.*(vecl + 1);
vecm
= ["electric","magnetic"];
polars = struct('l', int16(vecl),'m', int16(vecm), 'polarization', polars(vecs));
modes
= struct('embedding', medium^2, 'Au', epsilon);
epsilon
= struct('description', 'prolate spheroid', ...
geometry 'shape', 'spheroid','radiusxy', stParams.a, 'radiusz', stParams.c);
= struct('method','EBCM',...
computation 'software','SMARTIES',...
'version','1.1',...
'unit','nm', ...
'Lmax', globalN, ...
'Ntheta', globalnNbTheta, ...
'accuracy', accuracy);
= struct('name', 'Au prolate spheroid in water',...
comments 'description', 'Computation using SMARTIES, a numerically robust EBCM implementation for spheroids',...
'sources', 'Au from Raschke et al 10.1103/PhysRevB.86.235147',...
'keywords', 'gold, spheroid, ebcm', ...
'script', [mfilename '.m']);
, uuid] = tmatrix_hdf5('smarties_spectrum.tmat.h5', tmatrix, modes, wavelength, epsilon, geometry, computation, comments) [f
Output file: smarties_spectrum.tmat.h5