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

Retrieve specific parameters overrides from PlatformConfig #1093

Merged
merged 2 commits into from
Oct 11, 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 @@ -54,6 +54,8 @@ public class OpenLoadFlowParameters extends AbstractExtension<LoadFlowParameters

public static final LowImpedanceBranchMode LOW_IMPEDANCE_BRANCH_MODE_DEFAULT_VALUE = LowImpedanceBranchMode.REPLACE_BY_ZERO_IMPEDANCE_LINE;

public static final String MODULE_SPECIFIC_PARAMETERS = "open-loadflow-default-parameters";

public enum SlackDistributionFailureBehavior {
THROW,
FAIL,
Expand Down Expand Up @@ -1326,7 +1328,7 @@ public static OpenLoadFlowParameters load() {

public static OpenLoadFlowParameters load(PlatformConfig platformConfig) {
OpenLoadFlowParameters parameters = new OpenLoadFlowParameters();
platformConfig.getOptionalModuleConfig("open-loadflow-default-parameters")
platformConfig.getOptionalModuleConfig(MODULE_SPECIFIC_PARAMETERS)
.ifPresent(config -> parameters
.setSlackBusSelectionMode(config.getEnumProperty(SLACK_BUS_SELECTION_MODE_PARAM_NAME, SlackBusSelectionMode.class, SLACK_BUS_SELECTION_MODE_DEFAULT_VALUE))
.setSlackBusesIds(config.getStringListProperty(SLACK_BUSES_IDS_PARAM_NAME, Collections.emptyList()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.google.auto.service.AutoService;
import com.google.common.base.Stopwatch;
import com.powsybl.commons.config.ModuleConfig;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.extensions.Extension;
import com.powsybl.commons.extensions.ExtensionJsonSerializer;
Expand Down Expand Up @@ -49,6 +50,8 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.powsybl.openloadflow.OpenLoadFlowParameters.MODULE_SPECIFIC_PARAMETERS;

/**
* @author Sylvain Leclerc {@literal <sylvain.leclerc at rte-france.com>}
*/
Expand Down Expand Up @@ -329,4 +332,9 @@ public Map<String, String> createMapFromSpecificParameters(Extension<LoadFlowPar
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, e -> Objects.toString(e.getValue(), "")));
}

@Override
public Optional<ModuleConfig> getModuleConfig(PlatformConfig platformConfig) {
return platformConfig.getOptionalModuleConfig(MODULE_SPECIFIC_PARAMETERS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.powsybl.commons.config.MapModuleConfig;
import com.powsybl.commons.config.PlatformConfig;
import com.powsybl.commons.config.YamlModuleConfigRepository;
import com.powsybl.commons.parameters.Parameter;
import com.powsybl.commons.parameters.ParameterType;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.extensions.SlackTerminal;
Expand All @@ -39,6 +40,7 @@
import java.util.List;
import java.util.Map;

import static com.powsybl.openloadflow.OpenLoadFlowParameters.MODULE_SPECIFIC_PARAMETERS;
import static com.powsybl.openloadflow.util.LoadFlowAssert.assertVoltageEquals;
import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -137,6 +139,16 @@ void testInvalidOpenLoadflowConfigNewtonRaphson() {
assertThrows(IllegalArgumentException.class, () -> openLoadFlowParameters.setMaxReactivePowerMismatch(-1));
}

@Test
void testConfigSpecificParameters() {
MapModuleConfig olfModuleConfig = platformConfig.createModuleConfig(MODULE_SPECIFIC_PARAMETERS);
olfModuleConfig.setStringProperty("slackBusSelectionMode", "FIRST");

List<Parameter> olfParameters = new OpenLoadFlowProvider().getSpecificParameters(platformConfig);

assertEquals(SlackBusSelectionMode.FIRST.toString(), olfParameters.get(0).getDefaultValue());
}

@Test
void testFirstSlackBusSelector() throws IOException {
Path cfgDir = Files.createDirectory(fileSystem.getPath("config"));
Expand Down