Skip to content

base_power is always in natural units#1694

Merged
jd-lara merged 1 commit into
psy6from
lk/base-power-natural-units
Jun 10, 2026
Merged

base_power is always in natural units#1694
jd-lara merged 1 commit into
psy6from
lk/base-power-natural-units

Conversation

@luke-kiernan

Copy link
Copy Markdown
Contributor

Summary

Per the convention that base_power is the anchor every other field's per-unitization is defined against, get_base_power/set_base_power! now treat base_power as always being in natural units (MVA), rather than going through the per-unit-aware machinery like other fields.

Behavior:

  1. get_base_power(comp) and set_base_power!(comp, 0.5) need no units argument — they read/write the stored MVA value directly.
  2. get_base_power(comp, NU) and set_base_power!(comp, 0.5 * MW) (or * MVA) also work. Any power-dimensioned Unitful unit is accepted (conversion via uconvert/ustrip).
  3. Anything other than natural units errors:
    • Per-unit bases SU/DUArgumentError (expressing a base in terms of itself or the system base is circular).
    • Non-power Unitful units (e.g. kV) → Unitful.DimensionError, for free, from Unitful.

The system-level accessor (get_base_power(sys, ...)) is updated to mirror the component one.

Changes

  • src/models/components.jl — component base_power accessors + _base_power_units_error helper
  • src/base.jl — system base_power accessors
  • test/test_base_power.jl — updated to assert the new contract

Notes

  • This covers the base_power field only. Transformer3W's base_power_12/23/13 are generated :mva-conversion fields that still flow through the generic machinery and continue to accept SU/DU. Extending the natural-units-only rule to those is a follow-up (it touches the struct-generation path), so it's deliberately out of scope here.
  • No changes in InfrastructureSystems.jl — this is entirely a PSY-side dispatch concern.

🤖 Generated with Claude Code

Make get_base_power/set_base_power! treat base_power as always being in
natural units (MVA), per the convention that base_power fields are the
anchor every other field's per-unitization is defined against:

- get_base_power(c) / set_base_power!(c, 0.5) need no units argument and
  read/write the stored MVA value directly.
- get_base_power(c, NU) and set_base_power!(c, 0.5 * MW) (or * MVA) still
  work; any power-dimensioned Unitful unit is accepted via uconvert/ustrip.
- Per-unit bases (SU, DU) and non-power units now error: SU/DU throw an
  ArgumentError, non-power Unitful units throw a Unitful.DimensionError.

The system-level accessor mirrors the component one. Tests updated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jd-lara jd-lara merged commit efac2b4 into psy6 Jun 10, 2026
1 of 9 checks passed
@jd-lara jd-lara deleted the lk/base-power-natural-units branch June 16, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants