Devices & Geometry

The classes defined in superscreen.device, superscreen.geometry, and superscreen.parameters are used to set up the inputs to a SuperScreen simulation, namely:

  • The geometry and penetration depth of all superconducting films

  • The spatial distribution of the applied magnetic field

Devices

Device

class superscreen.device.device.Device(name, *, layers, films, holes=None, abstract_regions=None, length_units='um', solve_dtype='float64')[source]

An object representing a device composed of multiple layers of thin film superconductor.

Parameters
property length_units: str

Length units used for the device geometry.

Return type

str

property solve_dtype: dtype

Numpy dtype to use for floating point numbers.

Return type

dtype

property layers: Dict[str, Layer]

Dict of {layer_name: layer}

Return type

Dict[str, Layer]

property films: Dict[str, Polygon]

Dict of {film_name: film_polygon}

Return type

Dict[str, Polygon]

property holes: Dict[str, Polygon]

Dict of {hole_name: hole_polygon}

Return type

Dict[str, Polygon]

property abstract_regions: Dict[str, Polygon]

Dict of {region_name: region_polygon}

Return type

Dict[str, Polygon]

property polygons: Dict[str, Polygon]

A dict of {name: polygon} for all Polygons in the device.

Return type

Dict[str, Polygon]

polygons_by_layer(polygon_type=None)[source]

Returns a dict of {layer_name: list of polygons in layer}.

Parameters

polygon_type (Optional[str]) – One of ‘film’, ‘hole’, or ‘all’, specifying which types of polygons to include.

Return type

Dict[str, List[Polygon]]

Returns

A dict of {layer_name: list of polygons in layer of the given type}.

contains_points_by_layer(points, polygon_type=None, index=False, radius=0)[source]

For each layer, determines whether points lie within a polygon in that layer.

Parameters
  • points (ndarray) – Shape (n, 2) array of x, y coordinates.

  • polygon_type (Optional[str]) – One of ‘film’, ‘hole’, or ‘all’, specifying which types of polygons to include.

  • index (bool) – If True, then return the indices of the points in points that lie within the polygon. Otherwise, returns a shape (n, ) boolean array.

  • radius (float) – An additional margin on polygon.path. See matplotlib.path.Path.contains_points().

Return type

Dict[str, ndarray]

Returns

A dict of {layer_name: contains_points}. If index is True, then contains_points is an array of indices of the points in points that lie within any polygon in the layer. Otherwise, contains_points is a shape (n, ) boolean array indicating whether each point lies within a polygon in the layer.

property poly_points: ndarray

Shape (n, 2) array of (x, y) coordinates of all Polygons in the Device.

Return type

ndarray

property vertex_distances: ndarray

An array of the mesh vertex-to-vertex distances.

Return type

ndarray

property triangle_areas: ndarray

An array of the mesh triangle areas.

Return type

ndarray

get_arrays(copy_arrays=False, dense=True)[source]

Returns a dict of the large arrays that belong to the device.

Parameters
  • copy_arrays (bool) – Whether to copy all of the arrays or just return references to the existing arrays.

  • dense (bool) – Whether to convert any sparse matrices to dense numpy arrays.

Return type

Optional[Dict[str, Union[ndarray, csr_matrix, Dict[str, ndarray]]]]

Returns

A dict of arrays, with keys specified by Device.ARRAY_NAMES, or None if the arrays don’t exist.

set_arrays(arrays)[source]

Sets the Device’s large arrays from a dict like that returned by Device.get_arrays().

Parameters

arrays (Dict[str, Union[ndarray, csr_matrix, Dict[str, ndarray]]]) – The dict containing the arrays to use.

Return type

None

copy(with_arrays=True, copy_arrays=False)[source]

Copy this Device to create a new one.

Parameters
  • with_arrays (bool) – Whether to set the large arrays on the new Device.

  • copy_arrays (bool) – Whether to create copies of the large arrays, or just return references to the existing arrays.

Return type

Device

Returns

A new Device instance, copied from self

scale(xfact=1, yfact=1, origin=(0, 0))[source]

Returns a new device with polygons scaled horizontally and/or vertically.

Negative xfact (yfact) can be used to reflect the device horizontally (vertically) about the origin.

Parameters
  • xfact (float) – Factor by which to scale the device horizontally.

  • yfact (float) – Factor by which to scale the device vertically.

  • origin (Tuple[float, float]) – (x, y) coorindates of the origin.

