Browser-based FDTD (Finite-Difference Time-Domain) electromagnetic simulator. Cross-compiled openEMS to WebAssembly with a custom WebGPU compute backend for the FDTD time-stepping loop, near-to-far-field transform, and field energy reduction. Designs are written as JavaScript, compiled to openEMS XML at runtime, and simulated entirely client-side.
Live demo: https://efs.roman01la.workers.dev
- Parametric scripts — define geometry, materials, mesh, ports, and excitation in a JavaScript editor with autocomplete and live error diagnostics. Pre-built examples cover patch antennas, microstrip notch filters, helical antennas, rectangular waveguides, UWB dipoles, cloverleaf circular-polarization antennas, and infinite phased arrays.
param()API — declare tunable parameters that render as sliders, dropdowns, or toggles. Adjusting a control re-compiles the script and updates the 3D geometry preview live.- Sweeps — pick a parameter, set a range and step count, and the runner queues sequential simulations. Results overlay automatically.
- Trace overlay — every simulation run is color-coded and stacked on the S-parameter, impedance, and radiation plots so design variations can be compared at a glance.
- WebGPU FDTD engine — ~3000 MCells/s on a modern GPU, roughly 7x faster than native multi-threaded openEMS on CPU.
- NF2FF on GPU — near-field to far-field transform runs as a compute shader, producing 2D polar cuts and a full 3D directivity pattern.
- Field dump visualization — slice through E/H field volumes in any plane with linear or dB scaling.
- URL sharing — encode the script and current parameter overrides into a shareable URL fragment. Falls back to IndexedDB for large configs.
-
src/simulation-runtime.mjs— shared WebGPU runtime and openEMS output processing -
scripts/run-runtime.mjs— headless Node/Dawn runner -
native/cli.mm— native Apple Silicon XML runner -
src/webgpu-engine.mjs— WebGPU FDTD engine (field updates, NF2FF DFT accumulation, far-field shader, energy reduction) -
src/nf2ff.mjs— CPU NF2FF reference implementation -
src/ports.mjs— Lumped, MSL, coaxial, waveguide, and rectangular waveguide port classes -
src/embind_api.cpp— C++ Embind bindings exposing operator setup and coefficient extraction to JavaScript -
app/sim-worker.js— Web Worker that orchestrates the WASM/WebGPU hybrid pipeline (XML parse, operator setup, GPU dispatch, probe gather, NF2FF, HDF5 field dump readback) -
app/ems-api.mjs— Script-side API (OpenEMS,ContinuousStructure,Mesh,Property, primitives, transforms) -
app/examples.mjs— Pre-built parametric example designs -
app/geometry-viewer.mjs— Three.js geometry preview -
app/radiation-viewer.mjs— 3D radiation pattern viewer -
app/index.html— Editor, parameter panel, sweep runner, plots, walkthrough -
vendor/openEMS,vendor/CSXCAD— Upstream submodules
Initialize the upstream submodules and apply the recorded source patches before building the native CLI, the native Node addon, or the WASM runtime.
git submodule update --init --recursive
bash scripts/apply-vendor-patches.shThe patches include the shared openEMS runtime accessors, native material-setup changes, and the page-aligned allocator used by the Apple Silicon Metal backend.
WASM build (one-time setup, ~10 min for deps, ~2 min for the module):
npm run build:deps # cross-compile WASM dependencies
npm run build # build the WASM moduleNative openEMS build (for validation against the WebGPU pipeline):
bash scripts/build-native-deps.sh
cmake -B build-native -S . -DCMAKE_BUILD_TYPE=Release
cmake --build build-native -j$(nproc)The ems-sim CLI runs XML models with Metal or native CPU openEMS. Start with
the CLI build instructions. Metal uses shared, page-aligned
field buffers by default. Use --field-storage copy to benchmark the copied
buffer path with the same input. The benchmark report
covers Apple Metal and NVIDIA Vulkan.
Use Node.js 22+, an NVIDIA Linux driver with its Vulkan ICD, the system
Vulkan loader, and matching build-wasm/openems.js and openems.wasm files.
The WASM build files can be copied from another development machine. Install
the Node dependencies with npm ci and run:
node scripts/run-runtime.mjs --check-gpu --backend vulkan --require-nvidia
node scripts/run-runtime.mjs --xml model.xml --output-dir results \
--backend vulkan --require-nvidiaThe CLI writes the openEMS probes, any requested raw HDF5 dumps, and
runtime.json with the selected adapter, timing and stop reason. Add
--radiation to include radiation preview data when the XML provides the
required NF2FF setup. On a host with multiple adapters, use --adapter NAME
to select one. If the check fails, compare nvidia-smi -L with
vulkaninfo --summary: a CUDA-visible GPU also needs to be visible to Vulkan.
Use --core-workgroup XxYxZ to tune the voltage and current shader dispatch.
The output records the selected shape and breaks down operator setup, GPU
setup, adapter discovery, WASM loading and raw output writes.
For development, run a private one-shot job with the authenticated Modal CLI. It runs the same headless command on a Tesla T4 by default and checks for 1,000 completed steps and nonzero probe signals. The report records the NVIDIA driver, actual Dawn adapter, input/WASM hashes, timings and output sizes.
modal run modal_gpu.py --report /tmp/nvidia-smoke.jsonSet EMS_MODAL_GPU to select another Modal GPU type. To compare raw samples
against native openEMS CPU, pass --xml model.xml --reference cpu.emsrun.
Use the same XML and step count for both runs. The Modal command returns the
verification report; the Linux CLI writes the raw result files locally.
Pass --workgroups default,1x1x32,1x1x64 --repeats 5 to compare dispatch
shapes on one worker per GPU, with one warmup per shape and rotated run order.
The T4 verification report records
the fixed smoke fixture and its probe agreement with native openEMS CPU.
The Linux CLI can build the openEMS operator and process probes and dumps in native C++, with the existing Dawn/Vulkan kernels handling all FDTD steps. Material setup divides the grid along X. Each worker uses its own CSXCAD geometry because material lookup can mutate caches and usage flags.
On Debian 12, install the compiler and libraries below, along with Node.js
22+ and the headers matching your Node installation. Set NODE_INCLUDE_DIR
if the headers are outside the Node installation prefix.
sudo apt-get install cmake g++ make libfparser-dev libtinyxml-dev libhdf5-dev \
libboost-thread-dev libboost-date-time-dev libboost-serialization-dev \
libboost-chrono-dev libboost-program-options-dev
bash scripts/build-native-node.sh
node scripts/run-runtime.mjs --operator native --material-threads 4 \
--backend vulkan --require-nvidia --core-workgroup 1x1x64 \
--xml model.xml --output-dir resultsThe prototype uses the Cartesian BASIC field layout and rejects external
geometry/material files. Use --material-threads 1 for a serial native
comparison. Reports include the actual worker count, material and geometry
clone times, and total operator setup time. To reproduce the paired Linux
benchmark and the serial/parallel coefficient checks on Modal:
modal run --write-result /tmp/native-vulkan.json modal_native_vulkan.py::benchmarkOn the 1.08-million-cell cavity, native setup with four material workers reduced median L40S CLI time from 4.44 s to 1.79 s. Serial and parallel native setups produced identical GPU coefficients on the plain and weighted-material cases. The cavity probe samples matched the WASM baseline. See the paired benchmark.
Static dev server, then open http://localhost:8080/app/:
python3 -m http.server 8080The script editor auto-compiles on a 3-second debounce. Param controls debounce a 500 ms preview recompile.
npm test # 547 Node.js tests (WASM, API, GPU, examples)
npm run test:browser # 52 headless Chrome WebGPU tests
npm run test:all # everythingThe Cloudflare Workers deployment serves files from dist/:
rsync -a --delete app/ dist/app/
rsync -a --delete src/ dist/src/
cp app/index.html dist/index.html
npx wrangler deployparam(defaultValue, label, opts?)Numeric slider:
const patchW = param(32, 'Patch Width',
{ min: 20, max: 50, step: 1, unit: 'mm' });Enum dropdown:
const bc = param('MUR', 'Boundary',
{ options: ['PEC', 'PMC', 'MUR', 'PML_8'] });Boolean toggle:
const addRadome = param(false, 'Add Radome');Numeric without min/max renders as static read-only text. The
param() function is injected into the script scope alongside OpenEMS
and ContinuousStructure; no import needed.
| Engine | Time | MCells/s |
|---|---|---|
| openEMS basic (CPU) | 119 s | 134 |
| openEMS sse (CPU) | 110 s | 145 |
| openEMS multithreaded | 36 s | 444 |
| WebGPU | 6.2 s | 3000 |
Setup overhead: ~1.0 s (C++ operator 932 ms, GPU init 15 ms). NF2FF post-processing: ~30 ms (GPU accumulation + far-field).
GPL-3.0 (matching upstream openEMS).