【DDSCAT——離散偶極近似仿真程序05】模型設計Matlab代碼:多核殼球 、多核殼圓柱

       簡潔明瞭,後面及部分給出的都是模型設計的Matlab代碼,這些代碼都來自於一篇文章:Chin C W S. Localized Surface Plasmon Resonance with the use of Silver and Titanium Oxide Nanostructures[J]. 2011.

 

一、設計多個核殼球形結構

       1)Matlab代碼

       Matlab代碼生成shape文件,shape.dat會被自動放在當前路徑下的一個文件夾裏。

%**************************************************************************
% 希望此代碼能幫助各位學習DDSCAT的網友更近一步
% 作者:XD_Yangf 
% 來源:CSDN 
% 原文:Chin C W S. Localized Surface Plasmon Resonance with the use of Silver and Titanium Oxide Nanostructures[J]. 2011. 
% 版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!
% Date:2019-05-15
%**************************************************************************
clear;
clc;
%**************************************************************************
Ls = 15; %sphere radius for calculations
Li = 8; %inner sphere radius
spheres = 2; %number of spheres
offX = zeros(1,spheres);
offY = zeros(1,spheres);
offZ = zeros(1,spheres);
offX = [0,0,40,0,0,0];
offY = [-20,20,0,40,80,120];
% offZ = [0,20,-20,0,20];
%% calculation parameters for output file documentation
X = Ls; %sphere radius
Y = Ls;
Z = Ls;
Xd = X*2; %diameter
Yd = Y*2;
Zd = Z*2;
Xs = Li*2;
Ys = Li*2;
Zs = Li*2;
Out = [0 0 0 0 0 0 0];
d = 1; %dipole #
di = 1; %inner dipole #
off = 1;

for off = 1:spheres
    for i = (-Z+offZ(1,off)):(Z+offZ(1,off))
        for j = (-Y+offY(1,off)):(Y+offY(1,off))
            for k = (-X+offX(1,off)):(X+offX(1,off))
                L = ((i-offZ(1,off))^2 + (j-offY(1,off))^2 + (k-offX(1,off))^2)^.5;
                if L <= Ls
                    if L <= Li
                        Out = [Out; d k j i 1 1 1];
                        d = d + 1;
                        di = di + 1;
                    else
                        Out = [Out; d k j i 2 2 2];
                        d = d + 1;
                    end
                end
            end
        end
    end
end

Out(1,:) = [];

d = d - 1;
di = di - 1;

fid = fopen('output.txt', 'w');
fprintf(fid, ' >TARCEL: concentric spheres; AX,AY,AZ= %7.4f %7.4f %7.4f BX,BY,BZ= %7.4f %7.4f %7.4f', Xd, Yd, Zd, Xs, Ys, Zs);
fprintf(fid, '\r\n %8.0f %8.0f = NAT, NIN,', d, di);
fprintf(fid, '\r\n 1.000000 0.000000 0.000000 = A_1 vector\r\n 0.000000 1.000000 0.000000 = A_2 vector');
fprintf(fid, '\r\n 1.000000 1.000000 1.000000 = lattice spacings (d_x,d_y,d_z)/d');
fprintf(fid, '\r\n -0.50000 -0.50000 -0.50000 = lattice offset x0(1-3) = (x_TF,y_TF,z_TF)/d for dipole 0 0 0');
fprintf(fid, '\r\n JA IX IY IZ ICOMP(x,y,z)\r\n');
fprintf(fid,'%7d %3d %3d %3d %1d %1d %1d\r\n', Out');
fclose(fid);
foldername = sprintf('%dSpheres%dR%dr',spheres,Ls,Li);
folderpath = strcat(foldername,'/');
filename = sprintf('%dSpheres%dR%dr.txt',spheres,Ls,Li);
mkdir(foldername);
copyfile('output.txt',filename);
copyfile('output.txt','shape.dat');
movefile(filename, folderpath);
movefile('shape.dat',folderpath); % 將shape.dat文件移動到 %dSpheres%dR%dr/ 文件夾中

% 後面的也是一些文件複製移動的操作,大家可以註釋掉,需要用的話得去掉註釋自行修改代碼,否則會報錯
% copyfile('Ag.txt',folderpath);
% copyfile('Ti.txt',folderpath);
% copyfile('ddscat.exe',folderpath);
% copyfile('ddscat2.par','ddscat.par');
% movefile('ddscat.par',folderpath);
% disp(['Sucess, file saved to: ', foldername]);

       2)ddscat.par文件

       在這裏跑一下這個雙核殼球模型在300nm入射光下的消光計算,以便跟大家對比。

