pyOptiShared.DeviceGeometry.DeviceGeometry
- class pyOptiShared.DeviceGeometry.DeviceGeometry
Bases:
objectThis class handles the geometry of the device under simulation.
Methods
AddPort([port])Add ports manually to the geometry.
GetBoundingBox([with_buffer])This function returns the bounding box of the original domain size and optionaly you can add the buffer size.
GetMatVals(points)This method returns the material number of every point in points.
GetPermittivityMesh(points, wavelength[, temp])This method accepts a material mesh containing material numbers from the LayerStack and evaluates the permittivity of the mesh at particular wavelengths.
PlotGDS([filename, width, height])Displays the geometry configuration for the GDS file.
PlotGDSXSection([direction, pos])Plots the cross section of the GDS file
PlotSTL([opacity, html_file])Displays the 3D view of the stl files loaded for simulation
Prints the information of the detected ports.
SetAutoPortSettings([direction, ...])Sets the auto port detection settings.
SetFromFun(func[, layer_stack, parameters, ...])Configures a DeviceGeometry object from a function definition.
SetFromGDS(gds_file, layer_stack[, buffers, ...])Setup the DeviceGeometry object from the gds file.
SetFromSTL(stl_dict[, background_material, ...])Configures a DeviceGeometry object from STL file definitions.
UpdateScriptParams(parameters)Changes the input values to the func passed to SetFromFun method
Attributes
background_materialdomain_buffergds_wizardlayer_stackports- AddPort(port: PortInfo = None)
Add ports manually to the geometry.
- Parameters:
port (PortInfo, optional) – A PortInfo object defines all the information of the port. Defaults to None.
- GetBoundingBox(with_buffer=True)
This function returns the bounding box of the original domain size and optionaly you can add the buffer size. This option is set by the with_buffer option.
- Parameters:
with_buffer (bool, optional) – If True add the buffer to the bounding
True. (box of the original domain shape. Defaults to)
- Returns:
tuple[ tuple[float, float], tuple[float, float], tuple[float, float] ]: (xmin, xmax), (ymin, ymax), (zmin,zmax).
- GetMatVals(points: ndarray) → ndarray
This method returns the material number of every point in points. The material number corresponds to the specified material in the MaterialLibrary.
- Parameters:
points (np.ndarray) – A (N,3) 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
- GetPermittivityMesh(points: ndarray, wavelength: float | ndarray, temp: ndarray = None) → 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
- PlotGDS(filename: str = None, width=6, height=5)
Displays the geometry configuration for the GDS file.
- Parameters:
filename (str, optional) – Enables image export to formats supported by matplotlib. For more information, visit the matplotlib documentation.
- PlotGDSXSection(direction: Literal['x', 'y'] = 'x', pos: float = 0)
Plots the cross section of the GDS file
- Parameters:
direction (Literal['x','y'], optional) – The direction of the cut. Defaults to ‘x’.
pos (float, optional) – The position of the cut. Defaults to 0.
- PlotSTL(opacity: float = 1, html_file: str = '')
Displays the 3D view of the stl files loaded for simulation
- PrintPorts()
Prints the information of the detected ports.
- SetAutoPortSettings(direction: Literal['x', 'y', 'both'] = 'x', port_buffer: list[float, float] | float = [1.0, 1.0], min: list[float, float] | float = [0, 0], max: list[float, float] | float = [1000000, 100000], edge_tol_x: float = 1e-06, edge_tol_y: float = 1e-06, pad: bool = True)
Sets the auto port detection settings.
- Parameters:
direction (Literal['x', 'y', 'both']) – Which directions to detect the ports, x bounds, y bounds or both.
port_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
- SetFromFun(func: Callable[[ndarray], None], layer_stack: LayerStack = None, parameters: tuple | None = None, buffers: dict[str, float | list[float]] = {'x': [0.5, 0.5], 'y': [0.5, 0.5], 'z': [0.5, 0.5]}, domain_limits: dict[str, float | list[float]] = None)
Configures a DeviceGeometry object from a function definition.
- Parameters:
func (Callable[[np.ndarray],None], optional) – A function that retruns the gemoetry as a list of points Nx2 and the layer number. Each point is represented as tuple of (x,y). Defaults to None.
layer_stack (LayerStack, optional) – layer_stack (LayerStack): A LayerStack() object that defines the material and the thickness of each layer. Defaults to None.
parameters (tuple | None, optional) – tuple of the input arguments to the function passed to func. Should have the same length as the function inputs length. Defaults to None.
buffers (dict[str, float | list[float]], optional) – A dictionary specifying padding space to add around the geometry’s bounding box. Keys are ‘x’, ‘y’, ‘z’, and values are a list of two floats [pad_min, pad_max]. Defaults to a 0.5 buffer on all sides.
domain_limits (dict[str, float | list[float]], optional) – A dictionary to enforce absolute boundaries on the computational domain, overriding the bounds calculated from geometry and buffers. The key specifies the axis (‘x’, ‘y’, or ‘z’). The value can be a single float to set the minimum boundary or a list of two floats [min_limit, max_limit] to set both. Defaults to None.
- Raises:
ValueError – if func is not defined properly or None.
ValueError – if parameters length doesn’t match the number of input arguments of func or None.
ValueError – If buffers or domain_limits are formatted incorrectly.
ValueError – If layer_stack is None or not passed.
- SetFromGDS(gds_file: str, layer_stack: LayerStack, buffers: dict[str, float | list[float]] = {'x': [0.5, 0.5], 'y': [0.5, 0.5], 'z': [0.5, 0.5]}, domain_limits: dict[str, float | list[float]] = None)
Setup the DeviceGeometry object from the gds file.
This is the main method to be called when specifying the device under simulation.
- Parameters:
gds_file (str) – The path to a static GDSII file.
layer_stack (LayerStack) – A LayerStack() object that defines the material and the thickness of each layer.
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.
domain_limits (dict[str, float | list[float]], optional) – A dictionary to enforce absolute boundaries on the computational domain, overriding the bounds calculated from geometry and buffers. The key specifies the axis (‘x’, ‘y’, or ‘z’). The value can be a single float to set the minimum boundary or a list of two floats [min_limit, max_limit] to set both. Defaults to None.
- Returns:
None.
- Raises:
FileNotFoundError – If a path provided in gds_file does not exist.
ValueError – If layer_stack is None or not passed.
ValueError – If buffers or domain_limits are formatted incorrectly.
- SetFromSTL(stl_dict: dict[str, Material], background_material: Material = None, substrate_material: Material = None, substrate_zmax: float = 0.0, buffers: dict[str, float | list[float]] = {'x': 2, 'y': 2, 'z': 2}, domain_limits: dict[str, float | list[float]] = None)
Configures a DeviceGeometry object from STL file definitions.
This function serves as the primary constructor for the simulation’s physical layout. It processes one or more STL files to create geometric structures, embeds them within a specified background medium, and defines the overall computational domain boundaries, including optional padding.
- Parameters:
stl_dict (dict[str, Material]) – A dictionary mapping STL file paths to their corresponding Material objects.
background_material (Material, optional) – The material that fills the computational domain where no other geometry is defined. Defaults to None.
substrate_material (Material, optional) – The material for a substrate layer extending from the domain’s negative z-boundary up to substrate_zmax. Defaults to None.
substrate_zmax (float, optional) – The maximum z-coordinate for the substrate layer. Defaults to 0.0.
buffers (dict[str, float | list[float]], optional) – A dictionary specifying padding space to add around the geometry’s bounding box. Keys are ‘x’, ‘y’, ‘z’, and values are a list of two floats [pad_min, pad_max]. Defaults to a 0.5 buffer on all sides.
domain_limits (dict[str, float | list[float]], optional) – A dictionary to enforce absolute boundaries on the computational domain, overriding the bounds calculated from geometry and buffers. The key specifies the axis (‘x’, ‘y’, or ‘z’). The value can be a single float to set the minimum boundary or a list of two floats [min_limit, max_limit] to set both. Defaults to None.
- Returns:
None.
- Raises:
FileNotFoundError – If a path provided in stl_dict does not exist.
ValueError – If buffers or domain_limits are formatted incorrectly.