# Winding Patterns


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

## Executive Summary

**Purpose:** Describe any stator winding as coils placed at named
positions in the slots, so that the inductance calculations
(`emachines.inductance`) can tell where each phase sits inside a slot.

**What it does:** `WindingPattern` holds the signed turns of every phase
at every position of every slot, `slot_turns[phase, slot, position]`,
plus the coils that produced them. Builders make the common windings
(star-of-slots, integer-slot distributed, tooth-coil concentrated) or
take your own slot table or coil list. Every pattern can be checked for
balance, gives its winding factors and draws itself as a developed slot
diagram.

**Why a new object:** `build_coil_matrix` says only *top* or *bottom*
layer, and a single layer has no position at all. Position-dependent
slot leakage, side-by-side tooth coils and multi-layer (hairpin)
windings need the position of every coil side by name.

## How It Fits Into the Motor Design Workflow

**Upstream:** `emachines.winding.sos` (star of slots,
`build_coil_matrix`) and `design_windings`, which pick a balanced layout
for (Q, P, m).

**Downstream:** `emachines.inductance` (stator geometry now; air-gap and
slot-leakage inductance in the next steps). Every inductance part is
computed from `slot_turns`.

## Conventions

- Slots are numbered 0 … Q − 1 in the direction of increasing angle,
  drawn left to right. Tooth *i* sits between slot *i* and slot *i* + 1.
- Phases are 0-based in code (0 = A) and lettered in text and plots.
- A coil side carries +turns where current flows **out of** the page and
  −turns where it flows **into** the page, for a positive phase current.
- Positions inside a slot depend on the layout:

<table>
<colgroup>
<col style="width: 33%" />
<col style="width: 33%" />
<col style="width: 33%" />
</colgroup>
<thead>
<tr>
<th>Layout</th>
<th>Positions</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>single</code></td>
<td><code>full</code></td>
<td>one coil side fills the slot</td>
</tr>
<tr>
<td><code>over_under</code>, 2 layers</td>
<td><code>top</code>, <code>bottom</code></td>
<td><code>top</code> is on the air-gap side</td>
</tr>
<tr>
<td><code>over_under</code>, n &gt; 2 layers</td>
<td><code>1</code> … <code>n</code></td>
<td><code>1</code> is on the air-gap side (hairpin and bar
windings)</td>
</tr>
<tr>
<td><code>side_by_side</code></td>
<td><code>left</code>, <code>right</code></td>
<td>two halves across the slot width (tooth coils)</td>
</tr>
</tbody>
</table>

The slot geometry (`emachines.inductance.SlotGeometry.regions`) maps
each name to a region of the slot cross-section.

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

## Slot positions

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

### slot_positions

``` python
def slot_positions(
    layout:str, n:int=2
)->tuple[str, ...]: # 'single' -> ('full',); 'over_under' with n = 2 -> ('top', 'bottom');
'over_under' with n > 2 -> ('1', ..., 'n'), '1' on the air-gap side;
'side_by_side' -> ('left', 'right').
```

*Names of the conductor positions in a slot for a given layout.*

## Parameters

layout : str ‘single’, ‘over_under’ or ‘side_by_side’ (see `LAYOUTS`) n
: int Number of radial layers for ‘over_under’ (default 2); ignored
otherwise

## Returns

tuple of str ‘single’ -\> (‘full’,); ‘over_under’ with n = 2 -\> (‘top’,
‘bottom’); ‘over_under’ with n \> 2 -\> (‘1’, …, ‘n’), ‘1’ on the
air-gap side; ‘side_by_side’ -\> (‘left’, ‘right’).

``` python
# Examples
assert slot_positions("single") == ("full",)
assert slot_positions("over_under") == ("top", "bottom")
assert slot_positions("over_under", 4) == ("1", "2", "3", "4")
assert slot_positions("side_by_side") == ("left", "right")
```

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

## `Coil`

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

### Coil

``` python
def Coil(
    phase:int, out_slot:int, out_pos:str, in_slot:int, in_pos:str, turns:int=1
)->None:
```

*One coil of one phase, with a side in each of two slot positions.*

For a positive phase current, current flows out of the page in the `out`
side and into the page in the `in` side.

## Attributes

phase : int Phase index, 0-based (0 = A) out_slot : int Slot of the out
side, 0 … Q-1 out_pos : str Position of the out side in its slot (see
`slot_positions`) in_slot : int Slot of the in side in_pos : str
Position of the in side turns : int Turns in the coil (default 1)

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

## `WindingPattern`

The pattern stores `slot_turns`, shape (m, Q, number of positions).
Entry `[k, i, r]` is the signed number of turns of phase *k* at position
*r* of slot *i*, for one parallel path. With *a* parallel paths in each
phase, every path carries 1/*a* of the phase current, so the turns that
link flux per ampere of phase current are `slot_turns / a`. That is
`effective_turns()`, and it is what the inductance calculations use.

The balance check works on `slot_turns` directly. Phase *k* has the EMF
phasor

*E*<sub>*k*</sub> = ∑<sub>*i*</sub>∑<sub>*r*</sub>*n*<sub>*k*, *i*, *r*</sub> *e*<sup> *j**p* 2*π**i*/*Q*</sup>,

