Diego Guisasola
2018-10-16 01:30:14 UTC
Greetins.
I'm new to Meep and I have a few questions...
I'm running the following code:
import meep as mp
import numpy as np
import matplotlib.pyplot as plt
n = 3.4 # index of waveguide
w = 1 # width of waveguide
r = 1 # inner radius of ring
pad = 4 # padding between waveguide and edge of PML
dpml = 2 # thickness of PML
gap = 0.2 # s
sxy = 4 * (r + w + pad + dpml) # cell size
c1 = mp.Cylinder(radius=r+w, material=mp.Medium(index=n),
center=mp.Vector3(0, 2-r-w-gap-0.5))
c2 = mp.Cylinder(radius=r, center=mp.Vector3(0,2-r-w-gap-0.5))
sources = mp.Source(mp.ContinuousSource(frequency=0.15),
component=mp.Ez,
center=mp.Vector3(-7,2),
size=mp.Vector3(0, 1.2))
geometry = mp.Block(mp.Vector3(1e20, 1, 1e20),
center=mp.Vector3(0, 2),
material=mp.Medium(epsilon=12))
sim = mp.Simulation(cell_size=mp.Vector3(sxy, sxy),
geometry=[c1, c2, geometry],
sources=[sources],
resolution=10,
boundary_layers=[mp.PML(1.0)])
sim.run(until=2000)
eps_data = sim.get_array(center=mp.Vector3(r+0.1),
size=mp.Vector3(sxy, sxy), component=mp.Dielectric)
ez_data = sim.get_array(center=mp.Vector3(r+0.1), size=mp.Vector3(sxy,
sxy), component=mp.Ez)
plt.figure(dpi=200)
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()
freg = mp.FluxRegion(center=mp.Vector3(7*sxy-7, 2), size=(mp.Vector3(0, 2*1.2)))
nfreq = 500
trans = sim.add_flux(0.2, 0.25, nfreq, freg)
sim.display_fluxes(trans)
plt.plot(trans)
plt.show()
It runs just fine but at the end I get this error:
Traceback (most recent call last):
File "/home/diego/PycharmProjects/Meep/Calvo1.py", line 46, in <module>
plt.plot(trans)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/pyplot.py",
line 3363, in plot
ret = ax.plot(*args, **kwargs)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/__init__.py",
line 1867, in inner
return func(ax, *args, **kwargs)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_axes.py",
line 1529, in plot
self.add_line(line)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_base.py",
line 1960, in add_line
self._update_line_limits(line)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_base.py",
line 1982, in _update_line_limits
path = line.get_path()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/lines.py",
line 956, in get_path
self.recache()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/lines.py",
line 657, in recache
y = _to_unmasked_float_array(yconv).ravel()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/cbook/__init__.py",
line 2052, in _to_unmasked_float_array
return np.asarray(x, float)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/numpy/core/numeric.py",
line 501, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'DftFlux'
I know that this code gives a table with the values of the flux in one
dimension, what can I change in order to get the flux in 2 dimensions?
Thanks in advance
I'm new to Meep and I have a few questions...
I'm running the following code:
import meep as mp
import numpy as np
import matplotlib.pyplot as plt
n = 3.4 # index of waveguide
w = 1 # width of waveguide
r = 1 # inner radius of ring
pad = 4 # padding between waveguide and edge of PML
dpml = 2 # thickness of PML
gap = 0.2 # s
sxy = 4 * (r + w + pad + dpml) # cell size
c1 = mp.Cylinder(radius=r+w, material=mp.Medium(index=n),
center=mp.Vector3(0, 2-r-w-gap-0.5))
c2 = mp.Cylinder(radius=r, center=mp.Vector3(0,2-r-w-gap-0.5))
sources = mp.Source(mp.ContinuousSource(frequency=0.15),
component=mp.Ez,
center=mp.Vector3(-7,2),
size=mp.Vector3(0, 1.2))
geometry = mp.Block(mp.Vector3(1e20, 1, 1e20),
center=mp.Vector3(0, 2),
material=mp.Medium(epsilon=12))
sim = mp.Simulation(cell_size=mp.Vector3(sxy, sxy),
geometry=[c1, c2, geometry],
sources=[sources],
resolution=10,
boundary_layers=[mp.PML(1.0)])
sim.run(until=2000)
eps_data = sim.get_array(center=mp.Vector3(r+0.1),
size=mp.Vector3(sxy, sxy), component=mp.Dielectric)
ez_data = sim.get_array(center=mp.Vector3(r+0.1), size=mp.Vector3(sxy,
sxy), component=mp.Ez)
plt.figure(dpi=200)
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()
freg = mp.FluxRegion(center=mp.Vector3(7*sxy-7, 2), size=(mp.Vector3(0, 2*1.2)))
nfreq = 500
trans = sim.add_flux(0.2, 0.25, nfreq, freg)
sim.display_fluxes(trans)
plt.plot(trans)
plt.show()
It runs just fine but at the end I get this error:
Traceback (most recent call last):
File "/home/diego/PycharmProjects/Meep/Calvo1.py", line 46, in <module>
plt.plot(trans)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/pyplot.py",
line 3363, in plot
ret = ax.plot(*args, **kwargs)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/__init__.py",
line 1867, in inner
return func(ax, *args, **kwargs)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_axes.py",
line 1529, in plot
self.add_line(line)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_base.py",
line 1960, in add_line
self._update_line_limits(line)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/axes/_base.py",
line 1982, in _update_line_limits
path = line.get_path()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/lines.py",
line 956, in get_path
self.recache()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/lines.py",
line 657, in recache
y = _to_unmasked_float_array(yconv).ravel()
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/matplotlib/cbook/__init__.py",
line 2052, in _to_unmasked_float_array
return np.asarray(x, float)
File "/home/diego/desired_prefix/envs/mp/lib/python3.6/site-packages/numpy/core/numeric.py",
line 501, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number, not 'DftFlux'
I know that this code gives a table with the values of the flux in one
dimension, what can I change in order to get the flux in 2 dimensions?
Thanks in advance
--
Atentamente,
Diego Guisasola.
--
El contenido de este mensaje y sus anexos son únicamente para el uso del
destinatario y pueden contener información clasificada o reservada. Si
usted no es el destinatario intencional, absténgase de cualquier uso,
difusión, distribución o copia de esta comunicación.
Atentamente,
Diego Guisasola.
--
El contenido de este mensaje y sus anexos son únicamente para el uso del
destinatario y pueden contener información clasificada o reservada. Si
usted no es el destinatario intencional, absténgase de cualquier uso,
difusión, distribución o copia de esta comunicación.