def setup_module(module): ################ Light parameters ##################### # Set up light objects wl_super = 500.0 wavelengths = np.array([wl_super]) light_list = [ objects.Light(wl, theta=20, phi=40, max_order_PWs=1) for wl in wavelengths ] light = light_list[0] ################ Scattering matrices (for distinct layers) ############## """ Calculate scattering matrices for each distinct layer. Calculated in the order listed below, however this does not influence final structure which is defined later """ # period must be consistent throughout simulation!!! period = 600 NW_diameter = 120 num_BM = 20 NW_array = objects.NanoStruct('2D_array', period, NW_diameter, height_nm=2330, inclusion_a=materials.Si_c, background=materials.Air, loss=True, make_mesh_now=False, mesh_file='600_120.mail') sim_NW_array = NW_array.calc_modes(light, num_BM=num_BM) superstrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.Air, loss=False) sim_superstrate = superstrate.calc_modes(light) substrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.SiO2_a, loss=False) sim_substrate = substrate.calc_modes(light) ################ Construct & solve for full solar cell structure ############## """ Now when defining full structure order is critical and solar_cell list MUST be ordered from bottom to top! """ stack = Stack((sim_substrate, sim_NW_array, sim_superstrate)) stack.calc_scat() module.stack_list = [stack] last_light_object = light_list.pop() param_layer = NW_array # Specify the layer for which the parameters should be printed on figures. params_string = plotting.gen_params_string(param_layer, last_light_object, max_num_BMs=num_BM) active_layer_nu = 1 plotting.t_r_a_write_files(stack_list, wavelengths)
def setup_module(module): ################ Light parameters ##################### # Set up light objects wavelengths = np.array([700]) light_list = [ objects.Light(wl, max_order_PWs=2, theta=0.0, phi=0.0) for wl in wavelengths ] light = light_list[0] #period must be consistent throughout simulation!!! period = 500 NW_diameter = 120 num_BMs = 40 NW_array = objects.NanoStruct('2D_array', period, NW_diameter, height_nm=2330, inclusion_a=materials.InP, background=materials.Air, loss=True, make_mesh_now=True, force_mesh=True, lc_bkg=0.07, lc2=1.5, lc3=2.0) superstrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.Air, loss=False) substrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.SiO2, loss=False) ################ Evaluate each layer individually ############## sim_superstrate = superstrate.calc_modes(light) sim_NW_array = NW_array.calc_modes(light, num_BMs=num_BMs) sim_substrate = substrate.calc_modes(light) stack = Stack((sim_substrate, sim_NW_array, sim_superstrate)) stack.calc_scat(pol='TE') module.stack_list = [stack] plotting.t_r_a_write_files(stack_list, wavelengths)
def setup_module(module): ################ Light parameters ##################### wl_1 = 1.11 * 940 wl_2 = 1.15 * 940 no_wl_1 = 1 # Set up light objects wavelengths = np.linspace(wl_1, wl_2, no_wl_1) light_list = [ objects.Light(wl, max_order_PWs=4, theta=5.0, phi=0.0) for wl in wavelengths ] light = light_list[0] #period must be consistent throughout simulation!!! period = 940 diameter = 266 NHs = objects.NanoStruct('2D_array', period, diameter, height_nm=200, inclusion_a=materials.Air, background=materials.Au, loss=True, square=True, make_mesh_now=False, mesh_file='940_266_sq.mail') superstrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.Air, loss=False) substrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.Air, loss=False) num_BM = 100 ################ Evaluate each layer individually ############## sim_NHs = NHs.calc_modes(light, num_BM=num_BM) sim_superstrate = superstrate.calc_modes(light) sim_substrate = substrate.calc_modes(light) stack = Stack((sim_substrate, sim_NHs, sim_superstrate)) stack.calc_scat(pol='TM') module.stack_list = [stack]
def simulate_stack(lyte): wl = lyte[0] kx = lyte[1] light = objects.Light(wl, max_order_PWs=2, k_parallel=[kx, 0.000000000001]) ################ Evaluate each layer individually ############## sim_NWs = NW_array.calc_modes(light) sim_strate = strate.calc_modes(light) stack = Stack((sim_strate, sim_NWs, sim_strate)) stack.calc_scat(pol='TE') ###### Find the Fabry Perot modes ###### num_BMs = sim_NWs.num_BMs I_mat = np.matrix(np.eye(num_BMs), dtype='D') height = stack.heights_nm()[0] lay_interest = 1 P = stack.layers[lay_interest].prop_fwd(height / period) R21 = stack.layers[lay_interest].R21 det = np.linalg.det(I_mat - R21 * P * R21 * P) detskew = np.exp(1j) * det return detskew
def parseconfig(config): data = json.loads(config) objectlist, lights = [], [] for conf in data["objects"]: if conf["type"] == "sphere": posx, posy, posz = conf["position"] r = conf["radius"] col = conf["color"] roughness = conf["roughness"] obj = objects.CollidableSphere(position=euclid.Point3( posx, posy, posz), radius=r, color=col, roughness=roughness) elif conf["type"] == "plane": orix, oriy, oriz = conf["origin"] normx, normy, normz = conf["normal"] roughness = conf["roughness"] obj = objects.CollidablePlane( origin=euclid.Point3(orix, oriy, oriz), normal=euclid.Vector3(normx, normy, normz), roughness=roughness) objectlist.append(obj) for conf in data["lights"]: x, y, z = conf lights.append(objects.Light(position=euclid.Point3(x, y, z))) conf = data["camera"] imgw, imgh = conf["imageDim"] scrw, scrh = conf["screenDim"] focal = conf["focallength"] camera = Camera(imageDim=(imgw, imgh), focallength=focal, screenDim=(scrw, scrh)) scene = Scene(camera=camera, objects=objectlist, lights=lights) scene.skycolor = tuple(data["skycolor"]) depth = data["depth"] return camera, depth, lights, objectlist, scene
import materials import plotting from stack import * start = time.time() # Remove results of previous simulations. plotting.clear_previous() ################ Simulation parameters ################ # Select the number of CPUs to use in simulation. num_cores = 8 ################ Light parameters ##################### wl = 700 light = objects.Light(wl, max_order_PWs=0, theta=0.0, phi=0.0) # The period must be consistent throughout a simulation! period = 660 # Define each layer of the structure. superstrate = objects.ThinFilm(period, height_nm='semi_inf', material=materials.Air, world_1d=True) substrate = objects.ThinFilm(period, height_nm='semi_inf', material=materials.Air, loss=False, world_1d=True)
import plotting from stack import * start = time.time() ################ Simulation parameters ################ # Number of CPUs to use in simulation num_cores = 5 # Remove results of previous simulations plotting.clear_previous() ################ Light parameters ##################### azi_angles = np.linspace(0,20,5) wl = 1600 light_list = [objects.Light(wl, max_order_PWs = 2, theta = p, phi = 0.0) \ for p in azi_angles] ################ Grating parameters ##################### period = 760 superstrate = objects.ThinFilm(period, height_nm = 'semi_inf', material = materials.Air, loss = False) substrate = objects.ThinFilm(period, height_nm = 'semi_inf', material = materials.Air, loss = False) grating_1 = objects.NanoStruct('1D_array', period, small_d=period/2, diameter1=int(round(0.25*period)), diameter2=int(round(0.25*period)), height_nm = 150, inclusion_a = materials.Material(3.61 + 0.0j), inclusion_b = materials.Material(3.61 + 0.0j),
import objects import materials import plotting from stack import * import testing from numpy.testing import assert_allclose as assert_ac from numpy.testing import assert_equal ################ Light parameters ##################### # Set up light objects wl_1 = 400 wl_2 = 1000 no_wl_1 = 3 wavelengths = np.linspace(wl_1, wl_2, no_wl_1) light_list = [objects.Light(wl, max_order_PWs=1) for wl in wavelengths] ################ Scattering matrices (for distinct layers) ############## """ Calculate scattering matrices for each distinct layer. Calculated in the order listed below, however this does not influence final structure which is defined later """ # period must be consistent throughout simulation!!! period = 1 superstrate = objects.ThinFilm(period=period, height_nm='semi_inf', material=materials.Material(3.5 + 0.0j), loss=False)
import materials import plotting from stack import * start = time.time() ################ Simulation parameters ################ # Number of CPUs to use in simulation num_cores = 7 # Remove results of previous simulations plotting.clear_previous() ################ Light parameters ##################### wl = 615 light_list = [objects.Light(wl, max_order_PWs=10, theta=0.0, phi=0.0)] # Period must be consistent throughout simulation!!! period = 600 superstrate = objects.ThinFilm(period, height_nm='semi_inf', world_1d=True, material=materials.Air, loss=False) substrate = objects.ThinFilm(period, height_nm='semi_inf', world_1d=True, material=materials.Air, loss=False)
start = time.time() ################ Simulation parameters ################ # Number of CPUs to use in simulation num_cores = 4 # Remove results of previous simulations plotting.clear_previous() ################ Light parameters ##################### wl_1 = 300 wl_2 = 1000 no_wl_1 = 21 # Set up light objects wavelengths = np.linspace(wl_1, wl_2, no_wl_1) light_list = [objects.Light(wl, theta = 45, phi = 45, max_order_PWs = 2) \ for wl in wavelengths] # Period must be consistent throughout simulation!!! period = 165 diam1 = 140 diam2 = 60 ellipticity = (float(diam1 - diam2)) / float(diam1) # Replicating the geometry of the paper we set up a gold layer with elliptical air # holes. To get good agreement with the published work we use the Drude model for Au. # Note that better physical results are obtained using the tabulated data for Au! Au_NHs = objects.NanoStruct('2D_array', period, diam1, inc_shape='ellipse',
import plotting from stack import * start = time.time() ################ Light parameters ##################### wl_1 = 500 wl_2 = 600 no_wl_1 = 4 # Set up light objects, starting with the wavelengths, wavelengths = np.linspace(wl_1, wl_2, no_wl_1) # and also specifying angles of incidence and refractive medium of semi-infinite # layer that the light is incident upon (default value is n_inc = 1.0). # Fields in homogeneous layers are expressed in a Fourier series of diffraction # orders,where all orders within a radius of max_order_PWs in k-space are included. light_list = [objects.Light(wl, max_order_PWs = 1, theta = 0.0, phi = 0.0, \ n_inc=1.5) for wl in wavelengths] # Our structure must have a period, even if this is artificially imposed # on a homogeneous thin film. What's more, # it is critical that the period be consistent throughout a simulation! period = 300 # Define each layer of the structure. superstrate = objects.ThinFilm(period, height_nm = 'semi_inf', material = materials.Material(1.5 + 0.0j)) substrate = objects.ThinFilm(period, height_nm = 'semi_inf', material = materials.Material(3.0 + 0.0j)) def simulate_stack(light): ################ Evaluate each layer individually ############## sim_superstrate = superstrate.calc_modes(light)
start = time.time() # Remove results of previous simulations. plotting.clear_previous() ################ Simulation parameters ################ # Select the number of CPUs to use in simulation. num_cores = 2 ################ Light parameters ##################### wl_1 = 400 wl_2 = 800 no_wl_1 = 2 wavelengths = np.linspace(wl_1, wl_2, no_wl_1) light_list = [objects.Light(wl, max_order_PWs = 5, theta = 0.0, phi = 0.0) for wl in wavelengths] # The period must be consistent throughout a simulation! period = 300 # Define each layer of the structure # We need to inform EMUstack at this point that all layers in the stack will # be at most be periodic in one dimension (i.e. there are no '2D_arrays's). superstrate = objects.ThinFilm(period, height_nm = 'semi_inf', world_1d=True, material = materials.Air) substrate = objects.ThinFilm(period, height_nm = 'semi_inf', world_1d=True, material = materials.Air) # Define 1D grating that is periodic in x and contains 2 interleaved inclusions. # Inclusion_a is in the center of the unit cell. Inclusion_b has diameter # diameter2 and can be of a different refractive index and by default the
def setup_module(module): # Remove results of previous simulations plotting.clear_previous('.log') plotting.clear_previous('.pdf') plotting.clear_previous('.txt') ################ Light parameters ##################### wavelengths = np.linspace(800, 1600, 1) light_list = [ objects.Light(wl, max_order_PWs=6, theta=0.0, phi=0.0) for wl in wavelengths ] light = light_list[0] period = 760 superstrate = objects.ThinFilm(period, height_nm='semi_inf', world_1d=True, material=materials.Air, loss=False) substrate = objects.ThinFilm(period, height_nm='semi_inf', world_1d=True, material=materials.Air, loss=False) grating_1 = objects.NanoStruct('1D_array', period, diameter1=int(round(0.25 * period)), diameter2=int(round(0.25 * period)), height_nm=150, inclusion_a=materials.Material(1.46 + 0.0j), inclusion_b=materials.Material(1.46 + 0.0j), background=materials.Material(3.61 + 0.0j), loss=True, lc_bkg=0.005) grating_2 = objects.NanoStruct('1D_array', period, int(round(0.25 * period)), height_nm=900, background=materials.Material(3.61 + 0.0j), inclusion_a=materials.Material(1.46 + 0.0j), loss=True, lc_bkg=0.005) ################ Evaluate each layer individually ############## sim_superstrate = superstrate.calc_modes(light) sim_substrate = substrate.calc_modes(light) sim_grating_1 = grating_1.calc_modes(light) sim_grating_2 = grating_2.calc_modes(light) ################ Evaluate full solar cell structure ############## """ Now when defining full structure order is critical and stack list MUST be ordered from bottom to top! """ stack = Stack( (sim_substrate, sim_grating_1, sim_grating_2, sim_superstrate)) stack.calc_scat(pol='TE') module.stack_list = [stack] plotting.t_r_a_plots(stack_list, save_txt=True)
num_cores = 15 # Remove results of previous simulations plotting.clear_previous('.txt') plotting.clear_previous('.pdf') plotting.clear_previous('.gif') plotting.clear_previous('.log') ################ Light parameters ##################### wl_1 = 300 wl_2 = 1000 no_wl_1 = 21 # Set up light objects wavelengths = np.linspace(wl_1, wl_2, no_wl_1) light_list = [ objects.Light(wl, theta=45, phi=45, max_order_PWs=2) for wl in wavelengths ] #period must be consistent throughout simulation!!! period = 165 diam1 = 140 diam2 = 60 ellipticity = (float(diam1 - diam2)) / float(diam1) Au_NHs = objects.NanoStruct('2D_array', period, diam1, ellipticity=ellipticity, height_nm=60, inclusion_a=materials.Air, background=materials.Au_drude,
num_cores = 8 # Remove results of previous simulations plotting.clear_previous() ################ Light parameters ##################### wavelengths = np.linspace(1600, 900, 1) BMs = [ 11, 27, 59, 99, 163, 227, 299, 395, 507, 635, 755, 883, 1059, 1227, 1419 ] B = 0 for PWs in np.linspace(1, 10, 10): light_list = [ objects.Light(wl, max_order_PWs=PWs, theta=28.0, phi=0.0) for wl in wavelengths ] ################ Grating parameters ##################### period = 760 superstrate = objects.ThinFilm(period, height_nm='semi_inf', material=materials.Air, loss=False) substrate = objects.ThinFilm(period, height_nm='semi_inf', material=materials.Air, loss=False)
import time import sys if __name__=="__main__": #import rpdb2; rpdb2.start_embedded_debugger('1234') # do raycaster things objectlist = [objects.CollidableSphere(position=euclid.Point3(10.,-5.,5.), radius=3., color=(255, 215, 0), roughness=0.8), objects.CollidableSphere(position=euclid.Point3(6.,0.,0.), radius=1., color=(0, 255, 0), roughness=0.99), objects.CollidableSphere(position=euclid.Point3(20.,5.,0.), radius=11., color=(188, 188, 177), roughness=0.8), objects.CollidablePlane(origin=euclid.Point3(10.,0.,-10.) ,normal=euclid.Vector3(.5, 0.,-1.), roughness=0.8)] lights = [objects.Light(position=euclid.Point3(0.,0.,0.)), objects.Light(position=euclid.Point3(10.,0.,5.)), objects.Light(position=euclid.Point3(-50.,0.,55.))] try: i,j = sys.argv[1].split(",") i,j = int(i), int(j) except: i,j = 256, 256 camera = Camera(imageDim=(i,j),focallength=3., screenDim=(16,9)) myScene = Scene(camera=camera, objects=objectlist, lights=lights) myScene.skycolor = (90, 90, 255) starttime = time.clock() myScene.render(depth=3) endtime = time.clock() print("Took %.2f seconds for rendering a %dx%d image." % (endtime - starttime, camera.imagew, camera.imageh))