Skip to main content

Frequency-domain electromagnetic FEM solver in Rust, with a Python API and an optional local web UI.

Project description

PySimHub

RapidFEM

Electromagnetic FEM solver written in Rust, distributed as a Python package on PyPI. Two backends behind one geometry/material/physics API: a frequency-domain solver (Nédélec first-kind order-2 edge elements, complex-symmetric sparse linear algebra) and a time-domain DGTD solver (discontinuous Galerkin, Krylov/ETD exponential time integration, model-order reduction). The solver is scale-invariant, so sub-micron RFIC passives (with GDS / PDK-stack import) solve as reliably as metre-scale structures. Optional Flask-based local UI with code editor and live viewer.

Install

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

Wheels for Windows, Linux, and macOS are built via CI. The Rust core is compiled ahead of time — no Rust toolchain required on the user's machine. Gmsh (Python wheel gmsh) is pulled in automatically and provides the OpenCASCADE-based geometry + 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)

# 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)

See python_src/rapidfem/examples/ for end-to-end runs: microstrip and coupled lines, iris / 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).

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. Use rapidfem.show(g) to send 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 + ports in one call
  • RFIC / GDSrapidfem.rfic process stacks and Geometry.from_gds build on-chip passives, solved scale-invariantly down to sub-micron features
  • Canonical Nédélec R2 elements — first-kind order-2 curl–curl vector element, 20 DOFs per tetrahedron
  • 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 + conductivity, surface impedance for metals, Debye dispersion; cached across sweeps
  • Sparse solvers — pure-Rust faer LU baseline; optional MKL PARDISO (complex-symmetric LDLᵀ) on Windows / Linux; Apple Accelerate Bunch-Kaufman on macOS (~3× faster than faer)
  • Frequency sweep — assembles E/B once, refactors only the frequency- dependent K per point, reuses the symbolic LU pattern
  • Eigenmode solver — shift-invert Lanczos on the complex-symmetric system
  • 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
faer General sparse LU Pure Rust, no native dependencies — always available
MKL PARDISO Complex-symmetric LDLᵀ Fastest on Windows / Linux; opt-in, needs mkl_rt on PATH
Apple Accelerate Sparse Bunch-Kaufman LDLᵀ macOS only; ~3× faster than faer, ships with macOS

Select with RAPIDFEM_SOLVER ("auto", "pardiso", "accelerate", "faer"), set before import rapidfem. Default "auto" tries PARDISO → Accelerate → faer. Optional MKL: conda install mkl / pip install mkl (ensure mkl_rt is on PATH).

Performance

WR-90 iris waveguide driven sweep, 10 GHz, 2-port:

Mesh DOFs PARDISO faer
693 tets 5 512 0.14 s 0.22 s
1 096 tets 8 382 0.06 s 0.45 s
2 595 tets 19 196 0.17 s 1.39 s
3 284 tets 23 968 0.21 s 1.98 s

Larger: 327 k DOFs driven sweep (PARDISO) ~5 s/freq; 905 k DOFs eigenmode (3-turn spiral, shift-invert Lanczos) ~54 s.

Verification

cargo test --release checks element-level functions to machine precision (1e-12 – 1e-16). End-to-end S-parameter accuracy is tracked in tests/validation/ against analytical solutions and reference solvers.

License

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

Project details


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.13.1.tar.gz (83.5 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.13.1-cp310-abi3-win_amd64.whl (85.2 MB view details)

Uploaded CPython 3.10+Windows x86-64

rapidfem-0.13.1-cp310-abi3-manylinux_2_39_x86_64.whl (85.2 MB view details)

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

rapidfem-0.13.1-cp310-abi3-macosx_11_0_arm64.whl (84.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: rapidfem-0.13.1.tar.gz
  • Upload date:
  • Size: 83.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rapidfem-0.13.1.tar.gz
Algorithm Hash digest
SHA256 b69c1de34e917fa1a3fbfe77cf7fcd0f7c2794d308ddfffcf9d3a215a859b540
MD5 4e5ea4250314a3b821c9b39ad1b6157d
BLAKE2b-256 b229ecb59ea81e208141f1fb631fcf71667ae4381f07fc725ef8c65a0050f789

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.13.1.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.13.1-cp310-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for rapidfem-0.13.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe26d8c41b6f64e54482b205b783d0342b31912d3461b38ab72fe7e186c4cb08
MD5 443faaf0f68e4ae7d96a004a221399cc
BLAKE2b-256 c286be9dacaf7b10b0721d07a4376d2570c292100bd5d9034c53ad8696fcd2a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.13.1-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.13.1-cp310-abi3-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for rapidfem-0.13.1-cp310-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 03fb649e0ee7f14846fd82a35204b69e8e7f97570a8bf6b06060230bc3df7b5e
MD5 9ad991d1acea1620575cf73c3ca1ab63
BLAKE2b-256 1e74b7c3336f16d3a3f6774b73936348a6343558441f8ef9f21c4103b1a90769

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.13.1-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.13.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rapidfem-0.13.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fbb450494ae750f9021d81904dcd28e8b141881a965b70f6e63aa4f3227c588e
MD5 382d8c8e5c2cfb00fa6e5eaa9fe085cd
BLAKE2b-256 e5e83ee129a970afe9e1ca7a93763d4c8d0ba37fa58ff476aba155f850589229

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.13.1-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 Pingdom Monitoring Sentry Error logging StatusPage Status page