Skip to content

Commit

Permalink
Merge branch 'main' into nad_fixed_positions_param
Browse files Browse the repository at this point in the history
  • Loading branch information
CBiasuzzi committed Jan 17, 2025
2 parents 3784e49 + 1d563ca commit 4c3958b
Show file tree
Hide file tree
Showing 364 changed files with 2,215 additions and 551 deletions.
38 changes: 38 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1680,4 +1680,42 @@ JavaHandle createDefaultRaoParameters() {
return pypowsybl::PowsyblCaller::get()->callJava<JavaHandle>(::createDefaultRaoParameters);
}

JavaHandle createGrid2opBackend(const JavaHandle& networkHandle, bool considerOpenBranchReactiveFlow, int busesPerVoltageLevel, bool connectAllElementsToFirstBus) {
return pypowsybl::PowsyblCaller::get()->callJava<JavaHandle>(::createGrid2opBackend, networkHandle, considerOpenBranchReactiveFlow, busesPerVoltageLevel, connectAllElementsToFirstBus);
}

void freeGrid2opBackend(const JavaHandle& backendHandle) {
pypowsybl::PowsyblCaller::get()->callJava(::freeGrid2opBackend, backendHandle);
}

std::vector<std::string> getGrid2opStringValue(const JavaHandle& backendHandle, Grid2opStringValueType valueType) {
auto stringValueArrayPtr = pypowsybl::PowsyblCaller::get()->callJava<array*>(::getGrid2opStringValue, backendHandle, valueType);
return toVector<std::string>(stringValueArrayPtr); // do not release, will be done when freeing backend
}

array* getGrid2opIntegerValue(const JavaHandle& backendHandle, Grid2opIntegerValueType valueType) {
return pypowsybl::PowsyblCaller::get()->callJava<array*>(::getGrid2opIntegerValue, backendHandle, valueType); // do not release, will be done when freeing backend
}

array* getGrid2opDoubleValue(const JavaHandle& backendHandle, Grid2opDoubleValueType valueType) {
return pypowsybl::PowsyblCaller::get()->callJava<array*>(::getGrid2opDoubleValue, backendHandle, valueType); // do not release, will be done when freeing backend
}

void updateGrid2opDoubleValue(const JavaHandle& backendHandle, Grid2opUpdateDoubleValueType valueType, double* valuePtr, int* changedPtr) {
pypowsybl::PowsyblCaller::get()->callJava(::updateGrid2opDoubleValue, backendHandle, valueType, valuePtr, changedPtr);
}

void updateGrid2opIntegerValue(const JavaHandle& backendHandle, Grid2opUpdateIntegerValueType valueType, int* valuePtr, int* changedPtr) {
pypowsybl::PowsyblCaller::get()->callJava(::updateGrid2opIntegerValue, backendHandle, valueType, valuePtr, changedPtr);
}

bool checkGrid2opIsolatedAndDisconnectedInjections(const JavaHandle& backendHandle) {
return pypowsybl::PowsyblCaller::get()->callJava<bool>(::checkGrid2opIsolatedAndDisconnectedInjections, backendHandle);
}

LoadFlowComponentResultArray* runGrid2opLoadFlow(const JavaHandle& network, bool dc, const LoadFlowParameters& parameters) {
auto c_parameters = parameters.to_c_struct();
return new LoadFlowComponentResultArray(PowsyblCaller::get()->callJava<array*>(::runGrid2opLoadFlow, network, dc, c_parameters.get()));
}

}
10 changes: 10 additions & 0 deletions cpp/powsybl-cpp/powsybl-cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -855,5 +855,15 @@ JavaHandle getRaoResult(const JavaHandle& raoContext);
RaoComputationStatus getRaoResultStatus(const JavaHandle& raoResult);
JavaHandle createDefaultRaoParameters();

