Solvers API
Prismo provides a unified solver interface that supports multiple electromagnetic simulation methods. All solvers implement the same base interface, allowing you to switch between different solvers transparently.
Solver Interface
Abstract base class for electromagnetic solvers.
This module defines the unified interface that all solvers (FDTD, FEM, MEEP) must implement, allowing solver-agnostic simulation orchestration.
- class prismo.solvers.base.SolverBase(grid)[source]
Bases:
ABCAbstract base class for all electromagnetic solvers.
This class defines the unified interface that all solvers must implement, allowing the Simulation class to work with any solver type transparently.
- abstractmethod step(fields=None)[source]
Perform a single time step.
- Parameters:
fields (ElectromagneticFields, optional) – Fields to update. If None, uses internal fields.
- Return type:
- abstractmethod get_fields()[source]
Get the current electromagnetic fields.
- Returns:
Current field state.
- Return type:
ElectromagneticFields
- abstractmethod get_time_step()[source]
Get the time step used by the solver.
- Returns:
Time step in seconds.
- Return type:
- class prismo.solvers.base.TimeDomainSolver(grid)[source]
Bases:
SolverBaseBase class for time-domain solvers (FDTD, MEEP).
Time-domain solvers advance fields in time using time-stepping.
- class prismo.solvers.base.FrequencyDomainSolver(grid)[source]
Bases:
SolverBaseBase class for frequency-domain solvers (FEM).
Frequency-domain solvers solve for fields at specific frequencies.
Base Classes
SolverBase
- class prismo.solvers.base.SolverBase(grid)[source]
Abstract base class for all electromagnetic solvers.
This class defines the unified interface that all solvers must implement, allowing the Simulation class to work with any solver type transparently.
- abstractmethod step(fields=None)[source]
Perform a single time step.
- Parameters:
fields (ElectromagneticFields, optional) – Fields to update. If None, uses internal fields.
- Return type:
- abstractmethod get_fields()[source]
Get the current electromagnetic fields.
- Returns:
Current field state.
- Return type:
ElectromagneticFields
- abstractmethod get_time_step()[source]
Get the time step used by the solver.
- Returns:
Time step in seconds.
- Return type:
TimeDomainSolver
Base class for time-domain solvers (FDTD, MEEP). These solvers advance fields in time using time-stepping.
FrequencyDomainSolver
Base class for frequency-domain solvers (FEM). These solvers solve for fields at specific frequencies.
- class prismo.solvers.base.FrequencyDomainSolver(grid)[source]
Base class for frequency-domain solvers (FEM).
Frequency-domain solvers solve for fields at specific frequencies.
Solver Implementations
FDTDSolver
Native FDTD (Finite-Difference Time-Domain) solver implementation. This is the default solver and provides high performance with GPU acceleration support.
- class prismo.core.solver.FDTDSolver(grid, dt=None, material_arrays=None, backend=None)[source]
High-level FDTD solver combining grid, fields, and updater.
This class provides a convenient interface for running FDTD simulations with automatic time stepping and field management.
- Parameters:
- __init__(grid, dt=None, material_arrays=None, backend=None)[source]
Initialize the solver.
- Parameters:
grid (YeeGrid) – The simulation grid.
- step(fields=None)[source]
Perform a single FDTD time step.
- Parameters:
fields (ElectromagneticFields, optional) – Fields to update. If None, uses internal fields.
- Return type:
- get_time_step()[source]
Get the time step used by the solver.
- Returns:
Time step in seconds.
- Return type:
Example Usage:
from prismo.core import Simulation
# Create simulation with FDTD solver (default)
sim = Simulation(
size=(10e-6, 5e-6, 0),
resolution=50e6,
solver_type="fdtd" # This is the default
)
# Or create solver directly
from prismo.core.solver import FDTDSolver
from prismo.core.grid import YeeGrid, GridSpec
grid_spec = GridSpec(size=(10e-6, 5e-6, 0), resolution=50e6)
grid = YeeGrid(grid_spec)
solver = FDTDSolver(grid)
MEEPSolver
Wrapper for MIT MEEP FDTD solver. This provides access to MEEP’s advanced features while maintaining compatibility with Prismo’s interface.
Note: MEEP is an optional dependency. Install with:
conda install -c conda-forge pymeeus meep
- class prismo.solvers.meep_solver.MEEPSolver(grid, material_arrays=None, backend=None)[source]
MIT MEEP FDTD solver wrapper.
This class wraps MIT MEEP’s FDTD solver, providing the same interface as the native FDTDSolver for seamless integration.
- Parameters:
- __init__(grid, material_arrays=None, backend=None)[source]
Initialize the solver.
- Parameters:
grid (YeeGrid) – The simulation grid.
- step(fields=None)[source]
Perform a single MEEP time step.
- Parameters:
fields (ElectromagneticFields, optional) – Fields to update. If None, uses internal fields.
- Return type:
Example Usage:
from prismo.core import Simulation
# Create simulation with MEEP solver
sim = Simulation(
size=(10e-6, 5e-6, 0),
resolution=50e6,
solver_type="meep" # Use MEEP solver
)
Note: The MEEP solver wrapper is currently a placeholder implementation. Full integration with MEEP’s geometry and material systems is planned for future releases.
FEMSolver
Finite Element Method (FEM) solver using FEniCS/dolfinx for frequency-domain and eigenvalue electromagnetic problems.
Note: FEniCS is an optional dependency and is not available on PyPI. Install with:
conda install -c conda-forge fenics-dolfinx
Or install from source: https://fenicsproject.org/download/
- class prismo.solvers.fem_solver.FEMSolver(grid, geometry=None, materials=None, boundary_conditions=None, backend=None)[source]
Finite Element Method solver for electromagnetic simulations.
This solver uses FEniCS/dolfinx for frequency-domain and eigenvalue problems. It supports PMC and magnetic PML boundary conditions.
- Parameters:
grid (YeeGrid) – The simulation grid.
geometry (Any, optional) – Geometry definition (to be integrated with Prismo geometry system).
materials (dict, optional) – Material properties dictionary.
boundary_conditions (dict, optional) – Boundary condition specification, e.g., {‘x_min’: ‘pmc’, ‘x_max’: ‘pml’}.
backend (Backend, optional) – Computational backend to use.
- __init__(grid, geometry=None, materials=None, boundary_conditions=None, backend=None)[source]
Initialize the solver.
- Parameters:
grid (YeeGrid) – The simulation grid.
- solve(frequency)[source]
Solve for fields at a specific frequency.
- Parameters:
frequency (float) – Frequency in Hz.
- Returns:
Solution fields at the specified frequency.
- Return type:
ElectromagneticFields
- step(fields=None)[source]
FEM is frequency-domain, so step() is not applicable.
Use solve() or solve_eigenvalue() instead.
- Return type:
Example Usage:
from prismo.core import Simulation
# Create simulation with FEM solver
sim = Simulation(
size=(10e-6, 5e-6, 0),
resolution=50e6,
solver_type="fem" # Use FEM solver
)
# For frequency-domain problems
fields = sim.solver.solve(frequency=193e12) # 1550 nm
# For eigenvalue problems (e.g., waveguide modes)
eigenvalues, eigenmodes = sim.solver.solve_eigenvalue(num_modes=3)
Note: The FEM solver is currently a placeholder implementation. Full integration with FEniCS mesh generation, weak form assembly, and boundary conditions is planned for future releases.
Choosing a Solver
FDTD (default): Best for time-domain simulations, transient analysis, and broadband frequency sweeps. Supports GPU acceleration.
MEEP: Useful when you need MEEP’s specific features or want to compare results with MEEP simulations.
FEM: Best for frequency-domain problems, eigenvalue analysis (waveguide modes), and problems requiring unstructured meshes.
Solver Selection in Simulation
The solver type is specified when creating a Simulation:
sim = Simulation(
size=(10e-6, 5e-6, 0),
resolution=50e6,
solver_type="fdtd" # Options: "fdtd", "meep", "fem"
)
All solvers provide the same interface, so you can switch between them without changing your simulation code (except for frequency-domain specific methods in FEM solver).