emopt.misc¶
Miscellanious functions useful for simulation and optimization.
-
class
emopt.misc.DomainCoordinates(xmin, xmax, ymin, ymax, zmin, zmax, dx, dy, dz)¶ Bases:
future.types.newobject.newobjectDefine a domain coordinate.
A DomainCoordinate is a class which manages accessing data on a rectangular grid. It stores both the indexed positions and real-space coordinates of a desired line, plane, or volume.
-
x¶ The real-space x coordinates of the domain
Type: numpy.ndarray
-
y¶ The real-space y coordinates of the domain
Type: numpy.ndarray
-
z¶ The real-space z coordinates of the domain
Type: numpy.ndarray
-
k¶ The slice along the x direction
Type: numpy.ndarray
-
Nx
-
Ny
-
Nz
-
contains_index(k, j, i)¶
-
copy()¶ Copy the domain.
Returns: A new DomainCoordinates object with the exact same dimensions as this one. Return type: DomainCoordinates
-
dx
-
dy
-
dz
-
get_bounding_box()¶
-
grow(x1, x2, y1, y2, z1, z2)¶ Grow the size of DomainCoordinates in each direction by a specified number of grid cells.
Notes
If the input values are negative, the region will shrink! Use this with caution as we do not error check.
Parameters: - x1 (int) – The number of grid cells to grow in the -x direction
- x2 (int) – The number of grid cells to grow in the +x direction
- y1 (int) – The number of grid cells to grow in the -y direction
- y2 (int) – The number of grid cells to grow in the +y direction
- z1 (int) – The number of grid cells to grow in the -z direction
- z2 (int) – The number of grid cells to grow in the +z direction
-
i
-
j
-
k
-
set_region(k1, k2, j1, j2, i1, i2, dx, dy, dz)¶ Set the region contained within the DomainCoordinates.
Parameters: - k1 (int) – The minimum x index.
- k2 (int) – The maximum x index.
- j1 (int) – The minimum y index.
- j2 (int) – The maximum y index.
- i1 (int) – The minimum z index.
- i2 (int) – The maximum z index.
- dx (float) – The grid spacing along x
- dy (float) – The grid spacing along y
- dz (float) – The grid spacing along z
-
shape
-
x
-
xspan
-
y
-
yspan
-
z
-
zspan
-
-
exception
emopt.misc.EMOptWarning¶ Bases:
exceptions.RuntimeWarning
-
emopt.misc.error_message(message)¶ Print a formatted, easily-distinguishable error message.
In general, exceptions are probably preferable, but if you ever want to throw a non-disrupting error whose format is consistent with info_message and warning_message, use this!
Parameters: message (str) – The message to print.
-
emopt.misc.gaussian_fields(x, z, prop_dist, w0, theta, wavelength, n0)¶ Generate the fields of a Gaussian beam.
Notes
1. These fields are non-dimensionalized to be consistent with EMopt’s solvers. 2. A single E component and two H components is returned. These can be projected onto any desired polarization. 3. The fields are calculated in the x,z plane at the specified y position. 4. The fields are NOT normalized to unity power. 5. These fields are highly apporximate, and may not be accurate for very small
waist sizes.Parameters: - x (float or numpy.ndarray) – The x positions.
- z (float or numpy.ndarray) – The z positions.
- prop_dist (float) – The propagation distance along the beam direction
- w0 (float) – The waist size of the beam.
- theta (float) – The angle (with respect to y axis in the x-y plane) of propagation.
- wavelength (float) – The wavelength of light.
- n0 (float) – The refractive index of the propagation medium
Returns: The calculated electric and magnetic fields.
Return type: (numpy.ndarray, numpy.ndarray, numpy.ndarray)
-
emopt.misc.gaussian_mode(x, z, w0, theta, wavelength, n0)¶ Generate the fields of an approximately Gaussian mode.
This differs from gaussian_fields in that it assumes the generated field consists of only a single wave vector. This mimics the mode of an optical fiber. The electric field is assumed to point along the z direction.
Notes
1. These fields are non-dimensionalized to be consistent with EMopt’s solvers. 2. A single E component and two H components is returned. These can be projected onto any desired polarization. 3. The fields are calculated in the x,z plane. 4. The amplitude is equal to 1.0 5. Currently, the relative permeability is assumed to be 1.0
Parameters: - x (float or numpy.ndarray) – The x positions.
- z (float or numpy.ndarray) – The z positions.
- w0 (float) – The waist size of the beam.
- theta (float) – The angle (with respect to y axis in the x-y plane) of propagation.
- wavelength (float) – The wavelength of light.
- n0 (float) – The refractive index of the propagation medium
Returns: The calculated electric and magnetic fields.
Return type: (numpy.ndarray, numpy.ndarray, numpy.ndarray)
-
emopt.misc.get_dark_cmaps()¶ Generate dark-themed colormaps for eye-friendly visualization.
Returns: Two matplotlib colormaps. The first color map is for +/- image data while the second is intended for strictly positive valued images. Return type: tuple
-
emopt.misc.info_message(message)¶ Print a formatted, easily-distinguishable message.
Parameters: message (str) – The message to print.
-
emopt.misc.n_Si3N4(wavelength)¶ Load Si3N4 refractive index vs wavlength and interpolate at desired wavelength. A piecewise cubic fit is used for the interpolation.
Source: K. Luke, Y. Okawachi, M. R. E. Lamont, A. L. Gaeta, M. Lipson. Broadband mid-infrared frequency comb generation in a Si3N4 microresonator, Opt. Lett. 40, 4823-4826 (2015) via refractiveindex.info
Parameters: wavelength (float) – The wavlenegth in [um] between 0.31 um and 5.504 um Returns: Return type: Refractive index of SiO2 at desired wavelength.
-
emopt.misc.n_SiO2(wavelength)¶ Load SiO2 refractive index vs wavlength and interpolate at desired wavelength. A piecewise cubic fit is used for the interpolation.
Source: I. H. Malitson. Interspecimen comparison of the refractive index of fused silica, J. Opt. Soc. Am. 55, 1205-1208 (1965) via refractiveindex.info
Parameters: wavelength (float) – The wavlenegth in [um] between 0.21 um and 6.7 um Returns: Return type: Refractive index of SiO2 at desired wavelength.
-
emopt.misc.n_silicon(wavelength)¶ Load silicon refractive index vs wavlength and interpolate at desired wavelength. A piecewise cubic fit is used for the interpolation.
Source: H. H. Li. Refractive index of silicon and germanium and its wavelength and temperature derivatives, J. Phys. Chem. Ref. Data 9, 561-658 (1993) via refractiveindex.info
Parameters: wavelength (float) – The wavlenegth in [um] between 1.2 um and 14 um Returns: Return type: Refractive index of silicon at desired wavelength.
-
emopt.misc.run_on_master(func)¶ Prevent a decorated function from running on any node but the master node
-
emopt.misc.warning_message(message, module)¶