JavaHandle createGrid2opBackend(const JavaHandle& networkHandle, bool considerOpenBranchReactiveFlow, int busesPerVoltageLevel, bool connectAllElementsToFirstBus);
void freeGrid2opBackend(const JavaHandle& backendHandle);
std::vector<std::string> getGrid2opStringValue(const JavaHandle& backendHandle, Grid2opStringValueType valueType);
array* getGrid2opIntegerValue(const JavaHandle& backendHandle, Grid2opIntegerValueType valueType);
array* getGrid2opDoubleValue(const JavaHandle& backendHandle, Grid2opDoubleValueType valueType);
void updateGrid2opDoubleValue(const JavaHandle& backendHandle, Grid2opUpdateDoubleValueType valueType, double* valuePtr, int* changedPtr);
void updateGrid2opIntegerValue(const JavaHandle& backendHandle, Grid2opUpdateIntegerValueType valueType, int* valuePtr, int* changedPtr);
bool checkGrid2opIsolatedAndDisconnectedInjections(const JavaHandle& backendHandle);
LoadFlowComponentResultArray* runGrid2opLoadFlow(const JavaHandle& network, bool dc, const LoadFlowParameters& parameters);

}
#endif //PYPOWSYBL_H
89 changes: 89 additions & 0 deletions cpp/pypowsybl-cpp/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,36 @@ py::array seriesAsNumpyArray(const series& series) {
return py::array(py::dtype::of<T>(), series.data.length, series.data.ptr, py::cast(series));
}

py::memoryview pyGetGrid2opIntegerValue(const pypowsybl::JavaHandle& backendHandle, Grid2opIntegerValueType valueType) {
::array* array = pypowsybl::getGrid2opIntegerValue(backendHandle, valueType);
return py::memoryview::from_buffer(
static_cast<int*>(array->ptr),
{ array->length },
{ sizeof(int) }
);
}

py::memoryview pyGetGrid2opDoubleValue(const pypowsybl::JavaHandle& backendHandle, Grid2opDoubleValueType valueType) {
::array* array = pypowsybl::getGrid2opDoubleValue(backendHandle, valueType);
return py::memoryview::from_buffer(
static_cast<double*>(array->ptr),
{ array->length },
{ sizeof(double) }
);
}

void pyUpdateGrid2opDoubleValue(const pypowsybl::JavaHandle& backendHandle, Grid2opUpdateDoubleValueType valueType,
py::array_t<double, py::array::c_style | py::array::forcecast> value_array,
py::array_t<int, py::array::c_style | py::array::forcecast> changed_array) {
pypowsybl::updateGrid2opDoubleValue(backendHandle, valueType, value_array.mutable_data(), changed_array.mutable_data());
}

void pyUpdateGrid2opIntegerValue(const pypowsybl::JavaHandle& backendHandle, Grid2opUpdateIntegerValueType valueType,
py::array_t<int, py::array::c_style | py::array::forcecast> value_array,
py::array_t<int, py::array::c_style | py::array::forcecast> changed_array) {
pypowsybl::updateGrid2opIntegerValue(backendHandle, valueType, value_array.mutable_data(), changed_array.mutable_data());
}

