Skip to content

Commit

Permalink
Migrate to PowSyBl 2023.3.1 (#658)
Browse files Browse the repository at this point in the history
* Migrate to PowSyBl 2023.3.1

Signed-off-by: Geoffroy Jamgotchian <geoffroy.jamgotchian@gmail.com>
  • Loading branch information
geofjamg authored Oct 9, 2023
1 parent 782cede commit 21a2774
Show file tree
Hide file tree
Showing 31 changed files with 169 additions and 305 deletions.
18 changes: 9 additions & 9 deletions cpp/src/pypowsybl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,17 @@ JavaHandle createNetwork(const std::string& name, const std::string& id) {
return callJava<JavaHandle>(::createNetwork, (char*) name.data(), (char*) id.data());
}

void merge(JavaHandle network, std::vector<JavaHandle>& others) {
std::vector<void*> othersPtrs;
othersPtrs.reserve(others.size());
for(int i = 0; i < others.size(); ++i) {
void* ptr = others[i];
othersPtrs.push_back(ptr);
JavaHandle merge(std::vector<JavaHandle>& networks) {
std::vector<void*> networksPtrs;
networksPtrs.reserve(networks.size());
for (int i = 0; i < networks.size(); ++i) {
void* ptr = networks[i];
networksPtrs.push_back(ptr);
}
int count = othersPtrs.size();
void** networksData = (void**)othersPtrs.data();
int networkCount = networksPtrs.size();
void** networksData = (void**) networksPtrs.data();

callJava<>(::merge, network, networksData, count);
return callJava<JavaHandle>(::merge, networksData, networkCount);
}

std::vector<std::string> getNetworkImportFormats() {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/pypowsybl.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ std::string getVersionTable();

JavaHandle createNetwork(const std::string& name, const std::string& id);

void merge(JavaHandle network, std::vector<JavaHandle>& others);
JavaHandle merge(std::vector<JavaHandle>& others);

bool updateSwitchPosition(const JavaHandle& network, const std::string& id, bool open);

Expand Down
20 changes: 10 additions & 10 deletions docs/user_guide/flowdecomposition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ This example will highlight loop flows from the peripheral areas.
>>> flow_decomposition_dataframe = flow_decomposition.run(network)
>>> flow_decomposition_dataframe
branch_id contingency_id country1 country2 ac_reference_flow dc_reference_flow commercial_flow x_node_flow pst_flow internal_flow loop_flow_from_be loop_flow_from_es loop_flow_from_fr
xnec_id
xnec_id
BLOAD 11 FLOAD 11 1 BLOAD 11 FLOAD 11 1 BE FR NaN 200.0 0.000000e+00 0.0 0.0 0.0 0.000000e+00 100.0 1.000000e+02
EGEN 11 FGEN 11 1 EGEN 11 FGEN 11 1 ES FR NaN 100.0 -8.526513e-14 0.0 0.0 0.0 4.973799e-14 100.0 -1.421085e-14
FGEN 11 BGEN 11 1 FGEN 11 BGEN 11 1 FR BE NaN 200.0 -1.421085e-13 0.0 0.0 0.0 9.947598e-14 100.0 1.000000e+02
EGEN 11 FGEN 11 1 EGEN 11 FGEN 11 1 ES FR NaN 100.0 -8.526513e-14 0.0 0.0 0.0 3.552714e-14 100.0 -3.552714e-14
FGEN 11 BGEN 11 1 FGEN 11 BGEN 11 1 FR BE NaN 200.0 -1.421085e-13 0.0 0.0 0.0 8.526513e-14 100.0 1.000000e+02
FLOAD 11 ELOAD 11 1 FLOAD 11 ELOAD 11 1 FR ES NaN 100.0 0.000000e+00 0.0 0.0 0.0 0.000000e+00 100.0 0.000000e+00

On this example, the AC load flow does not converge, the fallback to DC load flow is activated by default.
On this example, the AC load flow does not converge, the fallback to DC load flow is activated by default.
This means that the AC reference values are NaNs.
For each line where the AC reference is not a number, the rescaling is disabled to prevent NaN propagation.

Expand Down Expand Up @@ -203,13 +203,13 @@ Merged X nodes will not be considered here.
>>> flow_decomposition = pp.flowdecomposition.create_decomposition().add_interconnections_as_monitored_elements()
>>> flow_decomposition.run(network)
branch_id contingency_id country1 country2 ac_reference_flow dc_reference_flow commercial_flow x_node_flow pst_flow internal_flow loop_flow_from_be loop_flow_from_de loop_flow_from_fr
xnec_id
XBD00011 BD000011 1 + XBD00011 DB000011 1 XBD00011 BD000011 1 + XBD00011 DB000011 1 BE DE 121.821917 124.685261 159.585145 -33.155274 2.951653 0.0 30.556687 -8.995130e-09 -35.252949
XBD00012 BD000011 1 + XBD00012 DB000011 1 XBD00012 BD000011 1 + XBD00012 DB000011 1 BE DE 121.821917 124.685261 159.585145 -33.155274 2.951653 0.0 30.556687 -8.995130e-09 -35.252949
xnec_id
XBD00011 BD000011 1 + XBD00011 DB000011 1 XBD00011 BD000011 1 + XBD00011 DB000011 1 BE DE 121.821917 124.685261 159.585145 -33.155274 2.951653 0.0 30.556687 -8.994903e-09 -35.252949
XBD00012 BD000011 1 + XBD00012 DB000011 1 XBD00012 BD000011 1 + XBD00012 DB000011 1 BE DE 121.821917 124.685261 159.585145 -33.155274 2.951653 0.0 30.556687 -8.994903e-09 -35.252949
XBF00011 BF000011 1 + XBF00011 FB000011 1 XBF00011 BF000011 1 + XBF00011 FB000011 1 BE FR -775.578124 -764.445217 883.442837 170.472453 7.112098 0.0 -198.693573 -6.713719e-09 -97.888598
XBF00021 BF000021 1 + XBF00021 FB000021 1 XBF00021 BF000021 1 + XBF00021 FB000021 1 BE FR -234.032855 -242.462652 217.863726 44.108499 -0.604396 0.0 45.528473 -1.954547e-09 -64.433650
XBF00022 BF000021 1 + XBF00022 FB000022 1 XBF00022 BF000021 1 + XBF00022 FB000022 1 BE FR -234.032855 -242.462652 217.863726 44.108499 -0.604396 0.0 45.528473 -1.954547e-09 -64.433650
XDF00011 DF000011 1 + XDF00011 FD000011 1 XDF00011 DF000011 1 + XDF00011 FD000011 1 DE FR -1156.356167 -1150.629478 1080.829711 216.310548 -5.903306 0.0 -23.613373 -2.032039e-08 -116.994101
XBF00021 BF000021 1 + XBF00021 FB000021 1 XBF00021 BF000021 1 + XBF00021 FB000021 1 BE FR -234.032855 -242.462652 217.863726 44.108499 -0.604396 0.0 45.528473 -1.954504e-09 -64.433650
XBF00022 BF000021 1 + XBF00022 FB000022 1 XBF00022 BF000021 1 + XBF00022 FB000022 1 BE FR -234.032855 -242.462652 217.863726 44.108499 -0.604396 0.0 45.528473 -1.954504e-09 -64.433650
XDF00011 DF000011 1 + XDF00011 FD000011 1 XDF00011 DF000011 1 + XDF00011 FD000011 1 DE FR -1156.356167 -1150.629478 1080.829711 216.310548 -5.903306 0.0 -23.613373 -2.032061e-08 -116.994101


Adder functions
Expand Down
4 changes: 2 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
<junit-jupiter.version>5.5.2</junit-jupiter.version>
<mapdb.version>3.0.8</mapdb.version>
<maven-dependency-plugin.version>3.6.0</maven-dependency-plugin.version>
<powsybl-dependencies.version>2023.2.4</powsybl-dependencies.version>
<powsybl-dependencies.version>2023.3.1</powsybl-dependencies.version>
<powsybl-open-reac.version>0.2.0</powsybl-open-reac.version>
<zstdjni.version>1.5.2-5</zstdjni.version>
<zstdjni.version>1.5.5-3</zstdjni.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ static NetworkDataframeMapper danglingLines() {
.strings("bus_breaker_bus_id", busBreakerViewBusId(), false)
.ints("node", dl -> getNode(dl.getTerminal()), false)
.booleans("connected", dl -> dl.getTerminal().isConnected(), connectInjection())
.strings("ucte-x-node-code", dl -> Objects.toString(dl.getUcteXnodeCode(), ""))
.strings("ucte-x-node-code", dl -> Objects.toString(dl.getPairingKey(), ""))
.booleans("fictitious", Identifiable::isFictitious, Identifiable::setFictitious, false)
.strings("tie_line_id", dl -> dl.getTieLine().map(Identifiable::getId).orElse(""))
.addProperties()
Expand All @@ -611,7 +611,7 @@ static NetworkDataframeMapper tieLines() {
.strings("name", tl -> tl.getOptionalName().orElse(""))
.strings("dangling_line1_id", tl -> tl.getDanglingLine1().getId())
.strings("dangling_line2_id", tl -> tl.getDanglingLine2().getId())
.strings("ucte_xnode_code", tl -> Objects.toString(tl.getUcteXnodeCode(), ""))
.strings("ucte_xnode_code", tl -> Objects.toString(tl.getPairingKey(), ""))
.booleans("fictitious", Identifiable::isFictitious, Identifiable::setFictitious, false)
.addProperties()
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ DanglingLineAdder createAdder(Network network, int row) {
applyIfPresent(x, row, adder::setX);
applyIfPresent(g, row, adder::setG);
applyIfPresent(b, row, adder::setB);
applyIfPresent(ucteXnodeCode, row, adder::setUcteXnodeCode);
applyIfPresent(ucteXnodeCode, row, adder::setPairingKey);
return adder;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.powsybl.dynamicsimulation.DynamicModel;
import com.powsybl.dynamicsimulation.DynamicModelsSupplier;
import com.powsybl.dynawaltz.models.automatons.CurrentLimitAutomaton;
import com.powsybl.dynawaltz.models.generators.GeneratorSynchronous;
import com.powsybl.dynawaltz.models.loads.LoadAlphaBeta;
import com.powsybl.dynawaltz.models.generators.SynchronousGenerator;
import com.powsybl.dynawaltz.models.loads.BaseLoad;
import com.powsybl.dynawaltz.models.loads.LoadOneTransformer;
import com.powsybl.dynawaltz.models.utils.SideConverter;
import com.powsybl.iidm.network.Branch;
Expand Down Expand Up @@ -55,7 +55,7 @@ private static Load getLoad(String staticId, Network network) {
public void addAlphaBetaLoad(String staticId, String parameterSetId) {
dynamicModelList.add(network -> {
Load load = getLoad(staticId, network);
return new LoadAlphaBeta(staticId, load, parameterSetId, "LoadAlphaBeta");
return new BaseLoad(staticId, load, parameterSetId, "LoadAlphaBeta");
});
}

Expand All @@ -77,7 +77,7 @@ public void addGeneratorSynchronous(String staticId, String parameterSetId, Stri
if (gen == null) {
throw new PowsyblException("Generator '" + staticId + "' not found");
}
return new GeneratorSynchronous(staticId, gen, parameterSetId, generatorLib);
return new SynchronousGenerator(staticId, gen, parameterSetId, generatorLib);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.nad.NadParameters;
import com.powsybl.nad.NetworkAreaDiagram;
import com.powsybl.nad.build.iidm.VoltageLevelFilter;
import com.powsybl.nad.svg.SvgParameters;
Expand All @@ -20,7 +21,10 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;

/**
Expand All @@ -38,11 +42,12 @@ static void writeSvg(Network network, List<String> voltageLevelIds, int depth, W
.setFixedWidth(800)
.setFixedHeight(600)
.setEdgeNameDisplayed(edgeNameDisplayed);
Predicate<VoltageLevel> filter = voltageLevelIds.size() > 0
Predicate<VoltageLevel> filter = !voltageLevelIds.isEmpty()
? getNominalVoltageFilter(network, voltageLevelIds, highNominalVoltageBound, lowNominalVoltageBound, depth)
: VoltageLevelFilter.NO_FILTER;
new NetworkAreaDiagram(network, filter)
.draw(writer, svgParameters);
NadParameters nadParameters = new NadParameters()
.setSvgParameters(svgParameters);
NetworkAreaDiagram.draw(network, writer, nadParameters, filter);
}

static String getSvg(Network network, List<String> voltageLevelIds, int depth, boolean edgeNameDisplayed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.powsybl.python.datasource.InMemoryZipFileDataSource;
import com.powsybl.python.report.ReportCUtils;
import com.powsybl.sld.layout.LayoutParameters;
import com.powsybl.sld.svg.SvgParameters;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.graalvm.nativeimage.IsolateThread;
Expand Down Expand Up @@ -574,17 +575,16 @@ public static PyPowsyblApiHeader.ArrayPointer<PyPowsyblApiHeader.SeriesPointer>
}

@CEntryPoint(name = "merge")
public static void merge(IsolateThread thread, ObjectHandle networkHandle, VoidPointerPointer othersHandle, int othersCount,
ExceptionHandlerPointer exceptionHandlerPtr) {
doCatch(exceptionHandlerPtr, () -> {
Network network = ObjectHandles.getGlobal().get(networkHandle);
Network[] otherNetworks = new Network[othersCount];
for (int i = 0; i < othersCount; ++i) {
ObjectHandle handleToMerge = othersHandle.read(i);
Network otherNetwork = ObjectHandles.getGlobal().get(handleToMerge);
otherNetworks[i] = otherNetwork;
public static ObjectHandle merge(IsolateThread thread, VoidPointerPointer networkHandles, int networkCount,
ExceptionHandlerPointer exceptionHandlerPtr) {
return doCatch(exceptionHandlerPtr, () -> {
Network[] networks = new Network[networkCount];
for (int i = 0; i < networkCount; ++i) {
ObjectHandle networkHandle = networkHandles.read(i);
Network network = ObjectHandles.getGlobal().get(networkHandle);
networks[i] = network;
}
network.merge(otherNetworks);
return ObjectHandles.getGlobal().create(Network.merge(networks));
});
}

Expand Down Expand Up @@ -837,29 +837,31 @@ public static boolean updateConnectableStatus(IsolateThread thread, ObjectHandle

public static class LayoutParametersExt {
public final LayoutParameters layoutParameters;
public final SvgParameters svgParameters;
public final boolean topologicalColoring;

public final String componentLibrary;

public LayoutParametersExt() {
this(new LayoutParameters(), true, "Convergence");
this(new LayoutParameters(), new SvgParameters(), true, "Convergence");
}

public LayoutParametersExt(LayoutParameters layoutParameters, boolean topologicalColoring, String componentLibrary) {
public LayoutParametersExt(LayoutParameters layoutParameters, SvgParameters svgParameters, boolean topologicalColoring, String componentLibrary) {
Objects.requireNonNull(layoutParameters);
this.layoutParameters = layoutParameters;
this.layoutParameters.setSvgWidthAndHeightAdded(true);
this.svgParameters = svgParameters;
this.svgParameters.setSvgWidthAndHeightAdded(true);
this.topologicalColoring = topologicalColoring;
this.componentLibrary = componentLibrary;
}
}

public static void copyToCLayoutParameters(LayoutParametersExt parameters, LayoutParametersPointer cParameters) {
cParameters.setUseName(parameters.layoutParameters.isUseName());
cParameters.setCenterName(parameters.layoutParameters.isLabelCentered());
cParameters.setDiagonalLabel(parameters.layoutParameters.isLabelDiagonal());
cParameters.setUseName(parameters.svgParameters.isUseName());
cParameters.setCenterName(parameters.svgParameters.isLabelCentered());
cParameters.setDiagonalLabel(parameters.svgParameters.isLabelDiagonal());
cParameters.setTopologicalColoring(parameters.topologicalColoring);
cParameters.setAddNodesInfos(parameters.layoutParameters.isAddNodesInfos());
cParameters.setAddNodesInfos(parameters.svgParameters.isAddNodesInfos());
cParameters.setComponentLibrary(CTypeUtil.toCharPtr(parameters.componentLibrary));
}

Expand Down Expand Up @@ -887,11 +889,12 @@ public static void freeLayoutParameters(IsolateThread thread, LayoutParametersPo
}

public static LayoutParametersExt convertLayoutParameters(LayoutParametersPointer layoutParametersPtr) {
return new LayoutParametersExt(new LayoutParameters()
.setUseName(layoutParametersPtr.isUseName())
.setLabelCentered(layoutParametersPtr.isCenterName())
.setLabelDiagonal(layoutParametersPtr.isDiagonalLabel())
.setAddNodesInfos(layoutParametersPtr.isAddNodesInfos()),
return new LayoutParametersExt(new LayoutParameters(),
new SvgParameters()
.setUseName(layoutParametersPtr.isUseName())
.setLabelCentered(layoutParametersPtr.isCenterName())
.setLabelDiagonal(layoutParametersPtr.isDiagonalLabel())
.setAddNodesInfos(layoutParametersPtr.isAddNodesInfos()),
layoutParametersPtr.isTopologicalColoring(),
CTypeUtil.toString(layoutParametersPtr.getComponentLibrary()));
}
Expand Down
Loading

0 comments on commit 21a2774

Please sign in to comment.