From 0e5aacd3d30ba9cfe0d7225cf633846654e29b8e Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Tue, 17 Dec 2024 11:33:34 +0100 Subject: [PATCH 1/3] Add missing element accessor and fix missing boolean attributes in dataframes. Signed-off-by: Bertrand Rix --- cpp/powsybljl-cpp/powsybl_jl.cpp | 13 ++++++++++++- src/Network.jl | 23 ++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cpp/powsybljl-cpp/powsybl_jl.cpp b/cpp/powsybljl-cpp/powsybl_jl.cpp index 842933e..77864f1 100644 --- a/cpp/powsybljl-cpp/powsybl_jl.cpp +++ b/cpp/powsybljl-cpp/powsybl_jl.cpp @@ -98,6 +98,9 @@ JLCXX_MODULE define_module_powsybl(jlcxx::Module& mod) }) .method("as_string_array", [](series& s) { return pypowsybl::toVector((array *) & s.data); + }) + .method("as_bool_array", [](series& s) { + return jlcxx::ArrayRef(static_cast(s.data.ptr), s.data.length); }); mod.add_type("NetworkMetadata") @@ -128,6 +131,14 @@ JLCXX_MODULE define_module_powsybl(jlcxx::Module& mod) mod.method("create_network_elements_series_array", [] (pypowsybl::JavaHandle handle, element_type type, std::vector const& attributes, filter_attributes_type filter_attributes, bool nominal_apparent_power, double per_unit) { return pypowsybl::createNetworkElementsSeriesArray(handle, type, filter_attributes, attributes, nullptr, nominal_apparent_power, per_unit); - }, "Get a series"); + }, "Create a network elements series array for a given element type"); + + mod.method("create_network_elements_extension_series_array", [] (pypowsybl::JavaHandle handle, std::string const& extension_name, std::string const& table_name) { + return pypowsybl::createNetworkElementsExtensionSeriesArray(handle, extension_name, table_name); + }, "Create a network elements extensions series array for a given extension name"); + + mod.method("get_extensions_names", [] () { + return pypowsybl::getExtensionsNames(); + }, "Get all the extensions names available"); } diff --git a/src/Network.jl b/src/Network.jl index 1d35cc7..2cc68ab 100644 --- a/src/Network.jl +++ b/src/Network.jl @@ -19,6 +19,10 @@ module Network return Powsybl.get_network_metadata(network.handle) end + function get_extensions_names() + return [String(extension_name) for extension_name in Powsybl.get_extensions_names()] + end + function get_elements(network::NetworkHandle, type::Powsybl.ElementType, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) filter_attributes = Powsybl.DEFAULT_ATTRIBUTES if all_attributes @@ -154,6 +158,19 @@ module Network return get_elements(network, Powsybl.TERMINAL, all_attributes, attributes) end + function get_loads(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) + return get_elements(network, Powsybl.LOAD, all_attributes, attributes) + end + + function get_operational_limits(network::NetworkHandle, all_attributes::Bool = false, attributes::Vector{String} = Vector{String}()) + return get_elements(network, Powsybl.OPERATIONAL_LIMITS, all_attributes, attributes) + end + + function get_extensions(network::NetworkHandle, extension_name::String, table_name::String = "") + series_array = Powsybl.create_network_elements_extension_series_array(network.handle, extension_name, table_name) + return create_dataframe_from_series_array(series_array[]) + end + function create_dataframe_from_series_array(array::Powsybl.SeriesArray) myArray = Powsybl.as_array(array) df = DataFrame() @@ -161,11 +178,15 @@ module Network type = Powsybl.type(serie) name = Powsybl.name(serie) if type == 0 - data = Powsybl.as_string_array(serie) + # To avoid getting CxxWrap StdString type in the dataframe + data = [String(cxx_str_elem) for cxx_str_elem in Powsybl.as_string_array(serie)] elseif type == 1 data = Powsybl.as_double_array(serie) elseif type == 2 data = Powsybl.as_int_array(serie) + elseif type == 3 + # To avoid getting CxxWrap CxxBool type in the dataframe + data = [Bool(cxx_bool_elem) for cxx_bool_elem in Powsybl.as_bool_array(serie)] else continue end From dfd840d422375c07ff27988d7c8fd663a9c8245e Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Tue, 17 Dec 2024 11:45:38 +0100 Subject: [PATCH 2/3] Update list of attributes. Signed-off-by: Bertrand Rix --- test/print_network.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/print_network.jl b/test/print_network.jl index e32c56d..1ab2c8c 100644 --- a/test/print_network.jl +++ b/test/print_network.jl @@ -10,9 +10,8 @@ network = Powsybl.Network.create_ieee9() @test network.case_date ≈ 1.240704e9 lines = Powsybl.Network.get_lines(network) -@test names(lines) == ["id", "name", "r", "x", "g1", "b1", "g2", - "b2", "p1", "q1", "i1", "p2", "q2", "i2", "voltage_level1_id", - "voltage_level2_id", "bus1_id", "bus2_id"] +@test names(lines) == ["id", "name", "r", "x", "g1", "b1", "g2", "b2", "p1", "q1", "i1", "p2", "q2", + "i2", "voltage_level1_id", "voltage_level2_id", "bus1_id", "bus2_id", "connected1", "connected2"] @test lines[:, "id"] == ["L7-8-0", "L9-8-0", "L7-5-0", "L9-6-0", "L5-4-0", "L6-4-0"] @test lines[:, "bus1_id"] == ["VL2_1", "VL3_1", "VL2_1", "VL3_1", "VL5_0", "VL6_0"] From 911e3d6e541726205e93be015cf2559ad770045b Mon Sep 17 00:00:00 2001 From: Bertrand Rix Date: Tue, 17 Dec 2024 17:03:27 +0100 Subject: [PATCH 3/3] Update readme Signed-off-by: Bertrand Rix --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/README.md b/README.md index 3815da1..f79fe38 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ From a loaded network you can have a access to the following network elements (a * buses * bus_breaker_view_buses * generators +* loads * batteries * lines * 2_windings_transformers @@ -53,6 +54,7 @@ From a loaded network you can have a access to the following network elements (a * injections * branches * terminals +* operational_limits ```julia @@ -106,4 +108,49 @@ julia> @info Powsybl.Network.get_lines(network)[:,["id", "name", "p1"]] ``` +### Network extensions +Network extensions can be accessed through a call to Powsybl.Network.get_extensions + +```julia + +julia> using Powsybl + +julia> network = Powsybl.Network.create_micro_grid_be() +Powsybl.Network.NetworkHandle(Powsybl.JavaHandleAllocated(Ptr{Nothing} @0x0000000020f43260), "urn:uuid:d400c631-75a0-4c30-8aed-832b0d282e73", "urn:uuid:d400c631-75a0-4c30-8aed-832b0d282e73", "CGMES", 0, 1.4016186e9) + +julia> Powsybl.Network.get_extensions(network, "activePowerControl") +2×6 DataFrame + Row │ id droop participate participation_factor max_target_p min_target_p + │ String Float64 Bool Float64 Float64 Float64 +─────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────── + 1 │ 3a3b27be-b18b-4385-b557-6735d733… NaN true 0.0 NaN NaN + 2 │ 550ebe0d-f2b2-48c1-991f-cebea43a… NaN true 0.0 NaN NaN + +``` + +Available extensions can be listed using the following call : + +```julia +julia> Powsybl.Network.get_extensions_names() +19-element Vector{String}: + "activePowerControl" + "branchObservability" + "busbarSectionPosition" + "coordinatedReactiveControl" + "detail" + "entsoeArea" + "entsoeCategory" + "generatorShortCircuit" + "hvdcAngleDroopActivePowerControl" + "hvdcOperatorActivePowerRange" + "identifiableShortCircuit" + "injectionObservability" + "linePosition" + "measurements" + "position" + "secondaryVoltageControl" + "slackTerminal" + "standbyAutomaton" + "substationPosition" +``` \ No newline at end of file