# Winding Design Candidates


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

## Executive Summary

Slots Q, poles P and phases m do not fix a winding: the number of layers
and the coil span are design choices. `design_windings(Q, P, m)` lists
every winding the star of slots can produce for that machine that **can
be wound into coils** and is **balanced**, best fundamental winding
factor first, so the trade-offs are visible before you pick one.

<table>
<colgroup>
<col style="width: 50%" />
<col style="width: 50%" />
</colgroup>
<thead>
<tr>
<th>You give</th>
<th>You get</th>
</tr>
</thead>
<tbody>
<tr>
<td>Q, P, m</td>
<td>All candidates: single layer and every double-layer coil span up to
the pole pitch</td>
</tr>
<tr>
<td>… and <code>layers</code></td>
<td>Only single-layer, or only double-layer, candidates</td>
</tr>
<tr>
<td>… and <code>w</code></td>
<td>Double layer with that coil span</td>
</tr>
<tr>
<td>… <code>layers=2</code> and <code>w</code></td>
<td>Exactly that winding</td>
</tr>
</tbody>
</table>

Each candidate reports kw₁, the largest other MMF harmonic, and any
sub-harmonics, and can produce its full winding-factor spectrum, MMF
spectrum and MMF waveform.

If the filters leave nothing, `design_windings` raises `ValueError` with
the reason for each rejected option, for example *“single layer: phase A
has 2 go and 1 return conductors, so it can’t be wound into coils”*.

## How It Fits Into Motor Design

    03_sos.ipynb      layout engine: star of slots, coil matrix, check_winding
          │
          ▼
    05_design.ipynb   ←── YOU ARE HERE: list and compare candidate windings
          │
          ▼
    01_factors.ipynb / 02_mmf.ipynb   analyse the chosen winding

The other winding functions use the first candidate whenever `layers` or
`w` is left out, so `winding_factor_spectrum(Q, P)` and
`design_windings(Q, P)[0].winding_factors()` always describe the same
winding.

## Rules

- **Candidates tried:** single layer, and double layer with coil spans w
  = 1 … ⌈Q/P⌉. Longer spans only repeat shorter ones mirrored about the
  pole pitch. An explicit `w` may be anything from 1 to Q − 1.
- **Kept only if** `check_winding` passes: each phase has as many go as
  return conductors, and the phase EMFs at ν = p are equal in magnitude
  and 360°/m apart.
- **Order:** highest kw₁ first; ties go to double layer, then to the
  shorter span (less end-winding copper).
- **`w` is the double-layer coil span.** Giving `w` without `layers`
  means double layer; `layers=1` with `w` is an error, since a
  single-layer winding has no free span.
- **Harmonics** are those of the balanced three-phase airgap MMF,
  normalised so the working harmonic ν = p is 1. “Largest other
  harmonic” excludes ν = p; sub-harmonics are the harmonics with ν \< p.

**References:** Pyrhönen, Jokinen, Hrabovcová (2014), Ch. 2; Bianchi &
Dai Pré, *IEE Proc. Electr. Power Appl.* 153(3), 2006.

## Imports and Setup

------------------------------------------------------------------------

## `WindingCandidate`

One buildable, balanced winding for a given (Q, P, m). It stores the
layout and the summary numbers, and computes spectra and waveforms on
request using the same functions as the rest of the module.

------------------------------------------------------------------------

### WindingCandidate

``` python
def WindingCandidate(
    Q:int, P:int, m:int, layers:int, w:int | None, kw1:float, largest_harmonic:tuple, subharmonics:tuple, nu_max:int,
    layout:np.ndarray
)->None:
```

*A buildable, balanced star-of-slots winding.*

## Attributes

Q, P, m : int Slots, poles, phases layers : int 1 (single layer) or 2
(double layer) w : int | None Double-layer coil span in slots (None for
single layer) kw1 : float Fundamental winding factor (at ν = p)
largest_harmonic : tuple (ν, amplitude) of the largest MMF harmonic
other than ν = p, amplitude relative to the working harmonic; (None,
0.0) if there is none up to nu_max subharmonics : tuple MMF harmonic
orders below p that are present nu_max : int Highest harmonic considered
for the two fields above layout : np.ndarray (layers, Q) coil matrix, as
from build_coil_matrix

------------------------------------------------------------------------

## `design_windings`

------------------------------------------------------------------------

### design_windings

``` python
def design_windings(
    Q:int, P:int, m:int=3, layers:int | None=None, w:int | None=None, nu_max:int | None=None, # None → max(40, 4p).
)->list[WindingCandidate]: # Never empty: if no option passes, ValueError is raised instead.
```

*List the buildable, balanced windings for (Q, P, m), best kw1 first.*

## Parameters

Q : int Number of stator slots P : int Number of poles (even, \>= 2) m :
int Number of phases (odd, default 3) layers : int | None 1 or 2 to keep
only that layer count; None for both w : int | None Double-layer coil
span in slots; implies layers=2 nu_max : int | None Highest MMF harmonic
summarised per candidate. None → max(40, 4p).

