# DC Motors


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

## Executive Summary

**Purpose:** Analyse permanent-magnet brushed DC motors with a
lumped-parameter model.

**What it does:** From geometry and material data it estimates the
air-gap flux, armature resistance, motor constant K (= K_t = K_e), rotor
inertia, the steady-state speed–torque line, losses and an efficiency
map.

### Why It Matters

An engineer needs to estimate torque, speed, and efficiency for a DC
motor before prototyping.

### Quick Start

**Inputs:** `GeometricParams` (stator, magnet, air gap, rotor and
armature-winding dimensions), `MaterialProperties` (copper, steel,
magnet, densities, iron-loss coefficients), `OperatingConditions`
(terminal voltage, brush drop and brush resistance).

**Outputs:** `LumpedParams` (R_a, K, J, B_g, Φ), speed–torque
characteristic, loss breakdown, efficiency map.

### Known limitations (being reworked)

- The magnetic circuit treats steel as linear (constant permeability)
  and omits the armature teeth.
- `armature_inductance` and `viscous_damping` in `LumpedParams` are
  placeholder values, not calculated from the design.
- Armature reaction, leakage flux and brush loss are not modelled.

## How It Fits Into the Motor Design Workflow

**Upstream (depends on):** nothing else in the library yet — the module
is self-contained.

**Downstream (used by):** design decisions

## DC Motor (Permanent Magnet Brushed)

A lumped-parameter model for brushed PMDC machines covering magnetic
circuit analysis, armature resistance, motor constants, rotor inertia,
steady-state torque-speed characteristics, and efficiency mapping.

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

### LumpedParams

``` python
def LumpedParams(
    armature_resistance:float, armature_inductance:float, motor_constant:float, rotor_inertia:float,
    viscous_damping:float, air_gap_flux_density:float, flux_per_pole:float
)->None:
```

*Calculated lumped-parameter motor model.*

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

### OperatingConditions

``` python
def OperatingConditions(
    terminal_voltage:float, brush_contact_drop_v:float=1.0, brush_resistance_total:float=0.05
)->None:
```

*Terminal operating conditions.*

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

### MaterialProperties

``` python
def MaterialProperties(
    copper_resistivity:float, steel_permeability:float, magnet_remanent_flux_density:float,
    magnet_recoil_permeability:float, steel_density:float, copper_density:float, shaft_density:float,
    hysteresis_coeff:float, steinmetz_exponent:float, eddy_current_coeff:float, lamination_thickness:float
)->None:
```

*Material properties for motor components (SI units).*

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

### GeometricParams

``` python
def GeometricParams(
    stator_outer_diameter:float, stator_inner_diameter:float, rotor_outer_diameter:float, rotor_inner_diameter:float,
    stack_length:float, air_gap_length:float, num_poles:int, num_armature_slots:int, slot_opening_width:float,
    magnet_arc_angle_deg:float, magnet_thickness:float, turns_per_coil:int, armature_wire_cross_section_m2:float,
    is_lap_winding:bool=True
)->None:
```

*Geometric dimensions of the motor (SI units).*

Magnets sit on the stator bore, so `rotor_outer_diameter` should equal
`stator_inner_diameter - 2*magnet_thickness - 2*air_gap_length`.

``` python
# Example motor used in the examples below.
# Illustrative dimensions and material values only — not a real or validated motor.
mu_0 = 4e-7 * np.pi
geom = GeometricParams(
    stator_outer_diameter=80e-3, stator_inner_diameter=60e-3,
    rotor_outer_diameter=49e-3, rotor_inner_diameter=10e-3,   # 60 - 2*5 - 2*0.5 = 49 mm
    stack_length=40e-3, air_gap_length=0.5e-3,
    num_poles=4, num_armature_slots=18, slot_opening_width=2e-3,
    magnet_arc_angle_deg=60, magnet_thickness=5e-3,
    turns_per_coil=20, armature_wire_cross_section_m2=0.5e-6, is_lap_winding=True,
)
mat = MaterialProperties(
    copper_resistivity=1.72e-8, steel_permeability=2000 * mu_0,
    magnet_remanent_flux_density=0.4, magnet_recoil_permeability=1.05 * mu_0,
    steel_density=7650, copper_density=8900, shaft_density=7850,
    hysteresis_coeff=100.0, steinmetz_exponent=2.0,
    eddy_current_coeff=0.3e6, lamination_thickness=0.5e-3,
)
op = OperatingConditions(terminal_voltage=24.0, brush_contact_drop_v=1.0, brush_resistance_total=0.05)
assert np.isclose(geom.rotor_outer_diameter,
                  geom.stator_inner_diameter - 2 * geom.magnet_thickness - 2 * geom.air_gap_length)
```

