def __init__(self, workingDir, use_var_fdtd, hide_fdtd_cad): """ Launches FDTD CAD and stores a handle. """ self.fdtd = lumapi.MODE( hide=hide_fdtd_cad) if use_var_fdtd else lumapi.FDTD( hide=hide_fdtd_cad) self.workingDir = workingDir self.fdtd.cd(self.workingDir)
def __init__(self, layers=[], num_periods=1): super().__init__(layers, num_periods) # open file if os.path.isfile("api.lms"): os.remove("api.lms") self.mode = lm.MODE(hide=True) self.mode.save("api.lms")
def setup_file(self): self.close_after = True # open file if os.path.isfile("api.lms"): os.remove("api.lms") self.mode = lm.MODE(hide=True) self.mode.save("api.lms")
def run_mode(scripts_dict, session=None, return_session=False): """ runs a dict of scripts in a MODE session there should be a main.lsf defined """ import lumapi dirpath = scripts_dict.get("dirpath", write_scripts(scripts_dict)) s = session or lumapi.MODE() s.cd(str(dirpath)) s.eval(scripts_dict["main.lsf"]) if return_session: return s
def __init__(self, component, hideGUI=True): self.mode = lumapi.MODE(hide=hideGUI) self.component = component self.mode.switchtolayout()
def solve(self): core_width = self.width core_thickness = self.thickness clad_width = self.cladding_width clad_thickness = self.cladding_thickness length = 10.0e-6 mesh = self.mesh num_modes = self.num_modes if self.lumapi_location: sys.path.append(self.lumapi_location) import lumapi as lm with lm.MODE(hide=True) as mode: # open file if os.path.isfile("api.lms"): os.remove("api.lms") mode.save("api.lms") cladding = mode.addrect() cladding.name = "cladding" cladding.x = 0 cladding.x_span = length cladding.y = 0 cladding.y_span = clad_width cladding.z = 0 cladding.z_span = clad_thickness # cladding.index = clad_index cladding.material = "SiO2 (Glass) - Palik" # add core x=prop y=width z=thickness core = mode.addrect() core.name = "core" core.x = 0 core.x_span = length core.y = 0 core.y_span = core_width core.z = 0 core.z_span = core_thickness # core.index = core_index core.material = "Si (Silicon) - Palik" # set up FDE fde = mode.addfde() fde.y = 0 fde.y_span = clad_width / 2 fde.solver_type = "2D X normal" fde.x = 0 fde.z = 0 fde.z_span = clad_thickness / 2 fde.mesh_cells_y = mesh fde.mesh_cells_z = mesh mode.run mode.set("number of trial modes", num_modes) mode.set("wavelength", self.wl) mode.findmodes() field = [] gridx = mode.getresult("FDE::data::mode1", "y") gridx = gridx.reshape(gridx.shape[0]) gridy = mode.getresult("FDE::data::mode1", "z") gridy = gridy.reshape(gridy.shape[0]) grid = [gridx.tolist(), gridy.tolist()] neff = [] for modeNum in range(1, num_modes + 1): mode_field = [] neff.append(mode.getdata("FDE::data::mode" + str(modeNum), "neff")[0][0]) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Hy").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Hy").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Hy").shape[2], ) ) ) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Hz").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Hz").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Hz").shape[2], ) ) ) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Hx").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Hx").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Hx").shape[2], ) ) ) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Ey").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Ey").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Ey").shape[2], ) ) ) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Ez").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Ez").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Ez").shape[2], ) ) ) mode_field.append( mode.getdata("FDE::data::mode" + str(modeNum), "Ex").reshape( ( mode.getdata("FDE::data::mode" + str(modeNum), "Ex").shape[1], mode.getdata("FDE::data::mode" + str(modeNum), "Ex").shape[2], ) ) ) field.append(mode_field) field = np.array(field).tolist() if os.path.isfile("api.lms"): os.remove("api.lms") self.x = grid[0] self.y = grid[1] self.neffs = neff self.fields = field
from initbase import init_base, change_pattern, fom import lumapi import numpy as np from collections import OrderedDict import os from bidict import bidict row_num = 5 column_num = 5 mode = lumapi.MODE() init_base(mode, size=(row_num, column_num)) mode.save("fdtd_files/base" + str(row_num) + "_" + str(column_num) + ".lms") pattern_matrix = np.random.randint(0, 2, (row_num, column_num)) change_pattern(mode, pattern_matrix) mode.run() best_result = fom(mode) t1 = mode.getresult("M1", "expansion for input")["T_forward"].squeeze() print(t1) a = input()
def waveguide( session=None, wg_width=500e-9, wg_height=220e-9, slab_height=0, box_height=2e-6, clad_height=2e-6, margin_wg_height=1e-6, margin_wg_width=2e-6, material_wg="si", material_wafer="si", material_clad="sio2", material_box="sio2", wavelength=1550e-9, mesh_size=10e-9, modes=4, ): """ draws a waveguide 2D mode solver Args: session: None wg_width: 500e-9 wg_height: 220e-9 slab_height: 0 box_height: 2e-6 clad_height: 2e-6 margin_wg_height: 1e-6 margin_wg_width: 2e-6 material_wg: "si" material_wafer: "si" material_clad: "sio2" material_box: "sio2" wavelength: 1550e-9 mesh_size: 10e-9 modes: 4 """ for material in [material_wg, material_box, material_clad, material_wafer]: if material not in materials: raise ValueError(f"{material} not in {list(materials.keys())}") material_wg = materials[material_wg] material_wafer = materials[material_wafer] material_clad = materials[material_clad] material_box = materials[material_box] import lumapi s = session or lumapi.MODE(hide=False) s.newproject() s.selectall() s.deleteall() xmin = -2e-6 xmax = 2e-6 zmin = -margin_wg_height zmax = wg_height + margin_wg_height dy = 2 * margin_wg_width + wg_width s.addrect() s.set("name", "clad") s.set("material", material_clad) s.set("z min", 0) s.set("z max", clad_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("override mesh order from material database", 1) s.set("mesh order", 3) # similar to "send to back", put the cladding as a background. s.set("alpha", 0.05) s.addrect() s.set("name", "box") s.set("material", material_box) s.set("z min", -box_height) s.set("z max", 0) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("alpha", 0.05) s.addrect() s.set("name", "wafer") s.set("material", material_wafer) s.set("z min", -box_height - 2e-6) s.set("z max", -box_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("alpha", 0.1) s.addrect() s.set("name", "waveguide") s.set("material", material_wg) s.set("z min", 0) s.set("z max", wg_height) s.set("y", 0) s.set("y span", wg_width) s.set("x min", xmin) s.set("x max", xmax) if slab_height > 0: s.addrect() s.set("name", "waveguide") s.set("material", material_wg) s.set("z min", 0) s.set("z max", slab_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.addfde() s.set("solver type", "2D X normal") s.set("x", 0) s.set("z max", zmax) s.set("z min", zmin) s.set("y", 0) s.set("y span", dy) s.set("wavelength", wavelength) s.set("solver type", "2D X normal") s.set("y min bc", "PML") s.set("y max bc", "PML") # radiation loss s.set("z min bc", "metal") s.set("z max bc", "metal") s.set("define y mesh by", "maximum mesh step") s.set("dy", mesh_size) s.set("define z mesh by", "maximum mesh step") s.set("dz", mesh_size) s.set("number of trial modes", modes) s.cleardcard() return s
s.addfde() s.set("solver type", "2D X normal") s.set("x", 0) s.set("z max", zmax) s.set("z min", zmin) s.set("y", 0) s.set("y span", dy) s.set("wavelength", wavelength) s.set("solver type", "2D X normal") s.set("y min bc", "PML") s.set("y max bc", "PML") # radiation loss s.set("z min bc", "metal") s.set("z max bc", "metal") s.set("define y mesh by", "maximum mesh step") s.set("dy", mesh_size) s.set("define z mesh by", "maximum mesh step") s.set("dz", mesh_size) s.set("number of trial modes", modes) s.cleardcard() return s if __name__ == "__main__": import lumapi s = lumapi.MODE() s = waveguide(session=s)
def lumerical_eme(args): # open file if os.path.isfile("api.lms"): os.remove("api.lms") mode = lm.MODE(hide=True) mode.save("api.lms") t = [] for wavelength in np.linspace(args.wl_lower, args.wl_upper, args.num_wavelengths): mode.deleteall() # define parameters vlength = 1e-6 * args.length vwidth1 = 1e-6 * args.width1 vwidth2 = 1e-6 * args.width2 vthickness = 1e-6 * args.thickness vnum_modes = args.num_modes vmesh = args.mesh vwavelength = 1e-6 * wavelength vnum_periods = args.num_periods # define cladding cladding = mode.addrect() cladding.name = "cladding" cladding.x = 0 cladding.x_span = 100 * vlength cladding.y = 0 cladding.y_span = 10 * max([vwidth1, vwidth2]) cladding.z = 0 cladding.z_span = 10 * vthickness cladding.material = "SiO2 (Glass) - Palik" # define core block 1 core1 = mode.addrect() core1.name = "core1" core1.x = -0.5 * vlength core1.x_span = vlength core1.y = 0 core1.y_span = vwidth1 core1.z = 0 core1.z_span = vthickness core1.material = "Si (Silicon) - Palik" # define core block 2 core2 = mode.addrect() core2.name = "core2" core2.x = 0.5 * vlength core2.x_span = vlength core2.y = 0 core2.y_span = vwidth2 core2.z = 0 core2.z_span = vthickness core2.material = "Si (Silicon) - Palik" # setup eme mode.addeme() mode.set("wavelength", vwavelength) mode.set("mesh cells y", vmesh) mode.set("mesh cells z", vmesh) mode.set("x min", -vlength) mode.set("y", 0) mode.set("y span", 2e-6) mode.set("z", 0) mode.set("z span", 2e-6) mode.set("allow custom eigensolver settings", 1) mode.set("cells", 2) mode.set("group spans", 2 * vlength) mode.set("modes", vnum_modes) mode.set("periods", vnum_periods) # mode.set("y min bc","PML") # mode.set("y max bc","PML") # mode.set("z min bc","PML") # mode.set("z max bc","PML") # run mode.run() mode.emepropagate() # postprocess internal_s_matrix = mode.getresult("EME", "internal s matrix") transmission_coefficient = np.abs(internal_s_matrix[0, vnum_modes])**2 t.append(transmission_coefficient) mode.switchtolayout() mode.close() return t
def waveguide_fixed_index( session=None, wg_width=500e-9, wg_height=220e-9, slab_height=0, box_height=2e-6, clad_height=2e-6, margin_wg_height=1e-6, margin_wg_width=2e-6, nclad=1.44, nbox=1.44, nwg=3.47, nwafer=3.47, wavelength=1550e-9, mesh_size=10e-9, modes=4, ): """Draws a waveguide 2D mode solver with non dispersive materials. Args: session: None wg_width: 500e-9 wg_height: 220e-9 slab_height: 0 box_height: 2e-6 clad_height: 2e-6 margin_wg_height: 1e-6 margin_wg_width: 2e-6 substrate_height: 2e-6 nwg: "si" nwafer: "si" nclad: "sio2" nbox: "sio2" wavelength: 1550e-9 mesh_size: 10e-9 modes: 4 """ material = "<Object defined dielectric>" import lumapi s = session or lumapi.MODE(hide=False) s.newproject() s.selectall() s.deleteall() xmin = -2e-6 xmax = 2e-6 zmin = -margin_wg_height zmax = wg_height + margin_wg_height dy = 2 * margin_wg_width + wg_width s.addrect() s.set("name", "clad") s.set("material", material) s.set("index", nclad) s.set("z min", 0) s.set("z max", clad_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("override mesh order from material database", 1) s.set( "mesh order", 3 ) # similar to "send to back", put the cladding as a background. s.set("alpha", 0.05) s.addrect() s.set("name", "box") s.set("material", material) s.set("index", nbox) s.set("z min", -box_height) s.set("z max", 0) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("alpha", 0.05) s.addrect() s.set("name", "wafer") s.set("material", material) s.set("index", nwafer) s.set("z min", -box_height - 2e-6) s.set("z max", -box_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.set("alpha", 0.1) s.addrect() s.set("name", "waveguide") s.set("material", material) s.set("index", nwg) s.set("z min", 0) s.set("z max", wg_height) s.set("y", 0) s.set("y span", wg_width) s.set("x min", xmin) s.set("x max", xmax) if slab_height > 0: s.addrect() s.set("name", "waveguide") s.set("material", material) s.set("index", nwg) s.set("z min", 0) s.set("z max", slab_height) s.set("y", 0) s.set("y span", dy) s.set("x min", xmin) s.set("x max", xmax) s.addfde() s.set("solver type", "2D X normal") s.set("x", 0) s.set("z max", zmax) s.set("z min", zmin) s.set("y", 0) s.set("y span", dy) s.set("wavelength", wavelength) s.set("solver type", "2D X normal") s.set("y min bc", "PML") s.set("y max bc", "PML") # radiation loss s.set("z min bc", "metal") s.set("z max bc", "metal") s.set("define y mesh by", "maximum mesh step") s.set("dy", mesh_size) s.set("define z mesh by", "maximum mesh step") s.set("dz", mesh_size) s.set("number of trial modes", modes) s.cleardcard() return s