Return type

Device

Returns

The scaled superscreen.device.device.Device.

rotate(degrees, origin=(0, 0))[source]

Returns a new device with polygons rotated a given amount counterclockwise about specified origin.

Parameters
  • degrees (float) – The amount by which to rotate the polygons.

  • origin (Tuple[float, float]) – (x, y) coorindates of the origin.

Return type

Device

Returns

The rotated superscreen.device.device.Device.

mirror_layers(about_z=0.0)[source]

Returns a new device with its layers mirrored about the plane z = about_z.

Parameters

about_z (float) – The z-position of the plane (parallel to the x-y plane) about which to mirror the layers.

Return type

Device

Returns

The mirrored superscreen.device.device.Device.

translate(dx=0, dy=0, dz=0, inplace=False)[source]

Translates the device polygons, layers, and mesh in space by a given amount.

Parameters
  • dx (float) – Distance by which to translate along the x-axis.

  • dy (float) – Distance by which to translate along the y-axis.

  • dz (float) – Distance by which to translate layers along the z-axis.

  • inplace (bool) – If True, modifies the device (self) in-place and returns None, otherwise, creates a new device, translates it, and returns it.

Return type

Device

Returns

The translated device.

translation(dx, dy, dz=0)[source]

A context manager that temporarily translates a device in-place, then returns it to its original position.

Parameters
  • dx (float) – Distance by which to translate polygons along the x-axis.

  • dy (float) – Distance by which to translate polygons along the y-axis.

  • dz (float) – Distance by which to translate layers along the z-axis.

Return type

None

make_mesh(bounding_polygon=None, compute_matrices=True, convex_hull=True, weight_method='half_cotangent', min_points=None, optimesh_steps=None, optimesh_method='cvt-block-diagonal', optimesh_tolerance=0.001, optimesh_verbose=False, **meshpy_kwargs)[source]

Generates and optimizes the triangular mesh.

Parameters
  • compute_matrices (bool) – Whether to compute the field-independent matrices (weights, Q, Laplace operator) needed for Brandt simulations.

  • convex_hull (bool) – If True, mesh the entire convex hull of the device’s polygons.

  • weight_method (str) – Weight methods for computing the Laplace operator: one of “uniform”, “half_cotangent”, or “inv_euclidian”.

  • min_points (Optional[int]) – Minimum number of vertices in the mesh. If None, then the number of vertices will be determined by meshpy_kwargs and the number of vertices in the underlying polygons.

  • optimesh_steps (Optional[int]) – Maximum number of optimesh steps. If None, then no optimization is done.

  • optimesh_method (str) – Name of the optimization method to use.

  • optimesh_tolerance (float) – Optimesh quality tolerance.

  • optimesh_verbose (bool) – Whether to use verbose mode in optimesh.

  • **meshpy_kwargs – Passed to meshpy.triangle.build().

  • bounding_polygon (Optional[str]) –

Return type

None

compute_matrices(weight_method='half_cotangent')[source]

Calculcates mesh weights, Laplace oeprator, and kernel functions.

Parameters

weight_method (str) – Meshing scheme: either “uniform”, “half_cotangent”, or “inv_euclidian”.

Return type

None

mutual_inductance_matrix(hole_polygon_mapping=None, units='pH', all_iterations=False, **solve_kwargs)[source]

Calculates the mutual inductance matrix \(\mathbf{M}\) for the Device.

\(\mathbf{M}\) is defined such that element \(M_{ij}\) is the mutual inductance \(\Phi^f_{S_i} / I_j\) between hole \(j\) and polygon \(S_{i}\), which encloses hole \(i\). \(\Phi^f_{S_i}\) is the fluxoid for polygon \(S_i\) and \(I_j\) is the current circulating around hole \(j\).

Parameters
  • hole_polygon_mapping (Optional[Dict[str, ndarray]]) – A dict of {hole_name: polygon_coordinates} specifying a mapping between holes in the device and polygons enclosing those holes, for which the fluxoid will be calculated. The length of this dict, n_holes, will determine the dimension of the square mutual inductance matrix \(M\).

  • units (str) – The units in which to report the mutual inductance.

  • all_iterations (bool) – Whether to return mutual inductance matrices for all iterations + 1 solutions, or just the final solution.

  • solve_kwargs – Keyword arguments passed to superscreen.solve.solve(), e.g. iterations.

Return type

