Skip to content

Commit

Permalink
Wip
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg committed Nov 10, 2023
1 parent 4aa5598 commit 2485b55
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ public enum SensitivityFunctionType {
BRANCH_REACTIVE_POWER_2,
BRANCH_ACTIVE_POWER_3,
BRANCH_CURRENT_3,
BRANCH_REACTIVE_POWER_3;
BRANCH_REACTIVE_POWER_3,
BUS_VOLTAGE;

@CEnumValue
public native int getCValue();
Expand Down
1 change: 1 addition & 0 deletions java/src/main/java/com/powsybl/python/commons/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public static SensitivityFunctionType convert(PyPowsyblApiHeader.SensitivityFunc
case BRANCH_ACTIVE_POWER_3 -> SensitivityFunctionType.BRANCH_ACTIVE_POWER_3;
case BRANCH_CURRENT_3 -> SensitivityFunctionType.BRANCH_CURRENT_3;
case BRANCH_REACTIVE_POWER_3 -> SensitivityFunctionType.BRANCH_REACTIVE_POWER_3;
case BUS_VOLTAGE -> SensitivityFunctionType.BUS_VOLTAGE;
};
}

Expand Down
4 changes: 2 additions & 2 deletions pypowsybl/sensitivity/impl/ac_sensitivity_analysis_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, result_context_ptr: _pypowsybl.JavaHandle, branches_ids: Dict
self.bus_ids = bus_ids
self.target_voltage_ids = target_voltage_ids

def get_bus_voltages_sensitivity_matrix(self, contingency_id: str = None) -> Optional[pd.DataFrame]:
def get_bus_voltages_sensitivity_matrix(self, matrix_id: str = 'default', contingency_id: str = None) -> Optional[pd.DataFrame]:
"""
Get the matrix of bus voltages sensitivities on the base case or on post contingency state.
Expand All @@ -35,7 +35,7 @@ def get_bus_voltages_sensitivity_matrix(self, contingency_id: str = None) -> Opt
Returns:
the matrix of sensitivities
"""
matrix = _pypowsybl.get_sensitivity_matrix(self.result_context_ptr,
matrix = _pypowsybl.get_sensitivity_matrix(self.result_context_ptr, matrix_id,
'' if contingency_id is None else contingency_id)
if matrix is None:
return None
Expand Down
12 changes: 4 additions & 8 deletions tests/test_sensitivity_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas as pd
from pypowsybl import PyPowsyblError
import pypowsybl.report as rp
from pypowsybl.sensitivity import SensitivityFunctionType, ContingencyContextType
from pypowsybl.sensitivity import SensitivityFunctionType, SensitivityVariableType, ContingencyContextType

TEST_DIR = pathlib.Path(__file__).parent
DATA_DIR = TEST_DIR.parent.joinpath('data')
Expand Down Expand Up @@ -239,10 +239,6 @@ def test_no_output_matrices_available():
df = result.get_branch_flows_sensitivity_matrix('default')
assert (2, 2) == df.shape

with pytest.raises(pp.PyPowsyblError) as errorContext:
result.get_bus_voltages_sensitivity_matrix()
assert 'bus voltage sensitivity matrix does not exist' == str(errorContext.value)

with pytest.raises(pp.PyPowsyblError) as errorContext:
result.get_branch_flows_sensitivity_matrix('')
assert 'Matrix \'\' not found' == str(errorContext.value)
Expand Down Expand Up @@ -316,11 +312,11 @@ def test_add_branch_factor_matrix():
analysis = pp.sensitivity.create_ac_analysis()

analysis.add_factor_matrix(['LINE_S3S4'], ['GTH2'], [], ContingencyContextType.NONE,
SensitivityFunctionType.BRANCH_REACTIVE_POWER_1, 'test')
SensitivityFunctionType.BRANCH_REACTIVE_POWER_1, SensitivityVariableType.BUS_TARGET_VOLTAGE, 'test')
analysis.add_factor_matrix(['LINE_S2S3'], ['GTH1'], [], ContingencyContextType.NONE,
SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, 'test1')
SensitivityFunctionType.BRANCH_ACTIVE_POWER_1, SensitivityVariableType.INJECTION_ACTIVE_POWER, 'test1')
analysis.add_factor_matrix(['LINE_S3S4'], ['GTH2'], [], ContingencyContextType.NONE,
SensitivityFunctionType.BRANCH_CURRENT_1, 'test2')
SensitivityFunctionType.BRANCH_CURRENT_1, SensitivityVariableType.BUS_TARGET_VOLTAGE, 'test2')
result = analysis.run(network)
pytest.approx(result.get_branch_flows_sensitivity_matrix('test').loc['GTH2']['LINE_S3S4'], 30.5280, 0.001)
assert 0.8 == result.get_branch_flows_sensitivity_matrix('test1').loc['GTH1']['LINE_S2S3']
Expand Down

0 comments on commit 2485b55

Please sign in to comment.