Discussion:
[Meep-discuss] An error when simulating and plotting a ring
Diego Guisasola
2018-10-16 01:30:14 UTC
Permalink
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
--
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.
Bukowsky, Colton R.
2018-10-16 14:31:31 UTC
Permalink
Your trying to plot a flux object rather than data. As in the docs you should call:

mp.get_fluxes(flux) — Given a flux object, returns a list of the current flux spectrum that it has accumulated.

Assign the return to a variable and you should be able to plot that

On Mon, Oct 15, 2018, 11:07 PM <meep-discuss-***@ab-initio.mit.edu<mailto:meep-discuss-***@ab-initio.mit.edu>> wrote:
Send meep-discuss mailing list submissions to
meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>

To subscribe or unsubscribe via the World Wide Web, visit
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss
or, via email, send a message with subject or body 'help' to
meep-discuss-***@ab-initio.mit.edu<mailto:meep-discuss-***@ab-initio.mit.edu>

You can reach the person managing the list at
meep-discuss-***@ab-initio.mit.edu<mailto:meep-discuss-***@ab-initio.mit.edu>

When replying, please edit your Subject line so it is more specific
than "Re: Contents of meep-discuss digest..."
Today's Topics:

1. An error when simulating and plotting a ring (Diego Guisasola)
2. Community resources (Bukowsky, Colton R.)
3. Re: Community resources (John Weiner)



---------- Forwarded message ----------
From: Diego Guisasola <***@utp.edu.co<mailto:***@utp.edu.co>>
To: meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>
Cc:
Bcc:
Date: Mon, 15 Oct 2018 20:30:14 -0500
Subject: [Meep-discuss] An error when simulating and plotting a ring
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
--
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.


---------- Forwarded message ----------
From: "Bukowsky, Colton R." <***@caltech.edu<mailto:***@caltech.edu>>
To: "meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>" <meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>>
Cc:
Bcc:
Date: Tue, 16 Oct 2018 05:13:29 +0000
Subject: [Meep-discuss] Community resources
All,

Is there any interest in a community repository, where users can post scripts that work for them, helper functions, strategies, specific photonics problem objectives and solutions, Jupyter notebooks, and even scripts from users that have published work using MEEP. This could augment the tutorials in the docs and [simpetus](http://simpetus.com/projects.html).

The docs are really great, but as user projects get more complicated its unreasonable to expect the doc tutorials to touch on everything. In particular, I've found there is a gap in moving from 2D to 3D simulations and the specific nuances involved. A repository of user examples might avoid some confusions/questions.

There is this mail list, but it seems it is oriented towards specific problem solving rather than sharing. Still, a lot of emails go unanswered, perhaps users just aren't knowledgeable enough or large enough in numbers. Also, the internet has moved on to better formats (wikis, forums, stackexchange). There is also the Github issue system, yet that was intended to facilitate code bugs/issues so that the devs can more effectively prioritize those. A stackexchange+wiki seems like it would be amazing, yet there is a barrier to starting one; there are open source alternatives<https://meta.stackexchange.com/a/37953>.

Has this been considered? What reasons would there be against this? The main con I can see is "who would maintain such a repository?". The devs likely have enough on their hands. Thanks.

-Colton Bukowsky



---------- Forwarded message ----------
From: John Weiner <***@gmail.com<mailto:***@gmail.com>>
To: "Bukowsky, Colton R." <***@caltech.edu<mailto:***@caltech.edu>>
Cc: "meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>" <meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>>
Bcc:
Date: Tue, 16 Oct 2018 08:07:39 +0200
Subject: Re: [Meep-discuss] Community resources
Yes, there is great interest in establishing some kind of repository or forum
at least from this user. I have been thinking along similar lines for quite some time. Such things exist on the internet
the "stack overflow" (https://stackoverflow.com) site comes to mind, but they need to be well-moderated, well-organised and well-filtered to be of any use. Maybe the meep Github repository could be enlarged to include a branch for such activity
maybe not. Any knowledgeable comments or suggestions would be most welcome.

John Weiner

On 16 Oct 2018, at 07:13, Bukowsky, Colton R. <***@caltech.edu<mailto:***@caltech.edu>> wrote:

All,

Is there any interest in a community repository, where users can post scripts that work for them, helper functions, strategies, specific photonics problem objectives and solutions, Jupyter notebooks, and even scripts from users that have published work using MEEP. This could augment the tutorials in the docs and [simpetus](http://simpetus.com/projects.html).

The docs are really great, but as user projects get more complicated its unreasonable to expect the doc tutorials to touch on everything. In particular, I've found there is a gap in moving from 2D to 3D simulations and the specific nuances involved. A repository of user examples might avoid some confusions/questions.

There is this mail list, but it seems it is oriented towards specific problem solving rather than sharing. Still, a lot of emails go unanswered, perhaps users just aren't knowledgeable enough or large enough in numbers. Also, the internet has moved on to better formats (wikis, forums, stackexchange). There is also the Github issue system, yet that was intended to facilitate code bugs/issues so that the devs can more effectively prioritize those. A stackexchange+wiki seems like it would be amazing, yet there is a barrier to starting one; there are open source alternatives<https://meta.stackexchange.com/a/37953>.

Has this been considered? What reasons would there be against this? The main con I can see is "who would maintain such a repository?". The devs likely have enough on their hands. Thanks.

-Colton Bukowsky
_______________________________________________
meep-discuss mailing list
meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

_______________________________________________
meep-discuss mailing list
meep-***@ab-initio.mit.edu<mailto:meep-***@ab-initio.mit.edu>
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss
--
Best,
Colton Bukowsky
Ph.D. Candidate, Atwater Research Group, Caltech
***@caltech.edu<mailto:***@caltech.edu>
o: +1-626-395-2821 | c: +1-954-559-9054
https://linkedin.com/in/cbukowsky
Loading...