' ========== Parameter file for v7.3 ===================' 
'**** Preliminaries ****'
'NOTORQ' = CMTORQ*6 (DOTORQ, NOTORQ) -- either do or skip torque calculations
'PBCGS2' = CMDSOL*6 (PBCGS2, PBCGST, GPBICG, QMRCCG, PETRKP) -- CCG method
'GPFAFT' = CMETHD*6 (GPFAFT, FFTMKL) -- FFT method
'GKDLDR' = CALPHA*6 (GKDLDR, LATTDR, FLTRCD) -- DDA method
'NOTBIN' = CBINFLAG (NOTBIN, ORIBIN, ALLBIN)
'**** Initial Memory Allocation ****'
150 150 150 = dimensioning allowance for target generation
'**** Target Geometry and Composition ****'
'FROM_FILE' = CSHAPE*9 shape directive
no SHPAR parameters needed
2         = NCOMP = number of dielectric materials
'../diel/SiO2' = file with refractive index 1
'../diel/Au_evap' = file with refractive index 2
'**** Additional Nearfield calculation? ****'
1 = NRFLD (=0 to skip nearfield calc., =1 to calculate nearfield E)
0.0 0.0 0.0 0.0 0.0 0.0 (fract. extens. of calc. vol. in -x,+x,-y,+y,-z,+z)
'**** Error Tolerance ****'
1.00e-5 = TOL = MAX ALLOWED (NORM OF |G>=AC|E>-ACA|X>)/(NORM OF AC|E>)
'**** Maximum number of iterations ****'
2000     = MXITER
'**** Integration cutoff parameter for PBC calculations ****'
1.00e-2 = GAMMA (1e-2 is normal, 3e-3 for greater accuracy)
'**** Angular resolution for calculation of <cos>, etc. ****'
0.5	= ETASCA (number of angles is proportional to [(3+x)/ETASCA]^2 )
'**** Vacuum wavelengths (micron) ****'
0.300 0.300 1 'LIN' = wavelengths (first,last,how many,how=LIN,INV,LOG)
'**** Refractive index of ambient medium'
1.0000 = NAMBIENT
'**** Effective Radii (micron) **** '
0.03 0.03 1 'LIN' = eff. radii (first, last, how many, how=LIN,INV,LOG)
'**** Define Incident Polarizations ****'
(0,0) (1.,0.) (0.,0.) = Polarization state e01 (k along x axis)
2 = IORTH  (=1 to do only pol. state e01; =2 to also do orth. pol. state)
'**** Specify which output files to write ****'
1 = IWRKSC (=0 to suppress, =1 to write ".sca" file for each target orient.
'**** Specify Target Rotations ****'
0.    0.   1  = BETAMI, BETAMX, NBETA  (beta=rotation around a1)
0.    0.   1  = THETMI, THETMX, NTHETA (theta=angle between a1 and k)
0.    0.   1  = PHIMIN, PHIMAX, NPHI (phi=rotation angle of a1 around k)
'**** Specify first IWAV, IRAD, IORI (normally 0 0 0) ****'
0   0   0    = first IWAV, first IRAD, first IORI (0 0 0 to begin fresh)
'**** Select Elements of S_ij Matrix to Print ****'
6	= NSMELTS = number of elements of S_ij to print (not more than 9)
11 12 21 22 31 41	= indices ij of elements to print
'**** Specify Scattered Directions ****'
'LFRAME' = CMDFRM (LFRAME, TFRAME for Lab Frame or Target Frame)
1 = NPLANES = number of scattering planes
0.  0. 180. 5 = phi, theta_min, theta_max (deg) for plane A
90. 0. 180. 5 = phi, theta_min, theta_max (deg) for plane B

       對於這個配置文件,我對核殼的選擇分別是SiO2和Au,Au_evap折射率文件是DDSCAT自帶的,SiO2是我在網上找的,然後自己寫到文件中的。下面是SiO2的折射率文件。

       來源網站:refractiveindex.info

SiO2,  (from refractiveindex.info)
1 2 3 0 0 = columns for wave, Re(n), Im(n), eps1, eps2
wave(um) Re(n)  Im(n)    eps1   eps2
0.9840	1.45	0.000	-40.27  2.79
0.8920	1.45	0.000	-32.04  1.93
0.8211	1.45	0.000	-25.81  1.63
0.7560	1.45	0.000   -20.61  1.27
0.7045	1.46	0.000   -16.82  1.07
0.6595	1.46	0.000   -13.65  1.04
0.6168	1.46	0.000   -10.66  1.37
0.5821	1.46	0.000    -8.11  1.66
0.5486	1.46	0.000    -5.84  2.11
0.5209	1.46	0.000    -3.95  2.58
0.4959	1.46	0.000    -2.28  3.81
0.4714	1.46	0.000    -1.70  4.84
0.4509	1.47	0.000    -1.76  5.28
0.4305	1.47	0.000    -1.69  5.65
0.4133	1.47	0.000    -1.70  5.72
0.3974	1.47	0.000    -1.65  5.74
0.3815	1.47	0.000    -1.60  5.64
0.3679	1.47	0.000    -1.40  5.61
0.3542	1.48	0.000    -1.23  5.60
0.3425	1.48	0.000    -1.31  5.54
0.3315	1.48	0.000    -1.36  5.57
0.3204	1.48	0.000    -1.23  5.85
0.3107	1.49	0.000    -1.24  5.79
0.3009	1.49	0.000    -1.23  5.78
0.2924	1.49	0.000    -1.31  5.60
0.2844	1.49	0.000    -1.33  5.49
0.2761	1.50	0.000    -1.37  5.28
0.2689	1.50	0.000    -1.35  4.98

       3)近場圖

       爲了計算快點,我就選了300 nm處的計算(這裏有個規律,就是入射光波長越長,計算時間越長),並將其在300 nm處的近場圖呈現了。

       正視近場圖。

       切面近場圖。

 

