pyOptiShared.DeviceGeometry.DeviceGeometry

class pyOptiShared.DeviceGeometry.DeviceGeometry

Bases: object

This class handles the geometry of the device under simulation.

Methods

AddParameter(parameter)

Adds a parameter to the parameter container.

GetBoundingBox([zbWithBuffer])

This function returns the bounding box of the original GDSFile and optionaly you can add the buffer size.

GetLayerStack()

This methos returns the LayerStack() object.

GetMaterialMesh(points)

This method returns the material number of every point in points.

GetMaterialObj(mat_num)

Returns a Material() object corresponding to a particular material number.

GetMaterialObjects(material_mesh)

This method returns the unique material objects present in the material mesh.

GetParamLayerIndex(parameter_name)

Returns the layer in which the parameter is affecting to.

GetPermittivityMesh(material_mesh, wavelength)

This method accepts a material mesh containing material numbers from the LayerStack and evaluates the permittivity of the mesh at particular wavelengths.

PlotMaterialMesh(points, material_mesh[, ...])

This method plots the material mesh based on the current layer stack properties.

PlotPermittivityMesh(points, permittivity_mesh)

This is a static method used to view the permittivity profile of a given pair of points and permittivity mesh.

SetAutoPortSettings([direction, buffer, ...])

Sets the auto port detection settings.

SetCurrentVal(param_name, value)

This method sets the current value zdVal for a particular parameter in the parameter container.

SetSettings(layer_stack, geometry_type, gds_file)

Setup the DeviceGeometry object.

Show([filename, width, height])

Displays the geometry configuration.

pad_geometry(x_padding, y_padding[, write_gds])

It calls the GDSWizard's pad_geometry() method for padding the ports with a length specified by the x and y buffers.

Attributes

background_material

The background material in the LayerStack().

buffers

Simulation buffers, to extend the simulation region.

device_materials

It is a dictionary with the background, substrate and layer (material, cladding) Material() objects.

gds_wizard

A GDSWizard object used to automate port detection in GDSII files.

layer_stack

Layer Stack object, containing the layers and theirs specs.

layers

All the layers in the layer stack stored as a dictionary, where the key is the layer number (int) and the values are LayerInfo() objects.

material_lib

It is the material library stored in the layer stack.

substrate_material

The substrate material in the LayerStack().

static PlotPermittivityMesh(points: ndarray, permittivity_mesh: ndarray, plot_real: bool = True, plot_index: bool = False, plotter_show: bool = True, walength_index: int = 0, opacity: float = 0.01) Plotter

This is a static method used to view the permittivity profile of a given pair of points and permittivity mesh.

Parameters:
  • points (np.ndarray) – A (3,N) numpy array containing the (x,y,z) coordinates of every point.

  • permittivity_mesh (np.ndarray) – A 1D or 2D numpy array with real or complex numbers indicating the permittivity value of every point in points across wavelength. If wavelength is more than 1 the second dimension of permittivity_mesh should iterate over them.

  • plot_real (bool, optional) – If True, plots the real part of the permittivity/index. Defaults to True.

  • plot_index (bool, optional) – If True, plots the refractive index instead of permittivity.

  • plotter_show (bool, optional) – If True, shows the plot. Defaults to True.

  • walength_index (int, optional) – Indicate the index of the wavelenth (second dimension) of the permittivity_mesh to be plotted. Defaults to 0.

  • opacity (float, optional) – Sets the opacitiy of the plot. Defaults to 0.01.

Raises:

ValueError – If permittivity_mesh is neither 1D nor 2D.

Returns:

A pyvista Plotter handler.

Return type:

pv.Plotter

AddParameter(parameter: Parameter)

Adds a parameter to the parameter container.

Parameters:

zoParam (Parameter) – A Paraemter() object.

GetBoundingBox(zbWithBuffer: bool = True) tuple[tuple[float, float], tuple[float, float], tuple[float, float]]

This function returns the bounding box of the original GDSFile and optionaly you can add the buffer size. This option is set by the zbWithBuffer option.

Parameters:
  • zbWithBuffer (bool, optional) – If True add the buffer to the bounding

  • True. (box of the original GDS file. Defaults to)

Returns:

tuple[ tuple[float, float], tuple[float, float], tuple[float, float] ]: (xmin, xmax), (ymin, ymax), (zmin,zmax).

GetLayerStack() LayerStack

This methos returns the LayerStack() object.

Returns:

The LayerStack() object.

Return type:

LayerStack

GetMaterialMesh(points: ndarray) ndarray

This method returns the material number of every point in points. The material number corresponds to that specified in the LayerStack.

