# emachines


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

[![CI](https://github.com/NaveenDeepak/emachines/actions/workflows/ci.yml/badge.svg)](https://github.com/NaveenDeepak/emachines/actions/workflows/ci.yml)
[![PyPI
version](https://badge.fury.io/py/emachines.svg)](https://pypi.org/project/emachines/)
[![Python](https://img.shields.io/pypi/pyversions/emachines.png)](https://pypi.org/project/emachines/)
[![License:
MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

`emachines` is an open-source Python library of well-documented, tested,
and citable implementations of the analytical models used in electric
motor design. It is the physics engine behind
[emdesignlabs.com](https://emdesignlabs.com).

Every function documents the equation it implements and its
bibliographic source.

## Installation

``` bash
pip install emachines
```

Requires Python \>= 3.10.

## Modules

<table>
<colgroup>
<col style="width: 40%" />
<col style="width: 60%" />
</colgroup>
<thead>
<tr>
<th>Module</th>
<th>Capability</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="winding/01_factors.ipynb">Winding</a></td>
<td>Winding factors (kp, kd, kw), MMF distribution, star-of-slots phasor
method</td>
</tr>
<tr>
<td><a href="motors/01_pmsm.ipynb">Motors</a></td>
<td>PMSM dq-frame model, DC motor analytical model</td>
</tr>
<tr>
<td><a href="magnetics/01_bh_models.ipynb">Magnetics</a></td>
<td>BH curve models, iron loss (Steinmetz, Bertotti), electrical steel
&amp; PM databases, hysteresis (Takács, dynamic widening)</td>
</tr>
<tr>
<td><a href="transformer/01_single_phase.ipynb">Transformer</a></td>
<td>Single-phase transformer: no-load current waveform, core loss,
equivalent circuit, load performance</td>
</tr>
<tr>
<td><a href="mec/02_solver.ipynb">MEC</a></td>
<td>Magnetic equivalent circuit Newton-Raphson solver with nonlinear
materials</td>
</tr>
</tbody>
</table>

## Quick Start

``` python
from emachines.winding import winding_factor
from emachines.magnetics.iron_loss import bertotti
from emachines.motors.pmsm import PMSMParams, torque

# Winding factor -- 12s/10p FSCW tooth-coil
kw = winding_factor(5, Q=12, P=10, w=1)   # mechanical order: working harmonic ν = p = 5
print(f'kw1 = {kw:.4f}')  # 0.9330

# Iron loss -- Bertotti forward model
loss = bertotti(f=400, B_peak=1.5, k_h=0.02, k_e=1e-4, k_a=1e-3)
print(f'Total loss = {loss["total"]:.2f} W/kg')

# PMSM torque
motor = PMSMParams(p=3, Ld=5e-3, Lq=8e-3, psi_m=0.15, Rs=0.1)
Te = torque(motor, id=-3.0, iq=10.0)
print(f'Torque = {Te:.2f} Nm')
```

    kw1 = 0.9330
    Total loss = 68.70 W/kg
    Torque = 7.16 Nm

## Design Philosophy

- **Equations first** – every function leads with the formula it
  implements
- **Cited** – every formula references a specific textbook, paper, or
  standard
- **Notebook-driven** – source lives in Jupyter notebooks; Python
  modules are auto-generated via [nbdev](https://nbdev.fast.ai/)
- **Tested** – validated against published datasets and reference tools
- **Dependency-light** – only numpy, scipy, pandas, and matplotlib
  required
