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

       繼續設計文獻裏面的模型

 

一、設計多個六棱柱

       1)Matlab代碼

%%All hex are oriented such that the incident light
%%is along the x axis and strikes the circular face of the hex
R = [20, 20, 20]; %Hex center to side distance
H = [10, 10, 10]; %Hex height
hex = 3; %number of cylinders (including ring)
offX = zeros(1,hex);
offY = zeros(1,hex);
offZ = zeros(1,hex);
%   offX = [0,-40,40]; %User defined offsets
    offY = [18,-18,-18]; %user defined offsets
    offZ = [0,21,-21]; %user defined offsets
%%Calculation variables for output file documantation
X = H;
Y = R*1.5;
Z = R*1.5;
Xd = X;
Yd = Y*2;
Zd = Z*2;
Out = [0 0 0 0 0 0 0];
d = 1; %dipole #
di = 1; %inner dipole #
for off = 1:hex;
    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))
                L1 = (abs(sqrt(3)/2*(j-offY(1,off))+1/2*(i-offZ(1,off))));
                L2 = (abs(sqrt(3)/2*(j-offY(1,off))-1/2*(i-offZ(1,off))));
                L3 = ((i-offZ(1,off))^2 + (j-offY(1,off))^2)^.5;
                if L1 <= R(1,off) && L2 <= R(1,off) && abs(i-offZ(1,off))<= R(1,off);
                    Out = [Out; d k j i 1 1 1];
                    d = d + 1;
                end
            end
        end
    end
end
Out(1,:) = [];
d = d - 1;
di = di - 1;
fid = fopen('output.txt', 'w');
fprintf(fid, ' >TARCEL: Hexagons; AX,AY,AZ= %7.4f %7.4f %7.4f', Xd, Yd, Zd);
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('%dHex%dR%dH',hex,R(1,1),H(1,1));
folderpath = strcat(foldername,'/');
filename = sprintf('%dHex%dR%dH.txt',hex,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文件

       先放一個會報錯的ddscat.par文件。

       

       下面是在命令行中運行的報錯結果。

       

       報錯的原因暫時還沒有找到,但是可以確定的是,其中X=3.00000D-01中的X表示的是入射光的波長。因爲我改變過波長的值,這個值也會跟着改變,繼續報錯。小範圍的波長改動依然會繼續報錯,但是大範圍的波長改動,會導致程序一直迭代下去,不會終止,且error誤差值很大。

 

       3)近場圖

       報這個錯誤最大的問題是,在ddpostprocess後處理之後,雖然產生了vtr文件,但是在vislt裏面無法讀取模型的強度值,即無法可視化。

       

 

        4)正確的ddscat.par文件

       在嘗試了很多次的改動之後,終於改出了可以正常運行不報錯、可以可視化的配置文件。結果其實很簡單,就是把介電常數的種類配置爲兩個。雖然這個純六棱柱模型是由一種物質構成的,但是我們設置有兩種配置文件沒有什麼影響,只要shape文件裏面只出現1,不出現2就行。結果,這樣一改,反而結果正確了。

       

       

       5)成功的近場圖

       

       6)模型的3D散點圖

       之後儘量給大家加上模型的一個三維散點圖,除了在電廠圖可視化的情況下認識模型,也同時在偶極子構成概念上了解模型。

       

 

二、設計多個圓柱核六棱柱殼模型

       1)Matlab代碼

       

%%All hex are oriented such that the incident light
%%is along the x axis and strikes the circular face of the hex
R = [20, 20, 20]; %Hex center to side distance
H = [20, 20, 20]; %Hex height
Ri = [10, 10, 10]; %Hex core radius
hex = 3; %number of cylinders (including ring)
offX = zeros(1,hex);
offY = zeros(1,hex);
offZ = zeros(1,hex);
% offX = [0,-40,40];
offY = [18,-18,-18];
offZ = [0,21,-21];
%% calculation parameters used for output documentation file
X = H;
Y = R*1.5;
Z = R*1.5;
Xd = X; %diameter
Yd = Y*2;
Zd = Z*2;
Xs = Ri*2;
Ys = Ri*2;
Zs = Ri*2;
Out = [0 0 0 0 0 0 0];
d = 1; %dipole #
di = 1; %inner dipole #
for off = 1:hex;
    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))
                L1 = (abs(sqrt(3)/2*(j-offY(1,off))+1/2*(i-offZ(1,off))));
                L2 = (abs(sqrt(3)/2*(j-offY(1,off))-1/2*(i-offZ(1,off))));
                L3 = ((i-offZ(1,off))^2 + (j-offY(1,off))^2)^.5;
                if L1 <= R(1,off) && L2 <= R(1,off) && abs(i-offZ(1,off))<= R(1,off);
                    if L3 <= Ri;
                        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: Hexegons with Cores; 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('%dHexCore%dR%dr%dH',hex,R(1,1),Ri(1,1),H(1,1));
folderpath = strcat(foldername,'/');
filename = sprintf('%dHexCore%dR%dr%dH.txt',hex,R(1,1),Ri(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文件

       

' ========== 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

       這裏的配置其實和上一個模型的正確配置文件的參數是一模一樣的,不過這次是沒有出現問題的。

 

       3)近場圖

       

       4)模型的3D散點圖

       

 

       繼續加油

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