This notebook implements the star-of-slots (SOS) method — the canonical winding layout engine for AC machines.
What it does
Given a slot/pole/phase combination (Q, P, m), the SOS method: 1. Projects each slot’s EMF phasor onto a circle divided into 2m sectors. 2. Assigns each slot conductor to a phase and current direction based on which sector its phasor falls in. 3. Builds the coil matrix used by winding factor and MMF analysis.
When to use this module
Winding layout: understand which slots carry which phase in which direction.
Feasibility check: verify that a given (Q, P, m) combination supports a valid balanced winding.
Input to winding factors and MMF: build_coil_matrix is the single output consumed by winding_factors.py and mmf.py.
Swappability: this module is deliberately isolated as the layout engine. Future layout techniques (e.g. optimal assignment, genetic algorithm) can replace it without changing winding_factors.py or mmf.py.
How It Fits Into Motor Design
01_winding_sos.ipynb ←── YOU ARE HERE
(winding layout)
│
▼
01_winding_factors.ipynb (kp, kd, kw, harmonic spectrum)
│
▼
01_winding_mmf.ipynb (MMF waveform, harmonic amplitudes)
│
▼
02_pmsm.ipynb (torque, back-EMF)
Depends on: nothing (this is the foundation layer).
These internal functions support the SOS algorithm and are not part of the public API.
get_basic_params: Winding Parameter Summary
Theory
All downstream calculations start from a handful of derived parameters. The winding periodicity t = gcd(Q, p) is the key symmetry parameter: a valid winding repeats itself t times around the stator.
def get_basic_params( Q:int, P:int, m:int=3)->dict: # p : int Pole pairs (P // 2)t : int Winding periodicity = gcd(Q, p)q : Fraction Slots per pole per phase = Q / (2mp)lcm_QP : int lcm(Q, P)alpha_e : float Electrical slot pitch (radians) = p · 2π/QQ_phase : int Slots per phase = Q // m (integer part)
Compute basic winding parameters from slot/pole/phase count.
Parameters
Q : int Number of stator slots P : int Number of poles (even) m : int Number of phases (default 3)
Returns
dict with keys: p : int Pole pairs (P // 2) t : int Winding periodicity = gcd(Q, p) q : Fraction Slots per pole per phase = Q / (2mp) lcm_QP : int lcm(Q, P) alpha_e : float Electrical slot pitch (radians) = p · 2π/Q Q_phase : int Slots per phase = Q // m (integer part)
from emachines.winding.sos import get_basic_paramsparams = get_basic_params(12, 10)print("12s/10p (FSCW):")for k, v in params.items():print(f" {k:10s} = {v}")print()params = get_basic_params(24, 4)print("24s/4p (integer-slot):")for k, v in params.items():print(f" {k:10s} = {v}")
12s/10p (FSCW):
p = 5
t = 1
q = 2/5
lcm_QP = 60
alpha_e = 2.6179938779914944
Q_phase = 4
24s/4p (integer-slot):
p = 2
t = 2
q = 2
lcm_QP = 24
alpha_e = 0.5235987755982988
Q_phase = 8
build_star_of_slots: EMF Phasor Angles
Theory
The star of slots (also called the voltage star or EMF star) maps each stator slot to a phasor angle in the electrical domain.
For slot i, the electrical phasor angle is:
\[
\alpha_i = i \cdot \alpha_e \mod 2\pi, \qquad \alpha_e = p \cdot \frac{2\pi}{Q}
\]
where p = P/2 is the number of pole pairs and α_e is the electrical slot pitch.
Plotting all Q phasors reveals the “star” pattern that names the method. Slots whose phasors point in similar directions naturally carry the same phase current.
from emachines.winding.sos import build_star_of_slotsimport numpy as npangles = build_star_of_slots(12, 10)print("12s/10p phasor angles (degrees):")for i, a inenumerate(angles):print(f" Slot {i:2d}: {np.degrees(a):6.1f}°")
The 2π electrical circle is divided into 2m equal sectors (width = π/m each). Phase j (0-based) has its go belt at j·2π/m and its return belt π further on, so the sectors interleave go (+) and return (−) belts of different phases. For three phases the six 60° sectors read:
Sector
0–60°
60–120°
120–180°
180–240°
240–300°
300–360°
Phase
+A
−C
+B
−A
+C
−B
This places the go belts of A, B and C 120° apart, as a balanced three-phase winding requires. The rule needs an odd phase count; even m raises ValueError.
Each slot’s phasor (from build_star_of_slots) is projected onto this sector map: - The slot is assigned to the phase whose sector contains the phasor. - Positive sector → forward conductor (+phase index). - Negative sector → return conductor (−phase index).
For FSCW, multiple slots in the same phase produce phasors close together, forming tight “clusters” in the star diagram.
Reference: Pyrhönen et al. (2008), §2.3; Bianchi & Bolognani (2002).
assign_phases
def assign_phases( Q:int, P:int, m:int=3)->np.ndarray: # Signed phase codes: +k = phase k forward, −k = phase k return.Phase index k ∈ {1, …, m}.
Assign each slot to a phase and current direction using the star-of-slots.
Parameters
Q : int Number of stator slots P : int Number of poles m : int Number of phases (default 3)
Returns
np.ndarray, shape (Q,), dtype int Signed phase codes: +k = phase k forward, −k = phase k return. Phase index k ∈ {1, …, m}.
check_winding: Can It Be Wound, and Is It Balanced?
A coil matrix describes a usable m-phase winding only if two conditions hold:
Buildable. Every coil has a go side and a return side, so each phase needs as many go (+) as return (−) conductors. Otherwise its conductors cannot be paired into coils. Odd Q, for example, can never be wound single-layer.
Balanced. At the working harmonic ν = p, the phase EMF phasors \(E_k = \sum_i s_i\, e^{j p \theta_i}\) (θᵢ = 2πi/Q) have equal magnitude and step by exactly 360°/m.
Counting conductors per phase is not enough: the old 60°-apart layouts had equal counts but were not balanced.
The fundamental winding factor is \(k_{w1} = |E_A| / N_A\), with \(N_A\) the conductors in phase A.
check_winding
def check_winding( matrix:np.ndarray, # Signed phase codes, as returned by ``build_coil_matrix``. P:int, m:int=3)->dict: # buildable : bool Each phase has as many go as return conductorsbalanced : bool Phase EMFs at ν = p equal in magnitude, 360°/m apartkw1 : float Fundamental winding factor |E_A|/ N_Ago, ret : list Go andreturn conductor counts per phasephase_angles : list|None Electrical angle of each phase EMF relative to phase A, in degrees (Noneif the EMF is zero)reason : str Why the winding fails, or''if it passes
Check that a coil matrix can be wound into coils and is balanced.
Parameters
matrix : np.ndarray, shape (layers, Q) Signed phase codes, as returned by build_coil_matrix. P : int Number of poles m : int Number of phases (default 3)
Returns
dict with keys: buildable : bool Each phase has as many go as return conductors balanced : bool Phase EMFs at ν = p equal in magnitude, 360°/m apart kw1 : float Fundamental winding factor |E_A| / N_A go, ret : list Go and return conductor counts per phase phase_angles : list | None Electrical angle of each phase EMF relative to phase A, in degrees (None if the EMF is zero) reason : str Why the winding fails, or ’’ if it passes
# Examplesassert check_winding(build_coil_matrix(12, 10, layers=2, w=1), 10)['balanced']assert check_winding(build_coil_matrix(9, 8, layers=1), 8)['reason'] == ("phase A has 2 go and 1 return conductors, so it can't be wound into coils")
from emachines.winding.sos import check_winding, build_coil_matrixfor Q, P, layers, w in [(12, 10, 2, 1), (24, 4, 1, None), (9, 8, 1, None), (9, 8, 2, 1), (24, 4, 2, 12)]: r = check_winding(build_coil_matrix(Q, P, layers=layers, w=w), P) label =f"{Q}s/{P}p {'single layer'if layers ==1elsef'double layer, w={w}'}" status ="✓"if r['buildable'] and r['balanced'] else"✗"print(f" {status}{label:<28} kw1={r['kw1']:.4f} phases at {r['phase_angles']}{r['reason']}")
✓ 12s/10p double layer, w=1 kw1=0.9330 phases at [0.0, 120.0, 240.0]
✓ 24s/4p single layer kw1=0.9659 phases at [0.0, 120.0, 240.0]
✗ 9s/8p single layer kw1=0.9598 phases at [0.0, 120.0, 240.0] phase A has 2 go and 1 return conductors, so it can't be wound into coils
✓ 9s/8p double layer, w=1 kw1=0.9452 phases at [0.0, 120.0, 240.0]
✗ 24s/4p double layer, w=12 kw1=0.0000 phases at None phase EMF at the working harmonic is zero
Winding candidates and the default layout (internal)
For a slot/pole/phase combination the star of slots can produce a single-layer winding and a double-layer winding for each coil span. _winding_options builds each one, keeps those that pass check_winding, and sorts them by fundamental winding factor kw₁, highest first. Ties go to double layer, then to the shorter span (less end-winding copper).
When w is not given, spans from 1 up to the pole pitch Q/P, rounded up, are tried; longer spans only repeat shorter ones mirrored.
_resolve_layout is how every function in the winding module fills in a missing layers or w: it takes the first candidate. Calls that give both layers and w, or layers=1, are used exactly as given. design_windings (in the design notebook) returns the full candidate list.
build_coil_matrix: Conductor Occupancy Matrix
Theory
A coil connects a go conductor in one slot to a return conductor w slots away (coil span w). For a single-layer winding, only go conductors are placed; the return side falls in a dedicated slot. For a double-layer winding, every slot has two conductor layers — a go side from one coil and a return from another.
The coil matrix shape is (layers, Q): - Value +k : phase k, forward current direction. - Value −k : phase k, return current direction. - Value 0 : empty slot (only possible in single-layer windings).
This matrix is the single interface consumed by winding_factors.py and mmf.py.
References: Hanselman (2003), Ch. 4; Pyrhönen et al. (2008), §2.3.
build_coil_matrix
def build_coil_matrix( Q:int, P:int, m:int=3, layers:int|None=None, # buildable, balanced candidate (see ``design_windings``). w:int|None=None, # Ignored for ``layers=1``.)->np.ndarray: # +k = phase k forward, −k = phase k return, 0 = empty.
Build the (layers × Q) conductor occupancy matrix.
Parameters
Q : int Number of stator slots P : int Number of poles m : int Number of phases (default 3) layers : int | None 1 (single-layer) or 2 (double-layer). None → the best buildable, balanced candidate (see design_windings). w : int | None Double-layer coil span in slots. None → the best span. Ignored for layers=1.
Returns
np.ndarray, shape (layers, Q), dtype int +k = phase k forward, −k = phase k return, 0 = empty.
where \(s_{i,\text{lyr}} \in \{+1, -1\}\) is the conductor direction, and \(N_k\) is the total conductor count per phase. The result is averaged over all m phases.
This phasor method works for all winding types — integer-slot, fractional-slot, and FSCW — without needing separate kp and kd formulas.
Winding factor |kw(ν)| via the star-of-slots phasor method.
Works for integer-slot, fractional-slot, and FSCW windings.
Parameters
nu : int Mechanical harmonic order Q : int Number of stator slots P : int Number of poles m : int Number of phases (default 3) layers : int 1 or 2 (default 1) w : int | None Coil span. None → Q // (P // 2).
from emachines.winding.sos import winding_factor_sosconfigs = [ (12, 10, 2, "12s/10p FSCW — ν=5 working"), (12, 8, 2, "12s/8p FSCW — ν=4 working"), ( 9, 8, 2, "9s/8p FSCW — ν=4 working"), (24, 4, 2, "24s/4p ISW — ν=2 working"),]print(f"{'Configuration':<35} kw at working ν")print("-"*55)for Q, P, layers, label in configs: p = P //2 kw = winding_factor_sos(p, Q, P, layers=layers)print(f" {label:<33}{kw:.4f}")
Configuration kw at working ν
-------------------------------------------------------
12s/10p FSCW — ν=5 working 0.9330
12s/8p FSCW — ν=4 working 0.8660
9s/8p FSCW — ν=4 working 0.9452
24s/4p ISW — ν=2 working 0.9659
check_symmetry: Validate Winding Balance
Theory
A valid three-phase winding must be balanced: each phase must carry the same number of conductors, and the total slot count must divide evenly.
The check verifies: 1. Q is divisible by m (equal slots per phase). 2. The total period t = gcd(Q, p) > 0. 3. The number of conductors per phase is equal across all m phases.
Reference: Pyrhönen et al. (2008), §2.1.
check_symmetry
def check_symmetry( Q:int, P:int, m:int=3, layers:int|None=None, # if no candidate exists. w:int|None=None)->dict: # balanced : bool Phase EMFs equal in magnitude and 360°/m apartbuildable : bool Each phase has as many go asreturn conductorsconductors : list Conductor count per phase [n_A, n_B, n_C, …]periodicity : int Winding periodicity t = gcd(Q, p)q : Fraction Slots per pole per phasevalid : bool balanced and buildable and Q % m ==0layers, w : int, int|None The layout that was checkedkw1 : float Fundamental winding factorreason : str Why it fails, or''
Check whether the star-of-slots winding for (Q, P, m) is usable.
Parameters
Q : int Number of stator slots P : int Number of poles m : int Number of phases (default 3) layers : int | None 1 or 2. None → the best candidate, or single layer if no candidate exists. w : int | None Double-layer coil span. None → the best span.
Returns
dict with keys: balanced : bool Phase EMFs equal in magnitude and 360°/m apart buildable : bool Each phase has as many go as return conductors conductors : list Conductor count per phase [n_A, n_B, n_C, …] periodicity : int Winding periodicity t = gcd(Q, p) q : Fraction Slots per pole per phase valid : bool balanced and buildable and Q % m == 0 layers, w : int, int | None The layout that was checked kw1 : float Fundamental winding factor reason : str Why it fails, or ’’
from emachines.winding.sos import check_symmetryfor Q, P, layers in [(12, 10, 2), (12, 8, 2), (9, 8, 2), (9, 8, 1), (24, 4, 1), (6, 2, 1)]: r = check_symmetry(Q, P, layers=layers) status ="✓"if r['valid'] else"✗"print(f" {status}{Q}s/{P}p layers={layers} balanced={r['balanced']} buildable={r['buildable']} "f"conductors={r['conductors']} q={r['q']} t={r['periodicity']}{r['reason']}")
✓ 12s/10p layers=2 balanced=True buildable=True conductors=[8, 8, 8] q=2/5 t=1
✓ 12s/8p layers=2 balanced=True buildable=True conductors=[8, 8, 8] q=1/2 t=4
✓ 9s/8p layers=2 balanced=True buildable=True conductors=[6, 6, 6] q=3/8 t=1
✗ 9s/8p layers=1 balanced=True buildable=False conductors=[3, 3, 3] q=3/8 t=1 phase A has 2 go and 1 return conductors, so it can't be wound into coils
✓ 24s/4p layers=1 balanced=True buildable=True conductors=[8, 8, 8] q=2 t=2
✓ 6s/2p layers=1 balanced=True buildable=True conductors=[2, 2, 2] q=1 t=1
get_valid_coil_spans: Valid Coil Span Enumeration
Theory
Not all coil spans produce a valid balanced winding. The valid spans are those that maintain winding symmetry — specifically those where the span does not coincide with a phase boundary, causing phase short-circuiting.
For FSCW (q < 1), the only valid span is typically w = 1 (tooth coil). For integer-slot windings, spans from 1 to full_pitch (= Q//p) are candidates; the full-pitch span maximises kw.
The function returns all spans that produce a balanced winding (equal conductors per phase).
Return True if (Q, P, m) supports a balanced m-phase winding.
A combination is valid when at least one star-of-slots winding (single layer, or double layer with some coil span) can be wound into coils and is balanced. P must be even and ≥ 2, and m odd.
Parameters
Q : int Number of stator slots P : int Number of poles m : int Number of phases (default 3)