二、設計多個核殼圓柱形結構

       1)Matlab代碼

%**************************************************************************
% 希望此代碼能幫助各位學習DDSCAT的網友更近一步
% 作者:XD_Yangf 
% 來源:CSDN 
% 原文:Chin C W S. Localized Surface Plasmon Resonance with the use of Silver and Titanium Oxide Nanostructures[J]. 2011.
% 版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!
% Date:2019-05-15
%**************************************************************************
clear;
clc;
%**************************************************************************
%%All cylinders are oriented such that the incident light
%%is along the x axis and strikes the circular face of the cylinder
R = [10, 10, 10]; %outer cylinder radius
r = [5, 5, 10]; %inner cylinder radius
H = [20, 20, 10]; %outer cylinder height
h = [10, 10, 10]; %inner cylinder height
hoff = [0, 0, 0]; %inner cylinder offset along x axis (0 means centered)
cylinders = 2; %number of cylinders
offX = zeros(1,cylinders);
offY = zeros(1,cylinders);
offZ = zeros(1,cylinders);
% offX = [0,-40,40];
offY = [-12,12];
% offZ = [0,20,-20,0,20];
X = H;
Y = R;
Z = R;
Rc = R; %cylinder radius for calculations
Xi = H/2 + hoff; %inner cylinder centered at half outer height (with offset)
Xo = Xi - h/2; %inner cylinder lower bound
Xmax = Xi + h/2;
Xd = X; %diameter
Yd = Y*2;
Zd = Z*2;
ri = r; %inner cylinder radius
Xs = ri*2;
Ys = ri*2;
Zs = ri*2;
Out = [0 0 0 0 0 0 0];
d = 1; %dipole #
di = 1; %inner dipole #
off = 1;
for off = 1:cylinders
    for i = (-Z(1,off)+offZ(1,off)):(Z(1,off)+offZ(1,off))
        for j = (-Y(1,off)+offY(1,off)):(Y(1,off)+offY(1,off))
            for k = (0+offX(1,off)):(X(1,off)+offX(1,off))
                L = ((i-offZ(1,off))^2 + (j-offY(1,off))^2)^.5;
                if L <= Rc(1,off)
                    if L <= ri(1,off)
                        if k >= Xo(1,off) && k <= Xmax(1,off)
                            Out = [Out; d k j i 1 1 1];
                            d = d + 1;
                            di = di + 1;
                        else
                            Out = [Out; d k j i 2 2 2];
                            d = d + 1;
                        end
                    else
                        Out = [Out; d k j i 2 2 2];
                        d = d + 1;
                    end
                end
            end
        end
    end
