EMDyna Sandbox Python API
Overview Manual & Theory Validation Suite Python API Gallery Open Simulator

Python Scripting API Specification

Complete documentation for the embedded in-browser Python (Pyodide) environment. Automate electromagnetic circuit design, batch sweeps, time-domain stepping, waveform acquisition, and geometric optimization using the global sim module.

Execution Environment & Conventions: The sim instance is injected directly into every script scope — no imports are necessary. All physical quantities adhere to standard SI units: lengths in meters [$\text{m}$], time in seconds [$\text{s}$], electrical potential in volts [$\text{V}$], current in amperes [$\text{A}$], magnetic flux density in teslas [$\text{T}$], force in newtons [$\text{N}$], torque in newton-meters [$\text{N}\cdot\text{m}$], and rotation in revolutions per minute [$\text{rpm}$]. Vectors and positions are 3-element lists [x, y, z] with the $+y$ axis oriented upwards.
Getting Started Example: Synchronous Motor Speed Sweep
# 1. Load an existing interactive preset scene
sim.load_preset("Synchronous motor (rotating magnet in three-phase field)")

# 2. Acquire a handle to the rotating permanent magnet
rotor = sim.part("Rotor (magnet)")

# 3. Drive the rotor with an external prime mover at 600 RPM
rotor.drive(rpm=600)

# 4. Advance time-domain simulation by 0.5 seconds
sim.run_for(0.5)

# 5. Extract mechanical status (torque, angular velocity, thrust)
status = rotor.info()
print(f"Rotor mechanical speed: {rotor.rpm:.1f} RPM")
print(f"Electrodynamic torque: {status['torque']:.4e} N*m")