FEMFy.FEFDSolver.FEFDSolver

class FEMFy.FEFDSolver.FEFDSolver

Bases: object

Interface for running simulations in FEFD.

ATTENTION: All external TIME, SPACE, FREQUENCY and WAVELENGTH attributes should be passed in terms of global units! Check FEFDSolver()’s GetGlobalUnits() method for more details on the units. Internal to FEFDSolver() they are treated in SI units.

Methods

GetElementsEpsilons()

Gets the Epsilon value of each element in the mesh.

GetElementsLayers()

Gets the layers where each element cuts.

ParseSolver(solver)

Run()

Runs the FEFD solver based on the settings passed to SetSimSettings function.

RunDistribution(elements_layers)

RunEpsilon(epsilons)

Function that runs the FEFD on a specific epsilon distribution.

SavePlot(fig, fname[, extent])

SetBoundaries([min_x, max_x, min_y, max_y, ...])

Sets the boundary conditions (BCs) of the computational domain

SetConfigurations(config)

SetDeviceGeometry(device_geometry)

SetExcitation([profile, mode_indices, ...])

Set the mode port settings.

SetResultsPath(results_path)

Set the path where the results will be saved.

SetSimSettings(device_geometry[, ...])

This method set the higher level simulation settings.

SetSimulationParams(pol, window)

WeightAdjoint(soli)

Attributes

adjoint_elements

adjoint_info

adjoint_solution

boundaries

current_epsilon

dS_dE

elements_centroids

fields

init_eps

interp_method

mesh

method

polarization

ports_monitors

resolution

results_path

simulation_type

stability

wavelength_range

weighted_adjoint

GetElementsEpsilons() ndarray

Gets the Epsilon value of each element in the mesh.

Returns:

An array of epsilion values.

Return type:

np.ndarray

GetElementsLayers() ndarray

Gets the layers where each element cuts.

Returns:

An array of the layers under each element.

Return type:

np.ndarray

Run() FEFDResults

Runs the FEFD solver based on the settings passed to SetSimSettings function.

Returns:

The results of the simulation.

Return type:

FEFDSimResults

RunEpsilon(epsilons: ndarray)

Function that runs the FEFD on a specific epsilon distribution.

Parameters:

epsilons (np.ndarray) – An array that defines the epsilon value of each element.

Returns:

_description_

Return type:

_type_

SetBoundaries(min_x: Literal['pmc', 'pec', 'pml'] = 'pmc', max_x: Literal['pmc', 'pec', 'pml'] = 'pmc', min_y: Literal['pmc', 'pec', 'pml'] = 'pmc', max_y: Literal['pmc', 'pec', 'pml'] = 'pmc', params: PML_Params = None)

Sets the boundary conditions (BCs) of the computational domain

Parameters:
  • min_x (str, optional) – type of the BC in the minimum x direction. Defaults to “pmc”.

  • max_x (str, optional) – type of the BC in the maximum x direction. Defaults to “pmc”.

  • min_y (str, optional) – type of the BC in the minimum y direction. Defaults to “pmc”.

  • max_y (str, optional) – type of the BC in the maximum y direction. Defaults to “pmc”.

  • params (PML_Params, optional) – PML_params object that defines the PML coefficients in every direction. Defaults to None.

SetExcitation(profile: str = 'mode', mode_indices: int | list[int] = [0], reciprocity: dict[str, str] | Literal['1x1', '1x2', '2x2', '4x'] = None, wavelength: ndarray = array([1.5, 1.51, 1.52, 1.53, 1.54, 1.55, 1.56, 1.57, 1.58, 1.59, 1.6])) None

Set the mode port settings. For proper units check GetGlobalUnits().

Parameters:
  • profile (str, optional) – Defines profile of the source. Defaults to “mode”.

  • mode_indices (int | list[int], optional) – Mode indices to be used in each port. Defaults to 0. If a single integer, it will be used for all ports. If a list it must match the number of ports in the device, otherwise it will append 0 (fundamental modes to the list). If the list is larger than the number of ports, then it will remove item until it matches the number of ports.

  • reciprocity (dict[str,str]|literal['1x1','1x2','2x2','4x'], optional) – This tells the solver symmetries between ports. It is a dictionary where the keys are the S-parameters and the values their respective symmetric s_parameters. Key and Value should be strings contanin port numbers separated by an underscore (“i_j”, where i and j are port numbers) or strings can be used for predefined symmetries. 1x1 - Straight, s-bend, 90 degree bend; 1x2 - Splitter or 1x2 MMI; 2x2 - Directional coupler, ring resonator; 4x - Waveguide crossing. A symmetric dielectric waveguide with two ports can have the following reciprocity: 1) reciprocity = {“1_2”:”2_1”,”2_2”:”1_1”} or 2) reciprocity = {“2_1”:”1_2”,”1_1”:”2_2”} Case 1) excites only port 1 (because 2 never appears as j in the values.) Case 2) excites only port 2 (because 1 never appears as j in the values.)

SetResultsPath(results_path: str)

Set the path where the results will be saved.

Parameters:

results_path (str) – A file path.

SetSimSettings(device_geometry: DeviceGeometry, simulation_type: str = 'nportsparam', order: int = 1, wavelength: ndarray = None, mesh: Mesh = None, method: Literal['direct', 'iterative'] = 'direct', resolution: int = 200, results_path: Path | str | None = None, device_name: str | None = None, interpolation: str = 'FEM', stability: float = 1.0, polarization: Literal['TE', 'TM', 'TE2.5', 'TM2.5'] = 'TE', adjoint_info: AdjointInfo = None, number_iterations: int = 1) None

This method set the higher level simulation settings.

Args: device_geometry (DeviceGeometry): Geometry instance containing the physical structure and material properties. simulation_type (str, optional): Calculation mode for the solver (e.g., “nportsparam”). Defaults to “nportsparam”. order (int, optional): Polynomial order of the finite elements. Defaults to 1. wavelength (np.ndarray, optional): Array of wavelength points to be solved. Defaults to None. mesh (Mesh, optional): Pre-defined mesh instance. If None, a mesh may be generated automatically. Defaults to None. method (Literal[‘direct’, ‘iterative’], optional): Linear system solver type. ‘direct’ is exact; ‘iterative’ uses convergence tolerances. Defaults to ‘direct’. resolution (int, optional): Grid density for sampled and saved field data. Defaults to 200. results_path (str, optional): Directory path for saving output files. Defaults to ‘’. device_name (str, optional): Name of the device being simulated. Defaults to None. interpolation (str, optional): Method for mapping unstructured FEM data to a structured grid for visualization. Defaults to ‘nearest’. stability (float, optional): Scaling factor to stabilize iterative solvers against numerical amplification. Defaults to 1.00. polarization (Literal[‘TE’, ‘TM’, ‘TE2.5’, ‘TM2.5’], optional): Electromagnetic polarization mode. Defaults to ‘TE’. adjoint_info (AdjointInfo, optional): Parameters and objectives for adjoint-based sensitivity analysis. Defaults to None. number_iterations (int, optional): Iteration count for 2.5D simulations to minimize thickness integration error. Defaults to 1.