Skip to content

Commit

Permalink
Merge pull request #804 from sudo-ac/fix/missing-validation-of-k-for-…
Browse files Browse the repository at this point in the history
…generic_branch

Fix/missing validation of k for generic branch
  • Loading branch information
mgovers authored Oct 22, 2024
2 parents 410494b + a802632 commit 7fff4d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/user_manual/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Here, $s_{\text{base}}$ is a constant value determined by the solver and $u_{\te
| `x1` | `double` | ohm | positive-sequence reactance | ✔ | ❌ | |
| `g1` | `double` | siemens | positive-sequence conductance | ✔ | ❌ | |
| `b1` | `double` | siemens | positive-sequence susceptance | ✔ | ❌ | |
| `k` | `double` | - | off-nominal ratio | ❌ default `1.0` | ❌ | |
| `k` | `double` | - | off-nominal ratio | ❌ default `1.0` | ❌ | `> 0` |
| `theta` | `double` | radian | angle shift | ❌ default `0.0` | ❌ | |
| `sn` | `double` | volt-ampere (VA) | rated power | ❌ default `0.0` | ❌ | `>= 0` |

Expand Down
2 changes: 2 additions & 0 deletions src/power_grid_model/validation/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ def validate_line(data: SingleDataset) -> list[ValidationError]:

def validate_generic_branch(data: SingleDataset) -> list[ValidationError]:
errors = validate_branch(data, ComponentType.generic_branch)
errors += all_greater_than_zero(data, ComponentType.generic_branch, "k")
errors += all_greater_than_or_equal_to_zero(data, ComponentType.generic_branch, "sn")
return errors


Expand Down
21 changes: 21 additions & 0 deletions tests/unit/validation/test_input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ def original_data() -> dict[ComponentType, np.ndarray]:
line["x0"] = [0, 0, 50]
line["i_n"] = [-3, 0, 50]

generic_branch = initialize_array(DatasetType.input, ComponentType.generic_branch, 1)
generic_branch["id"] = [6]
generic_branch["from_node"] = [1]
generic_branch["to_node"] = [2]
generic_branch["from_status"] = [1]
generic_branch["to_status"] = [1]
generic_branch["r1"] = [0.129059]
generic_branch["x1"] = [16.385859]
generic_branch["g1"] = [8.692e-7]
generic_branch["b1"] = [-2.336e-7]
generic_branch["k"] = [0.0]
generic_branch["theta"] = [0.0]
generic_branch["sn"] = [-10.0]

link = initialize_array(DatasetType.input, ComponentType.link, 2)
link["id"] = [12, 13]
link["from_node"] = [0, -1]
Expand Down Expand Up @@ -256,6 +270,7 @@ def original_data() -> dict[ComponentType, np.ndarray]:
data = {
ComponentType.node: node,
ComponentType.line: line,
ComponentType.generic_branch: generic_branch,
ComponentType.link: link,
ComponentType.transformer: transformer,
ComponentType.three_winding_transformer: three_winding_transformer,
Expand Down Expand Up @@ -667,3 +682,9 @@ def test_validate_input_data_asym_calculation(input_data):
def test_validate_input_data_invalid_structure():
with pytest.raises(TypeError, match=r"should be a Numpy structured array"):
validate_input_data({"node": np.array([[1, 10500.0], [2, 10500.0]])}, symmetric=True)


def test_generic_branch_input_data(input_data):
validation_errors = validate_input_data(input_data, symmetric=True)
assert NotGreaterThanError("generic_branch", "k", [6], 0) in validation_errors
assert NotGreaterOrEqualError("generic_branch", "sn", [6], 0) in validation_errors

0 comments on commit 7fff4d2

Please sign in to comment.