Skip to main content

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

Project description

RapidFEM

Frequency-domain electromagnetic FEM solver written in Rust, distributed as a Python package on PyPI. Second-kind Nedelec edge elements, complex-symmetric sparse linear algebra, optional Flask-based local UI with a code editor and live geometry 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 as a dependency and provides the OpenCASCADE-based geometry + mesher used by rapidfem.Geometry.

Quick start (Python API)

import numpy as np
import rapidfem

# Build geometry with named, tracked entities
g = rapidfem.Geometry()
sub = g.box(60e-3, 60e-3, 1.6e-3, position=(-30e-3, -30e-3, 0))
patch = g.xy_plate(38e-3, 29e-3, position=(-19e-3, -14.5e-3, 1.6e-3))
g.fragment(sub, patch)

sub.faces.min(axis="z").name = "ground"
patch.name = "patch_pec"
sub.material = "fr4"

# Mesh + simulate
mesh_bytes, name_to_tag = g.mesh(maxh=5e-3)
sim = (
    rapidfem.SimulationBuilder()
    .mesh(mesh_bytes, name_to_tag)
    .frequencies(np.linspace(2.3e9, 2.5e9, 21))
    .pec("ground", "patch_pec")
    .lumped_port("feed", direction=(0, 0, 1), z0=50.0)
    .material("fr4", er=4.4)
    .material("air", er=1.0)
    .build()
)

result = sim.run_sweep()
print(result.frequencies.shape, result.sparams.shape)

Local UI

rapidfem serve ./my_project/

Opens a browser window with:

  • a CodeMirror Python editor on the left,
  • a 3D geometry / mesh / field viewer on the right (raw WebGL2, viridis colormap for scalar fields),
  • S-parameter plots in a separate tab,
  • a Generate Mesh button (gmsh) and a Run Simulation button (FEM sweep).

The geometry view updates automatically every time you save the file (Ctrl+S). Mesh and solver runs are explicit.

Use rapidfem.show(g) at the bottom of your script to send a geometry to the viewer.

Features

  • Nedelec-2 elements — 20 DOFs per tetrahedron, vector edge basis for the curl–curl form of Maxwell's equations
  • Excitations — rectangular waveguide ports (arbitrary TE modes), lumped ports (TEM, multi-line voltage integral), and absorbing boundary conditions of order 1 and 2 (selectable coefficient types A–E)
  • PML — anisotropic stretched-coordinate perfectly matched layer
  • Lossy materials — complex permittivity with loss tangent + conductivity; frequency-independent caching speeds up sweeps
  • Sparse solvers — pure-Rust faer LU as the default in the PyPI wheel; optional MKL PARDISO (complex-symmetric LDLᵀ) for the fastest path
  • 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 (volume residual + face jumps) 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

Solver backends

Solver Type Notes
faer General sparse LU Pure Rust, no native dependencies — the default in the PyPI wheel
MKL PARDISO Complex-symmetric LDLᵀ Fastest path; opt-in, requires mkl_rt on PATH

Choose at simulation time via the builder or with the RAPIDFEM_SOLVER environment variable.

Installing MKL (optional)

  • conda: conda install mkl
  • pip: pip install mkl
  • Intel oneAPI: download

Ensure mkl_rt.dll (or mkl_rt.2.dll) is on the system 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 problems:

  • 327 k DOFs driven sweep (PARDISO): ~5 s per frequency
  • 905 k DOFs eigenmode (3-turn spiral, shift-invert Lanczos): ~54 s

Verification

Element-level functions (curl–curl integrals, Robin BC, second-order ABC, mode-power normalization, surface integrals) are checked to machine precision (1e-12 – 1e-16) by cargo test --release.

End-to-end S-parameter accuracy is tracked in tests/validation/ against analytical solutions and external reference solvers.

cargo test --release

License

GNU Affero General Public License v3.0 or later. If you run a modified version of rapidfem as a network service (e.g. SaaS), the AGPL requires that you make the modified source available to the users of that service. For commercial use under different terms, get in touch.

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.2.1.tar.gz (16.0 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.2.1-cp310-abi3-win_amd64.whl (12.0 MB view details)

Uploaded CPython 3.10+Windows x86-64

rapidfem-0.2.1-cp310-abi3-manylinux_2_39_x86_64.whl (12.1 MB view details)

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

rapidfem-0.2.1-cp310-abi3-macosx_11_0_arm64.whl (11.6 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for rapidfem-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a8e4306a05a76218bea649add2c5e178bd30475ca2e96867663e4ec76ecccebc
MD5 68c6f4745f036bee507e1208c94ad9cc
BLAKE2b-256 31347844641f6e73bdbb46f4511ad556ac9df013d5741f6e1296f9bb857471c2

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: rapidfem-0.2.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 12.0 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.2.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5e3e15bea044ac187c7b3d1eeb7fe611288efb0966d242cfdd1c138de0a3b49e
MD5 16d150a96a17829a30c50b50e71db193
BLAKE2b-256 02fc23e6f90d69ac58846ce953a1439bcf402c53b065f2672a06d659e77dc586

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rapidfem-0.2.1-cp310-abi3-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6a6d3523eb4c1b714e188716fb2a70b6fab308b0050ded65c04d8873d7506741
MD5 1add0320214fd7c8b70a6889bc6be4e7
BLAKE2b-256 d2781a1d2590a3318c22f8da5b6d99597044e71f4b3a34204766fef7655aad6e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rapidfem-0.2.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 771b6956a6e3fac719dcf227c8b69f0eb4c303944a7c97b9a7503572af1274be
MD5 c90f46da6628afe7081be135842d8313
BLAKE2b-256 8cf06aa6de2a030ede0d397975d4ffd7f287f3f4b3a2e6bb13e65ae4e45176b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for rapidfem-0.2.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