Lattice#

class nannos.Lattice(basis_vectors, discretization=(256, 256), truncation='circular', harmonics_array=None)[source]#

A lattice object defining the unit cell.

Parameters:
  • basis_vectors (tuple) – The lattice vectors \(((u_x,u_y),(v_x,v_y))\). For mono-periodic gratings, specify the x-periodicity with a float a.

  • discretization (int or tuple of length 2) – Spatial discretization of the lattice. If given an integer N, the discretization will be (N, N).

  • truncation (str) – The truncation method, available values are “circular” and “parallelogrammic” (the default is “circular”). This has no effect for mono-periodic gratings.

  • harmonics_array (array of shape (2, nh)) – Array of harmonics. If specified, this is used instead of harmonics generated by the lattice object and nh is deduced from it.

Layer(name='layer', thickness=0, epsilon=1, mu=1, lattice=None, tangent_field=None, tangent_field_type='opt')[source]#

Return a new Layer object.

Parameters:
  • name (str, optional) – Name of the layer. The default is “layer”.

  • thickness (float, optional) – Thickness of the layer. The default is 0.

  • epsilon (complex or array_like, optional) – Relative permittivity. The default is 1.

  • mu (complex or array_like, optional) – Relative permeability. The default is 1.

  • lattice (nannos.Lattice, optional) – The lattice object. The default is None.

  • tangent_field (array_like, optional) – The tangent field. The default is None.

  • tangent_field_type (str, optional) – Type of tangent field (‘opt’ or ‘fft’). The default is “opt”.

Returns:

The new layer object.

Return type:

nannos.Layer

circle(center, radius)[source]#

Return a boolean mask for a circle.

Parameters:
  • center (tuple of float) – The center of the circle.

  • radius (float) – The radius of the circle.

Returns:

The shape mask.

Return type:

array of bool

constant(value)[source]#

Return a new array filled with value.

Returns:

A uniform complex 2D array with shape self.discretization.

Return type:

array like

ellipse(center, radii, rotate=0)[source]#

Return a boolean mask for an ellipse.

Parameters:
  • center (tuple of float) – The center of the ellipse.

  • radii (tuple of float) – The radii of the ellipse.

  • rotate (float) – The rotation of the ellipse in degrees.

Returns:

The shape mask.

Return type:

array of bool

geometry_mask(geom)[source]#

Return a geametry boolean mask discretized on the lattice grid.

Parameters:

geom (Shapely object) – The geometry.

Returns:

The shape mask.

Return type:

array of bool

get_harmonics(nh, sort=False)[source]#

Get the harmonics with a given truncation method.

Parameters:

nh (int) – Number of harmonics.

Returns:

  • G (list of tuple of integers of length 2) – Harmonics (i1, i2).

  • nh (int) – The number of harmonics after truncation.

property grid#

Grid in lattice vectors basis.

Returns:

The grid of size equal to the attribute discretization.

Return type:

array like

property matrix#

Basis matrix.

Returns:

Matrix containing the lattice vectors (L1,L2).

Return type:

array like

ones()[source]#

Return a new array filled with ones.

Returns:

A uniform complex 2D array with shape self.discretization.

Return type:

array like

polygon(vertices)[source]#

Return a boolean mask for a polygon.

Parameters:

vertices (array like) – The vertices of the polygon.

Returns:

The shape mask.

Return type:

array of bool

property reciprocal#

Reciprocal matrix.

Returns:

Matrix containing the lattice vectors (K1,K2) in reciprocal space.

Return type:

array like

rectangle(center, widths, rotate=0)[source]#

Return a boolean mask for a rectangle.

Parameters:
  • center (tuple of float) – The center of the rectangle.

  • widths (tuple of float) – The widths of the rectangle.

Returns:

The shape mask.

Return type:

array of bool

square(center, width, rotate=0)[source]#

Return a boolean mask for a square.

Parameters:
  • center (tuple of float) – The center of the square.

  • width (float) – The width of the square.

  • rotate (float, optional) – The rotation angle in degrees. Defaults to 0.

Returns:

The shape mask.

Return type:

array of bool

stripe(center, width)[source]#

Return a boolean mask for a stripe along the x-axis.

Parameters:
  • center (float) – The center of the stripe.

  • width (float) – The width of the stripe.

Returns:

A boolean mask of the stripe.

Return type:

array of bool

transform(grid)[source]#

Transform from cartesian to lattice coordinates.

Parameters:

grid (tuple of array like) – Input grid, typically obtained by meshgrid.

Returns:

Transformed grid in lattice vectors basis.

Return type:

array like

property unit_grid#

Unit grid in cartesian coordinates.

Returns:

The unit grid of size equal to the attribute discretization.

Return type:

array like

zeros()[source]#

Return a new array filled with zeros.

Returns:

A uniform complex 2D array with shape self.discretization.

Return type:

array like

Examples#

Polarization conversion

Polarization conversion

Tangent field

Tangent field

One dimensional grating

One dimensional grating

Two photonic crystal slabs

Two photonic crystal slabs

Elliptical holes

Elliptical holes

Photonic crystal slab

Photonic crystal slab

Dielectric patch array

Dielectric patch array

Stress tensor

Stress tensor

Convergence

Convergence

Plotting layers

Plotting layers

Permittivity approximation

Permittivity approximation

Computing gradients

Computing gradients

Geometry tools

Geometry tools