I am trying to code up a simulation of a light source passing through a refractive waveguide under a static electric field. I adapted the fields in a waveguide code (https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/#fields-in-a-waveguide) by adding an extra source. I am running my code through the Ubuntu terminal by activating the PyMeep environment then python
then import meep
then entering my code. I would expect to see a similar pattern as shown in the waveguide tutorial example (https://meep.readthedocs.io/en/latest/Python_Tutorials/Basics/#fields-in-a-waveguide). When running my code I get a Matplotlib graph of a black bar and the following errors:
Traceback (most recent call last):
File "\", line 1, in \
TypeError: Simulation.__init__() got an unexpected keyword argument 'sources1'
> > > sim.run(until=200)
> > > Traceback (most recent call last):
> > > File "\", line 1, in \
> > > NameError: name 'sim' is not defined. Did you mean: 'sum'?
>
> > > import matplotlib.pyplot as plt
> > > import numpy as np
> > >
> > > eps_data = sim.get_array(center=mp.Vector3(), size=cell, component=mp.Dielectric)
> > > Traceback (most recent call last):
> > > File "\", line 1, in \
> > > NameError: name 'sim' is not defined. Did you mean: 'sum'?
>
> > > plt.figure()
\\>\>\> plt.imshow(eps_data.transpose(), interpolation="spline36", cmap="binary")
Traceback (most recent call last):
File "", line 1, in
NameError: name 'eps_data' is not defined
\\>\>\> plt.axis("off")
(0.0, 1.0, 0.0, 1.0)
\\>\>\> plt.show()\
How can I fix my code up to get it working?
Code:
\#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
import meep as mp
cell = mp.Vector3(16, 8, 0)
geometry = \[mp.Block(mp.Vector3(mp.inf, 1, mp.inf),
center=mp.Vector3(),
material=mp.Medium(epsilon=2),)\]
sources1 = \[mp.Source(mp.ContinuousSource(frequency=1), component=mp.Ez, center=mp.Vector3(-7, 0))\]
sources2 = \[mp.Source(mp.ContinuousSource(frequency=0),component=mp.Ez, center=mp.Vector3(-7.5,0), amplitude=10.0)\]
pml_layers = \[mp.PML(1.0)\]
resolution = 10
sim = mp.Simulation(cell_size=cell,
boundary_layers=pml_layers,
geometry=geometry,
sources1=sources1,
sources2=sources2,
resolution=resolution,)
sim.run(until=200)
import matplotlib.pyplot as plt
import numpy as np
eps_data = sim.get_array(center=mp.Vector3(), size=cell, component=mp.Dielectric)
plt.figure()
plt.imshow(eps_data.transpose(), interpolation="spline36", cmap="binary")
plt.axis("off")
plt.show()
ez_data = sim.get_array(center=mp.Vector3(), size=cell, component=mp.Ez)
plt.figure()
plt.imshow(eps_data.transpose(), interpolation="spline36", cmap="binary")
plt.imshow(ez_data.transpose(), interpolation="spline36", cmap="RdBu", alpha=0.9)
plt.axis("off")
plt.show()