Skip to content

MEEP API Styles

The gsim.meep API supports three equivalent styles for configuring simulations. All three produce identical Simulation objects — pick whichever reads best for your use case.

from ubcpdk import PDK, cells

PDK.activate()
c = cells.ebeam_y_1550()

Updates fields in place — only the fields you pass change, others keep their current values. No extra imports needed.

from gsim import meep
from gsim.meep.models.api import Material

sim = meep.Simulation()

sim.geometry(component=c)
sim.materials = {
    "si": Material(refractive_index=3.47),
    "SiO2": Material(refractive_index=1.44),
}
sim.source(port="o1", wavelength=1.55, wavelength_span=0.01)
sim.num_freqs = 21
sim.monitors = ["o1", "o2", "o3"]
sim.domain(pml=1.0, margin_x=0.5, margin_y=0.5, z_ref="stack")
sim.solver(resolution=20, simplify_tol=0.01, save_animation=True, verbose_interval=5.0)
FDTD(mode='3d', x_cut=None, y_cut=None, z_cut=None, resolution=20, stopping='energy_decay', max_time=2000.0, stopping_threshold=0.01, stopping_min_time=100.0, stopping_component='Ey', stopping_dt=20.0, stopping_monitor_port=None, wall_time_max=0.0, subpixel=False, subpixel_maxeval=0, subpixel_tol=0.0001, simplify_tol=0.01, dispersion='auto', dispersion_threshold=0.005, save_geometry=True, save_fields=True, save_epsilon_raw=False, save_animation=True, animation_interval=0.5, preview_only=False, verbose_interval=5.0)

2. Attribute style

One field per line. Most explicit — good when you need to set fields conditionally.

from gsim import meep
from gsim.meep.models.api import Material

sim = meep.Simulation()

sim.geometry.component = c

sim.materials = {
    "si": Material(refractive_index=3.47),
    "SiO2": Material(refractive_index=1.44),
}

sim.source.port = "o1"
sim.source.wavelength = 1.55
sim.source.wavelength_span = 0.01
sim.num_freqs = 21

sim.monitors = ["o1", "o2", "o3"]

sim.domain.pml = 1.0
sim.domain.margin_x = 0.5
sim.domain.margin_y = 0.5
sim.domain.z_ref = "stack"

sim.solver.resolution = 20
sim.solver.simplify_tol = 0.01
sim.solver.save_animation = True
sim.solver.verbose_interval = 5.0

3. Constructor style

Replaces the entire sub-object — fields you don't pass reset to defaults. Requires importing model classes, but useful when building configs programmatically or from saved presets.

from gsim import meep
from gsim.meep import FDTD, Domain, Geometry, Material, ModeSource

sim = meep.Simulation()

sim.geometry = Geometry(component=c)
sim.materials = {
    "si": Material(refractive_index=3.47),
    "SiO2": Material(refractive_index=1.44),
}
sim.source = ModeSource(port="o1", wavelength=1.55, wavelength_span=0.01)
sim.num_freqs = 21
sim.monitors = ["o1", "o2", "o3"]
sim.domain = Domain(pml=1.0, margin_x=0.5, margin_y=0.5, z_ref="stack")
sim.solver = FDTD(
    resolution=20, simplify_tol=0.01, save_animation=True, verbose_interval=5.0
)

Combining styles

All three styles can be freely combined. For example, use callable for bulk setup, then attribute for conditional tweaks:

from gsim import meep
from gsim.meep.models.api import Material

sim = meep.Simulation()

sim.geometry(component=c)
sim.materials = {
    "si": Material(refractive_index=3.47),
    "SiO2": Material(refractive_index=1.44),
}
sim.source(port="o1", wavelength=1.55, wavelength_span=0.01)
sim.num_freqs = 21
sim.monitors = ["o1", "o2", "o3"]
sim.domain(pml=1.0, margin_x=0.5, margin_y=0.5, z_ref="stack")
sim.solver(resolution=20, simplify_tol=0.01)

# Conditional tweaks with attribute style
debug = True
if debug:
    sim.solver.save_animation = True
    sim.solver.verbose_interval = 5.0