Union[ndarray, List[ndarray]]

Returns

If all_iterations is False, returns a shape (n_holes, n_holes) mutual inductance matrix from the final iteration. Otherwise, returns a list of mutual inductance matrices, each with shape (n_holes, n_holes). The length of the list is 1 if the device has a single layer, or iterations + 1 if the device has multiple layers.

plot(ax=None, subplots=False, legend=True, figsize=None, mesh=False, mesh_kwargs=None, **kwargs)[source]

Plot all of the device’s polygons.

Parameters
  • ax (Optional[Axes]) – matplotlib axis on which to plot. If None, a new figure is created.

  • subplots (bool) – If True, plots each layer on a different subplot.

  • legend (bool) – Whether to add a legend.

  • figsize (Optional[Tuple[float, float]]) – matplotlib figsize, only used if ax is None.

  • mesh (bool) – If True, plot the mesh.

  • mesh_kwargs (Optional[Dict[str, Any]]) – Keyword arguments passed to ax.triplot() if mesh is True.

  • kwargs – Passed to ax.plot() for the polygon boundaries.

Return type

Tuple[Figure, Axes]

Returns

Matplotlib Figure and Axes

patches()[source]

Returns a dict of {layer_name: {film_name: PathPatch}} for visualizing the device. `

Return type

Dict[str, Dict[str, PathPatch]]

draw(ax=None, subplots=False, max_cols=3, legend=False, figsize=None, alpha=0.5, exclude=None, layer_order='increasing')[source]

Draws all polygons in the device as matplotlib patches.

Parameters
  • ax (Optional[Axes]) – matplotlib axis on which to plot. If None, a new figure is created.

  • subplots (bool) – If True, plots each layer on a different subplot.

  • max_cols (int) – The maximum number of columns to create if subplots is True.

  • legend (bool) – Whether to add a legend.

  • figsize (Optional[Tuple[float, float]]) – matplotlib figsize, only used if ax is None.

  • alpha (float) – The alpha (opacity) value for the patches (0 <= alpha <= 1).

  • exclude (Union[str, List[str], None]) – A polygon name or list of polygon names to exclude from the figure.

  • layer_order (str) – If "increasing" ("decreasing") draw polygons in increasing (decreasing) order by layer height layer.z0.

Return type

Tuple[Figure, Union[Axes, ndarray]]

Returns

Matplotlib Figre and Axes.

to_file(directory, save_mesh=True, compressed=True)[source]

Serializes the Device to disk.

Parameters
  • directory (str) – The name of the directory in which to save the Device (must either be empty or not yet exist).

  • save_mesh (bool) – Whether to save the full mesh to file.

  • compressed (bool) – Whether to use numpy.savez_compressed rather than numpy.savez when saving the mesh.

Return type

None

classmethod from_file(directory, compute_matrices=False)[source]

Creates a new Device from one serialized to disk.

Parameters
  • directory (str) – The directory from which to load the device.

  • compute_matrices (bool) – Whether to compute the field-independent matrices for the device if the mesh already exists.

Return type

Device

Returns

The loaded Device instance

TransportDevice

class superscreen.device.TransportDevice(name, *, layer, film, source_terminals=None, drain_terminal=None, holes=None, abstract_regions=None, length_units='um', solve_dtype='float64')[source]

Bases: Device

An object representing a single-layer, single-film device to which a source-drain current bias can be applied.

There can be multiple source terminals, but only a single drain terminal. The drain terminal acts as a sink for currents from all source terminals.

Parameters
  • name (str) – Name of the device.

  • layer (Layer) – The Layer making up the device.

  • film (Polygon) – The Polygon representing superconducting film.

  • source_terminals (Optional[List[Polygon]]) – A list of Polygons representing source terminals for a transport current. Any mesh vertices that are on the boundary of the film and lie inside a source terminal will have current source boundary conditions.

  • drain_terminal (Optional[Polygon]) – Polygon representing the sole current drain (or output) terminal of the device.

  • holes (Union[List[Polygon], Dict[str, Polygon], None]) – Holes representing holes in superconducting films.

  • abstract_regions (Union[List[Polygon], Dict[str, Polygon], None]) – Polygons representing abstract regions in a device. Abstract regions will be meshed, and one can calculate the flux through them.

  • length_units (str) – Distance units for the coordinate system.

  • solve_dtype (Union[str, dtype]) – The float data type to use when solving the device.

property layers: Dict[str, Layer]

Dict of {layer_name: layer}

Return type

Dict[str, Layer]

property films: Dict[str, Polygon]

Dict of {film_name: film_polygon}

Return type

Dict[str, Polygon]

copy(with_arrays=True, copy_arrays=False)[source]

Copy this Device to create a new one.

Parameters
  • with_arrays (bool) – Whether to set the large arrays on the new Device.

  • copy_arrays (bool) – Whether to create copies of the large arrays, or just return references to the existing arrays.

Return type

TransportDevice

Returns

A new Device instance, copied from self

make_mesh(compute_matrices=True, weight_method='half_cotangent', min_points=None, optimesh_steps=None, optimesh_method='cvt-block-diagonal', optimesh_tolerance=0.001, optimesh_verbose=False, **meshpy_kwargs)[source]

Generates and optimizes the triangular mesh.

Parameters
  • compute_matrices (bool) – Whether to compute the field-independent matrices (weights, Q, Laplace operator) needed for Brandt simulations.

  • weight_method (str) – Weight methods for computing the Laplace operator: one of “uniform”, “half_cotangent”, or “inv_euclidian”.

  • min_points (Optional[int]) – Minimum number of vertices in the mesh. If None, then the number of vertices will be determined by meshpy_kwargs and the number of vertices in the underlying polygons.

  • optimesh_steps (Optional[int]) – Maximum number of optimesh steps. If None, then no optimization is done.

  • optimesh_method (str) – Name of the optimization method to use.

  • optimesh_tolerance (float) – Optimesh quality tolerance.

  • optimesh_verbose (bool) – Whether to use verbose mode in optimesh.

  • **meshpy_kwargs – Passed to meshpy.triangle.build().

Return type

None

boundary_vertices()[source]

An array of boundary vertex indices, ordered counterclockwise.

Return type

ndarray

Returns

An array of indices for vertices that are on the device boundary, ordered counterclockwise.

Layer

class superscreen.device.components.Layer(name, Lambda=None, london_lambda=None, thickness=None, z0=0)[source]

A single layer of a superconducting device.

You can provide either an effective penetration depth Lambda, or both a London penetration depth (lambda_london) and a layer thickness. Lambda and london_lambda can either be real numers or Parameters which compute the penetration depth as a function of position.

Parameters
  • name (str) – Name of the layer.

  • Lambda (Union[float, Parameter, None]) – The effective magnetic penetration depth of the superconducting film(s) in the layer.

  • thickness (Optional[float]) – Thickness of the superconducting film(s) located in the layer.

  • london_lambda (Union[float, Parameter, None]) – London penetration depth of the superconducting film(s) located in the layer.

  • z0 (float) – Vertical location of the layer.

property Lambda: Union[float, Parameter]

Effective penetration depth of the superconductor.

Return type

Union[float, Parameter]

Polygon

class superscreen.device.components.Polygon(name=None, *, layer=None, points, mesh=True)[source]

A polygonal region located in a Layer.

Parameters
  • name (Optional[str]) – Name of the polygon.

  • layer (Optional[str]) – Name of the layer in which the polygon is located.

  • points (Union[ndarray, LineString, LinearRing, Polygon]) – The polygon vertices. This can be a shape (n, 2) array of x, y coordinates or a shapely LineString, LinearRing, or Polygon.

  • mesh (bool) – Whether to include this polygon when computing a mesh.

property points: ndarray

A shape (n, 2) array of counter-clockwise-oriented polygon vertices.

Return type

ndarray

property is_valid: bool

True if the Polygon has a name and layer its geometry is valid.

Return type

bool

property area: float

The area of the polygon.

Return type

float

property extents: Tuple[float, float]

Returns the total x, y extent of the polygon, (Delta_x, Delta_y).

Return type

Tuple[float, float]

property polygon: Polygon

A shapely Polygon representing the Polygon.

Return type

Polygon

property path: Path

A matplotlib.path.Path representing the polygon boundary.

Return type

Path

contains_points(points, index=False, radius=0)[source]

Determines whether points lie within the polygon.

Parameters
  • points (ndarray) – Shape (n, 2) array of x, y coordinates.

  • index (bool) – If True, then return the indices of the points in points that lie within the polygon. Otherwise, returns a shape (n, ) boolean array.

  • radius (float) – An additional margin on self.path. See matplotlib.path.Path.contains_points().

Return type

Union[bool, ndarray]

Returns

If index is True, returns the indices of the points in points that lie within the polygon. Otherwise, returns a shape (n, ) boolean array indicating whether each point lies within the polygon.

on_boundary(points, radius=0.001, index=False)[source]

Determines whether points lie within a given radius of the Polygon boundary.

Parameters
  • points (ndarray) – Shape (n, 2) array of x, y coordinates.

  • radius (float) – Points within radius of the boundary are considered to lie on the boundary.

  • index (bool) – If True, then return the indices of the points in points that lie on the boundary. Otherwise, returns a shape (n, ) boolean array.

Returns

If index is True, returns the indices of the points in points that lie within the polygon. Otherwise, returns a shape (n, ) boolean array indicating whether each point lies within the polygon.

make_mesh(min_points=None, optimesh_steps=None, optimesh_method='cvt-block-diagonal', optimesh_tolerance=0.001, optimesh_verbose=False, **meshpy_kwargs)[source]

Returns the vertices and triangles of a Delaunay mesh covering the Polygon.

Parameters
  • min_points (Optional[int]) – Minimum number of vertices in the mesh. If None, then the number of vertices will be determined by meshpy_kwargs and the number of vertices in the underlying polygons.

  • optimesh_steps (Optional[int]) – Maximum number of optimesh steps. If None, then no optimization is done.

  • optimesh_method (str) – Name of the optimization method to use.

  • optimesh_tolerance (float) – Optimesh quality tolerance.

  • optimesh_verbose (bool) – Whether to use verbose mode in optimesh.

  • **meshpy_kwargs – Passed to meshpy.triangle.build().

Return type

Tuple[ndarray, ndarray]

Returns

Mesh vertex coordinates and triangle indices

rotate(degrees, origin=(0.0, 0.0), inplace=False)[source]

Rotates the polygon counterclockwise by a given angle.

Parameters
  • degrees (float) – The amount by which to rotate the polygon.

  • origin (Union[str, Tuple[float, float]]) – (x, y) coorindates about which to rotate, or the strings “center” (for the bounding box center) or “centroid” (for the polygon center of mass).

  • inplace (bool) – If True, modify the polygon in place. Otherwise, return a modified copy.

Return type

Polygon

Returns

The rotated polygon.

translate(dx=0.0, dy=0.0, inplace=False)[source]

Translates the polygon by a given distance.

Parameters
  • dx (float) – Distance by which to translate along the x-axis.

  • dy (float) – Distance by which to translate along the y-axis.

  • inplace (bool) – If True, modify the polygon in place. Otherwise, return a modified copy.

Return type

Polygon

Returns

The translated polygon.

scale(xfact=1.0, yfact=1.0, origin=(0, 0), inplace=False)[source]

Scales the polygon horizontally by xfact and vertically by yfact.

Negative xfact (yfact) can be used to reflect the polygon horizontally (vertically) about the origin.

Parameters
  • xfact (float) – Distance by which to translate along the x-axis.

  • yfact (float) – Distance by which to translate along the y-axis.

  • origin (Union[str, Tuple[float, float]]) – (x, y) coorindates for the scaling origin, or the strings “center” (for the bounding box center) or “centroid” (for the polygon center of mass).

  • inplace (bool) – If True, modify the polygon in place. Otherwise, return a modified copy.

Return type

Polygon

Returns

The scaled polygon.

union(*others, name=None)[source]

Returns the union of the polygon and zero or more other polygons.

Parameters
  • others (Union[Polygon, ndarray, LineString, LinearRing, Polygon]) – One or more objects with which to join the polygon.

  • name (Optional[str]) – A name for the resulting joined Polygon (defaults to self.name.)

Return type

Polygon

Returns

A new Polygon instance representing the union of self and others.

intersection(*others, name=None)[source]

Returns the intersection of the polygon and zero or more other polygons.

Parameters
  • others (Union[Polygon, ndarray, LineString, LinearRing, Polygon]) – One or more objects with which to join the polygon.

  • name (Optional[str]) – A name for the resulting joined Polygon (defaults to self.name.)

Return type

Polygon

Returns

A new Polygon instance representing the intersection of self and others.

difference(*others, symmetric=False, name=None)[source]

Returns the difference of the polygon and zero more other polygons.

Parameters
  • others (Union[Polygon, ndarray, LineString, LinearRing, Polygon]) – One or more objects with which to join the polygon.

  • symmetric (bool) – Whether to join via a symmetric difference operation (aka XOR). See the shapely documentation.

  • name (Optional[str]) – A name for the resulting joined Polygon (defaults to self.name.)

Return type

Polygon

Returns

A new Polygon instance representing the difference of self and others.

buffer(distance, join_style='mitre', mitre_limit=5.0, single_sided=True, as_polygon=True)[source]

Returns polygon points or a new Polygon object with vertices offset from self.points by a given distance. If distance > 0 this “inflates” the polygon, and if distance < 0 this shrinks the polygon.

Parameters
Return type

Union[ndarray, Polygon]

Returns

A new Polygon or an array of vertices offset by distance.

resample(num_points=None, degree=1, smooth=0)[source]

Resample vertices so that they are approximately uniformly distributed along the polygon boundary.

Parameters
  • num_points (Optional[int]) – Number of points to interpolate to. If num_points is None, the polygon is resampled to len(self.points) points. If num_points is not None and has a boolean value of False, then an unaltered copy of the polygon is returned.

  • degree (int) – The degree of the spline with which to iterpolate. Defaults to 1 (linear spline).

  • smooth (float) – Smoothing condition.

Return type

Polygon

plot(ax=None, **kwargs)[source]

Plots the Polygon’s vertices.

Parameters
  • ax (Optional[Axes]) – The matplotlib Axes on which to plot. If None is given, a new one is created.

  • kwargs – Passed to ax.plot().

Return type

Axes

Returns

The matplotlib Axes.

classmethod from_union(items, *, name=None, layer=None, mesh=True)[source]

Creates a new Polygon from the union of a sequence of polygons.

Parameters
  • items (Iterable[Union[Polygon, ndarray, LineString, LinearRing, Polygon]]) – A sequence of polygon-like objects to join.

  • name (Optional[str]) – Name of the polygon.

  • layer (Optional[str]) – Name of the layer in which the polygon is located.

  • mesh (bool) – Whether to include this polygon when computing a mesh.

Return type

Polygon

Returns

A new Polygon.

classmethod from_intersection(items, *, name=None, layer=None, mesh=True)[source]

Creates a new Polygon from the intersection of a sequence of polygons.

Parameters
  • items (Iterable[Union[Polygon, ndarray, LineString, LinearRing, Polygon]]) – A sequence of polygon-like objects to join.

  • name (Optional[str]) – Name of the polygon.

  • layer (Optional[str]) – Name of the layer in which the polygon is located.

  • mesh (bool) – Whether to include this polygon when computing a mesh.

Return type

Polygon

Returns

A new Polygon.

classmethod from_difference(items, *, name=None, layer=None, mesh=True, symmetric=False)[source]

Creates a new Polygon from the difference of a sequence of polygons.

Parameters
  • items (Iterable[Union[Polygon, ndarray, LineString, LinearRing, Polygon]]) – A sequence of polygon-like objects to join.

  • name (Optional[str]) – Name of the polygon.

  • layer (Optional[str]) – Name of the layer in which the polygon is located.

  • mesh (bool) – Whether to include this polygon when computing a mesh.

  • symmetric (bool) – If True, creates a new Polygon from the “symmetric difference” (aka XOR) of the inputs.

Return type

Polygon

Returns

A new Polygon.

Meshing

superscreen.device.mesh.generate_mesh(coords, min_points=None, convex_hull=False, boundary=None, **kwargs)[source]

Generates a Delaunay mesh for a given set of polygon vertex coordinates.

Additional keyword arguments are passed to triangle.build().

Parameters
  • coords (ndarray) – Shape (n, 2) array of polygon (x, y) coordinates.

  • min_points (Optional[int]) – The minimimum number of vertices in the resulting mesh.

  • convex_hull (bool) – If True, then the entire convex hull of the polygon will be meshed. Otherwise, only the polygon interior is meshed.

  • boundary (Optional[ndarray]) –

Return type

Tuple[ndarray, ndarray]

Returns

Mesh vertex coordinates and triangle indices.

superscreen.device.mesh.optimize_mesh(points, triangles, steps, method='cvt-block-diagonal', tolerance=0.001, verbose=False, **kwargs)[source]

Optimizes an existing mesh using optimesh.

See optimesh documentation for additional options.

Parameters
  • points (ndarray) – Mesh vertex coordinates.

  • triangles (ndarray) – Mesh triangle indices.

  • steps (int) – Number of optimesh steps to perform.

  • method (str) – See optimesh documentation.

  • tolerance (float) – See optimesh documentation.

  • verbose (bool) – See optimesh documentation.

Return type

Tuple[ndarray, ndarray]

Returns

Optimized mesh vertex coordinates and triangle indices.

Parameters

Parameter

class superscreen.parameter.Parameter(func, **kwargs)[source]

A callable object that computes a scalar or vector quantity as a function of position coordinates x, y (and optionally z).

Addition, subtraction, multiplication, and division between multiple Parameters and/or real numbers (ints and floats) is supported. The result of any of these operations is a CompositeParameter object.

Parameters
  • func (Callable) – A callable/function that actually calculates the parameter’s value. The function must take x, y (and optionally z) as the first and only positional arguments, and all other arguments must be keyword arguments. Therefore func should have a signature like func(x, y, z, a=1, b=2, c=True), func(x, y, *, a, b, c), func(x, y, z, *, a, b, c), or func(x, y, z, *, a, b=None, c=3).

  • kwargs – Keyword arguments for func.

CompositeParameter

class superscreen.parameter.CompositeParameter(left, right, operator_)[source]

Bases: Parameter

A callable object that behaves like a Parameter (i.e. it computes a scalar or vector quantity as a function of position coordinates x, y, z). A CompositeParameter object is created as a result of mathematical operations between Parameters, CompositeParameters, and/or real numbers.

Addition, subtraction, multiplication, division, and exponentiation between Parameters, CompositeParameters and real numbers (ints and floats) are supported. The result of any of these operations is a new CompositeParameter object.

Parameters

Constant

class superscreen.parameter.Constant(value, dimensions=2)[source]

Bases: Parameter

A Parameter whose value doesn’t depend on position.

Geometry

superscreen.geometry.rotate(coords, angle_degrees)[source]

Rotates an array of (x, y) coordinates counterclockwise by the specified angle.

Parameters
  • coords (ndarray) – Shape (n, 2) array of (x, y) coordinates.

  • angle_degrees (float) – The angle by which to rotate the coordinates.

Return type

ndarray

Returns

Shape (n, 2) array of rotated coordinates (x’, y’)

superscreen.geometry.translate(coords, dx, dy)[source]

Translates the given (x, y) coordinates in the palne by (dx, dy).

Parameters
  • coords (ndarray) – Shape (n, 2) array of (x, y) coordinates.

  • dx (float) – Amount by which to translate in the x direction.

  • dy (float) – Amount by which to translate in the y direction.

Return type

ndarray

Returns

Shape (n, 2) array of translated coordinates (x’, y’)

superscreen.geometry.ellipse(a, b, points=100, center=(0, 0), angle=0)[source]

Returns the coordinates for an ellipse with major axis a and semimajor axis b, rotated by the specified angle about (0, 0), then translated to the specified center.

Parameters
  • a (float) – Major axis length

  • b (float) – Semi-major axis length

  • points (int) – Number of points in the circle

  • center (Tuple[float, float]) – Coordinates of the center of the circle

  • angle (float) – Angle (in degrees) by which to rotate counterclockwise about (0, 0) before translating to the specified center.

Returns

A shape (points, 2) array of (x, y) coordinates

superscreen.geometry.circle(radius, points=100, center=(0, 0))[source]

Returns the coordinates for a circle with a given radius, centered at the specified center.

Parameters
  • radius (float) – Radius of the circle

  • points (int) – Number of points in the circle

  • center (Tuple[float, float]) – Coordinates of the center of the circle

Return type

ndarray

Returns

A shape (points, 2) array of (x, y) coordinates

superscreen.geometry.box(width, height=None, points_per_side=25, center=(0, 0), angle=0)[source]

Returns the coordinates for a rectangle with a given width and height, centered at the specified center.

Parameters
  • width (float) – Width of the rectangle (in the x direction).

  • height (Optional[float]) – Height of the rectangle (in the y direction). If None is given, then height is set to width and the function returns a square.

  • points_per_side (int) – Number of points on each side of the box.

  • center (Tuple[float, float]) – Coordinates of the center of the rectangle.

  • angle (float) – Angle (in degrees) by which to rotate counterclockwise about (0, 0) before translating to the specified center.

Return type

ndarray

Returns

A shape (4 * points_per_side, 2) array of (x, y) coordinates