Model

class strapy.Model.Model

Defines the optical network to be modelled.

The Model class holds the information that defines the structure of the optical network to be modelled with strapy, along with functions for building and evaluating the model. In general only the wavelength attribute should be accessed directly by the user - all other attributes should be set through the member functions.

Attributes:
wavelength : float

The vacuum (n = 1) wavelength of illuminating light.

components : dict

Dictionary of optical components that have been added to the model.

detectors : dict

Dictionary of detectors that have been added to the model.

nodes : dict

Dictionary of nodes that have been added to the model.

symbols : list

List of sympy symbols used by the model.

equations : list

List of sympy equations used by the model.

rhsVariables : list

List of sympy symbols that are included in the right hand side vector of the matrix equation.

matrixVariables : list

List of sympy symbols that are included in the network matrix.

updated : list

List of optical components that have changed since the model was last evaluated.

useLambdify : bool

True if sympy’s lambdify functionality should be used to set right hand side vector and matrix before evaluation. If false only components that are included in the updated list are updated in the matrix equation before solving. Lambdify is currently a fallback if there is more than one sympy symbol per matrix element.

Methods

add_component(component, name, nodes) Adds component to model and updates the node list.
add_detector(name, node[, properties]) Adds detector to model and updates list of nodes.
build([verbose]) Builds network matrix from defined components.
evaluate([timing]) Solve the network matrix and log optical properties at detectors.
add_component(component, name, nodes)

Adds component to model and updates the node list.

Parameters:
component : strapy.components.component

Type of component to be added.

name : str

Unique name of component.

nodes : str or tuple of str

Node(s) to which the component is attached.

add_detector(name, node, properties=('amplitude', ))

Adds detector to model and updates list of nodes.

For details on currently implemented properties see strapy.Detector().

Parameters:
name : str

Unique name of the detector.

nodes : str

Node monitored by detector.

properties : tuple of str

Optical properties to be logged - see strapy.Detector() for current options.

build(verbose=False)

Builds network matrix from defined components.

The model must be built before evaluate() is called. Additionally, if components or detectors are added to the model between runs, the model must be rebuilt.

Parameters:
verbose : bool

If true details of the constructed optical network will be printed during the build process.

evaluate(timing=False)

Solve the network matrix and log optical properties at detectors.

build() must have been called before the model is evaluated.

Parameters:
timing : bool

If true, the times taken to set values in the right hand side vector and network matrix (set_time), solve the network equation (solve_time) and pull out the detected values (detector_time) are returned.