Skip to content

Commit

Permalink
add type hints to Medium class
Browse files Browse the repository at this point in the history
  • Loading branch information
oskooi committed Jun 20, 2023
1 parent 96691e1 commit 1d959bb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
98 changes: 52 additions & 46 deletions python/geom.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from typing import Union, Tuple
"""
A collection of geometry-related objects and helper routines.
"""

from __future__ import annotations

from collections import namedtuple
from copy import deepcopy
import functools
import math
import numbers
from numbers import Number
import operator
from typing import List, NamedTuple, Optional, Type, Tuple, Union
import warnings
from collections import namedtuple
from copy import deepcopy
from numbers import Number

import numpy as np
import meep as mp

Expand Down Expand Up @@ -311,78 +317,78 @@ class Medium:

def __init__(
self,
epsilon_diag=Vector3(1, 1, 1),
epsilon_offdiag=Vector3(),
mu_diag=Vector3(1, 1, 1),
mu_offdiag=Vector3(),
E_susceptibilities=None,
H_susceptibilities=None,
E_chi2_diag=Vector3(),
E_chi3_diag=Vector3(),
H_chi2_diag=Vector3(),
H_chi3_diag=Vector3(),
D_conductivity_diag=Vector3(),
D_conductivity_offdiag=Vector3(),
B_conductivity_diag=Vector3(),
B_conductivity_offdiag=Vector3(),
epsilon=None,
index=None,
mu=None,
chi2=None,
chi3=None,
D_conductivity=None,
B_conductivity=None,
E_chi2=None,
E_chi3=None,
H_chi2=None,
H_chi3=None,
valid_freq_range=FreqRange(min=-mp.inf, max=mp.inf),
epsilon_diag: Vector3 = Vector3(1.0, 1.0, 1.0),
epsilon_offdiag: Vector3 = Vector3(),
mu_diag: Vector3 = Vector3(1.0, 1.0, 1.0),
mu_offdiag: Vector3 = Vector3(),
E_susceptibilities: Optional[List[Type[Susceptibility]]] = None,
H_susceptibilities: Optional[List[Type[Susceptibility]]] = None,
E_chi2_diag: Vector3 = Vector3(),
E_chi3_diag: Vector3 = Vector3(),
H_chi2_diag: Vector3 = Vector3(),
H_chi3_diag: Vector3 = Vector3(),
D_conductivity_diag: Vector3 = Vector3(),
D_conductivity_offdiag: Vector3 = Vector3(),
B_conductivity_diag: Vector3 = Vector3(),
B_conductivity_offdiag: Vector3 = Vector3(),
epsilon: Optional[float] = None,
index: Optional[float] = None,
mu: Optional[float] = None,
chi2: Optional[float] = None,
chi3: Optional[float] = None,
D_conductivity: Optional[float] = None,
B_conductivity: Optional[float] = None,
E_chi2: Optional[float] = None,
E_chi3: Optional[float] = None,
H_chi2: Optional[float] = None,
H_chi3: Optional[float] = None,
valid_freq_range: NamedTuple = FreqRange(min=-mp.inf, max=mp.inf),
):
"""
Creates a `Medium` object.
+ **`epsilon` [`number`]** The frequency-independent isotropic relative
+ **`epsilon` [ `number` ]** The frequency-independent isotropic relative
permittivity or dielectric constant. Default is 1. You can also use `index=n` as
a synonym for `epsilon=n*n`; note that this is not really the refractive index
if you also specify μ, since the true index is $\\sqrt{\\mu\\varepsilon}$. Using
if you also specify $\\mu$, since the true index is $\\sqrt{\\mu\\varepsilon}$. Using
`epsilon=ep` is actually a synonym for `epsilon_diag=mp.Vector3(ep, ep, ep)`.
+ **`epsilon_diag` and `epsilon_offdiag` [`Vector3`]** — These properties allow
+ **`epsilon_diag` and `epsilon_offdiag` [ `Vector3` ]** — These properties allow
you to specify ε as an arbitrary real-symmetric tensor by giving the diagonal
and offdiagonal parts. Specifying `epsilon_diag=Vector3(a, b, c)` and/or
`epsilon_offdiag=Vector3(u, v, w)` corresponds to a relative permittivity ε
`epsilon_offdiag=Vector3(u, v, w)` corresponds to a relative permittivity $\\varepsilon$
tensor \\begin{pmatrix} a & u & v \\\\ u & b & w \\\\ v & w & c \\end{pmatrix}
Default is the identity matrix ($a = b = c = 1$ and $u = v = w = 0$).
+ **`mu` [`number`]** — The frequency-independent isotropic relative permeability
μ. Default is 1. Using `mu=pm` is actually a synonym for `mu_diag=mp.Vector3(pm,
+ **`mu` [ `number` ]** — The frequency-independent isotropic relative permeability
$\\mu$. Default is 1. Using `mu=pm` is actually a synonym for `mu_diag=mp.Vector3(pm,
pm, pm)`.
+ **`mu_diag` and `mu_offdiag` [`Vector3`]** — These properties allow you to
specify μ as an arbitrary real-symmetric tensor by giving the diagonal and
offdiagonal parts exactly as for ε above. Default is the identity matrix.
+ **`mu_diag` and `mu_offdiag` [ `Vector3` ]** — These properties allow you to
specify $\\mu$ as an arbitrary real-symmetric tensor by giving the diagonal and
offdiagonal parts exactly as for $\\varepsilon$ above. Default is the identity matrix.
+ **`D_conductivity` [`number`]** — The frequency-independent electric
+ **`D_conductivity` [ `number` ]** — The frequency-independent electric
conductivity $\\sigma_D$. Default is 0. You can also specify a diagonal
anisotropic conductivity tensor by using the property `D_conductivity_diag`
which takes a `Vector3` to give the $\\sigma_D$ tensor diagonal. See also
[Conductivity](Materials.md#conductivity-and-complex).
+ **`B_conductivity` [`number`]** — The frequency-independent magnetic
+ **`B_conductivity` [ `number` ]** — The frequency-independent magnetic
conductivity $\\sigma_B$. Default is 0. You can also specify a diagonal
anisotropic conductivity tensor by using the property `B_conductivity_diag`
which takes a `Vector3` to give the $\\sigma_B$ tensor diagonal. See also
[Conductivity](Materials.md#conductivity-and-complex).
+ **`chi2` [`number`]** — The nonlinear electric
+ **`chi2` [ `number` ]** — The nonlinear electric
[Pockels](https://en.wikipedia.org/wiki/Pockels_effect) susceptibility
$\\chi^{(2)}$ (quadratic nonlinearity). Default is 0. See also [Nonlinearity](Materials.md#nonlinearity).
This is equivalent to setting `E_chi2`; alternatively, an analogous magnetic
nonlinearity can be specified using `H_chi2`. These are isotropic nonlinearities,
but *diagonal* anisotropic polarizations of the form $\\chi_i^{(2)} E_i^2$ can
be specified with `E_chi2_diag` (which defaults to `[E_chi2,E_chi2,E_chi2]`).
+ **`chi3` [`number`]** — The nonlinear electric
+ **`chi3` [ `number` ]** — The nonlinear electric
[Kerr](https://en.wikipedia.org/wiki/Kerr_effect) susceptibility $\\chi^{(3)}$
(cubic nonlinearity). Default is 0. See also [Nonlinearity](Materials.md#nonlinearity).
This is equivalent to setting `E_chi3`; alternatively, an analogous magnetic nonlinearity
Expand All @@ -391,12 +397,12 @@ def __init__(
`E_chi3_diag` (which defaults to `[E_chi3,E_chi3,E_chi3]`).
+ **`E_susceptibilities` [ list of `Susceptibility` class ]** — List of dispersive
susceptibilities (see below) added to the dielectric constant ε in order to
susceptibilities (see below) added to the dielectric constant $\\varepsilon$ in order to
model material dispersion. Defaults to none (empty list). See also [Material
Dispersion](Materials.md#material-dispersion).
+ **`H_susceptibilities` [ list of `Susceptibility` class ]** — List of dispersive
susceptibilities (see below) added to the permeability μ in order to model
susceptibilities (see below) added to the permeability $\\mu$ in order to model
material dispersion. Defaults to none (empty list). See also [Material
Dispersion](Materials.md#material-dispersion).
"""
Expand Down
2 changes: 1 addition & 1 deletion python/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ def __init__(
that are specified by geometric objects. You should list any materials other
than scalar dielectrics that are returned by `material_function` here.
+ **`chunk_layout` [ `string` or `Simulation` instance or `BinaryPartition` class]** —
+ **`chunk_layout` [ `string` or `Simulation` instance or `BinaryPartition` class ]** —
This will cause the `Simulation` to use the chunk layout described by either
(1) an `.h5` file (created using `Simulation.dump_chunk_layout`), (2) another
`Simulation` instance, or (3) a [`BinaryPartition`](#binarypartition) class object.
Expand Down

0 comments on commit 1d959bb

Please sign in to comment.