end
Out(1,:) = [];
d = d - 1;
di = di - 1;
fid = fopen('output.txt', 'w');
fprintf(fid, ' >TARCEL: concentric cylinders; AX,AY,AZ= %7.4f %7.4f %7.4f BX,BY,BZ= %7.4f %7.4f %7.4f', Xd, Yd, Zd, Xs, Ys, Zs);
fprintf(fid, '\r\n %8.0f %8.0f = NAT, NIN,', d, di);
fprintf(fid, '\r\n 1.000000 0.000000 0.000000 = A_1 vector\r\n 0.000000 1.000000 0.000000 = A_2 vector')
fprintf(fid, '\r\n 1.000000 1.000000 1.000000 = lattice spacings (d_x,d_y,d_z)/d')
fprintf(fid, '\r\n -0.50000 -0.50000 -0.50000 = lattice offset x0(1-3) = (x_TF,y_TF,z_TF)/d for dipole 0 0 0')
fprintf(fid, '\r\n JA IX IY IZ ICOMP(x,y,z)\r\n');
fprintf(fid,'%7d %3d %3d %3d %1d %1d %1d\r\n', Out');
fclose(fid);
foldername = sprintf('%dCylinder%dR%dr%dHh',cylinders,R(1,1),r(1,1),H(1,1));
folderpath = strcat(foldername,'/');
filename = sprintf('%dCylinder%dR%dr%dHh.txt',cylinders,R(1,1),r(1,1),H(1,1));
mkdir(foldername);
copyfile('output.txt',filename);
copyfile('output.txt','shape.dat');
movefile(filename, folderpath);
movefile('shape.dat',folderpath); % 將shape.dat文件移動到 %dSpheres%dR%dr/ 文件夾中

% 後面的也是一些文件複製移動的操作,大家可以註釋掉,需要用的話得去掉註釋自行修改代碼,否則會報錯
% copyfile('Ag.txt',folderpath);
% copyfile('Ti.txt',folderpath);
% copyfile('ddscat.exe',folderpath);
% copyfile('ddscat2.par','ddscat.par');
% movefile('ddscat.par',folderpath);
% disp(['Sucess, file saved to: ', foldername]);

       2)ddscat.par文件

       配置同上

 

       3)近場圖

       正視近場圖。

       切面近場圖。

 

       這個圓柱有點扁,不好看出來。

       後面再改改這一部分中模型的參數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章