## Raises

ValueError If no candidate is left, with the reason each option was
rejected; if `layers=1` is combined with `w`; or for invalid P, m,
layers, w.

``` python
from emachines.winding.design import design_windings

# Examples
assert [round(c.kw1, 4) for c in design_windings(12, 10)] == [0.9659, 0.933, 0.483]
c = design_windings(24, 4, w=5)[0]
assert (c.layers, c.w, round(c.kw1, 4)) == (2, 5, 0.933)
```

### Example: candidates for common machines

``` python
from emachines.winding.design import design_windings

for Q, P in [(12, 10), (9, 8), (24, 4), (36, 8), (15, 8)]:
    print(f"{Q}s/{P}p  (pole pitch {Q / P:.2f} slots)")
    for c in design_windings(Q, P):
        print("   ", c.describe())
    print()
```

    12s/10p  (pole pitch 1.20 slots)
        single layer: kw1 = 0.9659, largest other MMF harmonic ν=1 at 1.340, sub-harmonics ν=1
        double layer, w=1: kw1 = 0.9330, largest other MMF harmonic ν=7 at 0.714, sub-harmonics ν=1
        double layer, w=2: kw1 = 0.4830, largest other MMF harmonic ν=1 at 1.340, sub-harmonics ν=1

    9s/8p  (pole pitch 1.12 slots)
        double layer, w=1: kw1 = 0.9452, largest other MMF harmonic ν=5 at 0.800, sub-harmonics ν=1, 2
        double layer, w=2: kw1 = 0.3283, largest other MMF harmonic ν=1 at 1.389, sub-harmonics ν=1, 2

    24s/4p  (pole pitch 6.00 slots)
        double layer, w=6: kw1 = 0.9659, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        single layer: kw1 = 0.9659, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=5: kw1 = 0.9330, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=4: kw1 = 0.8365, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=3: kw1 = 0.6830, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=2: kw1 = 0.4830, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=1: kw1 = 0.2500, largest other MMF harmonic ν=10 at 0.200, no sub-harmonics

    36s/8p  (pole pitch 4.50 slots)
        double layer, w=4: kw1 = 0.9452, largest other MMF harmonic ν=32 at 0.125, no sub-harmonics
        double layer, w=5: kw1 = 0.9452, largest other MMF harmonic ν=32 at 0.125, no sub-harmonics
        double layer, w=3: kw1 = 0.8312, largest other MMF harmonic ν=32 at 0.125, no sub-harmonics
        double layer, w=2: kw1 = 0.6169, largest other MMF harmonic ν=8 at 0.142, no sub-harmonics
        double layer, w=1: kw1 = 0.3283, largest other MMF harmonic ν=8 at 0.174, no sub-harmonics

    15s/8p  (pole pitch 1.88 slots)
        double layer, w=2: kw1 = 0.9514, largest other MMF harmonic ν=11 at 0.364, sub-harmonics ν=1, 2
        double layer, w=1: kw1 = 0.7109, largest other MMF harmonic ν=11 at 0.364, sub-harmonics ν=1, 2

### Example: filters and rejections

``` python
from emachines.winding.design import design_windings

for kwargs in [dict(layers=2), dict(layers=1), dict(w=5), dict(layers=2, w=5)]:
    print(f"24s/4p {kwargs}:")
    for c in design_windings(24, 4, **kwargs):
        print("   ", c.describe())

for Q, P, kwargs in [(9, 8, dict(layers=1)), (9, 8, dict(layers=1, w=1)), (24, 4, dict(layers=2, w=12))]:
    try:
        design_windings(Q, P, **kwargs)
    except ValueError as e:
        print(f"\n{Q}s/{P}p {kwargs} → ValueError: {e}")
```

    24s/4p {'layers': 2}:
        double layer, w=6: kw1 = 0.9659, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=5: kw1 = 0.9330, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=4: kw1 = 0.8365, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=3: kw1 = 0.6830, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=2: kw1 = 0.4830, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
        double layer, w=1: kw1 = 0.2500, largest other MMF harmonic ν=10 at 0.200, no sub-harmonics
    24s/4p {'layers': 1}:
        single layer: kw1 = 0.9659, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
    24s/4p {'w': 5}:
        double layer, w=5: kw1 = 0.9330, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics
    24s/4p {'layers': 2, 'w': 5}:
        double layer, w=5: kw1 = 0.9330, largest other MMF harmonic ν=22 at 0.091, no sub-harmonics

    9s/8p {'layers': 1} → ValueError: No buildable, balanced winding for 9s/8p (m=3, layers=1). single layer: phase A has 2 go and 1 return conductors, so it can't be wound into coils

    9s/8p {'layers': 1, 'w': 1} → ValueError: w applies to double-layer windings only; a single-layer winding has no free coil span

    24s/4p {'layers': 2, 'w': 12} → ValueError: No buildable, balanced winding for 24s/4p (m=3, layers=2, w=12). double layer, w=12: phase EMF at the working harmonic is zero

------------------------------------------------------------------------

## Tests
