Skip to content

Commit

Permalink
Use TimelineEvent instead of StringTimeSeries
Browse files Browse the repository at this point in the history
Signed-off-by: lisrte <[email protected]>
  • Loading branch information
Lisrte committed Nov 22, 2023
1 parent 0afb060 commit aa41a4e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th
DumpFileParameters dumpFileParameters = parameters.getDumpFileParameters();

DynamicSimulationResult.Status status = DynamicSimulationResult.Status.SUCCEED;
String error = "";
String statusText = "";
List<TimelineEvent> timeline = new ArrayList<>();
Map<String, TimeSeries> curves = new HashMap<>();

//Dynawo log
Expand All @@ -216,7 +217,7 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th
} else {
LOGGER.warn("Output IIDM file not found");
status = DynamicSimulationResult.Status.FAILED;
error = "Dynawo Output IIDM file not found";
statusText = "Dynawo Output IIDM file not found";
}
}

Expand All @@ -234,7 +235,10 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th
Path timelineFile = outputsFolder.resolve(DYNAWO_TIMELINE_FOLDER).resolve(TIMELINE_FILENAME);
if (Files.exists(timelineFile)) {
Reporter timelineReporter = DynawaltzReports.createDynaWaltzTimelineReporter(reporter);
new CsvTimeLineParser().parse(timelineFile).forEach(e -> CommonReports.reportTimelineEvent(timelineReporter, e));
new CsvTimeLineParser().parse(timelineFile).forEach(e -> {
CommonReports.reportTimelineEvent(timelineReporter, e);
timeline.add(new TimelineEvent(e.time(), e.modelName(), e.message()));
});
} else {
LOGGER.warn("Timeline file not found");
}
Expand All @@ -248,20 +252,20 @@ public DynamicSimulationResult after(Path workingDir, ExecutionReport report) th
} else {
LOGGER.warn("Curves folder not found");
status = DynamicSimulationResult.Status.FAILED;
error = "Dynawo curves folder not found";
statusText = "Dynawo curves folder not found";
}
}
} else {
status = DynamicSimulationResult.Status.FAILED;
error = errorMatcher.group().substring(DYNAWO_ERROR_PATTERN.length());
statusText = errorMatcher.group().substring(DYNAWO_ERROR_PATTERN.length());
}
} else {
LOGGER.warn("Error file not found");
status = DynamicSimulationResult.Status.FAILED;
error = "Dynawo error log file not found";
statusText = "Dynawo error log file not found";
}

return new DynamicSimulationResultImpl(status, error, curves, DynamicSimulationResult.emptyTimeLine());
return new DynamicSimulationResultImpl(status, statusText, curves, timeline);
}

private void writeInputFiles(Path workingDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.powsybl.iidm.network.VariantManagerConstants;
import com.powsybl.iidm.network.test.SvcTestCaseFactory;
import com.powsybl.timeseries.DoubleTimeSeries;
import com.powsybl.timeseries.StringTimeSeries;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -50,7 +49,7 @@ void setUp() throws Exception {
super.setUp();
provider = new DynaWaltzProvider(new DynaWaltzConfig(Path.of("/dynawo"), false));
parameters = new DynamicSimulationParameters()
.setStartTime(1)
.setStartTime(0)
.setStopTime(100);
dynaWaltzParameters = new DynaWaltzParameters();
parameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters);
Expand Down Expand Up @@ -86,15 +85,14 @@ void testIeee14() {
.join();

assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());
assertTrue(result.isOk());
assertTrue(result.getError().isEmpty());
assertTrue(result.getStatusText().isEmpty());
assertEquals(41, result.getCurves().size());
DoubleTimeSeries ts1 = (DoubleTimeSeries) result.getCurve("_GEN____1_SM_generator_UStatorPu");
assertEquals("_GEN____1_SM_generator_UStatorPu", ts1.getMetadata().getName());
assertEquals(587, ts1.toArray().length);
StringTimeSeries timeLine = result.getTimeLine();
assertEquals(1, timeLine.toArray().length);
assertNull(timeLine.toArray()[0]); // FIXME
List<TimelineEvent> timeLine = result.getTimeLine();
assertEquals(23, timeLine.size());
checkFirstTimeLineEvent(timeLine.get(0), 0,"_GEN____8_SM", "PMIN : activation");
}