Substrate are all points below the minimum z_min specified in the LayerStack. Background includes all the points whose materials are the same as that specified by the “Background” item in the LayerStack. It is possible that a layer has a “Cladding” specified as well. In that case, points in that layer, that are NOT inside any polygons are automatically set to the cladding material, otherwise, they are set to Background.

Parameters:

points (np.ndarray) – A (3,N) corresponding to the (x,y,z) coordinates of N points.

Returns:

A 1D array containing the material number of every point in points.

Return type:

np.ndarray

GetMaterialObj(mat_num: int | int64) Material

Returns a Material() object corresponding to a particular material number.

Parameters:

mat_num (int | np.int64) – The mateiral number.

Returns:

The material object corresponding to the number, otherwise None.

Return type:

Material

GetMaterialObjects(material_mesh: ndarray) dict

This method returns the unique material objects present in the material mesh. The material numbers in material_mesh should match the ones in the current LayerStack material objects.Use GetMAterialMesh() first to get the appropriate material mesh mapping with respect to the layer stack material objects/numbers.

Parameters:

material_mesh (np.ndarray) – A 1D array of material numbers.

Returns:

A dictionary where keys are the material numbers and values

are their respective material objects from the current LayerStack.

Return type:

dict

GetParamLayerIndex(parameter_name: str) int

Returns the layer in which the parameter is affecting to.

Parameters:

zstrParamName (str) – Parameter name.

Returns:

Layer number.

Return type:

int

GetPermittivityMesh(material_mesh: ndarray, wavelength: float | ndarray) ndarray

This method accepts a material mesh containing material numbers from the LayerStack and evaluates the permittivity of the mesh at particular wavelengths. Use GetMAterialMesh() first to get the appropriate material mesh mapping with respect to the layer stack material objects/numbers.

Parameters:
  • material_mesh (np.ndarray) – An (N,) array with material numbers.

  • wavelength (float | np.ndarray) – A (M,) numpy array or single float specifying the wavelength in units used by the material model.

Returns:

Returns an array of size (N,) or (N,M).

Return type:

np.ndarray

PlotMaterialMesh(points: ndarray, material_mesh: ndarray, plot_subs: bool = True, plot_bg: bool = False, plotter_show: bool = True) Plotter

This method plots the material mesh based on the current layer stack properties.

Substrate are all points below the minimum z_min specified in the LayerStack. Background includes all the points whose materials are the same as that specified by the “Background” item in the LayerStack. If inner polygons are made of this materials and the plot_bg is false, they will not appear in the plot. It is possible that a layer has a “Cladding” specified as well. In that case, points in that layer, that are NOT inside any polygons are automatically set to the cladding material, otherwise, they are set to Background. Again, setting ‘plot_bg’ to False will omit those points from the plot.

Parameters:
  • points (np.ndarray) – A (3,N) array containing the (x,y,z) coordinates of each point in the mesh.

  • material_mesh (np.ndarray) – A 1D array with N elements representing the material number of every point.

  • plot_subs (bool, optional) – If True, plots the substrate. Defaults to True.

  • plot_bg (bool, optional) – If True, plots the background. Defaults to False.

  • plotter_show (bool, optional) – If True, shows the pyvista Plotter window. Defaults to True.

Returns:

_description_

Return type:

pv.Plotter

SetAutoPortSettings(direction: Literal['x', 'y', 'both'] = 'x', buffer: list[float, float] | float = [1.0, 1.0], min: list[float, float] | float = [0, 0], max: list[float, float] | float = [1000000, 100000], ports: Ports = None, edge_tol_x: float = 0.01, edge_tol_y: float = 0.01)

Sets the auto port detection settings.

Parameters:
  • direction (Literal['x', 'y', 'both']) – Which directions to detect the ports, x bounds, y bounds or both.

  • buffer (list[list[float, float], list[float, float]] | list[float, float] | float) – These are the Port Buffers, that are used to extend the port region to accomodate the mode profiles. It will not exceed the the simulation dimensions. There are three options: - A single float, and it will be used for all the dimensions (width height) of the ports in x and y bounds. - A list with two floats specifying <width and height> buffers independently for both x and y ports; or - A list with two list of two float: [[width_x,height_x],[width_y,height_y]] for x and y independently.

  • min (list[float,float] | float, optional) – A minimum port width for detecting the port in the GDS File. Defaults to [0,0]. There are two options: (microns) - A single float determines the minimum for both x and y bound port detections. - A list of two floats, specify the minimum for x and y bound ports, respectively.

  • max (list[float,float] | float, optional) – A maximum port width for detecting the port in the GDS File. Defaults to [1000000, 100000]. There are two options: (microns) - A single float determines the maximum for both x and y bound port detections. - A list of two floats, specify the maximum for x and y bound ports, respectively.

  • ports (Ports, optional) – A Ports object that overrides the other settings.

  • edge_tol_x (float, optional) – Edge tolerance for port detection in x. Defaults to 1e-2

  • edge_tol_y (float, optional) – Edge tolerance for port detection in y. Defaults to 1e-2

