diff --git a/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java b/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java index f5608d56fa..026a2a7779 100644 --- a/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java +++ b/java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java @@ -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(); diff --git a/java/src/main/java/com/powsybl/python/commons/Util.java b/java/src/main/java/com/powsybl/python/commons/Util.java index b2a2d56914..d1ad5bc040 100644 --- a/java/src/main/java/com/powsybl/python/commons/Util.java +++ b/java/src/main/java/com/powsybl/python/commons/Util.java @@ -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; }; } diff --git a/pypowsybl/sensitivity/impl/ac_sensitivity_analysis_result.py b/pypowsybl/sensitivity/impl/ac_sensitivity_analysis_result.py index 445b7b9d02..60d656eb26 100644 --- a/pypowsybl/sensitivity/impl/ac_sensitivity_analysis_result.py +++ b/pypowsybl/sensitivity/impl/ac_sensitivity_analysis_result.py @@ -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. @@ -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 diff --git a/tests/test_sensitivity_analysis.py b/tests/test_sensitivity_analysis.py index aff7dfc3c2..eaef55eeed 100644 --- a/tests/test_sensitivity_analysis.py +++ b/tests/test_sensitivity_analysis.py @@ -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') @@ -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) @@ -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']