Skip to content

Commit

Permalink
Fix integration test
Browse files Browse the repository at this point in the history
Add writeFinalState to DynaWaltzParameters

Signed-off-by: lisrte <laurent.issertial@rte-france.com>
  • Loading branch information
Lisrte authored and flo-dup committed May 19, 2023
1 parent 249f24f commit dbc871f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DynaWaltzParameters extends AbstractExtension<DynamicSimulationPara
public static final String MODELS_OUTPUT_PARAMETERS_FILE = "models.par";
public static final String NETWORK_OUTPUT_PARAMETERS_FILE = "network.par";
public static final String SOLVER_OUTPUT_PARAMETERS_FILE = "solvers.par";
private static final boolean DEFAULT_WRITE_FINAL_STATE = true;

public enum SolverType {
SIM,
Expand All @@ -47,6 +48,7 @@ public enum SolverType {
private ParametersSet solverParameters;
private SolverType solverType;
private boolean mergeLoads;
private boolean writeFinalState = DEFAULT_WRITE_FINAL_STATE;

/**
* Loads parameters from the default platform configuration.
Expand Down Expand Up @@ -94,6 +96,9 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
// If merging loads on each bus to simplify dynawo's analysis
boolean mergeLoads = config.flatMap(c -> c.getOptionalBooleanProperty("mergeLoads")).orElse(DEFAULT_MERGE_LOADS);

// Writes final state IIDM
boolean writeFinalState = config.flatMap(c -> c.getOptionalBooleanProperty("writeFinalState")).orElse(DEFAULT_WRITE_FINAL_STATE);

// Load xml files
List<ParametersSet> modelsParameters = ParametersXml.load(parametersPath);
ParametersSet networkParameters = ParametersXml.load(networkParametersPath, networkParametersId);
Expand All @@ -104,7 +109,8 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
.setSolverType(solverType)
.setMergeLoads(mergeLoads);
.setMergeLoads(mergeLoads)
.setWriteFinalState(writeFinalState);
}

@Override
Expand Down Expand Up @@ -163,4 +169,13 @@ public DynaWaltzParameters setMergeLoads(boolean mergeLoads) {
this.mergeLoads = mergeLoads;
return this;
}

public DynaWaltzParameters setWriteFinalState(boolean writeFinalState) {
this.writeFinalState = writeFinalState;
return this;
}

public boolean isWriteFinalState() {
return writeFinalState;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,13 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th
super.after(workingDir, report);
context.getNetwork().getVariantManager().setWorkingVariant(context.getWorkingVariantId());
boolean status = true;
Path outputNetworkFile = workingDir.resolve("outputs").resolve("finalState").resolve(OUTPUT_IIDM_FILENAME);
if (Files.exists(outputNetworkFile)) {
NetworkResultsUpdater.update(context.getNetwork(), NetworkXml.read(outputNetworkFile), context.getDynaWaltzParameters().isMergeLoads());
} else {
status = false;
if(context.getDynaWaltzParameters().isWriteFinalState()) {
Path outputNetworkFile = workingDir.resolve("outputs").resolve("finalState").resolve(OUTPUT_IIDM_FILENAME);
if (Files.exists(outputNetworkFile)) {
NetworkResultsUpdater.update(context.getNetwork(), NetworkXml.read(outputNetworkFile), context.getDynaWaltzParameters().isMergeLoads());
} else {
status = false;
}
}
Path curvesPath = workingDir.resolve(CURVES_OUTPUT_PATH).toAbsolutePath().resolve(CURVES_FILENAME);
Map<String, TimeSeries> curves = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context
writer.writeAttribute("exportMode", "TXT");

writer.writeEmptyElement(DYN_URI, "finalState");
writer.writeAttribute("exportIIDMFile", "true");
writer.writeAttribute("exportIIDMFile", Boolean.toString(context.getDynaWaltzParameters().isWriteFinalState()));
writer.writeAttribute("exportDumpFile", "false");

if (context.withCurves()) {
Expand Down
1 change: 1 addition & 0 deletions dynawaltz/src/test/resources/DynaWaltzParameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"solverType" : "IDA",
"mergeLoads" : false,
"writeFinalState" : true,
"modelsParameters" : [ {
"id" : "test",
"parameters" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,15 @@ void testSmib() {
dynaWaltzParameters.setModelsParameters(modelsParameters)
.setNetworkParameters(networkParameters)
.setSolverParameters(solverParameters)
.setSolverType(DynaWaltzParameters.SolverType.IDA);
.setSolverType(DynaWaltzParameters.SolverType.IDA)
.setWriteFinalState(false);

DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier,
VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters)
.join();

assertTrue(result.isOk());
assertEquals(0, result.getCurves().size());
assertEquals(35, result.getCurves().size());
StringTimeSeries timeLine = result.getTimeLine();
assertEquals(1, timeLine.toArray().length);
assertNull(timeLine.toArray()[0]); // FIXME
Expand Down

0 comments on commit dbc871f

Please sign in to comment.