SetCurrentVal(param_name: str, value)

This method sets the current value zdVal for a particular parameter in the parameter container.

Parameters:
  • zstrParamName (str) – Parameter name.

  • zdVal (Any) – Parameter value.

SetSettings(layer_stack: LayerStack, geometry_type: Literal['fixed', 'parametrized', 'stl'], gds_file: str, buffers: dict[str, float | list[float]] = {'x': [0.5, 0.5], 'y': [0.5, 0.5], 'z': [0.5, 0.5]}, parameters: ParamCont | None = None, gds_funct_name: str | None = None, gds_script_file: str | None = None, stl_filename: str | None = None, stl_mesher_type: Literal['cpu', 'gpu'] = None)

Setup the DeviceGeometry object. This is the main method to be called when specifying the device under simulation.

Parameters:
  • layer_stack (LayerStack) – A LayerStack() object.

  • geometry_type (Literal["fixed", "parametrized", "stl"]) – Either “fixed” or “parameterized”. Fixed corresponds to a static GDS file. Otherwise a python script file that generates a parametrized GDS file. In this case, parameters, gds_funct_name and gds_script_file must be specified. Finaly, “stl” for providing an .stl file as the device geometry (under development).

  • gds_file (str) – The path to a static GDSII file.

  • buffers (dict[str,float|list[float]], optional) – A dictionary with the simulation buffer settings. Defaults to {“x”:[0.5,0.5],”y”:[0.5,0.5],”z”:[0.5,0.5]}. This indicates how much padding should be added around the geometry. Useful for cases where we want to prevent the geometry to touch directly the bounds of the simulation region.

  • parameters (ParamCont | None, optional) – A parameter container object. Defaults to None. This container contain all the paraperemeters available to sweep under a parametrized geometry. Check the ParamCont() class for more details.

  • gds_funct_name (str | None, optional) – The name of the function to be called under the gds_script_file that will generate the .gds file with proper parameter values. Defaults to None.

  • gds_script_file (str | None, optional) – Path to the python script file, that contains the function to generate the parametrized GDS file. Defaults to None.

  • stl_filename (str | None, optional) – STL filepath (under development). Defaults to None.

  • stl_mesher_type (Literal["cpu", "gpu"] | None, optional) – STL mesher type: ‘cpu’ or ‘gpu’ (under development). Defaults to None.

Show(filename: str = None, width=6, height=5)

Displays the geometry configuration.

Parameters:

filename (str, optional) – Enables image export to formats supported by matplotlib. For more information, visit the matplotlib documentation.

pad_geometry(x_padding: list[float, float], y_padding: list[float, float], write_gds: bool = True) tuple[Library, str | None]

It calls the GDSWizard’s pad_geometry() method for padding the ports with a length specified by the x and y buffers. It can return or not a string with the location of the new/padded gds file.

Parameters:
  • x_padding (list[float,float]) – A two element list specifying padding for ports on the left and right of the device/circuit boundaries.

  • y_padding (list[float,float]) – A two element list specifying the padding for ports at the top and bottom of the device/circuit boundaries.

  • write_gds (bool, optional) – If true writes the new GDS library. Defaults to True.

Raises:

ValueError – If length of x_padding and y_padding is not equals to two.

Returns:

File location of the new padded GDS file.

Return type:

str|None

property background_material

The background material in the LayerStack(). Background is set to any empty space above the substrate and whenever a cladding material is not specified in a particular layer.

property buffers: tuple

Simulation buffers, to extend the simulation region. For example, to avoid ports touching the simulation edged and misscalculating modes.

property device_materials

It is a dictionary with the background, substrate and layer (material, cladding) Material() objects. The keys are -2 for background, -1 for substrate and then each layer’s key is its corresponding layer number. For layer the values are lists containing two Material() objects: material and cladding. The material is used for regions containing objects, and cladding defines the properties of the empty spaces inside that layer. If cladding is not specified we use the background material as default.

property gds_wizard: GDSWizard

A GDSWizard object used to automate port detection in GDSII files.

property layer_stack

Layer Stack object, containing the layers and theirs specs.

property layers

All the layers in the layer stack stored as a dictionary, where the key is the layer number (int) and the values are LayerInfo() objects.

property material_lib

It is the material library stored in the layer stack.

property substrate_material

The substrate material in the LayerStack(). It is the material set to all empty region below the minimum zmin in the layer stack.