### Carter’s Coefficient

Armature slotting increases the effective air gap: flux fringes round
the slot openings, so the gap is crossed over a smaller area than the
full slot pitch.

**Theory:**
$$g\_{eff} = k_c \\ g, \qquad k_c = \frac{\tau_s}{\tau_s - \gamma \\ g} \ge 1, \qquad \gamma = \frac{(w\_{so}/g)^2}{5 + w\_{so}/g}$$

where *τ*<sub>*s*</sub> is the slot pitch and *w*<sub>*s**o*</sub> the
slot opening. Since *γ**g* \< *w*<sub>*s**o*</sub>, the denominator
stays positive whenever *w*<sub>*s**o*</sub> \< *τ*<sub>*s*</sub>.

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

### calculate_carter_coefficient

``` python
def calculate_carter_coefficient(
    g:float, w_so:float, slot_pitch:float
)->float:
```

*Carter’s coefficient k_c \>= 1 for the slotted armature surface.*

The slot openings lengthen the effective air gap to g_eff = k_c \* g.
k_c = 1 for a slotless surface (w_so = 0).

Args: g: Air gap \[m\] w_so: Slot opening width \[m\] slot_pitch: Slot
pitch (distance between slots) \[m\]

Raises: ValueError: if g or slot_pitch is not positive, or w_so is not
in \[0, slot_pitch).

``` python
# Examples
# g = 0.5 mm, w_so = 2 mm, slot pitch 20 mm: gamma = 16/9, k_c = 20 / (20 - 0.8889) = 1.0465
assert np.isclose(calculate_carter_coefficient(0.5e-3, 2.0e-3, 20e-3), 1.0465, atol=1e-4)
assert calculate_carter_coefficient(0.5e-3, 0.0, 20e-3) == 1.0       # slotless: no correction
```

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

### calculate_magnetic_circuit

``` python
def calculate_magnetic_circuit(
    geom:GeometricParams, mat:MaterialProperties
)->tuple[float, float]:
```

*Magnetic circuit analysis via reluctance network.*

``` python
# Examples
B_g, flux = calculate_magnetic_circuit(geom, mat)
pole_face_area = geom.magnet_arc_angle_deg / 360 * np.pi * geom.rotor_outer_diameter * geom.stack_length
assert np.isclose(B_g, flux / pole_face_area)
assert 0 < B_g < mat.magnet_remanent_flux_density     # the gap flux density stays below B_r
```

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

### calculate_armature_resistance

``` python
def calculate_armature_resistance(
    geom:GeometricParams, mat:MaterialProperties
)->float:
```

*Armature winding resistance.*

``` python
# Examples
# R ∝ 1/a²: a 4-pole lap winding (a = 4) has 1/4 the resistance of the same wire as a wave winding (a = 2)
R_lap = calculate_armature_resistance(geom, mat)
R_wave = calculate_armature_resistance(replace(geom, is_lap_winding=False), mat)
assert np.isclose(R_lap / R_wave, (2 / 4) ** 2)
# on 2 poles lap and wave both have a = 2
g2 = replace(geom, num_poles=2)
assert np.isclose(calculate_armature_resistance(g2, mat),
                  calculate_armature_resistance(replace(g2, is_lap_winding=False), mat))
```

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

### calculate_motor_constants

``` python
def calculate_motor_constants(
    geom:GeometricParams, flux_per_pole:float
)->float:
```

*Motor constant K = Kt = Ke.*

``` python
# Examples
# K = Z P Φ / (2π a): Z = 2*20*18 = 720 conductors, P = 4, a = 4  ->  K = 720 Φ / (2π)
assert np.isclose(calculate_motor_constants(geom, 1e-3), 720 * 1e-3 / (2 * np.pi))
# a wave winding (a = 2) on 4 poles doubles K for the same conductors
assert np.isclose(calculate_motor_constants(replace(geom, is_lap_winding=False), 1e-3),
                  2 * calculate_motor_constants(geom, 1e-3))
```

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

### calculate_rotor_inertia

``` python
def calculate_rotor_inertia(
    geom:GeometricParams, mat:MaterialProperties
)->float:
```

*Rotor moment of inertia.*

``` python
# Examples
r_o, r_i, L = geom.rotor_outer_diameter / 2, geom.rotor_inner_diameter / 2, geom.stack_length
J_core = 0.5 * mat.steel_density * np.pi * (r_o**2 - r_i**2) * L * (r_o**2 + r_i**2)   # hollow cylinder
J_shaft = 0.5 * mat.shaft_density * np.pi * r_i**2 * L * r_i**2                       # solid cylinder
assert np.isclose(calculate_rotor_inertia(geom, mat), 1.15 * J_core + J_shaft)       # +15 % for the winding
```

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

### calculate_lumped_parameters

``` python
def calculate_lumped_parameters(
    geom:GeometricParams, mat:MaterialProperties
)->LumpedParams:
```

*Complete lumped model.*

``` python
# Examples
params = calculate_lumped_parameters(geom, mat)
assert params.armature_resistance == calculate_armature_resistance(geom, mat)
assert params.motor_constant == calculate_motor_constants(geom, params.flux_per_pole)
assert params.rotor_inertia == calculate_rotor_inertia(geom, mat)
```

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

### calculate_steady_state_performance

``` python
def calculate_steady_state_performance(
    params:LumpedParams, op:OperatingConditions
)->dict:
```

*Steady-state speed-torque characteristic.*

The circuit resistance is R_a plus `op.brush_resistance_total`; the
brush contact drop is subtracted from the terminal voltage.

``` python
# Examples
ss = calculate_steady_state_performance(params, op)
K, R = params.motor_constant, params.armature_resistance + op.brush_resistance_total
V_eff = op.terminal_voltage - op.brush_contact_drop_v
assert np.isclose(ss["no_load_speed_rpm"], V_eff / K * 60 / (2 * np.pi))
assert np.isclose(ss["stall_torque"], K * V_eff / R)     # brush resistance in series with R_a
assert np.isclose(ss["speed_rpm"][-1], 0, atol=1e-6)      # zero speed at stall
```

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

### calculate_losses_and_efficiency

``` python
def calculate_losses_and_efficiency(
    params:LumpedParams, geom:GeometricParams, mat:MaterialProperties, torque:float, speed_rpm:float
)->dict:
```

*Loss breakdown and efficiency.*

``` python
# Examples
T, n = 0.5 * ss["stall_torque"], 0.5 * ss["no_load_speed_rpm"]
d = calculate_losses_and_efficiency(params, geom, mat, T, n)
assert np.isclose(d["p_out"], T * n * 2 * np.pi / 60)
assert 0 < d["efficiency"] < 1
```

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

### plot_efficiency_map

``` python
def plot_efficiency_map(
    params:LumpedParams, geom:GeometricParams, mat:MaterialProperties, op_conditions:OperatingConditions,
    steady_state_data:dict, target_torque:Optional[float]=None, target_speed_rpm:Optional[float]=None
):
```

*2-D efficiency contour map.*

``` python
# Examples
fig = plot_efficiency_map(params, geom, mat, op, ss)
assert fig.axes[0].get_xlabel() == "Torque (Nm)"
plt.close(fig)
```

## Tests

``` python
# Test Carter coefficient: k_c >= 1 and it grows with the slot opening
k_small = calculate_carter_coefficient(1e-3, 0.5e-3, 5e-3)
k_large = calculate_carter_coefficient(1e-3, 2.0e-3, 5e-3)
assert 1 < k_small < k_large
for bad in [(0, 1e-3, 5e-3), (1e-3, 1e-3, 0), (1e-3, 5e-3, 5e-3), (1e-3, -1e-3, 5e-3)]:
    try:
        calculate_carter_coefficient(*bad)
    except ValueError:
        pass
    else:
        raise AssertionError(f"no ValueError for {bad}")
print(f"✓ Carter coefficient: {k_small:.4f} < {k_large:.4f}")

# Test brush resistance lowers stall torque, but not no-load speed
ss0 = calculate_steady_state_performance(params, replace(op, brush_resistance_total=0.0))
ss1 = calculate_steady_state_performance(params, replace(op, brush_resistance_total=0.5))
assert ss1["stall_torque"] < ss0["stall_torque"]
assert np.isclose(ss1["no_load_speed_rpm"], ss0["no_load_speed_rpm"])
print("✓ Brush resistance in series with the armature")
```

    ✓ Carter coefficient: 1.0092 < 1.1290
    ✓ Brush resistance in series with the armature

## References

- Carter, F.W. (1901). Air-gap induction. *Electrical World and
  Engineer*, 38, 884–888.
- Pyrhönen, J., Jokinen, T., Hrabovcová, V. (2008). *Design of Rotating
  Electrical Machines*. Wiley — Carter’s coefficient (γ form).
- Chapman, S.J. (2005). *Electric Machinery Fundamentals*. McGraw-Hill —
  DC machine EMF and torque, K = ZPΦ/(2πa).
- Fitzgerald, A.E., Kingsley, C., Umans, S.D. (2003). *Electric
  Machinery*. McGraw-Hill.
