Skip to content

Commit

Permalink
[WIP] DynaFlow: add mergeLoads
Browse files Browse the repository at this point in the history
Signed-off-by: BAUDRIER Dimitri <dimitri.baudrier@rte-france.com>
  • Loading branch information
BAUDRIER Dimitri committed Nov 22, 2022
1 parent eead11b commit 167abde
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public boolean isSerializable() {
private static final String CHOSEN_OUTPUTS = "chosenOutputs";
private static final String TIME_STEP = "timeStep";
private static final String STARTING_POINT_MODE = "startingPointMode";
private static final String MERGE_LOADS = "mergeLoads";

private static final boolean DEFAULT_MERGE_LOADS = true;

private Boolean svcRegulationOn = null;
private Boolean shuntRegulationOn = null;
Expand All @@ -94,6 +97,7 @@ public boolean isSerializable() {
private List<String> chosenOutputs = null;
private Double timeStep = null;
private StartingPointMode startingPointMode = null;
private boolean mergeLoads = DEFAULT_MERGE_LOADS;

public Boolean getSvcRegulationOn() {
return svcRegulationOn;
Expand Down Expand Up @@ -234,6 +238,15 @@ public DynaFlowParameters setSa(Sa securityAnalysis) {
return this;
}

@JsonIgnore
public boolean getMergeLoads() {
return mergeLoads;
}

public void setMergeLoads(boolean mergeLoads) {
this.mergeLoads = mergeLoads;
}

@Override
public String getName() {
return "DynaFlowParameters";
Expand All @@ -256,6 +269,7 @@ public String toString() {
.add(CHOSEN_OUTPUTS, chosenOutputs)
.add(TIME_STEP, timeStep)
.add(STARTING_POINT_MODE, startingPointMode)
.add(MERGE_LOADS, mergeLoads)
.toString();
}

Expand Down Expand Up @@ -321,6 +335,9 @@ private static void load(DynaFlowParameters parameters, ModuleConfig config) {
if (config.hasProperty(STARTING_POINT_MODE)) {
parameters.setStartingPointMode(StartingPointMode.fromString(config.getStringProperty(STARTING_POINT_MODE)));
}
if (config.hasProperty(MERGE_LOADS)) {
parameters.setMergeLoads(config.getBooleanProperty(MERGE_LOADS, DEFAULT_MERGE_LOADS));
}
}

public void update(Map<String, String> properties) {
Expand All @@ -345,6 +362,7 @@ public void update(Map<String, String> properties) {
setChosenOutputs(Stream.of(prop.split(CHOSEN_OUTPUT_STRING_DELIMITER)).map(String::trim).collect(Collectors.toList())));
Optional.ofNullable(properties.get(TIME_STEP)).ifPresent(prop -> setTimeStep(Double.parseDouble(prop)));
Optional.ofNullable(properties.get(STARTING_POINT_MODE)).ifPresent(prop -> setStartingPointMode(StartingPointMode.fromString(prop)));
Optional.ofNullable(properties.get(MERGE_LOADS)).ifPresent(prop -> setMergeLoads(Boolean.parseBoolean(prop)));
}

public static DynaFlowParameters load(Map<String, String> properties) {
Expand All @@ -357,7 +375,7 @@ public static List<String> getSpecificParametersNames() {
return Arrays.asList(
SVC_REGULATION_ON, SHUNT_REGULATION_ON, AUTOMATIC_SLACK_BUS_ON, DSO_VOLTAGE_LEVEL,
ACTIVE_POWER_COMPENSATION, SETTING_PATH, ASSEMBLING_PATH, START_TIME, STOP_TIME, PRECISION_NAME,
Sa.TIME_OF_EVENT, CHOSEN_OUTPUTS, TIME_STEP, STARTING_POINT_MODE
Sa.TIME_OF_EVENT, CHOSEN_OUTPUTS, TIME_STEP, STARTING_POINT_MODE, MERGE_LOADS
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void checkParameters() {
List<String> chosenOutputs = Arrays.asList(OutputTypes.STEADYSTATE.name(), OutputTypes.TIMELINE.name());
double timeStep = 0;
StartingPointMode startingPointMode = StartingPointMode.FLAT;
boolean mergedLoads = false;

DynaFlowParameters.Sa securityAnalysis = new DynaFlowParameters.Sa();
securityAnalysis.setTimeOfEvent(2.);
Expand All @@ -93,6 +94,7 @@ public void checkParameters() {
moduleConfig.setStringListProperty("chosenOutputs", chosenOutputs);
moduleConfig.setStringProperty("timeStep", Double.toString(timeStep));
moduleConfig.setStringProperty("startingPointMode", startingPointMode.getName());
moduleConfig.setStringProperty("mergeLoads", Boolean.toString(mergedLoads));

DynaFlowParameters parameters = DynaFlowParameters.load(platformConfig);

Expand All @@ -110,6 +112,7 @@ public void checkParameters() {
assertArrayEquals(chosenOutputs.toArray(), parameters.getChosenOutputs().toArray());
assertEquals(timeStep, parameters.getTimeStep(), 0.1d);
assertEquals(startingPointMode, parameters.getStartingPointMode());
assertEquals(mergedLoads, parameters.getMergeLoads());
}

@Test
Expand All @@ -132,14 +135,15 @@ public void checkDefaultParameters() {
assertNull(parametersExt.getChosenOutputs());
assertNull(parametersExt.getTimeStep());
assertNull(parametersExt.getStartingPointMode());
assertTrue(parametersExt.getMergeLoads());
}

@Test
public void checkDefaultToString() {
LoadFlowParameters parameters = LoadFlowParameters.load(platformConfig);
DynaFlowParameters parametersExt = parameters.getExtension(DynaFlowParameters.class);

String expectedString = "{}";
String expectedString = "{mergeLoads=true}";

assertEquals(expectedString, parametersExt.toString());

Expand All @@ -163,6 +167,7 @@ public void checkAllParametersAssignedToString() {
List<String> chosenOutputs = Arrays.asList(OutputTypes.STEADYSTATE.name(), OutputTypes.TIMELINE.name());
double timeStep = 0;
StartingPointMode startingPointMode = StartingPointMode.WARM;
boolean mergeLoad = false;

Map<String, String> properties = new HashMap<>();
properties.put("svcRegulationOn", Boolean.toString(svcRegulationOn));
Expand All @@ -179,6 +184,7 @@ public void checkAllParametersAssignedToString() {
properties.put("chosenOutputs", OutputTypes.STEADYSTATE.name() + "," + OutputTypes.TIMELINE.name());
properties.put("timeStep", Double.toString(timeStep));
properties.put("startingPointMode", startingPointMode.name());
properties.put("mergeLoads", Boolean.toString(mergeLoad));

parametersExt.update(properties);

Expand All @@ -196,7 +202,8 @@ public void checkAllParametersAssignedToString() {
"{timeOfEvent=" + timeOfEvent + "}" +
", chosenOutputs=" + chosenOutputs +
", timeStep=" + timeStep +
", startingPointMode=" + startingPointMode + "}";
", startingPointMode=" + startingPointMode +
", mergeLoads=" + mergeLoad + "}";
assertEquals(expectedString, parametersExt.toString());
System.out.println(expectedString);
}
Expand Down Expand Up @@ -241,6 +248,7 @@ public void parametersSerialization() throws IOException {
dynaFlowParameters.setChosenOutputs(Collections.singletonList(OutputTypes.STEADYSTATE.name()));
dynaFlowParameters.setTimeStep(2.6);
dynaFlowParameters.setStartingPointMode(StartingPointMode.WARM);
dynaFlowParameters.setMergeLoads(false);
lfParameters.addExtension(DynaFlowParameters.class, dynaFlowParameters);

Path workingDir = fileSystem.getPath("dynaflow/workingDir");
Expand Down Expand Up @@ -270,6 +278,7 @@ public void loadMapDynaflowParameters() {
List<String> chosenOutputs = Arrays.asList(OutputTypes.STEADYSTATE.name(), OutputTypes.TIMELINE.name());
double timeStep = 0;
StartingPointMode startingPointMode = StartingPointMode.WARM;
boolean mergeLoads = false;

Map<String, String> properties = new HashMap<>();
properties.put("svcRegulationOn", Boolean.toString(svcRegulationOn));
Expand All @@ -286,6 +295,7 @@ public void loadMapDynaflowParameters() {
properties.put("chosenOutputs", OutputTypes.STEADYSTATE.name() + ", " + OutputTypes.TIMELINE.name());
properties.put("timeStep", Double.toString(timeStep));
properties.put("startingPointMode", startingPointMode.getName());
properties.put("mergeLoads", Boolean.toString(mergeLoads));

DynaFlowParameters dynaFlowParameters = DynaFlowParameters.load(properties);

Expand All @@ -303,5 +313,6 @@ public void loadMapDynaflowParameters() {
assertArrayEquals(chosenOutputs.toArray(), dynaFlowParameters.getChosenOutputs().toArray());
assertEquals(timeStep, dynaFlowParameters.getTimeStep(), 0.1d);
assertEquals(startingPointMode, dynaFlowParameters.getStartingPointMode());
assertEquals(mergeLoads, dynaFlowParameters.getMergeLoads());
}
}
3 changes: 2 additions & 1 deletion dynaflow/src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"chosenOutputs" : [ "STEADYSTATE", "TIMELINE" ],
"timeStep" : 2.6,
"startingPointMode" : "warm"
"startingPointMode" : "warm",
"mergeLoads" : false
}
}
}

0 comments on commit 167abde

Please sign in to comment.