Skip to content

Commit

Permalink
trafo tap_pos optional + test
Browse files Browse the repository at this point in the history
Signed-off-by: petersalemink95 <peter.salemink95@gmail.com>
  • Loading branch information
petersalemink95 committed Jun 4, 2024
1 parent d74097b commit 7f65dc9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class Transformer : public Branch {
winding_to_{transformer_input.winding_to},
clock_{transformer_input.clock},
tap_side_{transformer_input.tap_side},
tap_pos_{transformer_input.tap_pos},
tap_pos_{transformer_input.tap_pos == na_IntS
? (transformer_input.tap_nom == na_IntS ? (IntS)0 : transformer_input.tap_nom)
: transformer_input.tap_pos},
tap_min_{transformer_input.tap_min},
tap_max_{transformer_input.tap_max},
tap_nom_{transformer_input.tap_nom == na_IntS ? (IntS)0 : transformer_input.tap_nom},
Expand Down Expand Up @@ -71,14 +73,14 @@ class Transformer : public Branch {
double phase_shift() const final { return clock_ * deg_30; }
bool is_param_mutable() const final { return true; }
// getters
constexpr IntS tap_pos() const { return tap_pos_; }
constexpr BranchSide tap_side() const { return tap_side_; }
constexpr IntS tap_min() const { return tap_min_; }
constexpr IntS tap_max() const { return tap_max_; }
constexpr IntS tap_nom() const { return tap_nom_; }
IntS tap_pos() const { return tap_pos_; }
BranchSide tap_side() const { return tap_side_; }
IntS tap_min() const { return tap_min_; }
IntS tap_max() const { return tap_max_; }
IntS tap_nom() const { return tap_nom_; }

// setter
constexpr bool set_tap(IntS new_tap) {
bool set_tap(IntS new_tap) {
if (new_tap == na_IntS || new_tap == tap_pos_) {
return false;
}
Expand Down Expand Up @@ -142,7 +144,7 @@ class Transformer : public Branch {
return {r / base_z, x / base_z};
}

constexpr IntS tap_limit(IntS new_tap) const {
IntS tap_limit(IntS new_tap) const {
new_tap = std::min(new_tap, std::max(tap_max_, tap_min_));
new_tap = std::max(new_tap, std::min(tap_max_, tap_min_));
return new_tap;
Expand Down Expand Up @@ -265,6 +267,4 @@ class Transformer : public Branch {
}
};

static_assert(transformer_c<Transformer>);

} // namespace power_grid_model
12 changes: 12 additions & 0 deletions tests/cpp_unit_tests/test_transformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ TEST_CASE("Test transformer") {
.r_grounding_to = nan,
.x_grounding_to = nan};

SUBCASE("Test optional inputs") {
input.tap_nom = 1;
input.tap_pos = na_IntS;
std::vector<Transformer> vec;
vec.emplace_back(input, 150e3, 10e3);
input.tap_nom = na_IntS;
vec.emplace_back(input, 150e3, 10e3);
CHECK(vec[0].tap_pos() == 1);
CHECK(vec[1].tap_pos() == 0);
CHECK(vec[1].tap_nom() == 0);
}

std::vector<Transformer> vec;
// 0 YNyn12
vec.emplace_back(input, 150e3, 10e3);
Expand Down

0 comments on commit 7f65dc9

Please sign in to comment.