Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typos in LoadFlowParameters yml parsing #3237

Merged
merged 6 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ protected static void load(LoadFlowParameters parameters, PlatformConfig platfor
config.getOptionalBooleanProperty("dc").ifPresent(parameters::setDc);
config.getOptionalBooleanProperty("distributedSlack").ifPresent(parameters::setDistributedSlack);
config.getOptionalEnumProperty("balanceType", BalanceType.class).ifPresent(parameters::setBalanceType);
config.getOptionalBooleanProperty("dcUseTranformerRatio").ifPresent(parameters::setDcUseTransformerRatio);
config.getOptionalEnumSetProperty("contriesToBalance", Country.class).ifPresent(parameters::setCountriesToBalance);
config.getOptionalBooleanProperty("dcUseTransformerRatio").ifPresent(parameters::setDcUseTransformerRatio);
config.getOptionalEnumSetProperty("countriesToBalance", Country.class).ifPresent(parameters::setCountriesToBalance);
config.getOptionalEnumProperty("connectedComponentMode", ConnectedComponentMode.class).ifPresent(parameters::setConnectedComponentMode);
config.getOptionalBooleanProperty("hvdcAcEmulation").ifPresent(parameters::setHvdcAcEmulation);
config.getOptionalDoubleProperty("dcPowerFactor").ifPresent(parameters::setDcPowerFactor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void checkValues(LoadFlowParameters parameters, LoadFlowParameters.Volta
boolean dc, boolean distributedSlack, LoadFlowParameters.BalanceType balanceType,
boolean dcUseTransformerRatio, Set<Country> countriesToBalance,
LoadFlowParameters.ConnectedComponentMode computedConnectedComponent,
boolean hvdcAcEmulation) {
boolean hvdcAcEmulation, double dcPowerFactor) {
assertEquals(parameters.getVoltageInitMode(), voltageInitMode);
assertEquals(parameters.isTransformerVoltageControlOn(), transformerVoltageControlOn);
assertEquals(parameters.isPhaseShifterRegulationOn(), phaseShifterRegulationOn);
Expand All @@ -66,6 +66,7 @@ private void checkValues(LoadFlowParameters parameters, LoadFlowParameters.Volta
assertEquals(parameters.getCountriesToBalance(), countriesToBalance);
assertEquals(parameters.getConnectedComponentMode(), computedConnectedComponent);
assertEquals(parameters.isHvdcAcEmulation(), hvdcAcEmulation);
assertEquals(parameters.getDcPowerFactor(), dcPowerFactor);
}

@Test
Expand All @@ -86,51 +87,8 @@ void testNoConfig() {
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT,
LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE,
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
}

@Test
void checkConfig() {
boolean transformerVoltageControlOn = true;
boolean noGeneratorReactiveLimits = true;
boolean phaseShifterRegulationOn = true;
boolean twtSplitShuntAdmittance = true;
boolean simulShunt = true;
boolean readSlackBus = true;
boolean writeSlackBus = true;
boolean voltageRemoteControl = true;
boolean dc = true;
boolean distributedSlack = true;
LoadFlowParameters.BalanceType balanceType = LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD;
LoadFlowParameters.VoltageInitMode voltageInitMode = LoadFlowParameters.VoltageInitMode.UNIFORM_VALUES;
boolean dcUseTransformerRatio = true;
Set<Country> countriesToBalance = new HashSet<>();
LoadFlowParameters.ConnectedComponentMode computedConnectedComponent = LoadFlowParameters.ConnectedComponentMode.MAIN;
boolean hvdcAcEmulation = false;

MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-default-parameters");
moduleConfig.setStringProperty("voltageInitMode", "UNIFORM_VALUES");
moduleConfig.setStringProperty("transformerVoltageControlOn", Boolean.toString(transformerVoltageControlOn));
moduleConfig.setStringProperty("noGeneratorReactiveLimits", Boolean.toString(noGeneratorReactiveLimits));
moduleConfig.setStringProperty("phaseShifterRegulationOn", Boolean.toString(phaseShifterRegulationOn));
moduleConfig.setStringProperty("twtSplitShuntAdmittance", Boolean.toString(twtSplitShuntAdmittance));
moduleConfig.setStringProperty("simulShunt", Boolean.toString(simulShunt));
moduleConfig.setStringProperty("readSlackBus", Boolean.toString(readSlackBus));
moduleConfig.setStringProperty("writeSlackBus", Boolean.toString(writeSlackBus));
moduleConfig.setStringProperty("voltageRemoteControl", Boolean.toString(voltageRemoteControl));
moduleConfig.setStringProperty("dc", Boolean.toString(dc));
moduleConfig.setStringProperty("distributedSlack", Boolean.toString(dc));
moduleConfig.setStringProperty("balanceType", balanceType.name());
moduleConfig.setStringProperty("dcUseTransformerRatio", Boolean.toString(dc));
moduleConfig.setStringListProperty("countriesToBalance", countriesToBalance.stream().map(e -> e.name()).toList());
moduleConfig.setStringProperty("computedConnectedComponent", computedConnectedComponent.name());
moduleConfig.setStringProperty("hvdcAcEmulation", Boolean.toString(hvdcAcEmulation));

LoadFlowParameters parameters = new LoadFlowParameters();
LoadFlowParameters.load(parameters, platformConfig);
checkValues(parameters, voltageInitMode, transformerVoltageControlOn,
!noGeneratorReactiveLimits, phaseShifterRegulationOn, twtSplitShuntAdmittance, simulShunt, readSlackBus, writeSlackBus,
dc, distributedSlack, balanceType, dcUseTransformerRatio, countriesToBalance, computedConnectedComponent, hvdcAcEmulation);
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -146,7 +104,8 @@ void checkIncompleteConfig() {
LoadFlowParameters.DEFAULT_SHUNT_COMPENSATOR_VOLTAGE_CONTROL_ON, LoadFlowParameters.DEFAULT_READ_SLACK_BUS, LoadFlowParameters.DEFAULT_WRITE_SLACK_BUS,
LoadFlowParameters.DEFAULT_DC, LoadFlowParameters.DEFAULT_DISTRIBUTED_SLACK, LoadFlowParameters.DEFAULT_BALANCE_TYPE,
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT, LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -159,7 +118,8 @@ void checkDefaultPlatformConfig() {
LoadFlowParameters.DEFAULT_SHUNT_COMPENSATOR_VOLTAGE_CONTROL_ON, LoadFlowParameters.DEFAULT_READ_SLACK_BUS, LoadFlowParameters.DEFAULT_WRITE_SLACK_BUS,
LoadFlowParameters.DEFAULT_DC, LoadFlowParameters.DEFAULT_DISTRIBUTED_SLACK, LoadFlowParameters.DEFAULT_BALANCE_TYPE,
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT, LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -173,7 +133,8 @@ void checkConstructorByVoltageInitMode() {
LoadFlowParameters.DEFAULT_SHUNT_COMPENSATOR_VOLTAGE_CONTROL_ON, LoadFlowParameters.DEFAULT_READ_SLACK_BUS, LoadFlowParameters.DEFAULT_WRITE_SLACK_BUS,
LoadFlowParameters.DEFAULT_DC, LoadFlowParameters.DEFAULT_DISTRIBUTED_SLACK, LoadFlowParameters.DEFAULT_BALANCE_TYPE,
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT, LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE, LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -195,7 +156,8 @@ void checkConstructorByVoltageInitModeAndTransformerVoltageControlOn() {
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT,
LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE,
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -216,7 +178,8 @@ void checkConstructorByLoadFlowParameters() {
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT,
LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE,
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);

LoadFlowParameters parameters1 = new LoadFlowParameters(parameters);
parameters1.setDc(true);
Expand All @@ -236,7 +199,8 @@ void checkConstructorByLoadFlowParameters() {
LoadFlowParameters.DEFAULT_DC_USE_TRANSFORMER_RATIO_DEFAULT,
LoadFlowParameters.DEFAULT_COUNTRIES_TO_BALANCE,
LoadFlowParameters.DEFAULT_CONNECTED_COMPONENT_MODE,
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON);
LoadFlowParameters.DEFAULT_HVDC_AC_EMULATION_ON,
LoadFlowParameters.DEFAULT_DC_POWER_FACTOR);
}

@Test
Expand All @@ -256,6 +220,7 @@ void checkSetters() {
Set<Country> countriesToBalance = new HashSet<>();
LoadFlowParameters.ConnectedComponentMode computedConnectedComponent = LoadFlowParameters.ConnectedComponentMode.MAIN;
boolean hvdcAcEmulation = false;
double dcPowerFactor = 0.95;

LoadFlowParameters parameters = new LoadFlowParameters();
LoadFlowParameters.load(parameters, platformConfig);
Expand All @@ -270,11 +235,12 @@ void checkSetters() {
.setDc(dc)
.setDistributedSlack(distributedSlack)
.setBalanceType(balanceType)
.setHvdcAcEmulation(hvdcAcEmulation);
.setHvdcAcEmulation(hvdcAcEmulation)
.setDcPowerFactor(dcPowerFactor);

checkValues(parameters, voltageInitMode, transformerVoltageControlOn, useReactiveLimits,
phaseShifterRegulationOn, twtSplitShuntAdmittance, simulShunt, readSlackBus, writeSlackBus,
dc, distributedSlack, balanceType, dcUseTransformerRatio, countriesToBalance, computedConnectedComponent, hvdcAcEmulation);
dc, distributedSlack, balanceType, dcUseTransformerRatio, countriesToBalance, computedConnectedComponent, hvdcAcEmulation, dcPowerFactor);
}

@Test
Expand All @@ -294,6 +260,7 @@ void checkClone() {
Set<Country> countriesToBalance = new HashSet<>();
LoadFlowParameters.ConnectedComponentMode computedConnectedComponent = LoadFlowParameters.ConnectedComponentMode.MAIN;
boolean hvdcAcEmulation = false;
double dcPowerFactor = 0.95;
LoadFlowParameters parameters = new LoadFlowParameters()
.setVoltageInitMode(voltageInitMode)
.setTransformerVoltageControlOn(transformerVoltageControlOn)
Expand All @@ -309,13 +276,14 @@ void checkClone() {
.setDcUseTransformerRatio(dcUseTransformerRatio)
.setCountriesToBalance(countriesToBalance)
.setConnectedComponentMode(computedConnectedComponent)
.setHvdcAcEmulation(hvdcAcEmulation);
.setHvdcAcEmulation(hvdcAcEmulation)
.setDcPowerFactor(dcPowerFactor);
LoadFlowParameters parametersCloned = parameters.copy();
checkValues(parametersCloned, parameters.getVoltageInitMode(), parameters.isTransformerVoltageControlOn(),
parameters.isUseReactiveLimits(), parameters.isPhaseShifterRegulationOn(), parameters.isTwtSplitShuntAdmittance(),
parameters.isShuntCompensatorVoltageControlOn(), parameters.isReadSlackBus(), parameters.isWriteSlackBus(),
parameters.isDc(), parameters.isDistributedSlack(), parameters.getBalanceType(), parameters.isDcUseTransformerRatio(),
parameters.getCountriesToBalance(), parameters.getConnectedComponentMode(), parameters.isHvdcAcEmulation());
parameters.getCountriesToBalance(), parameters.getConnectedComponentMode(), parameters.isHvdcAcEmulation(), parameters.getDcPowerFactor());
}

@Test
Expand Down Expand Up @@ -360,4 +328,95 @@ void testExtensionFromConfig() {
assertInstanceOf(DummyExtension.class, parameters.getExtensionByName("dummy-extension"));
assertNotNull(parameters.getExtension(DummyExtension.class));
}

@Test
void checkAllValuesNonDefault() {
LoadFlowParameters.VoltageInitMode voltageInitMode = LoadFlowParameters.VoltageInitMode.DC_VALUES;
boolean transformerVoltageControlOn = true;
boolean useReactiveLimits = false;
boolean phaseShifterRegulationOn = true;
boolean twtSplitShuntAdmittance = true;
boolean shuntCompensatorVoltageControlOn = true;
boolean readSlackBus = false;
boolean writeSlackBus = false;
boolean dc = true;
boolean distributedSlack = false;
LoadFlowParameters.BalanceType balanceType = LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD;
boolean dcUseTransformerRatio = false;
Set<Country> countriesToBalance = Set.of(Country.FR);
LoadFlowParameters.ConnectedComponentMode connectedComponentMode = LoadFlowParameters.ConnectedComponentMode.ALL;
boolean hvdcAcEmulation = false;
double dcPowerFactor = 0.95;

MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-default-parameters");
moduleConfig.setStringProperty("voltageInitMode", voltageInitMode.name());
moduleConfig.setStringProperty("transformerVoltageControlOn", Boolean.toString(transformerVoltageControlOn));
moduleConfig.setStringProperty("useReactiveLimits", Boolean.toString(useReactiveLimits));
moduleConfig.setStringProperty("phaseShifterRegulationOn", Boolean.toString(phaseShifterRegulationOn));
moduleConfig.setStringProperty("twtSplitShuntAdmittance", Boolean.toString(twtSplitShuntAdmittance));
moduleConfig.setStringProperty("shuntCompensatorVoltageControlOn", Boolean.toString(shuntCompensatorVoltageControlOn));
moduleConfig.setStringProperty("readSlackBus", Boolean.toString(readSlackBus));
moduleConfig.setStringProperty("writeSlackBus", Boolean.toString(writeSlackBus));
moduleConfig.setStringProperty("dc", Boolean.toString(dc));
moduleConfig.setStringProperty("distributedSlack", Boolean.toString(distributedSlack));
moduleConfig.setStringProperty("balanceType", balanceType.name());
moduleConfig.setStringProperty("dcUseTransformerRatio", Boolean.toString(dcUseTransformerRatio));
moduleConfig.setStringListProperty("countriesToBalance", countriesToBalance.stream().map(Enum::name).toList());
moduleConfig.setStringProperty("connectedComponentMode", connectedComponentMode.name());
moduleConfig.setStringProperty("hvdcAcEmulation", Boolean.toString(hvdcAcEmulation));
moduleConfig.setStringProperty("dcPowerFactor", Double.toString(dcPowerFactor));

LoadFlowParameters parameters = new LoadFlowParameters();
LoadFlowParameters.load(parameters, platformConfig);
checkValues(parameters, voltageInitMode, transformerVoltageControlOn, useReactiveLimits, phaseShifterRegulationOn,
twtSplitShuntAdmittance, shuntCompensatorVoltageControlOn, readSlackBus, writeSlackBus, dc, distributedSlack,
balanceType, dcUseTransformerRatio, countriesToBalance, connectedComponentMode, hvdcAcEmulation, dcPowerFactor);
}

@Test
void checkSecondaryNamesNonDefault() {
LoadFlowParameters.VoltageInitMode voltageInitMode = LoadFlowParameters.VoltageInitMode.DC_VALUES;
boolean transformerVoltageControlOn = true;
boolean useReactiveLimits = false;
boolean phaseShifterRegulationOn = true;
boolean twtSplitShuntAdmittance = true;
boolean shuntCompensatorVoltageControlOn = true;
boolean readSlackBus = false;
boolean writeSlackBus = false;
boolean dc = true;
boolean distributedSlack = false;
LoadFlowParameters.BalanceType balanceType = LoadFlowParameters.BalanceType.PROPORTIONAL_TO_LOAD;
boolean dcUseTransformerRatio = false;
Set<Country> countriesToBalance = Set.of(Country.FR);
LoadFlowParameters.ConnectedComponentMode connectedComponentMode = LoadFlowParameters.ConnectedComponentMode.ALL;
boolean hvdcAcEmulation = false;
double dcPowerFactor = 0.95;

MapModuleConfig moduleConfig = platformConfig.createModuleConfig("load-flow-default-parameters");
moduleConfig.setStringProperty("voltageInitMode", voltageInitMode.name());
moduleConfig.setStringProperty("transformerVoltageControlOn", Boolean.toString(transformerVoltageControlOn));
// useReactiveLimits can be replaced by noGeneratorReactiveLimits (inverted)
moduleConfig.setStringProperty("noGeneratorReactiveLimits", Boolean.toString(!useReactiveLimits));
moduleConfig.setStringProperty("phaseShifterRegulationOn", Boolean.toString(phaseShifterRegulationOn));
// twtSplitShuntAdmittance can be replaced by specificCompatibility
moduleConfig.setStringProperty("specificCompatibility", Boolean.toString(twtSplitShuntAdmittance));
// shuntCompensatorVoltageControlOn can be replaced by simulShunt
moduleConfig.setStringProperty("simulShunt", Boolean.toString(shuntCompensatorVoltageControlOn));
moduleConfig.setStringProperty("readSlackBus", Boolean.toString(readSlackBus));
moduleConfig.setStringProperty("writeSlackBus", Boolean.toString(writeSlackBus));
moduleConfig.setStringProperty("dc", Boolean.toString(dc));
moduleConfig.setStringProperty("distributedSlack", Boolean.toString(distributedSlack));
moduleConfig.setStringProperty("balanceType", balanceType.name());
moduleConfig.setStringProperty("dcUseTransformerRatio", Boolean.toString(dcUseTransformerRatio));
moduleConfig.setStringListProperty("countriesToBalance", countriesToBalance.stream().map(Enum::name).toList());
moduleConfig.setStringProperty("connectedComponentMode", connectedComponentMode.name());
moduleConfig.setStringProperty("hvdcAcEmulation", Boolean.toString(hvdcAcEmulation));
moduleConfig.setStringProperty("dcPowerFactor", Double.toString(dcPowerFactor));

LoadFlowParameters parameters = new LoadFlowParameters();
LoadFlowParameters.load(parameters, platformConfig);
checkValues(parameters, voltageInitMode, transformerVoltageControlOn, useReactiveLimits, phaseShifterRegulationOn,
twtSplitShuntAdmittance, shuntCompensatorVoltageControlOn, readSlackBus, writeSlackBus, dc, distributedSlack,
balanceType, dcUseTransformerRatio, countriesToBalance, connectedComponentMode, hvdcAcEmulation, dcPowerFactor);
}
}