Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotting Waveguide mode components #90

Open
lukasc-ubc opened this issue Sep 12, 2023 · 2 comments
Open

plotting Waveguide mode components #90

lukasc-ubc opened this issue Sep 12, 2023 · 2 comments

Comments

@lukasc-ubc
Copy link

It would be nice to be able to plot only Ex, Ey, or Ez, rather than all three as displayed by the mode.show() method.

I looked at the plot_mode function, and I see that plotting all three is hard coded. Adding an optional parameter to the function would be an easy addition.

https://github.com/HelgeGehring/femwell/blob/main/femwell/maxwell/waveguide.py

@lukasc-ubc
Copy link
Author

It would also be nice to be able to get an object returned from the .show() method, namely the fig and ax, so we can edit, and change the axis limits for example.

Here is some code that generated what I am looking for:

# Plot Real(Ex) field
fig, ax = plt.subplots()
mode = modes[0]
basis = mode.basis
from skfem import ElementVector; ElementDG; ElementTriP1
(et, et_basis), (ez, ez_basis) = basis.split(mode.E.real)
plot_basis = et_basis.with_element(ElementVector(ElementDG(ElementTriP1())))
et_xy = plot_basis.project(et_basis.interpolate(et))
(et_x, et_x_basis), (et_y, et_y_basis) = plot_basis.split(et_xy)
plt.title("Electric field, x component")
plt.axis([-core_width*2, core_width*2, -core_thickness*2, core_thickness*3])
plt.xlabel('Width [microns]')
plt.ylabel('Thickness direction [microns]')
for subdomain in basis.mesh.subdomains.keys() - {"gmsh:bounding_entities"}:
    basis.mesh.restrict(subdomain).draw(ax=ax, boundaries_only=True, color="k", linewidth=3)
et_x_basis.plot(et_x, ax=ax, shading="gouraud", colorbar=True)

@HelgeGehring
Copy link
Owner

Looks great, thanks!
Adding a parameter sounds like a great enhancement!

maybe something like `plot_mode(...., components="xy"), where one can just submit one letter to have one field as well as a arbitary combination?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants