Skip to main content

PySimHub

RapidFEM

Electromagnetic FEM solver written in Rust, distributed as a Python package on PyPI. Two backends sit behind one geometry / material / physics API: a frequency-domain solver (Nédélec first-kind curl-conforming elements, complex-symmetric sparse linear algebra) and a time-domain DGTD solver (nodal discontinuous Galerkin, Krylov/ETD exponential time integration, model-order reduction). The geometry is non-dimensionalised before assembly, so sub-micron RFIC passives and metre-scale structures use the same numerical path. An optional Flask-based local UI provides a code editor and a live viewer.

Install

pip install rapidfem            # solver only
pip install rapidfem[ui]        # solver + local UI

Wheels for Windows, Linux, and macOS are built in CI; the Rust core is compiled ahead of time, so no Rust toolchain is needed on the user's machine. Gmsh (the gmsh Python wheel) is pulled in automatically and provides the OpenCASCADE geometry kernel and mesher used by rapidfem.Geometry.

Quick start (Python API)

import numpy as np
import rapidfem as rf

# Build geometry; attach materials + physics directly to entities
g = rf.Geometry(maxh=rf.lambda_maxh(f_max=12e9))
air = g.box(22.86e-3, 10.16e-3, 30e-3, position=(-11.43e-3, -5.08e-3, 0),
            material=rf.Air())

rf.RectWaveguidePort(air.faces.min(axis="z"))
rf.RectWaveguidePort(air.faces.max(axis="z"))
rf.PEC(*air.faces.unassigned)

g.mesh()

# Define the problem once, run any number of analyses on it
prob = rf.Problem(g)                      # Problem is the frequency-domain ProblemFD
result = prob.sweep(np.linspace(8e9, 12e9, 21))
print(result.frequencies.shape, result.sparams.shape)

# The same Problem can also drive an eigenmode solve or a far-field pattern:
# modes   = prob.eigenmode(target_frequency=10e9, n_modes=6)
# pattern = prob.farfield(result, freq_idx=10, port_idx=0)

python_src/rapidfem/examples/ has end-to-end runs: microstrip and coupled lines, iris and stepped-impedance filters, patch / Vivaldi / inverted-F antennas (PML + far-field), pyramidal horns, dielectric resonators, and the fd_rfic_* on-chip passives. RFIC geometry comes from a process stack and layout via rapidfem.rfic (rfic.Stack, Geometry.from_gds).

Importing external CAD and meshes

g.load(path) brings external geometry into the scene; the action is chosen from the file extension.

g = rf.Geometry(maxh=rf.lambda_maxh(f_max=20e9))

# STEP / IGES / BREP land in the same OpenCASCADE kernel as the primitives,
# so the result is a normal GeoObject: boolean it, transform it, select its
# faces, attach materials and physics, exactly like a g.box(...).
part = g.load("horn.step", material=rf.Air())   # mm STEP -> metres by default
post = g.cylinder(radius=0.5e-3, height=5e-3)
g.cut(part, post)                                # compose CAD with primitives
g.rotate(part, math.pi / 2, axis=(0, 1, 0))      # full transform API applies
rf.RectWaveguidePort(part.faces.max(axis="z"))
rf.PEC(*part.faces.unassigned)
g.mesh()

# Place/orient any import at load time, like a primitive's position= kwarg:
part = g.load("horn.step", position=(0, 0, 5e-3), rotation=(math.pi, (0, 0, 1)))

# STL is a surface triangulation, healed into a meshable solid. It is a discrete
# body (its geometry is the mesh), so it stays standalone: it takes a material,
# physics, placement and meshing, but it cannot be combined with OCC primitives
# or boolean ops (export STEP/IGES/BREP for that). STL is unit-less; pass scale=
# (metres per file unit) for a model authored in mm.
g = rf.Geometry(maxh=0.5e-3)
blob = g.load("antenna.stl", material=rf.Air(), scale=1e-3, position=(0, 0, 1e-3))

# A pre-built .msh volume mesh is already tessellated, so loading one switches
# the geometry into mesh mode: its named physical groups become selectable
# handles for materials and physics. g.mesh() bakes the bindings (no remeshing)
# and the usual Problem/sweep pipeline runs unchanged.
g = rf.Geometry()
scene = g.load("waveguide.msh")
scene.group("air").material = rf.Air()
rf.RectWaveguidePort(scene.group("port_in"))
rf.RectWaveguidePort(scene.group("port_out"))
rf.PEC(scene.group("walls"))
g.mesh()
result = rf.Problem(g).sweep(np.linspace(8e9, 12e9, 21))

unit= sets the target unit OpenCASCADE converts a STEP/IGES file into (default "M", so a millimetre file arrives at metre coordinates); scale= is an extra metres-per-file-unit factor for unit-less STL or a mis-declared CAD unit. examples/fd_step_import.py is a full STEP-driven sweep.

Local UI

rapidfem serve ./my_project/

Opens a browser window with a CodeMirror Python editor, a 3D geometry / mesh / field viewer (raw WebGL2), and S-parameter plots. The geometry view updates on save (Ctrl+S); mesh and solver runs are explicit. Results stream in as the solve runs; fields are fetched on demand as you scrub frequency and port. rapidfem.show(g) sends a geometry to the viewer.

Features

  • Geometry builder: OpenCASCADE primitives with boolean ops, transforms, and fillet/chamfer. Ready-made RF structures in rf.structures (coax, microstrip, CPW, stripline, waveguides, helix) build geometry and ports in one call.
  • External CAD / mesh import: g.load(path) pulls in STEP / IGES / BREP solids as composable primitives, heals STL surfaces into meshable solids, or loads a pre-built .msh and exposes its named physical groups for material / physics binding.
  • RFIC / GDS: rapidfem.rfic process stacks and Geometry.from_gds build on-chip passives, solved after non-dimensionalisation down to sub-micron features.
  • Element: Nédélec first-kind curl-conforming tetrahedral elements, order 2 (20 DOFs per cell), in a hierarchical basis. Opt-in per-cell mixed order (1-2) via [element] order_policy = "adaptive"; the default is uniform order 2.
  • Excitations: rectangular waveguide ports (arbitrary TE modes), lumped ports (TEM, multi-line voltage integral), coax and wave ports, Floquet plane-wave port (normal incidence), first-order absorbing boundary.
  • PML: anisotropic stretched-coordinate perfectly matched layer.
  • Lossy materials: complex permittivity with loss tangent and conductivity, surface impedance for metals, Debye dispersion; cached across sweeps.
  • Sparse solvers: pure-Rust rslab complex-symmetric LDLᵀ (Bunch-Kaufman) with a-priori memory estimates; optional MKL PARDISO where mkl_rt is installed.
  • Frequency sweep: assembles E/B once, refactors only the frequency-dependent K per point, reuses the symbolic factorisation pattern.
  • Eigenmode solver: shift-invert Lanczos in the B inner product, with a per-mode residual check.
  • Adaptive refinement: residual error estimator with Dörfler marking, exports a size field for gmsh re-meshing.
  • Output: Touchstone (.s1p/.s2p/.snp), VTK field export, far-field NFFT.
  • Parallel assembly: rayon-based element matrix evaluation.

Time-domain backend (DGTD)

ProblemTD, behind the same API, compiles a structure into an explicit linear ODE dy/dt = A·y and exposes it as a model at every level:

  • DGTD: nodal discontinuous Galerkin on tetrahedra, upwind or energy-conserving central flux.
  • Exponential time integration: matrix-free Krylov/ETD propagator, exact for the linear system at any step size (no CFL limit).
  • Model export / reduction: the RHS, the verbatim sparse operator A, an exponential stepper, or Krylov-projected reduced models.
  • Materials: heterogeneous, lossy, anisotropic, and Debye-dispersive media; matched absorbing layers; periodic boundaries.
  • Output: field probes, RFT transfer function, VTK field-animation export.
import rapidfem as rf

ptd  = rf.ProblemTD.box(size=(1, 1, 1), cells=(2, 2, 2), order=2)
traj = ptd.transient(y0, dt=0.02, steps=200)   # turnkey transient
rom  = ptd.reduce(y0, dim=60)                   # model-order reduction
A    = ptd.state_space()                        # the verbatim operator

Method notes and the ProblemTD API are in docs/td-backend.md.

Solver backends

Solver Type Notes
rslab Complex-symmetric LDLᵀ (Bunch-Kaufman) Pure Rust, no native dependencies, always available. Numeric-only refactorisation across sweeps, a-priori RAM gate.
MKL PARDISO Complex-symmetric LDLᵀ Opt-in, needs mkl_rt on PATH.

Select with RAPIDFEM_SOLVER ("auto", "pardiso", "rslab"), set before import rapidfem. The default "auto" tries PARDISO, then rslab. For MKL: conda install mkl or pip install mkl (ensure mkl_rt is on PATH).

Verification

cargo test --release pins the element and solver kernels against independent symbolic derivations to machine precision: the Nédélec element matrices, the barycentric integration coefficients, the surface-element trace, the hierarchical-basis and exact-sequence properties, the global assembly, and the eigensolver against a densely computed cavity spectrum. The derivations, completeness proofs, and entrywise cross-checks live in derivations/.

python/tests/ runs end-to-end S-parameter checks on microstrip, stripline, CPW, waveguide, filter, and antenna geometries against closed-form values. Those run real solves, so they are run locally (cd python && pytest -m slow), not in CI.

Acknowledgments

rapidfem began as a Rust port of EMerge (PyPI), Robert Fennis' open-source Python electromagnetic FEM solver. Its script-first design shaped the geometry / material / physics API, and the early releases ported its Python implementation to Rust. Thanks to Robert Fennis for building and sharing it.

The solver kernels have since been independently re-derived from primary sources: Nédélec's edge-element construction, standard microwave theory, and the barycentric integration identities. The derivations and cross-checks are in derivations/.

License

GPL-3.0-or-later with the Gmsh additional permission; see LICENSE. Copyright (C) Milan Rother and rapidfem contributors; commercial terms available.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rapidfem-0.21.0.tar.gz (84.3 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rapidfem-0.21.0-cp310-abi3-win_amd64.whl (85.5 MB view details)

Uploaded CPython 3.10+Windows x86-64

rapidfem-0.21.0-cp310-abi3-manylinux_2_39_x86_64.whl (85.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.39+ x86-64

rapidfem-0.21.0-cp310-abi3-macosx_11_0_arm64.whl (85.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file rapidfem-0.21.0.tar.gz.

File metadata

  • Download URL: rapidfem-0.21.0.tar.gz
  • Upload date:
  • Size: 84.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rapidfem-0.21.0.tar.gz
Algorithm Hash digest
SHA256 53373973bc4a28fc72d94ae4dc3b91a1235928fde418b17b0c945b278d2f8513
MD5 c422d0b99842f2f995b298b9d8190103
BLAKE2b-256 263f77a66b5cc9940c0bb82e4f702edbaac8a71ed1760892f8c2af62f56513dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.21.0.tar.gz:

Publisher: wheels.yml on milanofthe/rapidfem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rapidfem-0.21.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: rapidfem-0.21.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 85.5 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for rapidfem-0.21.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fd7d9dc83288a575657822dc96f32ed864a808ce694f6a0572315f61b0168c8e
MD5 5cac19226e923a27445acabc0100239c
BLAKE2b-256 c4917a7521c09e9c380a2dbd1cd0d8c91b5a551516e6b3cfb9ea1cb4a2f79858

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.21.0-cp310-abi3-win_amd64.whl:

Publisher: wheels.yml on milanofthe/rapidfem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rapidfem-0.21.0-cp310-abi3-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for rapidfem-0.21.0-cp310-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6ad90c67f6764fd5871e01b19b7661b25290e3ec67dfc153b162fa49dbfc3d1c
MD5 9951f723ab90f609b4702b9fd82d0a88
BLAKE2b-256 50ff4e8158f66fd74aec5ce641c6dc4f7a62d952a33e1e1fdd686e3f5a38279b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.21.0-cp310-abi3-manylinux_2_39_x86_64.whl:

Publisher: wheels.yml on milanofthe/rapidfem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rapidfem-0.21.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rapidfem-0.21.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 945dd840b788a491a9b92a6ba570ecbb8b2055b34e422e0dc35fe7f7a29768e6
MD5 a747c0e6513cc724f21a698e6fca5ce7
BLAKE2b-256 11ad809a444b45e3b1c962a2aab4da1de30cd7aee5b725811a279a407a8b5254

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.21.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on milanofthe/rapidfem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page