base_power is always in natural units#1694
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Per the convention that
base_poweris the anchor every other field's per-unitization is defined against,get_base_power/set_base_power!now treatbase_poweras always being in natural units (MVA), rather than going through the per-unit-aware machinery like other fields.Behavior:
get_base_power(comp)andset_base_power!(comp, 0.5)need no units argument — they read/write the stored MVA value directly.get_base_power(comp, NU)andset_base_power!(comp, 0.5 * MW)(or* MVA) also work. Any power-dimensionedUnitfulunit is accepted (conversion viauconvert/ustrip).SU/DU→ArgumentError(expressing a base in terms of itself or the system base is circular).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— componentbase_poweraccessors +_base_power_units_errorhelpersrc/base.jl— systembase_poweraccessorstest/test_base_power.jl— updated to assert the new contractNotes
base_powerfield only.Transformer3W'sbase_power_12/23/13are generated:mva-conversion fields that still flow through the generic machinery and continue to acceptSU/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.🤖 Generated with Claude Code