Meep fields#

Using the gplugins/gmeep utilities, we can also extract the output fields of the simulations.

This requires using a continuous source instead of the broad(er)band gaussian used in S-parameter extraction. Since we are working at a definite frequency, we can also leverage the finite-difference frequency domain solver.

In the spatial domain, this reuses the geometry and eigenmode source definitions of the plugin.

from __future__ import annotations

import gdsfactory as gf
import meep as mp

from gplugins.gmeep.get_simulation import get_simulation
Using MPI version 4.1, 1 processes
2024-05-10 10:18:05.350 | INFO     | gplugins.gmeep:<module>:39 - Meep '1.28.0' installed at ['/home/runner/micromamba/lib/python3.11/site-packages/meep']

Define a component#

c = gf.components.straight(length=10)

component = gf.add_padding_container(
    c,
    default=0,
    top=3.2,
    bottom=3.2,
)

component.plot()
../_images/e59fc4d32caa7fb906786f453cdc009eb049dbb4725e4011820f727d6e826485.png

Define a continuous source simulation#

import matplotlib.pyplot as plt

component = gf.add_padding_container(
    c,
    default=0,
    top=3.2,
    bottom=3.2,
)

sim_dict = get_simulation(
    component,
    is_3d=False,
    port_source_offset=-0.1,
    extend_ports_length=3,
    continuous_source=True,
    force_complex_fields=True,
)
sim = sim_dict["sim"]
sim.plot2D()
plt.show()
2024-05-10 10:18:05.846 | WARNING  | gdsfactory.klive:show:49 - UserWarning: Could not connect to klive server. Is klayout open and klive plugin installed?
2024-05-10 10:18:05.864 | WARNING  | meep:_get_epsilon_grid:4442 - ComplexWarning: Casting complex values to real discards the imaginary part
../_images/1205531c015a0670ad45a91ae884919571d9fd68a78605a008d114c54db069b8.png

FDFD simulation#

sim.init_sim()
sim.solve_cw(1e-6, 10000, 10)
2024-05-10 10:18:06.021 | WARNING  | meep:create_structure:4436 - ComplexWarning: Casting complex values to real discards the imaginary part
2024-05-10 10:18:06.022 | WARNING  | meep:_set_materials:4439 - ComplexWarning: Casting complex values to real discards the imaginary part
True
sx = sim.cell_size.x
sy = sim.cell_size.y
dpml = sim.boundary_layers[0].thickness
nonpml_vol = mp.Volume(mp.Vector3(), size=mp.Vector3(sx - 2 * dpml, sy - 2 * dpml))
ez_dat = sim.get_array(vol=nonpml_vol, component=mp.Ez)
import numpy as np

eps_data = sim.get_array(vol=nonpml_vol, component=mp.Dielectric)
ez_data = np.real(ez_dat)

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()
../_images/d2586ea82ca7a0aa77868c8c4d99ebc39bba452cc449c944afa64784cd64c013.png

Steady-state FDTD simulation#

We can also just run the time-domain simulation with the continuous source until the field is stabilized:

sim.run(until=400)
eps_data = sim.get_epsilon()
ez_data = np.real(sim.get_efield_z())

import matplotlib.pyplot as plt

plt.figure()
sim.plot2D(
    fields=mp.Ez,
    plot_sources_flag=True,
    plot_monitors_flag=False,
    plot_boundaries_flag=True,
)
plt.axis("off")
plt.show()
../_images/4ebd5eb144d2809b83296cccd455fe38c14b0d4458e2a8b6c50f3ccea55542a0.png