and its winding factor at harmonic ν is
*k*<sub>*w**ν*</sub> = |∑*n* *e*<sup>*j**ν*2*π**i*/*Q*</sup>|/∑|*n*|.
The winding is **buildable** if each phase has as many out turns as in
turns, and **balanced** if the m phasors are equal in size and 360°/m
apart (in either sequence). This is the same test as `check_winding`,
extended to any number of positions and to turns.

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

### WindingPattern

``` python
def WindingPattern(
    Q:int, P:int, m:int, layout:str, positions:tuple, slot_turns:np.ndarray, coils:tuple | None=None,
    parallel_paths:int=1, name:str=''
)->None:
```

*A stator winding as signed turns per phase, slot and slot position.*

Build one with a classmethod (`from_star_of_slots`, `distributed`,
`concentrated`, `from_slot_table` or `custom`) rather than directly.

## Attributes

Q, P, m : int Slots, poles, phases layout : str ‘single’, ‘over_under’
or ‘side_by_side’ positions : tuple of str Position names, as from
`slot_positions` slot_turns : np.ndarray Shape (m, Q, len(positions)),
signed turns per path coils : tuple | None The coils, or None if built
from a slot table parallel_paths : int Parallel paths per phase, a
(default 1) name : str Short description

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

## Examples

A 36-slot, 4-pole, short-pitched double-layer winding (pitch 7 of 9
slots), with 10 turns per coil and 2 parallel paths:

``` python
pat = WindingPattern.distributed(36, 4, layers=2, pitch=7, turns=10, parallel_paths=2)
print(pat.describe())
assert pat.check()["balanced"] and np.isclose(pat.check()["kw1"], 0.9019, atol=1e-4)
assert np.allclose(pat.series_turns(), 36 * 10 / 3 / 2)        # 12 coils of 10 turns per phase, 2 paths
pat.plot();
```

    distributed, q=3, double layer, pitch 7/9: 36s/4p, m=3, over_under ('top', 'bottom'), N_s = 60, kw1 = 0.9019, balanced

![](06_pattern_files/figure-commonmark/cell-6-output-2.png)

The short pitch puts two phases in some slots, one in the top layer and
one in the bottom. These are the slots where the cross-slot mutual
inductance comes from:

``` python
shared = [i for i in range(pat.Q) if (np.abs(pat.slot_turns[:, i, :]).sum(axis=1) > 0).sum() == 2]
print(f"slots shared by two phases: {shared}")
assert len(shared) == 24
```

    slots shared by two phases: [1, 2, 4, 5, 7, 8, 10, 11, 13, 14, 16, 17, 19, 20, 22, 23, 25, 26, 28, 29, 31, 32, 34, 35]

Tooth-coil windings for 12 slots and 10 poles, side by side on every
tooth and single layer on alternate teeth:

``` python
fig, axes = plt.subplots(2, 1, figsize=(7, 4.8))
for ax, p in zip(axes, [WindingPattern.concentrated(12, 10),
                        WindingPattern.concentrated(12, 10, all_teeth=False)]):
    print(p.describe())
    p.plot(ax=ax)
plt.tight_layout()
```

    concentrated, all teeth, side-by-side: 12s/10p, m=3, side_by_side ('left', 'right'), N_s = 4, kw1 = 0.9330, balanced
    concentrated, alternate teeth: 12s/10p, m=3, single ('full',), N_s = 2, kw1 = 0.9659, balanced

![](06_pattern_files/figure-commonmark/cell-8-output-2.png)

Your own winding, from a slot table (rows are positions, top first) or
from a coil list:

``` python
table = [[1, 1, -3, -3, 2, 2, -1, -1, 3, 3, -2, -2],      # top layer
         [1, -3, -3, 2, 2, -1, -1, 3, 3, -2, -2, 1]]      # bottom layer
own = WindingPattern.from_slot_table(table, P=2, turns=5)
print(own.describe())

coils = [Coil(0, 0, "top", 5, "bottom", 8), Coil(1, 4, "top", 9, "bottom", 8), Coil(2, 8, "top", 1, "bottom", 8)]
print(WindingPattern.custom(12, 2, coils).describe())
```

    slot table: 12s/2p, m=3, over_under ('top', 'bottom'), N_s = 20, kw1 = 0.9330, balanced
    custom: 12s/2p, m=3, over_under ('top', 'bottom'), N_s = 8, kw1 = 0.9659, balanced

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

## Tests

## References

- Bianchi, N., Dai Prè, M. (2006). Use of the star of slots in designing
  fractional-slot single-layer synchronous motors. *IEE Proc. Electric
  Power Applications* 153(3) — star of slots, single-layer tooth-coil
  windings.
- Pyrhönen, J., Jokinen, T., Hrabovcová, V. (2014). *Design of Rotating
  Electrical Machines* (2nd ed.). Wiley — Chapter 2, windings.
- Sudhoff, S.D. *Power Magnetic Devices* (2nd ed.), §8.1–8.5 — conductor
  distribution by slot, used here per slot position.
