Skip to content

Commit

Permalink
to revert
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
  • Loading branch information
EtienneLt committed Jun 24, 2024
1 parent 7af2b13 commit c56f59a
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cpp/powsybl-cpp/powsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ typedef enum {
THREE,
} ThreeSide;

typedef struct voltage_range_struct {
double minimum_nominal_voltage;
double maximum_nominal_voltage;
double voltage;
double range_coefficient;
} voltage_range;

typedef struct shortcircuit_analysis_parameters_struct {
unsigned char with_voltage_result;
unsigned char with_feeder_result;
Expand All @@ -383,6 +390,7 @@ typedef struct shortcircuit_analysis_parameters_struct {
unsigned char with_fortescue_result;
double min_voltage_drop_proportional_threshold;
int initial_voltage_profile_mode;
array voltage_ranges;
char** provider_parameters_keys;
int provider_parameters_keys_count;
char** provider_parameters_values;
Expand Down
3 changes: 2 additions & 1 deletion cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,8 @@ void deleteShortCircuitAnalysisParameters(shortcircuit_analysis_parameters* ptr)
pypowsybl::deleteCharPtrPtr(ptr->provider_parameters_values, ptr->provider_parameters_values_count);
}

ShortCircuitAnalysisParameters::ShortCircuitAnalysisParameters(shortcircuit_analysis_parameters* src)
ShortCircuitAnalysisParameters::ShortCircuitAnalysisParameters(shortcircuit_analysis_parameters* src):
voltage_ranges(&src->voltage_ranges)
{
with_feeder_result = (bool) src->with_feeder_result;
with_limit_violations = (bool) src->with_limit_violations;
Expand Down
2 changes: 2 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ typedef Array<post_contingency_result> PostContingencyResultArray;
typedef Array<operator_strategy_result> OperatorStrategyResultArray;
typedef Array<limit_violation> LimitViolationArray;
typedef Array<series> SeriesArray;
typedef Array<voltage_range> VoltageRangeArray;


template<typename T>
Expand Down Expand Up @@ -444,6 +445,7 @@ class ShortCircuitAnalysisParameters {
bool with_fortescue_result;
double min_voltage_drop_proportional_threshold;
InitialVoltageProfileMode initial_voltage_profile_mode;
VoltageRangeArray voltage_ranges;

std::vector<std::string> provider_parameters_keys;
std::vector<std::string> provider_parameters_values;
Expand Down
17 changes: 17 additions & 0 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,22 @@ PYBIND11_MODULE(_pypowsybl, m) {
.value("STEADY_STATE", pypowsybl::ShortCircuitStudyType::STEADY_STATE,
"The last stage of the short circuit, once all transient effects are gone.");

py::class_<voltage_range>(m, "VoltageRange")
.def_property_readonly("minimum_nominal_voltage", [](const voltage_range& v) {
return v.minimum_nominal_voltage;
})
.def_property_readonly("maximum_nominal_voltage", [](const voltage_range& v) {
return v.maximum_nominal_voltage;
})
.def_property_readonly("voltage", [](const voltage_range& v) {
return v.voltage;
})
.def_property_readonly("range_coefficient", [](const voltage_range& v) {
return v.range_coefficient;
});

bindArray<pypowsybl::VoltageRangeArray>(m, "VoltageRangeArray");

py::class_<pypowsybl::ShortCircuitAnalysisParameters>(m, "ShortCircuitAnalysisParameters")
.def(py::init(&pypowsybl::createShortCircuitAnalysisParameters))
.def_readwrite("with_voltage_result", &pypowsybl::ShortCircuitAnalysisParameters::with_voltage_result)
Expand All @@ -1007,6 +1023,7 @@ PYBIND11_MODULE(_pypowsybl, m) {
.def_readwrite("with_fortescue_result", &pypowsybl::ShortCircuitAnalysisParameters::with_fortescue_result)
.def_readwrite("min_voltage_drop_proportional_threshold", &pypowsybl::ShortCircuitAnalysisParameters::min_voltage_drop_proportional_threshold)
.def_readwrite("initial_voltage_profile_mode", &pypowsybl::ShortCircuitAnalysisParameters::initial_voltage_profile_mode)
.def_readwrite("voltage_ranges", &pypowsybl::ShortCircuitAnalysisParameters::voltage_ranges)
.def_readwrite("provider_parameters_keys", &pypowsybl::ShortCircuitAnalysisParameters::provider_parameters_keys)
.def_readwrite("provider_parameters_values", &pypowsybl::ShortCircuitAnalysisParameters::provider_parameters_values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private static ShortCircuitParameters createShortCircuitAnalysisParameters(PyPow

private static List<VoltageRange> createVoltageRangeList(PyPowsyblApiHeader.ArrayPointer<PyPowsyblApiHeader.VoltageRangePointer> voltageRangePointerArrayPointer) {
List<VoltageRange> voltageRanges = new ArrayList<>();
for (int i=0; i<= voltageRangePointerArrayPointer.getLength(); i++) {
for (int i = 0; i <= voltageRangePointerArrayPointer.getLength(); i++) {
PyPowsyblApiHeader.VoltageRangePointer voltageRangePointer = voltageRangePointerArrayPointer.getPtr().addressOf(i);
voltageRanges.add(new VoltageRange(voltageRangePointer.getMinimumNominalVoltage(),
voltageRangePointer.getMaximumNominalVoltage(),
Expand Down
20 changes: 19 additions & 1 deletion pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -689,16 +689,34 @@ class InitialVoltageProfileMode:
CONFIGURED: ClassVar[InitialVoltageProfileMode] = ...
PREVIOUS_VALUE: ClassVar[InitialVoltageProfileMode] = ...

class VoltageRange:
@property
def minimum_nominal_voltage(self) -> float: ...

@property
def maximum_nominal_voltage(self) -> float: ...

@property
def voltage(self) -> float: ...
@property
def range_coefficient(self) -> float: ...

class VoltageRangeArray:
def __iter__(self) -> Iterator: ...
def __len__(self) -> int: ...
def __getitem__(self) -> VoltageRange: ...

class ShortCircuitAnalysisParameters:
with_voltage_result: bool
with_feeder_result: bool
with_limit_violations: bool
study_type: ShortCircuitStudyType
with_fortescue_result: bool
min_voltage_drop_proportional_threshold: float
initial_voltage_profile_mode: InitialVoltageProfileMode
voltage_ranges: VoltageRangeArray
provider_parameters_keys: List[str]
provider_parameters_values: List[str]
initial_voltage_profile_mode: InitialVoltageProfileMode
def __init__(self) -> None: ...

def add_contingency(analysis_context: JavaHandle, contingency_id: str, elements_ids: List[str]) -> None: ...
Expand Down
1 change: 1 addition & 0 deletions pypowsybl/shortcircuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
get_default_provider,
get_provider_names,
get_provider_parameters_names)
from .impl.voltage_range import VoltageRange
11 changes: 10 additions & 1 deletion pypowsybl/shortcircuit/impl/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pypowsybl import _pypowsybl
from pypowsybl._pypowsybl import ShortCircuitStudyType, InitialVoltageProfileMode
from .voltage_range import VoltageRange

ShortCircuitStudyType.__module__ = __name__
ShortCircuitStudyType.__name__ = 'ShortCircuitStudyType'
Expand Down Expand Up @@ -37,6 +38,7 @@ class Parameters: # pylint: disable=too-few-public-methods
min_voltage_drop_proportional_threshold: specifies a threshold for filtering the voltage results.
Only nodes where the voltage drop due to the short circuit is greater than this property are retained.
study_type: specifies the type of short-circuit study. It can be SUB_TRANSIENT, TRANSIENT or STEADY_STATE.
voltage_ranges:
initial_voltage_profile_mode: specify how the computation is initialized. It can be NOMINAL, CONFIGURED or PREVIOUS_VALUE
"""

Expand All @@ -48,7 +50,8 @@ def __init__(self,
study_type: ShortCircuitStudyType = None,
provider_parameters: Dict[str, str] = None,
with_fortescue_result: bool = None,
initial_voltage_profile_mode: InitialVoltageProfileMode = None):
initial_voltage_profile_mode: InitialVoltageProfileMode = None,
voltage_ranges: list[VoltageRange] = None):
self._init_with_default_values()
if with_feeder_result is not None:
self.with_feeder_result = with_feeder_result
Expand All @@ -66,6 +69,8 @@ def __init__(self,
self.with_fortescue_result = with_fortescue_result
if initial_voltage_profile_mode is not None:
self.initial_voltage_profile_mode = initial_voltage_profile_mode
if voltage_ranges is not None:
self.voltage_ranges = voltage_ranges

def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters) -> None:
self.with_feeder_result = c_parameters.with_feeder_result
Expand All @@ -77,6 +82,7 @@ def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters)
zip(c_parameters.provider_parameters_keys, c_parameters.provider_parameters_values))
self.with_fortescue_result = c_parameters.with_fortescue_result
self.initial_voltage_profile_mode = c_parameters.initial_voltage_profile_mode
self.voltage_ranges = c_parameters.voltage_ranges

def _init_with_default_values(self) -> None:
self._init_from_c(_pypowsybl.ShortCircuitAnalysisParameters())
Expand All @@ -87,6 +93,7 @@ def _init_with_default_values(self) -> None:
self.study_type = ShortCircuitStudyType.TRANSIENT
self.with_fortescue_result = False
self.initial_voltage_profile_mode = InitialVoltageProfileMode.NOMINAL
self.voltage_ranges = []

def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
c_parameters = _pypowsybl.ShortCircuitAnalysisParameters()
Expand All @@ -97,6 +104,7 @@ def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
c_parameters.with_fortescue_result = self.with_fortescue_result
c_parameters.min_voltage_drop_proportional_threshold = self.min_voltage_drop_proportional_threshold
c_parameters.initial_voltage_profile_mode = self.initial_voltage_profile_mode
c_parameters.voltage_ranges = []
c_parameters.provider_parameters_keys = []
c_parameters.provider_parameters_values = []
return c_parameters
Expand All @@ -110,4 +118,5 @@ def __repr__(self) -> str:
f", study_type={self.study_type!r}" \
f", with_fortescue_result={self.with_fortescue_result!r}" \
f", initial_voltage_profile_mode={self.initial_voltage_profile_mode!r}" \
f", voltage_ranges={self.voltage_ranges!r}" \
f")"
5 changes: 5 additions & 0 deletions tests/test_shortcircuit_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#
import pypowsybl as pp
import pypowsybl.network as pn
from pypowsybl.shortcircuit import VoltageRange
import pytest
import pathlib
import pandas as pd
Expand Down Expand Up @@ -83,3 +84,7 @@ def test_run_analysis():
# run the short-circuit analysis using a nonexistent provider
with pytest.raises(Exception, match='No short-circuit analysis provider for name \'provider-unknown\''):
results = sc.run(n, pars, 'provider-unknown')


def test_voltage_range_parameter():
pars = pp.shortcircuit.Parameters(voltage_ranges=[VoltageRange(1, 2, 3, 4)])

0 comments on commit c56f59a

Please sign in to comment.