Skip to content

Commit

Permalink
filter out generators with nan PF in getParticipatingElements
Browse files Browse the repository at this point in the history
Signed-off-by: Caio Luke <caio.luke@artelys.com>
  • Loading branch information
Caio Luke authored and obrix committed Jan 24, 2023
1 parent 2d4656d commit 5c2727a
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,7 @@ static LfNetworkParameters getNetworkParameters(LoadFlowParameters parameters, O
.setLowImpedanceThreshold(parametersExt.getLowImpedanceThreshold())
.setSvcVoltageMonitoring(parametersExt.isSvcVoltageMonitoring())
.setMaxSlackBusCount(parametersExt.getMaxSlackBusCount())
.setDebugDir(parametersExt.getDebugDir())
.setBalanceType(parameters.getBalanceType());
.setDebugDir(parametersExt.getDebugDir());
}

public static AcLoadFlowParameters createAcParameters(Network network, LoadFlowParameters parameters, OpenLoadFlowParameters parametersExt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.Country;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.openloadflow.OpenLoadFlowParameters;
import com.powsybl.openloadflow.graph.EvenShiloachGraphDecrementalConnectivityFactory;
import com.powsybl.openloadflow.graph.GraphConnectivityFactory;
Expand Down Expand Up @@ -91,8 +90,6 @@ public class LfNetworkParameters {

private String debugDir = DEBUG_DIR_DEFAULT_VALUE;

private LoadFlowParameters.BalanceType balanceType = LoadFlowParameters.DEFAULT_BALANCE_TYPE;

public SlackBusSelector getSlackBusSelector() {
return slackBusSelector;
}
Expand Down Expand Up @@ -337,15 +334,6 @@ public LfNetworkParameters setDebugDir(String debugDir) {
return this;
}

public LoadFlowParameters.BalanceType getBalanceType() {
return balanceType;
}

public LfNetworkParameters setBalanceType(LoadFlowParameters.BalanceType balanceType) {
this.balanceType = balanceType;
return this;
}

@Override
public String toString() {
return "LfNetworkParameters(" +
Expand Down Expand Up @@ -374,7 +362,6 @@ public String toString() {
", svcVoltageMonitoring=" + svcVoltageMonitoring +
", maxSlackBusCount=" + maxSlackBusCount +
", debugDir=" + debugDir +
", balanceType=" + balanceType +
')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.powsybl.commons.PowsyblException;
import com.powsybl.iidm.network.*;
import com.powsybl.loadflow.LoadFlowParameters;
import com.powsybl.openloadflow.network.*;
import com.powsybl.openloadflow.util.PerUnit;
import org.slf4j.Logger;
Expand Down Expand Up @@ -314,7 +313,7 @@ public double getParticipationFactor() {
return participationFactor;
}

protected boolean checkActivePowerControl(double targetP, double minP, double maxP, double participationFactor,
protected boolean checkActivePowerControl(double targetP, double minP, double maxP,
LfNetworkParameters parameters, LfNetworkLoadingReport report) {
boolean participating = true;
if (Math.abs(targetP) < POWER_EPSILON_SI) {
Expand Down Expand Up @@ -347,12 +346,6 @@ protected boolean checkActivePowerControl(double targetP, double minP, double ma
report.generatorsDiscardedFromActivePowerControlBecauseMaxPEqualsMinP++;
participating = false;
}
if ((parameters.getBalanceType() == LoadFlowParameters.BalanceType.PROPORTIONAL_TO_GENERATION_PARTICIPATION_FACTOR) && Double.isNaN(participationFactor)) {
LOGGER.trace("Discard generator '{}' from active power control because balanceType is PROPORTIONAL_TO_GENERATION_PARTICIPATION_FACTOR and participationFactor is {}",
getId(), participationFactor);
report.generatorsWithNaNParticipationFactor++;
participating = false;
}
return participating;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private LfBatteryImpl(Battery battery, LfNetwork network, LfNetworkParameters pa
this.setParticipationFactor(activePowerControl.getParticipationFactor());
}

if (!checkActivePowerControl(battery.getTargetP(), battery.getMinP(), battery.getMaxP(), this.getParticipationFactor(), parameters, report)) {
if (!checkActivePowerControl(battery.getTargetP(), battery.getMinP(), battery.getMaxP(), parameters, report)) {
participating = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private LfGeneratorImpl(Generator generator, LfNetwork network, LfNetworkParamet
this.setParticipationFactor(activePowerControl.getParticipationFactor());
}

if (!checkActivePowerControl(generator.getTargetP(), generator.getMinP(), generator.getMaxP(), this.getParticipationFactor(), parameters, report)) {
if (!checkActivePowerControl(generator.getTargetP(), generator.getMinP(), generator.getMaxP(), parameters, report)) {
participating = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,11 +820,6 @@ private LfNetwork create(int numCC, int numSC, List<Bus> buses, List<Switch> swi
lfNetwork, report.generatorsWithInconsistentTargetVoltage);
}

if (report.generatorsWithNaNParticipationFactor > 0) {
LOGGER.warn("Network {}: {} generators have been discarded from active power control because they have NaN participation factors",
lfNetwork, report.generatorsWithNaNParticipationFactor);
}

if (parameters.getDebugDir() != null) {
Path debugDir = DebugUtil.getDebugDir(parameters.getDebugDir());
String dateStr = DateTime.now().toString(DATE_TIME_FORMAT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,4 @@ class LfNetworkLoadingReport {
int nonImpedantBranches = 0;

int generatorsWithInconsistentTargetVoltage = 0;

int generatorsWithNaNParticipationFactor = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public List<ParticipatingElement> getParticipatingElements(Collection<LfBus> bus
return buses.stream()
.filter(bus -> bus.isParticipating() && !bus.isDisabled() && !bus.isFictitious())
.flatMap(bus -> bus.getGenerators().stream())
.filter(generator -> generator.isParticipating() && getParticipationFactor(generator) != 0)
.filter(generator -> generator.isParticipating() && getParticipationFactor(generator) != 0 && !Double.isNaN(getParticipationFactor(generator)))
.map(generator -> new ParticipatingElement(generator, getParticipationFactor(generator)))
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void test() {
void testDcParameters() {
Network network = Mockito.mock(Network.class);
DcLoadFlowParameters dcParameters = OpenLoadFlowParameters.createDcParameters(network, new LoadFlowParameters().setReadSlackBus(true), new OpenLoadFlowParameters(), new DenseMatrixFactory(), new EvenShiloachGraphDecrementalConnectivityFactory<>(), true);
assertEquals("DcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, connectivityFactory=EvenShiloachGraphDecrementalConnectivityFactory, generatorVoltageRemoteControl=false, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, dc=true, reactiveLimits=false, hvdcAcEmulation=false, minPlausibleTargetVoltage=0.8, maxPlausibleTargetVoltage=1.2, loaderPostProcessorSelection=[], reactiveRangeCheckMode=MAX, lowImpedanceThreshold=1.0E-8, svcVoltageMonitoring=false, maxSlackBusCount=1, debugDir=null, balanceType=PROPORTIONAL_TO_GENERATION_P_MAX), equationSystemCreationParameters=DcEquationSystemCreationParameters(updateFlows=true, forcePhaseControlOffAndAddAngle1Var=true, useTransformerRatio=true), matrixFactory=DenseMatrixFactory, distributedSlack=true, balanceType=PROPORTIONAL_TO_GENERATION_P_MAX, setVToNan=true)",
assertEquals("DcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, connectivityFactory=EvenShiloachGraphDecrementalConnectivityFactory, generatorVoltageRemoteControl=false, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, dc=true, reactiveLimits=false, hvdcAcEmulation=false, minPlausibleTargetVoltage=0.8, maxPlausibleTargetVoltage=1.2, loaderPostProcessorSelection=[], reactiveRangeCheckMode=MAX, lowImpedanceThreshold=1.0E-8, svcVoltageMonitoring=false, maxSlackBusCount=1, debugDir=null), equationSystemCreationParameters=DcEquationSystemCreationParameters(updateFlows=true, forcePhaseControlOffAndAddAngle1Var=true, useTransformerRatio=true), matrixFactory=DenseMatrixFactory, distributedSlack=true, balanceType=PROPORTIONAL_TO_GENERATION_P_MAX, setVToNan=true)",
dcParameters.toString());
}

@Test
void testAcParameters() {
Network network = Mockito.mock(Network.class);
AcLoadFlowParameters acParameters = OpenLoadFlowParameters.createAcParameters(network, new LoadFlowParameters().setReadSlackBus(true), new OpenLoadFlowParameters(), new DenseMatrixFactory(), new EvenShiloachGraphDecrementalConnectivityFactory<>(), false, false);
assertEquals("AcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, connectivityFactory=EvenShiloachGraphDecrementalConnectivityFactory, generatorVoltageRemoteControl=true, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, dc=false, reactiveLimits=true, hvdcAcEmulation=true, minPlausibleTargetVoltage=0.8, maxPlausibleTargetVoltage=1.2, loaderPostProcessorSelection=[], reactiveRangeCheckMode=MAX, lowImpedanceThreshold=1.0E-8, svcVoltageMonitoring=true, maxSlackBusCount=1, debugDir=null, balanceType=PROPORTIONAL_TO_GENERATION_P_MAX), equationSystemCreationParameters=AcEquationSystemCreationParameters(forceA1Var=false), newtonRaphsonParameters=NewtonRaphsonParameters(maxIteration=30, minRealisticVoltage=0.5, maxRealisticVoltage=1.5, stoppingCriteria=DefaultNewtonRaphsonStoppingCriteria, stateVectorScalingMode=NONE), outerLoops=[DistributedSlackOuterLoop, MonitoringVoltageOuterLoop, ReactiveLimitsOuterLoop], matrixFactory=DenseMatrixFactory, voltageInitializer=UniformValueVoltageInitializer)",
assertEquals("AcLoadFlowParameters(networkParameters=LfNetworkParameters(slackBusSelector=NetworkSlackBusSelector, connectivityFactory=EvenShiloachGraphDecrementalConnectivityFactory, generatorVoltageRemoteControl=true, minImpedance=false, twtSplitShuntAdmittance=false, breakers=false, plausibleActivePowerLimit=5000.0, computeMainConnectedComponentOnly=true, countriesToBalance=[], distributedOnConformLoad=false, phaseControl=false, transformerVoltageControl=false, voltagePerReactivePowerControl=false, reactivePowerRemoteControl=false, dc=false, reactiveLimits=true, hvdcAcEmulation=true, minPlausibleTargetVoltage=0.8, maxPlausibleTargetVoltage=1.2, loaderPostProcessorSelection=[], reactiveRangeCheckMode=MAX, lowImpedanceThreshold=1.0E-8, svcVoltageMonitoring=true, maxSlackBusCount=1, debugDir=null), equationSystemCreationParameters=AcEquationSystemCreationParameters(forceA1Var=false), newtonRaphsonParameters=NewtonRaphsonParameters(maxIteration=30, minRealisticVoltage=0.5, maxRealisticVoltage=1.5, stoppingCriteria=DefaultNewtonRaphsonStoppingCriteria, stateVectorScalingMode=NONE), outerLoops=[DistributedSlackOuterLoop, MonitoringVoltageOuterLoop, ReactiveLimitsOuterLoop], matrixFactory=DenseMatrixFactory, voltageInitializer=UniformValueVoltageInitializer)",
acParameters.toString());
}

Expand Down

0 comments on commit 5c2727a

Please sign in to comment.