diff --git a/doc/docs/Materials.md b/doc/docs/Materials.md index df3c5769a..b18a40a3a 100644 --- a/doc/docs/Materials.md +++ b/doc/docs/Materials.md @@ -119,18 +119,16 @@ All of the above features that are supported for the electric permittivity ε ar Materials Library ----------------- -A materials library is available for [Python](https://github.com/stevengj/meep/tree/master/python/examples/materials_library.py) and [Scheme](https://github.com/stevengj/meep/tree/master/scheme/examples/materials-library.scm) containing [crystalline silicon](https://en.wikipedia.org/wiki/Crystalline_silicon), [amorphous silicon](https://en.wikipedia.org/wiki/Amorphous_silicon) (including hydrogenated), [silicon dioxide](https://en.wikipedia.org/wiki/Silicon_dioxide) (SiO2), [indium tin oxide](https://en.wikipedia.org/wiki/Indium_tin_oxide) (ITO), [alumina](https://en.wikipedia.org/wiki/Aluminium_oxide) (Al2O3), [gallium arsenide](https://en.wikipedia.org/wiki/Gallium_arsenide) (GaAs), [aluminum arsenide](https://en.wikipedia.org/wiki/Aluminium_arsenide) (AlAs), [aluminum nitride](https://en.wikipedia.org/wiki/Aluminium_nitride) (AlN), [borosilicate glass](https://en.wikipedia.org/wiki/Borosilicate_glass) (BK7), [fused quartz](https://en.wikipedia.org/wiki/Fused_quartz), [silicon nitride](https://en.wikipedia.org/wiki/Silicon_nitride) (Si3N4), [germanium](https://en.wikipedia.org/wiki/Germanium) (Ge), [indium phosphide](https://en.wikipedia.org/wiki/Indium_phosphide) (InP), [poly(methyl methacrylate)](https://en.wikipedia.org/wiki/Poly(methyl_methacrylate)), [polycarbonate](https://en.wikipedia.org/wiki/Polycarbonate), [polystyrene](https://en.wikipedia.org/wiki/Polystyrene), [cellulose](https://en.wikipedia.org/wiki/Cellulose), as well as 11 elemental metals: [silver](https://en.wikipedia.org/wiki/Silver) (Ag), [gold](https://en.wikipedia.org/wiki/Gold) (Au), [copper](https://en.wikipedia.org/wiki/Copper) (Cu), [aluminum](https://en.wikipedia.org/wiki/Aluminium) (Al), [berylium](https://en.wikipedia.org/wiki/Beryllium) (Be), [chromium](https://en.wikipedia.org/wiki/Chromium) (Cr), [nickel](https://en.wikipedia.org/wiki/Nickel) (Ni), [palladium](https://en.wikipedia.org/wiki/Palladium) (Pd), [platinum](https://en.wikipedia.org/wiki/Platinum) (Pt), [titanium](https://en.wikipedia.org/wiki/Titanium) (Ti), and [tungsten](https://en.wikipedia.org/wiki/Tungsten) (W). +A materials library is available for [Python](https://github.com/stevengj/meep/tree/master/python/materials_library.py) and [Scheme](https://github.com/stevengj/meep/tree/master/scheme/examples/materials-library.scm) containing [crystalline silicon](https://en.wikipedia.org/wiki/Crystalline_silicon), [amorphous silicon](https://en.wikipedia.org/wiki/Amorphous_silicon) (including hydrogenated), [silicon dioxide](https://en.wikipedia.org/wiki/Silicon_dioxide) (SiO2), [indium tin oxide](https://en.wikipedia.org/wiki/Indium_tin_oxide) (ITO), [alumina](https://en.wikipedia.org/wiki/Aluminium_oxide) (Al2O3), [gallium arsenide](https://en.wikipedia.org/wiki/Gallium_arsenide) (GaAs), [aluminum arsenide](https://en.wikipedia.org/wiki/Aluminium_arsenide) (AlAs), [aluminum nitride](https://en.wikipedia.org/wiki/Aluminium_nitride) (AlN), [borosilicate glass](https://en.wikipedia.org/wiki/Borosilicate_glass) (BK7), [fused quartz](https://en.wikipedia.org/wiki/Fused_quartz), [silicon nitride](https://en.wikipedia.org/wiki/Silicon_nitride) (Si3N4), [germanium](https://en.wikipedia.org/wiki/Germanium) (Ge), [indium phosphide](https://en.wikipedia.org/wiki/Indium_phosphide) (InP), [poly(methyl methacrylate)](https://en.wikipedia.org/wiki/Poly(methyl_methacrylate)), [polycarbonate](https://en.wikipedia.org/wiki/Polycarbonate), [polystyrene](https://en.wikipedia.org/wiki/Polystyrene), [cellulose](https://en.wikipedia.org/wiki/Cellulose), as well as 11 elemental metals: [silver](https://en.wikipedia.org/wiki/Silver) (Ag), [gold](https://en.wikipedia.org/wiki/Gold) (Au), [copper](https://en.wikipedia.org/wiki/Copper) (Cu), [aluminum](https://en.wikipedia.org/wiki/Aluminium) (Al), [berylium](https://en.wikipedia.org/wiki/Beryllium) (Be), [chromium](https://en.wikipedia.org/wiki/Chromium) (Cr), [nickel](https://en.wikipedia.org/wiki/Nickel) (Ni), [palladium](https://en.wikipedia.org/wiki/Palladium) (Pd), [platinum](https://en.wikipedia.org/wiki/Platinum) (Pt), [titanium](https://en.wikipedia.org/wiki/Titanium) (Ti), and [tungsten](https://en.wikipedia.org/wiki/Tungsten) (W). Experimental values of the complex refractive index are fit to a [Drude-Lorentz susceptibility profile](#material-dispersion) over various wavelength ranges. For example, the fit for crystalline silicon is based on [Progress in Photovoltaics, Vol. 3, pp. 189-92, 1995](https://onlinelibrary.wiley.com/doi/full/10.1002/pip.4670030303) for the wavelength range of 0.4 to 1.0 µm as described in [J. Optical Society of America A, Vol. 28, pp. 770-77, 2011](https://www.osapublishing.org/josaa/abstract.cfm?uri=josaa-28-5-770). The fit for the elemental metals is over the range of 0.2 to 12.4 μm and is described in [Applied Optics, Vol. 37, pp. 5271-83, 1998](https://www.osapublishing.org/ao/abstract.cfm?uri=ao-37-22-5271). -Fitting parameters for all materials are defined for a unit distance of 1 µm. For simulations which use a different value for the unit distance, the predefined variable `um_scale` (Python) or `um-scale` (Scheme) must be scaled by *multiplying* by whatever the unit distance is, in units of µm. For example, if the unit distance is 100 nm, this would require adding the line `um_scale = 0.1*um_scale` after the line where [`um_scale` is defined](https://github.com/stevengj/meep/blob/master/python/examples/materials_library.py#L7). This change must be made directly to the materials library file. +Fitting parameters for all materials are defined for a unit distance of 1 µm. For simulations which use a different value for the unit distance, the predefined variable `um_scale` (Python) or `um-scale` (Scheme) must be scaled by *multiplying* by whatever the unit distance is, in units of µm. For example, if the unit distance is 100 nm, this would require adding the line `um_scale = 0.1*um_scale` after the line where [`um_scale` is defined](https://github.com/stevengj/meep/blob/master/python/materials_library.py#L7). This change must be made directly to the materials library file. As an example, to import aluminum from the library into a Python script requires adding the following lines: ```python -import sys -sys.path.insert(0, '/path/to/materials_library/') -from materials_library import Al +from meep.materials_library import Al ``` Then, the material can be simply used as `geometry = [meep.Cylinder(material=Al, ...]`. diff --git a/doc/docs/Python_Tutorials/Material_Dispersion.md b/doc/docs/Python_Tutorials/Material_Dispersion.md index 0d39e094d..f98ff2db7 100644 --- a/doc/docs/Python_Tutorials/Material_Dispersion.md +++ b/doc/docs/Python_Tutorials/Material_Dispersion.md @@ -14,7 +14,7 @@ The wavelength-dependent, lossless permittivity of fused quartz, measured experi $$\varepsilon(\lambda) = 1 + \frac{0.6961663\lambda^2}{\lambda^2-0.0684043^2} + \frac{0.4079426\lambda^2}{\lambda^2-0.1162414^2} + \frac{0.8974794\lambda^2}{\lambda^2-9.896161^2}$$ -The wavelength λ is in units of microns. This equation is valid from 0.21 to 6.7 μm. The Sellmeier form for the permittivity of fused quartz can be imported into Meep as a [Lorentzian susceptibility](Materials/#material-dispersion) via a slight reorganization to convert the wavelength dependence into frequency. This is implemented in the [materials library](https://github.com/stevengj/meep/blob/master/python/examples/materials_library.py#L165-L181). +The wavelength λ is in units of microns. This equation is valid from 0.21 to 6.7 μm. The Sellmeier form for the permittivity of fused quartz can be imported into Meep as a [Lorentzian susceptibility](Materials/#material-dispersion) via a slight reorganization to convert the wavelength dependence into frequency. This is implemented in the [materials library](https://github.com/stevengj/meep/blob/master/python/materials_library.py#L165-L181). The simulation involves a 1d cell. A planewave current source with a pulsed profile spanning visible wavelengths of 0.4 to 0.8 μm is normally incident on the fused quartz from air. The reflectance is computed using the convention of two separate runs: (1) an empty cell to obtain the incident power, and (2) with the fused quartz to obtain the reflected power. The details of this type of calculation are described in [Tutorial/Basics](Basics/#transmittance-spectrum-of-a-waveguide-bend). The grid resolution, and by direct extension the time resolution via the [Courant condition](https://en.wikipedia.org/wiki/Courant%E2%80%93Friedrichs%E2%80%93Lewy_condition), must be made sufficiently fine to obtain agreement with the analytic results and to ensure [numerical stability](Materials/#numerical-stability). Coarse resolutions may lead to field instabilities. @@ -22,10 +22,7 @@ The simulation script is below and in [refl-quartz.py](https://github.com/steven ```py import meep as mp - -import sys -sys.path.insert(0, '/path/to/materials_library/') -from materials_library import * +from meep.materials_library import fused_quartz resolution = 200 # pixels/μm diff --git a/python/Makefile.am b/python/Makefile.am index 82aaafe04..16758e0c7 100644 --- a/python/Makefile.am +++ b/python/Makefile.am @@ -8,7 +8,7 @@ HPPFILES= \ $(top_srcdir)/libmeepgeom/material_data.hpp BUILT_SOURCES = meep-python.cpp mpb-python.cpp __init__.py mpb.py -EXTRA_DIST = $(BUILT_SOURCES) typemap_utils.cpp solver.py mpb_data.py examples tests +EXTRA_DIST = $(BUILT_SOURCES) typemap_utils.cpp solver.py mpb_data.py materials_library.py examples tests CLEANFILES = $(BUILT_SOURCES) meep.py @@ -81,7 +81,7 @@ TESTS_ENVIRONMENT = export PYTHONPATH=$(abs_top_builddir)/python:$$PYTHONPATH; if WITH_PYTHON pympbdir = $(pkgpythondir)/mpb - pkgpython_PYTHON = geom.py __init__.py source.py simulation.py + pkgpython_PYTHON = geom.py __init__.py source.py simulation.py materials_library.py pkgpyexec_LTLIBRARIES = _meep.la pympb_DATA = mpb.py solver.py mpb_data.py pympb_LTLIBRARIES = _mpb.la @@ -130,11 +130,12 @@ MPB_PY = $(srcdir)/mpb.py endif # MAINTAINER_MODE -PY_PKG_FILES = \ - $(INIT_PY) \ - $(srcdir)/geom.py \ - $(srcdir)/simulation.py \ - $(srcdir)/source.py \ +PY_PKG_FILES = \ + $(INIT_PY) \ + $(srcdir)/geom.py \ + $(srcdir)/simulation.py \ + $(srcdir)/source.py \ + $(srcdir)/materials_library.py \ .libs/_meep.so meep: _meep.la _mpb.la __init__.py diff --git a/python/examples/absorber-1d.py b/python/examples/absorber-1d.py index 0abe50592..f95e98296 100644 --- a/python/examples/absorber-1d.py +++ b/python/examples/absorber-1d.py @@ -1,10 +1,9 @@ from __future__ import division import argparse -import math import meep as mp +from meep.materials_library import Al -from materials_library import * def main(args): diff --git a/python/examples/refl-quartz.py b/python/examples/refl-quartz.py index bd375193f..9a799adba 100644 --- a/python/examples/refl-quartz.py +++ b/python/examples/refl-quartz.py @@ -1,10 +1,7 @@ # -*- coding: utf-8 -*- import meep as mp - -import sys -sys.path.insert(0, '/path/to/materials_library/') -from materials_library import * +from meep.materials_library import fused_quartz resolution = 200 # pixels/μm @@ -20,7 +17,7 @@ fcen = 0.5*(fmax+fmin) df = fmax-fmin nfreq = 50 - + sources = [ mp.Source(mp.GaussianSource(fcen,fwidth=df), component=mp.Ex, center=mp.Vector3(0,0,-0.5*sz+dpml)) ] sim = mp.Simulation(cell_size=cell_size, @@ -37,7 +34,7 @@ empty_flux = mp.get_fluxes(refl) empty_data = sim.get_flux_data(refl) sim.reset_meep() - + geometry = [ mp.Block(mp.Vector3(mp.inf,mp.inf,0.5*sz), center=mp.Vector3(0,0,0.25*sz), material=fused_quartz) ] sim = mp.Simulation(cell_size=cell_size, @@ -49,7 +46,7 @@ refl = sim.add_flux(fcen, df, nfreq, refl_fr) sim.load_minus_flux_data(refl, empty_data) - + sim.run(until_after_sources=mp.stop_when_fields_decayed(50, mp.Ex, mp.Vector3(), 1e-9)) refl_flux = mp.get_fluxes(refl) diff --git a/python/examples/materials_library.py b/python/materials_library.py similarity index 100% rename from python/examples/materials_library.py rename to python/materials_library.py diff --git a/python/tests/absorber_1d.py b/python/tests/absorber_1d.py index c30e22b8f..74b748f09 100644 --- a/python/tests/absorber_1d.py +++ b/python/tests/absorber_1d.py @@ -1,15 +1,9 @@ from __future__ import division -import math import unittest import meep as mp +from meep.materials_library import Al -import os -import sys -matlib_dir = os.path.join(os.path.abspath(os.path.realpath(os.path.dirname(__file__))), - '..', 'examples') -sys.path.insert(0, matlib_dir) -from materials_library import * class TestAbsorber(unittest.TestCase): @@ -57,5 +51,6 @@ def test_absorber_2d(self): self.assertAlmostEqual(-4.058476603571745e-11, p.real) + if __name__ == '__main__': unittest.main() diff --git a/python/tests/simulation.py b/python/tests/simulation.py index 8b62ddf66..a2d674206 100644 --- a/python/tests/simulation.py +++ b/python/tests/simulation.py @@ -14,10 +14,6 @@ unicode = str -examples_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'examples')) -sys.path.insert(0, examples_dir) - - class TestSimulation(unittest.TestCase): fname = 'simulation-ez-000200.00.h5' @@ -482,10 +478,10 @@ def test_epsilon_warning(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - from materials_library import Si + from meep.materials_library import Si self.assertEqual(len(w), 0) - from materials_library import Mo + from meep.materials_library import Mo geom = [mp.Sphere(radius=0.2, material=Mo)] sim = self.init_simple_simulation(geometry=geom) with warnings.catch_warnings(record=True) as w: @@ -494,7 +490,7 @@ def test_epsilon_warning(self): self.assertGreater(len(w), 0) self.assertIn("Epsilon", str(w[0].message)) - from materials_library import SiO2 + from meep.materials_library import SiO2 geom = [mp.Sphere(radius=0.2, material=SiO2)] sim = self.init_simple_simulation(geometry=geom) with warnings.catch_warnings(record=True) as w: