Skip to content

Commit

Permalink
Improve loadflow results completion (#1988)
Browse files Browse the repository at this point in the history
Signed-off-by: José Antonio Marqués <marquesja@aia.es>
  • Loading branch information
marqueslanauja authored Mar 4, 2022
1 parent 8e4dff4 commit 8ac81dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.powsybl.commons.datasource.ResourceDataSource;
import com.powsybl.commons.datasource.ResourceSet;
import com.powsybl.iidm.import_.Importer;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.xml.NetworkXml;
import com.powsybl.loadflow.LoadFlowParameters;
Expand Down Expand Up @@ -86,16 +84,7 @@ private static ValidationConfig loadFlowValidationConfig(double threshold) {
}

public static void computeMissingFlows(Network network, LoadFlowParameters lfparams) {
for (Load l : network.getLoads()) {
l.getTerminal().setP(l.getP0());
l.getTerminal().setQ(l.getQ0());
}
for (Generator g : network.getGenerators()) {
g.getTerminal().setP(-g.getTargetP());
if (Double.isNaN(g.getTerminal().getQ())) {
g.getTerminal().setQ(-g.getTargetQ());
}
}

LoadFlowResultsCompletionParameters p = new LoadFlowResultsCompletionParameters(
LoadFlowResultsCompletionParameters.EPSILON_X_DEFAULT,
LoadFlowResultsCompletionParameters.APPLY_REACTANCE_CORRECTION_DEFAULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import com.powsybl.iidm.network.extensions.ThreeWindingsTransformerPhaseAngleClock;
import com.powsybl.iidm.network.extensions.TwoWindingsTransformerPhaseAngleClock;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Line;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Terminal;
import com.powsybl.iidm.network.ThreeWindingsTransformer;
Expand Down Expand Up @@ -84,6 +86,9 @@ public void run(Network network, ComputationManager computationManager) {
LOGGER.info("LoadFlowResultsCompletionParameters={}", parameters);
LOGGER.info("LoadFlowParameters={}", lfParameters);

network.getLoadStream().forEach(load -> completeTerminalData(load.getTerminal(), load));
network.getGeneratorStream().forEach(generator -> completeTerminalData(generator.getTerminal(), generator));

network.getLineStream()
// Do not try to compute flows on loops
.filter(l -> l.getTerminal1().getBusView().getBus() != l.getTerminal2().getBusView().getBus())
Expand Down Expand Up @@ -148,6 +153,32 @@ public void run(Network network, ComputationManager computationManager) {
z0FlowsCompletion.complete();
}

private void completeTerminalData(Terminal terminal, Load load) {
if (terminal.isConnected() && terminal.getBusView().getBus() != null && terminal.getBusView().getBus().isInMainConnectedComponent()) {
if (Double.isNaN(terminal.getP())) {
LOGGER.debug("Load {}, setting p = {}", load.getId(), load.getP0());
terminal.setP(load.getP0());
}
if (Double.isNaN(terminal.getQ())) {
LOGGER.debug("Load {}, setting q = {}", load.getId(), load.getQ0());
terminal.setQ(load.getQ0());
}
}
}

private void completeTerminalData(Terminal terminal, Generator generator) {
if (terminal.isConnected() && terminal.getBusView().getBus() != null && terminal.getBusView().getBus().isInMainConnectedComponent()) {
if (Double.isNaN(terminal.getP())) {
LOGGER.debug("Generator {}, setting p = {}", generator.getId(), -generator.getTargetP());
terminal.setP(-generator.getTargetP());
}
if (Double.isNaN(terminal.getQ())) {
LOGGER.debug("Generator {}, setting q = {}", generator.getId(), -generator.getTargetQ());
terminal.setQ(-generator.getTargetQ());
}
}
}

private void completeTerminalData(Terminal terminal, Side side, BranchData branchData) {
if (terminal.isConnected() && terminal.getBusView().getBus() != null && terminal.getBusView().getBus().isInMainConnectedComponent()) {
if (Double.isNaN(terminal.getP())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.powsybl.commons.AbstractConverterTest;
import com.powsybl.commons.datasource.FileDataSource;
import com.powsybl.iidm.import_.Importer;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.NetworkFactory;
import com.powsybl.iidm.xml.NetworkXml;
Expand Down Expand Up @@ -180,22 +178,7 @@ private static ValidationConfig loadFlowValidationConfig(double threshold) {
}

private static void computeMissingFlows(Network network, LoadFlowParameters lfparams) {
for (Load l : network.getLoads()) {
if (Double.isNaN(l.getTerminal().getP())) {
l.getTerminal().setP(l.getP0());
}
if (Double.isNaN(l.getTerminal().getQ())) {
l.getTerminal().setQ(l.getQ0());
}
}
for (Generator g : network.getGenerators()) {
if (Double.isNaN(g.getTerminal().getP())) {
g.getTerminal().setP(-g.getTargetP());
}
if (Double.isNaN(g.getTerminal().getQ())) {
g.getTerminal().setQ(-g.getTargetQ());
}
}

LoadFlowResultsCompletionParameters p = new LoadFlowResultsCompletionParameters(
LoadFlowResultsCompletionParameters.EPSILON_X_DEFAULT,
LoadFlowResultsCompletionParameters.APPLY_REACTANCE_CORRECTION_DEFAULT,
Expand Down

0 comments on commit 8ac81dc

Please sign in to comment.