Skip to content

Commit 2dec5a4

Browse files
committed
add new shortCircuit parameter
Signed-off-by: Etienne LESOT <etienne.lesot@rte-france.com>
1 parent d0eb810 commit 2dec5a4

File tree

11 files changed

+63
-5
lines changed

11 files changed

+63
-5
lines changed

cpp/powsybl-cpp/powsybl-api.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ typedef struct shortcircuit_analysis_parameters_struct {
382382
int study_type;
383383
unsigned char with_fortescue_result;
384384
double min_voltage_drop_proportional_threshold;
385+
int initial_voltage_profile_mode;
385386
char** provider_parameters_keys;
386387
int provider_parameters_keys_count;
387388
char** provider_parameters_values;
@@ -397,4 +398,10 @@ typedef enum {
397398
MIN_GENERATION = 0,
398399
BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT,
399400
SPECIFIC_VOLTAGE_PROFILE,
400-
} VoltageInitializerObjective;
401+
} VoltageInitializerObjective;
402+
403+
typedef enum {
404+
NOMINAL = 0,
405+
CONFIGURED,
406+
PREVIOUS_VALUE,
407+
} InitialVoltageProfileMode;

cpp/powsybl-cpp/powsybl-cpp.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ ShortCircuitAnalysisParameters::ShortCircuitAnalysisParameters(shortcircuit_anal
13521352
with_fortescue_result = (bool) src->with_fortescue_result;
13531353
with_voltage_result = (bool) src->with_voltage_result;
13541354
min_voltage_drop_proportional_threshold = (double) src->min_voltage_drop_proportional_threshold;
1355+
initial_voltage_profile_mode = static_cast<InitialVoltageProfileMode>(src->initial_voltage_profile_mode);
13551356

13561357
copyCharPtrPtrToVector(src->provider_parameters_keys, src->provider_parameters_keys_count, provider_parameters_keys);
13571358
copyCharPtrPtrToVector(src->provider_parameters_values, src->provider_parameters_values_count, provider_parameters_values);
@@ -1365,6 +1366,7 @@ std::shared_ptr<shortcircuit_analysis_parameters> ShortCircuitAnalysisParameters
13651366
res->study_type = study_type;
13661367
res->with_fortescue_result = (bool) with_fortescue_result;
13671368
res->min_voltage_drop_proportional_threshold = min_voltage_drop_proportional_threshold;
1369+
res->initial_voltage_profile_mode = initial_voltage_profile_mode;
13681370

13691371
res->provider_parameters_keys = pypowsybl::copyVectorStringToCharPtrPtr(provider_parameters_keys);
13701372
res->provider_parameters_keys_count = provider_parameters_keys.size();

cpp/powsybl-cpp/powsybl-cpp.h

+7
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ enum ShortCircuitStudyType {
426426
STEADY_STATE
427427
};
428428

429+
enum InitialVoltageProfileMode {
430+
NOMINAL = 0,
431+
CONFIGURED,
432+
PREVIOUS_VALUE
433+
};
434+
429435
class ShortCircuitAnalysisParameters {
430436
public:
431437
ShortCircuitAnalysisParameters(shortcircuit_analysis_parameters* src);
@@ -437,6 +443,7 @@ class ShortCircuitAnalysisParameters {
437443
ShortCircuitStudyType study_type;
438444
bool with_fortescue_result;
439445
double min_voltage_drop_proportional_threshold;
446+
InitialVoltageProfileMode initial_voltage_profile_mode;
440447

441448
std::vector<std::string> provider_parameters_keys;
442449
std::vector<std::string> provider_parameters_values;

cpp/pypowsybl-cpp/bindings.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ void voltageInitializerBinding(py::module_& m) {
187187
.value("MIN_GENERATION", VoltageInitializerObjective::MIN_GENERATION)
188188
.value("BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT", VoltageInitializerObjective::BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT)
189189
.value("SPECIFIC_VOLTAGE_PROFILE", VoltageInitializerObjective::SPECIFIC_VOLTAGE_PROFILE);
190+
191+
py::enum_<InitialVoltageProfileMode>(m, "InitialVoltageProfileMode")
192+
.value("NOMINAL", InitialVoltageProfileMode::NOMINAL)
193+
.value("CONFIGURED", InitialVoltageProfileMode::CONFIGURED)
194+
.value("PREVIOUS_VALUE", InitialVoltageProfileMode::PREVIOUS_VALUE);
190195

191196
m.def("create_voltage_initializer_params", &pypowsybl::createVoltageInitializerParams);
192197

@@ -943,6 +948,14 @@ PYBIND11_MODULE(_pypowsybl, m) {
943948

944949
m.def("create_network_modification", ::createNetworkModificationBind, "Create and apply network modification", py::arg("network"), py::arg("dataframe"), py::arg("network_modification_type"), py::arg("raise_exception"), py::arg("report_node"));
945950

951+
py::enum_<pypowsybl::ShortCircuitStudyType>(m, "ShortCircuitStudyType", "Indicates the type of short circuit study")
952+
.value("SUB_TRANSIENT", pypowsybl::ShortCircuitStudyType::SUB_TRANSIENT,
953+
"It is the first stage of the short circuit, right when the fault happens. The subtransient reactance of generators will be used.")
954+
.value("TRANSIENT", pypowsybl::ShortCircuitStudyType::TRANSIENT,
955+
"The second stage of the short circuit, before the system stabilizes. The transient reactance of generators will be used.")
956+
.value("STEADY_STATE", pypowsybl::ShortCircuitStudyType::STEADY_STATE,
957+
"The last stage of the short circuit, once all transient effects are gone.");
958+
946959
py::enum_<pypowsybl::ShortCircuitStudyType>(m, "ShortCircuitStudyType", "Indicates the type of short circuit study")
947960
.value("SUB_TRANSIENT", pypowsybl::ShortCircuitStudyType::SUB_TRANSIENT,
948961
"It is the first stage of the short circuit, right when the fault happens. The subtransient reactance of generators will be used.")
@@ -959,6 +972,7 @@ PYBIND11_MODULE(_pypowsybl, m) {
959972
.def_readwrite("study_type", &pypowsybl::ShortCircuitAnalysisParameters::study_type)
960973
.def_readwrite("with_fortescue_result", &pypowsybl::ShortCircuitAnalysisParameters::with_fortescue_result)
961974
.def_readwrite("min_voltage_drop_proportional_threshold", &pypowsybl::ShortCircuitAnalysisParameters::min_voltage_drop_proportional_threshold)
975+
.def_readwrite("initial_voltage_profile_mode", &pypowsybl::ShortCircuitAnalysisParameters::initial_voltage_profile_mode)
962976
.def_readwrite("provider_parameters_keys", &pypowsybl::ShortCircuitAnalysisParameters::provider_parameters_keys)
963977
.def_readwrite("provider_parameters_values", &pypowsybl::ShortCircuitAnalysisParameters::provider_parameters_values);
964978

java/src/main/java/com/powsybl/python/commons/PyPowsyblApiHeader.java

+6
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,12 @@ public interface ShortCircuitAnalysisParametersPointer extends PointerBase {
12241224
@CField("min_voltage_drop_proportional_threshold")
12251225
void setMinVoltageDropProportionalThreshold(double minVoltageDropProportionalThreshold);
12261226

1227+
@CField("initial_voltage_profile_mode")
1228+
int getInitialVoltageProfileMode();
1229+
1230+
@CField("initial_voltage_profile_mode")
1231+
void setInitialVoltageProfileMode(int initialVoltageProfileMode);
1232+
12271233
@CField("provider_parameters_keys")
12281234
void setProviderParametersKeys(CCharPointerPointer providerParametersKeys);
12291235

java/src/main/java/com/powsybl/python/shortcircuit/ShortCircuitAnalysisCFunctions.java

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private static ShortCircuitAnalysisParametersPointer convertToShortCircuitAnalys
126126
paramsPtr.setWithFortescueResult(parameters.isWithFortescueResult());
127127
paramsPtr.setMinVoltageDropProportionalThreshold(parameters.getMinVoltageDropProportionalThreshold());
128128
paramsPtr.setStudyType(parameters.getStudyType().ordinal());
129+
paramsPtr.setInitialVoltageProfileMode(parameters.getInitialVoltageProfileMode().ordinal());
129130
paramsPtr.setProviderParametersValuesCount(0);
130131
paramsPtr.setProviderParametersKeysCount(0);
131132
return paramsPtr;

java/src/main/java/com/powsybl/python/shortcircuit/ShortCircuitAnalysisCUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.powsybl.python.commons.CTypeUtil;
1313
import com.powsybl.python.commons.PyPowsyblApiHeader;
1414
import com.powsybl.python.commons.PyPowsyblConfiguration;
15+
import com.powsybl.shortcircuit.InitialVoltageProfileMode;
1516
import com.powsybl.shortcircuit.ShortCircuitAnalysisProvider;
1617
import com.powsybl.shortcircuit.ShortCircuitParameters;
1718
import com.powsybl.shortcircuit.StudyType;
@@ -61,6 +62,7 @@ private static ShortCircuitParameters createShortCircuitAnalysisParameters(PyPow
6162
.setWithFortescueResult(shortCircuitAnalysisParametersPointer.isWithFortescueResult())
6263
.setWithLimitViolations(shortCircuitAnalysisParametersPointer.isWithLimitViolations())
6364
.setMinVoltageDropProportionalThreshold(shortCircuitAnalysisParametersPointer.getMinVoltageDropProportionalThreshold())
65+
.setInitialVoltageProfileMode(InitialVoltageProfileMode.values()[shortCircuitAnalysisParametersPointer.getInitialVoltageProfileMode()])
6466
.setStudyType(StudyType.values()[shortCircuitAnalysisParametersPointer.getStudyType()]);
6567
}
6668

pypowsybl/_pypowsybl.pyi

+7
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ class ShortCircuitStudyType:
661661
TRANSIENT: ClassVar[ShortCircuitStudyType] = ...
662662
STEADY_STATE: ClassVar[ShortCircuitStudyType] = ...
663663

664+
class InitialVoltageProfileMode:
665+
__members__: ClassVar[Dict[str, InitialVoltageProfileMode]] = ... # read-only
666+
NOMINAL: ClassVar[InitialVoltageProfileMode] = ...
667+
CONFIGURED: ClassVar[InitialVoltageProfileMode] = ...
668+
PREVIOUS_VALUE: ClassVar[InitialVoltageProfileMode] = ...
669+
664670
class ShortCircuitAnalysisParameters:
665671
with_voltage_result: bool
666672
with_feeder_result: bool
@@ -670,6 +676,7 @@ class ShortCircuitAnalysisParameters:
670676
min_voltage_drop_proportional_threshold: float
671677
provider_parameters_keys: List[str]
672678
provider_parameters_values: List[str]
679+
initial_voltage_profile_mode: InitialVoltageProfileMode
673680
def __init__(self) -> None: ...
674681

675682
def add_contingency(analysis_context: JavaHandle, contingency_id: str, elements_ids: List[str]) -> None: ...

pypowsybl/shortcircuit/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
55
# SPDX-License-Identifier: MPL-2.0
66
#
7-
from .impl.parameters import Parameters, ShortCircuitStudyType
7+
from .impl.parameters import Parameters, ShortCircuitStudyType, InitialVoltageProfileMode
88
from .impl.short_circuit_analysis import ShortCircuitAnalysis
99
from .impl.short_circuit_analysis_result import ShortCircuitAnalysisResult
1010
from .impl.util import (create_analysis,

pypowsybl/shortcircuit/impl/parameters.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
from typing import Dict
88

99
from pypowsybl import _pypowsybl
10-
from pypowsybl._pypowsybl import ShortCircuitStudyType
10+
from pypowsybl._pypowsybl import ShortCircuitStudyType, InitialVoltageProfileMode
1111

1212
ShortCircuitStudyType.__module__ = __name__
1313
ShortCircuitStudyType.__name__ = 'ShortCircuitStudyType'
14+
InitialVoltageProfileMode.__module__ = __name__
15+
InitialVoltageProfileMode.__name__ = 'InitialVoltageProfileMode'
1416

1517

1618
class Parameters: # pylint: disable=too-few-public-methods
@@ -35,6 +37,7 @@ class Parameters: # pylint: disable=too-few-public-methods
3537
min_voltage_drop_proportional_threshold: specifies a threshold for filtering the voltage results.
3638
Only nodes where the voltage drop due to the short circuit is greater than this property are retained.
3739
study_type: specifies the type of short-circuit study. It can be SUB_TRANSIENT, TRANSIENT or STEADY_STATE.
40+
initial_voltage_profile_mode: specify how the computation is initialized. It can be NOMINAL, CONFIGURED or PREVIOUS_VALUE
3841
"""
3942

4043
def __init__(self,
@@ -44,7 +47,8 @@ def __init__(self,
4447
min_voltage_drop_proportional_threshold: float = None,
4548
study_type: ShortCircuitStudyType = None,
4649
provider_parameters: Dict[str, str] = None,
47-
with_fortescue_result: bool = None):
50+
with_fortescue_result: bool = None,
51+
initial_voltage_profile_mode: InitialVoltageProfileMode = None):
4852
self._init_with_default_values()
4953
if with_feeder_result is not None:
5054
self.with_feeder_result = with_feeder_result
@@ -60,6 +64,8 @@ def __init__(self,
6064
self.provider_parameters = provider_parameters
6165
if with_fortescue_result is not None:
6266
self.with_fortescue_result = with_fortescue_result
67+
if initial_voltage_profile_mode is not None:
68+
self.initial_voltage_profile_mode = initial_voltage_profile_mode
6369

6470
def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters) -> None:
6571
self.with_feeder_result = c_parameters.with_feeder_result
@@ -70,6 +76,7 @@ def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters)
7076
self.provider_parameters = dict(
7177
zip(c_parameters.provider_parameters_keys, c_parameters.provider_parameters_values))
7278
self.with_fortescue_result = c_parameters.with_fortescue_result
79+
self.initial_voltage_profile_mode = c_parameters.initial_voltage_profile_mode
7380

7481
def _init_with_default_values(self) -> None:
7582
self._init_from_c(_pypowsybl.ShortCircuitAnalysisParameters())
@@ -79,6 +86,7 @@ def _init_with_default_values(self) -> None:
7986
self.min_voltage_drop_proportional_threshold = 0
8087
self.study_type = ShortCircuitStudyType.TRANSIENT
8188
self.with_fortescue_result = False
89+
self.initial_voltage_profile_mode = InitialVoltageProfileMode.NOMINAL
8290

8391
def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
8492
c_parameters = _pypowsybl.ShortCircuitAnalysisParameters()
@@ -88,6 +96,7 @@ def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
8896
c_parameters.study_type = self.study_type
8997
c_parameters.with_fortescue_result = self.with_fortescue_result
9098
c_parameters.min_voltage_drop_proportional_threshold = self.min_voltage_drop_proportional_threshold
99+
c_parameters.initial_voltage_profile_mode = self.initial_voltage_profile_mode
91100
c_parameters.provider_parameters_keys = []
92101
c_parameters.provider_parameters_values = []
93102
return c_parameters
@@ -100,4 +109,5 @@ def __repr__(self) -> str:
100109
f", min_voltage_drop_proportional_threshold={self.min_voltage_drop_proportional_threshold!r}" \
101110
f", study_type={self.study_type!r}" \
102111
f", with_fortescue_result={self.with_fortescue_result!r}" \
112+
f", initial_voltage_profile_mode={self.initial_voltage_profile_mode!r}" \
103113
f")"

tests/test_shortcircuit_analysis.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ def test_run_analysis():
5757
pars = pp.shortcircuit.Parameters(with_feeder_result=False, with_limit_violations=False,
5858
with_voltage_result=False, min_voltage_drop_proportional_threshold=0,
5959
study_type=pp.shortcircuit.ShortCircuitStudyType.TRANSIENT,
60-
with_fortescue_result=True)
60+
with_fortescue_result=True,
61+
initial_voltage_profile_mode=pp.shortcircuit.InitialVoltageProfileMode.PREVIOUS_VALUE)
6162
assert pars is not None
6263
assert not pars.with_feeder_result
6364
assert not pars.with_limit_violations
6465
assert not pars.with_voltage_result
6566
assert pars.min_voltage_drop_proportional_threshold == 0
6667
assert pars.study_type == pp.shortcircuit.ShortCircuitStudyType.TRANSIENT
6768
assert pars.with_fortescue_result
69+
assert pars.initial_voltage_profile_mode == pp.shortcircuit.InitialVoltageProfileMode.PREVIOUS_VALUE
6870

6971
# create a short-circuit analysis context
7072
sc = pp.shortcircuit.create_analysis()

0 commit comments

Comments
 (0)