Skip to content

Commit

Permalink
add new shortCircuit parameter
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 5, 2024
1 parent d0eb810 commit 950fc05
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 6 deletions.
9 changes: 8 additions & 1 deletion cpp/powsybl-cpp/powsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ typedef struct shortcircuit_analysis_parameters_struct {
int study_type;
unsigned char with_fortescue_result;
double min_voltage_drop_proportional_threshold;
int initial_voltage_profile_mode;
char** provider_parameters_keys;
int provider_parameters_keys_count;
char** provider_parameters_values;
Expand All @@ -397,4 +398,10 @@ typedef enum {
MIN_GENERATION = 0,
BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT,
SPECIFIC_VOLTAGE_PROFILE,
} VoltageInitializerObjective;
} VoltageInitializerObjective;

typedef enum {
NOMINAL = 0,
CONFIGURED,
PREVIOUS_VALUE,
} InitialVoltageProfileMode;
2 changes: 2 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ ShortCircuitAnalysisParameters::ShortCircuitAnalysisParameters(shortcircuit_anal
with_fortescue_result = (bool) src->with_fortescue_result;
with_voltage_result = (bool) src->with_voltage_result;
min_voltage_drop_proportional_threshold = (double) src->min_voltage_drop_proportional_threshold;
initial_voltage_profile_mode = static_cast<InitialVoltageProfileMode>(src->initial_voltage_profile_mode);

copyCharPtrPtrToVector(src->provider_parameters_keys, src->provider_parameters_keys_count, provider_parameters_keys);
copyCharPtrPtrToVector(src->provider_parameters_values, src->provider_parameters_values_count, provider_parameters_values);
Expand All @@ -1365,6 +1366,7 @@ std::shared_ptr<shortcircuit_analysis_parameters> ShortCircuitAnalysisParameters
res->study_type = study_type;
res->with_fortescue_result = (bool) with_fortescue_result;
res->min_voltage_drop_proportional_threshold = min_voltage_drop_proportional_threshold;
res->initial_voltage_profile_mode = initial_voltage_profile_mode;

res->provider_parameters_keys = pypowsybl::copyVectorStringToCharPtrPtr(provider_parameters_keys);
res->provider_parameters_keys_count = provider_parameters_keys.size();
Expand Down
7 changes: 7 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ enum ShortCircuitStudyType {
STEADY_STATE
};

enum InitialVoltageProfileMode {
NOMINAL = 0,
CONFIGURED,
PREVIOUS_VALUE
};

class ShortCircuitAnalysisParameters {
public:
ShortCircuitAnalysisParameters(shortcircuit_analysis_parameters* src);
Expand All @@ -437,6 +443,7 @@ class ShortCircuitAnalysisParameters {
ShortCircuitStudyType study_type;
bool with_fortescue_result;
double min_voltage_drop_proportional_threshold;
InitialVoltageProfileMode initial_voltage_profile_mode;

std::vector<std::string> provider_parameters_keys;
std::vector<std::string> provider_parameters_values;
Expand Down
11 changes: 10 additions & 1 deletion cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void voltageInitializerBinding(py::module_& m) {
.value("MIN_GENERATION", VoltageInitializerObjective::MIN_GENERATION)
.value("BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT", VoltageInitializerObjective::BETWEEN_HIGH_AND_LOW_VOLTAGE_LIMIT)
.value("SPECIFIC_VOLTAGE_PROFILE", VoltageInitializerObjective::SPECIFIC_VOLTAGE_PROFILE);

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

m.def("voltage_initializer_add_variable_shunt_compensators", &pypowsybl::voltageInitializerAddVariableShuntCompensators, py::arg("params_handle"), py::arg("id_ptr"));
Expand Down Expand Up @@ -943,6 +943,14 @@ PYBIND11_MODULE(_pypowsybl, m) {

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"));

py::enum_<pypowsybl::InitialVoltageProfileMode>(m, "InitialVoltageProfileMode", "configure the initialization of short circuit study")
.value("NOMINAL", pypowsybl::InitialVoltageProfileMode::NOMINAL,
"")
.value("CONFIGURED", pypowsybl::InitialVoltageProfileMode::CONFIGURED,
"Voltage profile given by the user.")
.value("PREVIOUS_VALUE", pypowsybl::InitialVoltageProfileMode::PREVIOUS_VALUE,
"Voltage profile from the loadflow.");

py::enum_<pypowsybl::ShortCircuitStudyType>(m, "ShortCircuitStudyType", "Indicates the type of short circuit study")
.value("SUB_TRANSIENT", pypowsybl::ShortCircuitStudyType::SUB_TRANSIENT,
"It is the first stage of the short circuit, right when the fault happens. The subtransient reactance of generators will be used.")
Expand All @@ -959,6 +967,7 @@ PYBIND11_MODULE(_pypowsybl, m) {
.def_readwrite("study_type", &pypowsybl::ShortCircuitAnalysisParameters::study_type)
.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("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 @@ -1224,6 +1224,12 @@ public interface ShortCircuitAnalysisParametersPointer extends PointerBase {
@CField("min_voltage_drop_proportional_threshold")
void setMinVoltageDropProportionalThreshold(double minVoltageDropProportionalThreshold);

@CField("initial_voltage_profile_mode")
int getInitialVoltageProfileMode();

@CField("initial_voltage_profile_mode")
void setInitialVoltageProfileMode(int initialVoltageProfileMode);

@CField("provider_parameters_keys")
void setProviderParametersKeys(CCharPointerPointer providerParametersKeys);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ private static ShortCircuitAnalysisParametersPointer convertToShortCircuitAnalys
paramsPtr.setWithFortescueResult(parameters.isWithFortescueResult());
paramsPtr.setMinVoltageDropProportionalThreshold(parameters.getMinVoltageDropProportionalThreshold());
paramsPtr.setStudyType(parameters.getStudyType().ordinal());
paramsPtr.setInitialVoltageProfileMode(parameters.getInitialVoltageProfileMode().ordinal());
paramsPtr.setProviderParametersValuesCount(0);
paramsPtr.setProviderParametersKeysCount(0);
return paramsPtr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.powsybl.python.commons.CTypeUtil;
import com.powsybl.python.commons.PyPowsyblApiHeader;
import com.powsybl.python.commons.PyPowsyblConfiguration;
import com.powsybl.shortcircuit.InitialVoltageProfileMode;
import com.powsybl.shortcircuit.ShortCircuitAnalysisProvider;
import com.powsybl.shortcircuit.ShortCircuitParameters;
import com.powsybl.shortcircuit.StudyType;
Expand Down Expand Up @@ -61,6 +62,7 @@ private static ShortCircuitParameters createShortCircuitAnalysisParameters(PyPow
.setWithFortescueResult(shortCircuitAnalysisParametersPointer.isWithFortescueResult())
.setWithLimitViolations(shortCircuitAnalysisParametersPointer.isWithLimitViolations())
.setMinVoltageDropProportionalThreshold(shortCircuitAnalysisParametersPointer.getMinVoltageDropProportionalThreshold())
.setInitialVoltageProfileMode(InitialVoltageProfileMode.values()[shortCircuitAnalysisParametersPointer.getInitialVoltageProfileMode()])
.setStudyType(StudyType.values()[shortCircuitAnalysisParametersPointer.getStudyType()]);
}

Expand Down
7 changes: 7 additions & 0 deletions pypowsybl/_pypowsybl.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,12 @@ class ShortCircuitStudyType:
TRANSIENT: ClassVar[ShortCircuitStudyType] = ...
STEADY_STATE: ClassVar[ShortCircuitStudyType] = ...

class InitialVoltageProfileMode:
__members__: ClassVar[Dict[str, InitialVoltageProfileMode]] = ... # read-only
NOMINAL: ClassVar[InitialVoltageProfileMode] = ...
CONFIGURED: ClassVar[InitialVoltageProfileMode] = ...
PREVIOUS_VALUE: ClassVar[InitialVoltageProfileMode] = ...

class ShortCircuitAnalysisParameters:
with_voltage_result: bool
with_feeder_result: bool
Expand All @@ -670,6 +676,7 @@ class ShortCircuitAnalysisParameters:
min_voltage_drop_proportional_threshold: float
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
2 changes: 1 addition & 1 deletion pypowsybl/shortcircuit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
#
from .impl.parameters import Parameters, ShortCircuitStudyType
from .impl.parameters import Parameters, ShortCircuitStudyType, InitialVoltageProfileMode
from .impl.short_circuit_analysis import ShortCircuitAnalysis
from .impl.short_circuit_analysis_result import ShortCircuitAnalysisResult
from .impl.util import (create_analysis,
Expand Down
14 changes: 12 additions & 2 deletions pypowsybl/shortcircuit/impl/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
from typing import Dict

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

ShortCircuitStudyType.__module__ = __name__
ShortCircuitStudyType.__name__ = 'ShortCircuitStudyType'
InitialVoltageProfileMode.__module__ = __name__
InitialVoltageProfileMode.__name__ = 'InitialVoltageProfileMode'


class Parameters: # pylint: disable=too-few-public-methods
Expand All @@ -35,6 +37,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.
initial_voltage_profile_mode: specify how the computation is initialized. It can be NOMINAL, CONFIGURED or PREVIOUS_VALUE
"""

def __init__(self,
Expand All @@ -44,7 +47,8 @@ def __init__(self,
min_voltage_drop_proportional_threshold: float = None,
study_type: ShortCircuitStudyType = None,
provider_parameters: Dict[str, str] = None,
with_fortescue_result: bool = None):
with_fortescue_result: bool = None,
initial_voltage_profile_mode: InitialVoltageProfileMode = None):
self._init_with_default_values()
if with_feeder_result is not None:
self.with_feeder_result = with_feeder_result
Expand All @@ -60,6 +64,8 @@ def __init__(self,
self.provider_parameters = provider_parameters
if with_fortescue_result is not None:
self.with_fortescue_result = with_fortescue_result
if initial_voltage_profile_mode is not None:
self.initial_voltage_profile_mode = initial_voltage_profile_mode

def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters) -> None:
self.with_feeder_result = c_parameters.with_feeder_result
Expand All @@ -70,6 +76,7 @@ def _init_from_c(self, c_parameters: _pypowsybl.ShortCircuitAnalysisParameters)
self.provider_parameters = dict(
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

def _init_with_default_values(self) -> None:
self._init_from_c(_pypowsybl.ShortCircuitAnalysisParameters())
Expand All @@ -79,6 +86,7 @@ def _init_with_default_values(self) -> None:
self.min_voltage_drop_proportional_threshold = 0
self.study_type = ShortCircuitStudyType.TRANSIENT
self.with_fortescue_result = False
self.initial_voltage_profile_mode = InitialVoltageProfileMode.NOMINAL

def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
c_parameters = _pypowsybl.ShortCircuitAnalysisParameters()
Expand All @@ -88,6 +96,7 @@ def _to_c_parameters(self) -> _pypowsybl.ShortCircuitAnalysisParameters:
c_parameters.study_type = self.study_type
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.provider_parameters_keys = []
c_parameters.provider_parameters_values = []
return c_parameters
Expand All @@ -100,4 +109,5 @@ def __repr__(self) -> str:
f", min_voltage_drop_proportional_threshold={self.min_voltage_drop_proportional_threshold!r}" \
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")"
4 changes: 3 additions & 1 deletion tests/test_shortcircuit_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ def test_run_analysis():
pars = pp.shortcircuit.Parameters(with_feeder_result=False, with_limit_violations=False,
with_voltage_result=False, min_voltage_drop_proportional_threshold=0,
study_type=pp.shortcircuit.ShortCircuitStudyType.TRANSIENT,
with_fortescue_result=True)
with_fortescue_result=True,
initial_voltage_profile_mode=pp.shortcircuit.InitialVoltageProfileMode.PREVIOUS_VALUE)
assert pars is not None
assert not pars.with_feeder_result
assert not pars.with_limit_violations
assert not pars.with_voltage_result
assert pars.min_voltage_drop_proportional_threshold == 0
assert pars.study_type == pp.shortcircuit.ShortCircuitStudyType.TRANSIENT
assert pars.with_fortescue_result
assert pars.initial_voltage_profile_mode == pp.shortcircuit.InitialVoltageProfileMode.PREVIOUS_VALUE

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

0 comments on commit 950fc05

Please sign in to comment.