@Test
Expand Down Expand Up @@ -130,7 +128,7 @@ void testIeee14WithDump() throws IOException {
DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier,
VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, NO_OP)
.join();
assertTrue(result.isOk());
assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());

//Use exported dump as input
parameters.setStartTime(30);
Expand All @@ -147,8 +145,6 @@ void testIeee14WithDump() throws IOException {
.join();

assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());
assertTrue(result.isOk());
assertTrue(result.getError().isEmpty());
}

@Test
Expand All @@ -173,12 +169,11 @@ void testSvc() {
.join();

assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());
assertTrue(result.isOk());
assertTrue(result.getError().isEmpty());
assertTrue(result.getStatusText().isEmpty());
assertTrue(result.getCurves().isEmpty());
StringTimeSeries timeLine = result.getTimeLine();
assertEquals(1, timeLine.toArray().length);
assertNull(timeLine.toArray()[0]); // FIXME
List<TimelineEvent> timeLine = result.getTimeLine();
assertEquals(1, timeLine.size());
checkFirstTimeLineEvent(timeLine.get(0), 0, "G1", "PMIN : activation");
}

@Test
Expand All @@ -203,12 +198,11 @@ void testHvdc() {
.join();

assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());
assertTrue(result.isOk());
assertTrue(result.getError().isEmpty());
assertTrue(result.getStatusText().isEmpty());
assertTrue(result.getCurves().isEmpty());
StringTimeSeries timeLine = result.getTimeLine();
assertEquals(1, timeLine.toArray().length);
assertNull(timeLine.toArray()[0]); // FIXME
List<TimelineEvent> timeLine = result.getTimeLine();
assertEquals(7, timeLine.size());
checkFirstTimeLineEvent(timeLine.get(0), 30.0, "_BUS____5-BUS____6-1_PS", "Tap +1");
}

@Test
Expand Down Expand Up @@ -242,12 +236,10 @@ void testSmib() {
.join();

assertEquals(DynamicSimulationResult.Status.SUCCEED, result.getStatus());
assertTrue(result.isOk());
assertTrue(result.getError().isEmpty());
assertTrue(result.getStatusText().isEmpty());
assertEquals(35, result.getCurves().size());
StringTimeSeries timeLine = result.getTimeLine();
assertEquals(1, timeLine.toArray().length);
assertNull(timeLine.toArray()[0]); // FIXME
List<TimelineEvent> timeLine = result.getTimeLine();
assertTrue(timeLine.isEmpty());
}

@Test
Expand All @@ -274,9 +266,14 @@ void testSimulationError() {
.join();

assertEquals(DynamicSimulationResult.Status.FAILED, result.getStatus());
assertFalse(result.isOk());
assertEquals("time step <= 0.1 s for more than 10 iterations ( DYNSolverCommonFixedTimeStep.cpp:419 )", result.getError());
assertEquals(DynamicSimulationResult.emptyTimeLine(), result.getTimeLine());
assertEquals("time step <= 0.1 s for more than 10 iterations ( DYNSolverCommonFixedTimeStep.cpp:419 )", result.getStatusText());
assertTrue(result.getTimeLine().isEmpty());
assertTrue(result.getCurves().isEmpty());
}

private void checkFirstTimeLineEvent(TimelineEvent event, double time, String modelName, String message) {
assertEquals(time, event.time());
assertEquals(modelName, event.modelName());
assertEquals(message, event.message());
}
}

0 comments on commit aa41a4e

Please sign in to comment.