void dynamicSimulationBindings(py::module_& m) {

py::enum_<DynamicMappingType>(m, "DynamicMappingType")
Expand Down Expand Up @@ -1129,6 +1159,65 @@ PYBIND11_MODULE(_pypowsybl, m) {
m.def("serialize_rao_results_to_buffer", ::saveRaoResultsToBinaryBuffer, "Run a rao", py::arg("rao_result"), py::arg("crac"));
m.def("get_rao_result_status", &pypowsybl::getRaoResultStatus, "Get the status of a rao result", py::arg("rao_result"));

py::enum_<Grid2opStringValueType>(m, "Grid2opStringValueType")
.value("VOLTAGE_LEVEL_NAME", Grid2opStringValueType::VOLTAGE_LEVEL_NAME)
.value("LOAD_NAME", Grid2opStringValueType::LOAD_NAME)
.value("GENERATOR_NAME", Grid2opStringValueType::GENERATOR_NAME)
.value("SHUNT_NAME", Grid2opStringValueType::SHUNT_NAME)
.value("BRANCH_NAME", Grid2opStringValueType::BRANCH_NAME);

py::enum_<Grid2opIntegerValueType>(m, "Grid2opIntegerValueType")
.value("LOAD_VOLTAGE_LEVEL_NUM", Grid2opIntegerValueType::LOAD_VOLTAGE_LEVEL_NUM)
.value("GENERATOR_VOLTAGE_LEVEL_NUM", Grid2opIntegerValueType::GENERATOR_VOLTAGE_LEVEL_NUM)
.value("SHUNT_VOLTAGE_LEVEL_NUM", Grid2opIntegerValueType::SHUNT_VOLTAGE_LEVEL_NUM)
.value("BRANCH_VOLTAGE_LEVEL_NUM_1", Grid2opIntegerValueType::BRANCH_VOLTAGE_LEVEL_NUM_1)
.value("BRANCH_VOLTAGE_LEVEL_NUM_2", Grid2opIntegerValueType::BRANCH_VOLTAGE_LEVEL_NUM_2)
.value("SHUNT_LOCAL_BUS", Grid2opIntegerValueType::SHUNT_LOCAL_BUS)
.value("TOPO_VECT", Grid2opIntegerValueType::TOPO_VECT);

py::enum_<Grid2opDoubleValueType>(m, "Grid2opDoubleValueType")
.value("LOAD_P", Grid2opDoubleValueType::LOAD_P)
.value("LOAD_Q", Grid2opDoubleValueType::LOAD_Q)
.value("LOAD_V", Grid2opDoubleValueType::LOAD_V)
.value("GENERATOR_P", Grid2opDoubleValueType::GENERATOR_P)
.value("GENERATOR_Q", Grid2opDoubleValueType::GENERATOR_Q)
.value("GENERATOR_V", Grid2opDoubleValueType::GENERATOR_V)
.value("SHUNT_P", Grid2opDoubleValueType::SHUNT_P)
.value("SHUNT_Q", Grid2opDoubleValueType::SHUNT_Q)
.value("SHUNT_V", Grid2opDoubleValueType::SHUNT_V)
.value("BRANCH_P1", Grid2opDoubleValueType::BRANCH_P1)
.value("BRANCH_P2", Grid2opDoubleValueType::BRANCH_P2)
.value("BRANCH_Q1", Grid2opDoubleValueType::BRANCH_Q1)
.value("BRANCH_Q2", Grid2opDoubleValueType::BRANCH_Q2)
.value("BRANCH_V1", Grid2opDoubleValueType::BRANCH_V1)
.value("BRANCH_V2", Grid2opDoubleValueType::BRANCH_V2)
.value("BRANCH_I1", Grid2opDoubleValueType::BRANCH_I1)
.value("BRANCH_I2", Grid2opDoubleValueType::BRANCH_I2)
.value("BRANCH_PERMANENT_LIMIT_A", Grid2opDoubleValueType::BRANCH_PERMANENT_LIMIT_A);

py::enum_<Grid2opUpdateDoubleValueType>(m, "Grid2opUpdateDoubleValueType")
.value("UPDATE_LOAD_P", Grid2opUpdateDoubleValueType::UPDATE_LOAD_P)
.value("UPDATE_LOAD_Q", Grid2opUpdateDoubleValueType::UPDATE_LOAD_Q)
.value("UPDATE_GENERATOR_P", Grid2opUpdateDoubleValueType::UPDATE_GENERATOR_P)
.value("UPDATE_GENERATOR_V", Grid2opUpdateDoubleValueType::UPDATE_GENERATOR_V);

py::enum_<Grid2opUpdateIntegerValueType>(m, "Grid2opUpdateIntegerValueType")
.value("UPDATE_LOAD_BUS", Grid2opUpdateIntegerValueType::UPDATE_LOAD_BUS)
.value("UPDATE_GENERATOR_BUS", Grid2opUpdateIntegerValueType::UPDATE_GENERATOR_BUS)
.value("UPDATE_SHUNT_BUS", Grid2opUpdateIntegerValueType::UPDATE_SHUNT_BUS)
.value("UPDATE_BRANCH_BUS1", Grid2opUpdateIntegerValueType::UPDATE_BRANCH_BUS1)
.value("UPDATE_BRANCH_BUS2", Grid2opUpdateIntegerValueType::UPDATE_BRANCH_BUS2);

m.def("create_grid2op_backend", &pypowsybl::createGrid2opBackend, "Create a Grid2op backend", py::arg("network"),
py::arg("consider_open_branch_reactive_flow"), py::arg("buses_per_voltage_level"), py::arg("connect_all_elements_to_first_bus"));
m.def("free_grid2op_backend", &pypowsybl::freeGrid2opBackend, "Free a Grid2op backend", py::arg("backend"));
m.def("get_grid2op_string_value", &pypowsybl::getGrid2opStringValue, "From a Grid2op backend get a string value vector", py::arg("backend"), py::arg("value_type"));
m.def("get_grid2op_integer_value", &::pyGetGrid2opIntegerValue, "From a Grid2op backend get a integer value vector", py::arg("backend"), py::arg("value_type"));
m.def("get_grid2op_double_value", &::pyGetGrid2opDoubleValue, "From a Grid2op backend get a double value vector", py::arg("backend"), py::arg("value_type"));
m.def("update_grid2op_double_value", &::pyUpdateGrid2opDoubleValue, "From a Grid2op backend update a double value vector", py::arg("backend"), py::arg("value_type"), py::arg("value"), py::arg("changed"));
m.def("update_grid2op_integer_value", &::pyUpdateGrid2opIntegerValue, "From a Grid2op backend update a integer value vector", py::arg("backend"), py::arg("value_type"), py::arg("value"), py::arg("changed"));
m.def("check_grid2op_isolated_and_disconnected_injections", &pypowsybl::checkGrid2opIsolatedAndDisconnectedInjections, "From a Grid2op backend check if there is isolated or disconnected injections", py::arg("backend"));
m.def("run_grid2op_loadflow", &pypowsybl::runGrid2opLoadFlow, "From a Grid2op backend, run a load flow", py::call_guard<py::gil_scoped_release>(), py::arg("backend"), py::arg("dc"), py::arg("parameters"));
}

void setLogLevelFromPythonLogger(pypowsybl::GraalVmGuard* guard, exception_handler* exc) {
Expand Down
6 changes: 3 additions & 3 deletions cpp/pypowsybl-java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(CMAKE_CXX_STANDARD 17)
include(ExternalProject)

if(NOT DEFINED PYPOWSYBL_JAVA_SRC_DIR)
set(PYPOWSYBL_JAVA_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../java)
set(PYPOWSYBL_JAVA_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../java/pypowsybl)
endif()
set(PYPOWSYBL_JAVA_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/../java)
set(PYPOWSYBL_JAVA_BIN_DIR ${PYPOWSYBL_JAVA_BIN_DIR}/../java PARENT_SCOPE)
Expand Down Expand Up @@ -44,8 +44,8 @@ macro(extract_and_install_native_lib jar_file jar_entry library_file)
endif()
endmacro()

set(math-native-jar ${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/powsybl-math-native.jar)
set(ortools-jar ${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/ortools-${CMAKE_SYSTEM_NAME}-${ARCH_ID}.jar)
cmake_path(SET math-native-jar "${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/powsybl-math-native.jar")
cmake_path(SET ortools-jar "${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/ortools-${CMAKE_SYSTEM_NAME}-${ARCH_ID}.jar")

if(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
extract_and_install_native_lib(${math-native-jar} natives/windows_${OS_BITS} math.dll)
Expand Down
55 changes: 55 additions & 0 deletions cpp/pypowsybl-java/powsybl-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,58 @@ typedef enum {
DEFAULT = 0,
FAILURE,
} RaoComputationStatus;

typedef enum {
VOLTAGE_LEVEL_NAME = 0,
LOAD_NAME,
GENERATOR_NAME,
SHUNT_NAME,
BRANCH_NAME,
} Grid2opStringValueType;

typedef enum {
LOAD_VOLTAGE_LEVEL_NUM = 0,
GENERATOR_VOLTAGE_LEVEL_NUM,
SHUNT_VOLTAGE_LEVEL_NUM,
BRANCH_VOLTAGE_LEVEL_NUM_1,
BRANCH_VOLTAGE_LEVEL_NUM_2,
SHUNT_LOCAL_BUS,
TOPO_VECT,
} Grid2opIntegerValueType;

typedef enum {
LOAD_P = 0,
LOAD_Q,
LOAD_V,
GENERATOR_P,
GENERATOR_Q,
GENERATOR_V,
SHUNT_P,
SHUNT_Q,
SHUNT_V,
BRANCH_P1,
BRANCH_P2,
BRANCH_Q1,
BRANCH_Q2,
BRANCH_V1,
BRANCH_V2,
BRANCH_I1,
BRANCH_I2,
BRANCH_PERMANENT_LIMIT_A,
} Grid2opDoubleValueType;

typedef enum {
UPDATE_LOAD_P = 0,
UPDATE_LOAD_Q,
UPDATE_GENERATOR_P,
UPDATE_GENERATOR_V,
} Grid2opUpdateDoubleValueType;


typedef enum {
UPDATE_LOAD_BUS = 0,
UPDATE_GENERATOR_BUS,
UPDATE_SHUNT_BUS,
UPDATE_BRANCH_BUS1,
UPDATE_BRANCH_BUS2,
} Grid2opUpdateIntegerValueType;
29 changes: 19 additions & 10 deletions docs/user_guide/per_unit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ The nominal apparent power is by default 100 MVA. It can be set like this :
Per Unit formula
----------------

#. Resistance R
Resistance R
~~~~~~~~~~~~

for network elements with only one nominal voltage :

Expand All @@ -43,7 +44,8 @@ For lines, it is according to both sides :

.. math:: \frac{S_n}{V_{nominal1} V_{nominal2}} R

#. Reactance X
Reactance X
~~~~~~~~~~~

for network elements with only one nominal voltage :

Expand All @@ -55,7 +57,8 @@ For lines, it is according to both sides :

.. math:: \frac{S_n}{V_{nominal1} V_{nominal2}} X

#. Susceptance B
Susceptance B
~~~~~~~~~~~~~

for network elements with only one nominal voltage :

Expand All @@ -69,7 +72,8 @@ For lines, B is **on side one** according to both sides :

where Y is the admittance (Y = 1/Z where Z is the impedance) and Im() the imaginary part

#. Conductance G
Conductance G
~~~~~~~~~~~~~

for network elements with only one nominal voltage :

Expand All @@ -84,30 +88,35 @@ For lines, G is **on side one** according to both sides :
where Y is the admittance (Y = 1/Z where Z is the impedance) and Re() the real part
for side 2 just inverse Vnominal1 and Vnominal2

#. Voltage V
Voltage V
~~~~~~~~~

.. math:: \frac{V}{V_{nominal}}

the voltage is perunit by the nominal voltage. For network element with a target voltage, it per united by the nominal voltage of the target element.

#. Active Power P
Active Power P
~~~~~~~~~~~~~~

.. math:: \frac{P}{S_{n}}

with Sn the nominal apparent power

#. Reactive Power Q
Reactive Power Q
~~~~~~~~~~~~~~~~

.. math:: \frac{Q}{S_{n}}

with Sn the nominal apparent power

#. Electric Current I
Electric Current I
~~~~~~~~~~~~~~~~~~

.. math:: \frac{ \sqrt{3} V_{nominal}}{S_{n} 10^3} I

with Sn the nominal apparent power

#. Angle
Angle
~~~~~

the angle are in degrees in PyPowSyBl, but when per-unit is activated it is in radian even if it is not really related to per-uniting.
the angle are in degrees in PyPowSyBl, but when per-unit is activated it is in radian even if it is not really related to per-uniting.
Loading

0 comments on commit 4c3958b

Please sign in to comment.