Skip to content

Transformer: support periodic clock input #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class ThreeWindingTransformer : public Branch3 {
constexpr IntS tap_min() const { return tap_min_; }
constexpr IntS tap_max() const { return tap_max_; }
constexpr IntS tap_nom() const { return tap_nom_; }
constexpr IntS clock_12() const { return clock_12_; }
constexpr IntS clock_13() const { return clock_13_; }
Comment on lines +122 to +123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably good to also add clock_23 then?

Copy link
Contributor Author

@Jerry-Jinfeng-Guo Jerry-Jinfeng-Guo Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute clock_23 does not exist in the component. If needed, the physics needs to be revisited

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these getters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test


// setter
constexpr bool set_tap(IntS new_tap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ class Transformer : public Branch {
throw InvalidTransformerClock{id(), clock_};
}

// set clock to zero if it is 12
clock_ = static_cast<IntS>(clock_ % 12);
// handle periodic clock input -> in range [0, 11]
clock_ = static_cast<IntS>((clock_ % 12 + 12) % 12);
// check tap bounds
tap_pos_ = tap_limit(tap_pos_);
}
Expand All @@ -82,6 +82,7 @@ class Transformer : public Branch {
constexpr IntS tap_min() const { return tap_min_; }
constexpr IntS tap_max() const { return tap_max_; }
constexpr IntS tap_nom() const { return tap_nom_; }
constexpr IntS clock() const { return clock_; }

// setter
constexpr bool set_tap(IntS new_tap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ constexpr double tap_adjust_impedance(double tap_pos, double tap_min, double tap
constexpr bool is_valid_clock(IntS clock, WindingType winding_from, WindingType winding_to) {
using enum WindingType;

bool const clock_in_range = 0 <= clock && clock <= 12;
bool const clock_is_even = (clock % 2) == 0;

bool const is_from_wye = winding_from == wye || winding_from == wye_n;
bool const is_to_wye = winding_to == wye || winding_to == wye_n;

// even clock number is only possible when both sides are wye winding or both sides aren't
// and conversely for odd clock number
bool const correct_clock_winding = (clock_is_even == (is_from_wye == is_to_wye));

return clock_in_range && correct_clock_winding;
return (clock_is_even == (is_from_wye == is_to_wye));
}

// add tap
Expand Down
17 changes: 17 additions & 0 deletions tests/cpp_unit_tests/test_transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@ TEST_CASE("Test transformer") {
CHECK(vec[0].tap_pos() == 9);
}

SUBCASE("periodic clock input") {
input.clock = 24;
Transformer trafo_24(input, 150.0e3, 10.0e3);
input.clock = 36;
Transformer trafo_36(input, 150.0e3, 10.0e3);
input.clock = -2;
Transformer trafo_m2(input, 150.0e3, 10.0e3);
CHECK(trafo_24.clock() == 0);
CHECK(trafo_36.clock() == 0);
CHECK(trafo_m2.clock() == 10);

input.winding_to = WindingType::delta;
input.clock = 25;
Transformer trafo_25(input, 150.0e3, 10.0e3);
CHECK(trafo_25.clock() == 1);
}

SUBCASE("symmetric parameters") {
for (size_t i = 0; i < 5; i++) {
auto changed =
Expand Down
Loading