################################################################################### # scriptfile: usr_importnk_3d.lsf # # description: The first section of this file shows how # to create a text file with 3D n,k data. This script also works for anisotropy. # # # The second section shows how to import n,k data # from a text file into an import object. # # Copyright 2015, Lumerical Solutions, Inc. ################################################################################### clear; anisotropic = 1; ################################################################################### # Section 1 # export n,k data to a text file # generate a volume of refractive index data x = linspace(-10,10,40); y = linspace(-10,10,35); z = linspace(-10,10,20); # set resolution to 2 for 2D X = meshgrid3dx(x,y,z); Y = meshgrid3dy(x,y,z); Z = meshgrid3dz(x,y,z); if (anisotropic){ n=matrix(length(x),length(y),length(z),3); # a matrix for all 3 directions, anisotropic n(1:length(x), 1:length(y), 1:length(z),1) = 1.5 + sin(2*pi*X/6)*exp(-((X^2+Y^2+Z^2)/5^2)) + 0.1i*cos(Y); # x direction n(1:length(x), 1:length(y), 1:length(z),2) = 1.5 + 0.1i*sin(2*pi*X/6)*exp(-((X^2+Y^2+Z^2)/5^2)) + sin(Y); # y direction n(1:length(x), 1:length(y), 1:length(z),3) = 1.5 + cos(2*pi*Y/6)*exp(-((X^2+Y^2+Z^2)/10^2)) + 0.2i*sin(Y);# z direction }else{ n=matrix(length(x),length(y),length(z)); # isotropic n(1:length(x), 1:length(y), 1:length(z)) = 1.5 + sin(2*pi*X/6)*exp(-((X^2+Y^2+Z^2)/5^2)) + 0.1i*cos(Y); } # choose a filename and delete the file if it exists filename = "usr_importnk_3d.txt"; rm(filename); # write the header write(filename,num2str(length(x)) + " " + num2str(x(1)) + " " + num2str(x(length(x)))); write(filename,num2str(length(y)) + " " + num2str(y(1)) + " " + num2str(y(length(y)))); write(filename,num2str(length(z)) + " " + num2str(z(1)) + " " + num2str(z(length(z)))); # copy the data into a temporary vector if (anisotropic) { temp_mat = matrix(length(x)*length(y)*length(z),6); }else{ temp_mat = matrix(length(x)*length(y)*length(z),2); } nn = size(n); pos = 0; for(k=1:nn(3)) { for(j=1:nn(2)) { for(i=1:nn(1)) { pos = pos + 1; if (anisotropic){ temp_mat(pos,1) = real( n(i,j,k,1) ); temp_mat(pos,2) = imag( n(i,j,k,1) ); temp_mat(pos,3) = real( n(i,j,k,2) ); temp_mat(pos,4) = imag( n(i,j,k,2) ); temp_mat(pos,5) = real( n(i,j,k,3) ); temp_mat(pos,6) = imag( n(i,j,k,3) ); } else { temp_mat(pos,1) = real( n(i,j,k) ); temp_mat(pos,2) = imag( n(i,j,k) ); } } } ?"Completed " + num2str(k/nn(3)*100) + "%"; } # write the vector to file write(filename,num2str(temp_mat)); # End of section 1 ################################################################################### ################################################################################### # Section 2 # load n,k data from a text file into import object # add an import object addimport; # choose the desired options filename = "usr_importnk_3d.txt"; file_units = "microns"; x0 = 0; y0 = 0; z0 = 0; reverse_index_order = 0; # choose 1 to reverse order of indices as read from file # import the data from file importnk(filename,file_units,x0,y0,z0,reverse_index_order); # End of section 2 ###################################################################################