From fb8d952e2b208d7fbf01a8206edbcbcab20aaf0f Mon Sep 17 00:00:00 2001 From: Lisrte Date: Wed, 15 May 2024 10:45:46 +0200 Subject: [PATCH] Various refactors (#345) * Add equipment id to default model warning/report * Remove deprecated and other minors errors * Refactor ModelConfigsJsonDeserializer * Fix test, checkstyle; replace AtomicReference with anonymous object Signed-off-by: lisrte --- .../dynawo/commons/dynawologs/LogUtils.java | 2 +- .../dynaflow/DynaFlowParametersTest.java | 36 +++---- .../dynaflow/DynaFlowProviderTest.java | 8 +- .../JsonDynaFlowParametersSerializerTest.java | 32 +++---- .../powsybl/dynawaltz/dsl/DslReports.groovy | 2 +- .../DynaWaltzGroovyCurvesSupplierTest.java | 2 +- .../dsl/EventModelsSupplierTest.java | 2 +- .../ModelConfigsJsonDeserializer.java | 96 +++++++++---------- .../defaultmodels/DefaultModelsHandler.java | 4 +- dynawaltz/src/main/resources/models.json | 44 ++++----- .../dynawaltz/DynaWaltzProviderTest.java | 5 +- .../builders/ModelConfigLoaderTest.java | 12 +-- .../DefaultModelHandlerTest.java | 2 +- .../com/powsybl/dynawo/it/DynaFlowTest.java | 8 +- .../com/powsybl/dynawo/it/DynaWaltzTest.java | 2 +- 15 files changed, 125 insertions(+), 132 deletions(-) diff --git a/commons/src/main/java/com/powsybl/dynawo/commons/dynawologs/LogUtils.java b/commons/src/main/java/com/powsybl/dynawo/commons/dynawologs/LogUtils.java index cefcccdf9..06c2f0a34 100644 --- a/commons/src/main/java/com/powsybl/dynawo/commons/dynawologs/LogUtils.java +++ b/commons/src/main/java/com/powsybl/dynawo/commons/dynawologs/LogUtils.java @@ -27,7 +27,7 @@ private LogUtils() { public static Optional createLog(String severity, String message) { if (severity == null) { - LOGGER.warn("Inconsistent log entry (modelName: '{}', message: '{}')", severity, message); + LOGGER.warn("Inconsistent log entry (message: '{}')", message); } else { if (emptyMessage(message)) { LOGGER.debug("Empty message, the entry will be skipped : {}", message); diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java index 52347e736..ad6dd9447 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowParametersTest.java @@ -193,7 +193,7 @@ void checkAllParametersAssignedToString() { @Test void defaultParametersSerialization() throws IOException { LoadFlowParameters lfParameters = LoadFlowParameters.load(platformConfig); - lfParameters.setNoGeneratorReactiveLimits(true); + lfParameters.setUseReactiveLimits(false); lfParameters.setPhaseShifterRegulationOn(false); DynaFlowParameters dynaFlowParameters = new DynaFlowParameters(); @@ -212,25 +212,25 @@ void defaultParametersSerialization() throws IOException { @Test void parametersSerialization() throws IOException { LoadFlowParameters lfParameters = LoadFlowParameters.load(platformConfig); - lfParameters.setNoGeneratorReactiveLimits(true); + lfParameters.setUseReactiveLimits(false); lfParameters.setPhaseShifterRegulationOn(false); - DynaFlowParameters dynaFlowParameters = new DynaFlowParameters(); - dynaFlowParameters.setSvcRegulationOn(true); - dynaFlowParameters.setShuntRegulationOn(false); - dynaFlowParameters.setAutomaticSlackBusOn(true); - dynaFlowParameters.setDsoVoltageLevel(32.4); - dynaFlowParameters.setActivePowerCompensation(ActivePowerCompensation.P); - dynaFlowParameters.setSettingPath("path/to/settingFile"); - dynaFlowParameters.setAssemblingPath("path/to/assemblingFile"); - dynaFlowParameters.setStartTime(0.); - dynaFlowParameters.setStopTime(100.); - dynaFlowParameters.setPrecision(0.); - dynaFlowParameters.setTimeOfEvent(10.); - dynaFlowParameters.setChosenOutputs(Collections.singletonList(OutputTypes.STEADYSTATE.name())); - dynaFlowParameters.setTimeStep(2.6); - dynaFlowParameters.setStartingPointMode(StartingPointMode.WARM); - dynaFlowParameters.setMergeLoads(false); + DynaFlowParameters dynaFlowParameters = new DynaFlowParameters() + .setSvcRegulationOn(true) + .setShuntRegulationOn(false) + .setAutomaticSlackBusOn(true) + .setDsoVoltageLevel(32.4) + .setActivePowerCompensation(ActivePowerCompensation.P) + .setSettingPath("path/to/settingFile") + .setAssemblingPath("path/to/assemblingFile") + .setStartTime(0.) + .setStopTime(100.) + .setPrecision(0.) + .setTimeOfEvent(10.) + .setChosenOutputs(Collections.singletonList(OutputTypes.STEADYSTATE.name())) + .setTimeStep(2.6) + .setStartingPointMode(StartingPointMode.WARM) + .setMergeLoads(false); lfParameters.addExtension(DynaFlowParameters.class, dynaFlowParameters); Path workingDir = fileSystem.getPath("dynaflow/workingDir"); diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java index e04371357..ff68bbb7a 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/DynaFlowProviderTest.java @@ -35,6 +35,8 @@ import static com.powsybl.commons.test.ComparisonUtils.compareXml; import static com.powsybl.dynaflow.DynaFlowConstants.*; +import static com.powsybl.loadflow.LoadFlowResult.Status.FAILED; +import static com.powsybl.loadflow.LoadFlowResult.Status.FULLY_CONVERGED; import static org.junit.jupiter.api.Assertions.*; /** @@ -134,7 +136,7 @@ void testWithoutMergeLoads() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()); LoadFlowResult result = dynaFlowSimulation.run(network, computationManager, params); assertNotNull(result); - assertTrue(result.isOk()); + assertEquals(FULLY_CONVERGED, result.getStatus()); InputStream pReferenceOutput = getClass().getResourceAsStream("/output.xiidm"); Network expectedNetwork = NetworkSerDe.read(pReferenceOutput); @@ -155,7 +157,7 @@ void testWithMergeLoads() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()); LoadFlowResult result = dynaFlowSimulation.run(network, computationManager, params); assertNotNull(result); - assertTrue(result.isOk()); + assertEquals(FULLY_CONVERGED, result.getStatus()); InputStream pReferenceOutput = getClass().getResourceAsStream("/output.xiidm"); Network expectedNetwork = NetworkSerDe.read(pReferenceOutput); @@ -175,7 +177,7 @@ void testFail() throws Exception { ComputationManager computationManager = new LocalComputationManager(new LocalComputationConfig(fileSystem.getPath("/working-dir"), 1), commandExecutor, ForkJoinPool.commonPool()); LoadFlowResult result = dynaFlowSimulation.run(network, computationManager, params); assertNotNull(result); - assertFalse(result.isOk()); + assertEquals(FAILED, result.getStatus()); } @Test diff --git a/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java b/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java index fcc5c4982..f81e5cadc 100644 --- a/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java +++ b/dynaflow/src/test/java/com/powsybl/dynaflow/json/JsonDynaFlowParametersSerializerTest.java @@ -69,24 +69,24 @@ void roundTripParameters() throws IOException { InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); LoadFlowParameters parameters = LoadFlowParameters.load(platformConfig); - parameters.setNoGeneratorReactiveLimits(true); + parameters.setUseReactiveLimits(false); parameters.setPhaseShifterRegulationOn(false); - DynaFlowParameters params = new DynaFlowParameters(); - params.setSvcRegulationOn(true); - params.setShuntRegulationOn(false); - params.setAutomaticSlackBusOn(true); - params.setDsoVoltageLevel(54.23); - params.setActivePowerCompensation(DynaFlowConstants.ActivePowerCompensation.P); - params.setSettingPath("path/to/settingFile"); - params.setAssemblingPath("path/to/assemblingFile"); - params.setStartTime(0.); - params.setStopTime(100.); - params.setPrecision(0.); - params.setTimeOfEvent(10.); - params.setChosenOutputs(Collections.singletonList(DynaFlowConstants.OutputTypes.STEADYSTATE.name())); - params.setTimeStep(2.6); - params.setStartingPointMode(DynaFlowConstants.StartingPointMode.WARM); + DynaFlowParameters params = new DynaFlowParameters() + .setSvcRegulationOn(true) + .setShuntRegulationOn(false) + .setAutomaticSlackBusOn(true) + .setDsoVoltageLevel(54.23) + .setActivePowerCompensation(DynaFlowConstants.ActivePowerCompensation.P) + .setSettingPath("path/to/settingFile") + .setAssemblingPath("path/to/assemblingFile") + .setStartTime(0.) + .setStopTime(100.) + .setPrecision(0.) + .setTimeOfEvent(10.) + .setChosenOutputs(Collections.singletonList(DynaFlowConstants.OutputTypes.STEADYSTATE.name())) + .setTimeStep(2.6) + .setStartingPointMode(DynaFlowConstants.StartingPointMode.WARM); parameters.addExtension(DynaFlowParameters.class, params); diff --git a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/DslReports.groovy b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/DslReports.groovy index 9f28bce91..3b071e602 100644 --- a/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/DslReports.groovy +++ b/dynawaltz-dsl/src/main/groovy/com/powsybl/dynawaltz/dsl/DslReports.groovy @@ -7,7 +7,7 @@ */ package com.powsybl.dynawaltz.dsl -import com.powsybl.commons.report.ReportNode; +import com.powsybl.commons.report.ReportNode /** * @author Laurent Issertial {@literal } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java index 613e2c139..cd04ca96e 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/DynaWaltzGroovyCurvesSupplierTest.java @@ -90,7 +90,7 @@ private static Stream provideFileError() { private List validateGroovyExtension() { List extensions = GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME); assertEquals(1, extensions.size()); - assertTrue(extensions.get(0) instanceof DynaWaltzCurveGroovyExtension); + assertInstanceOf(DynaWaltzCurveGroovyExtension.class, extensions.get(0)); return extensions; } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/EventModelsSupplierTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/EventModelsSupplierTest.java index 224310852..5b4b57ed3 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/EventModelsSupplierTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/EventModelsSupplierTest.java @@ -111,7 +111,7 @@ faultTime should be strictly positive (0.0) 'staticId' field value 'SVC2' not found for equipment type(s) GENERATOR/LOAD 'deltaP' field is not set Model Step_SVC2 cannot be instantiated - """), + """), Arguments.of("/eventWarnings/missingDisconnectionEquipment.groovy", EurostagTutorialExample1Factory.create(), """ + DSL tests diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsJsonDeserializer.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsJsonDeserializer.java index 31536a9f4..fb8489c49 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsJsonDeserializer.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/builders/ModelConfigsJsonDeserializer.java @@ -11,12 +11,11 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.powsybl.commons.json.JsonUtil; import java.io.IOException; import java.util.*; -import static com.fasterxml.jackson.core.JsonToken.VALUE_STRING; - /** * @author Laurent Issertial {@literal } */ @@ -32,69 +31,60 @@ public Map deserialize(JsonParser parser, DeserializationC while (parser.nextToken() != JsonToken.END_OBJECT) { String category = parser.getCurrentName(); parser.nextToken(); - configMap.put(category, deserializeModelConfigs(parser)); + configMap.put(category, parseModelConfigs(parser)); } return configMap; } - private ModelConfigs deserializeModelConfigs(JsonParser parser) throws IOException { - String defaultLib = null; - Map libs = null; - while (parser.nextToken() != JsonToken.END_OBJECT) { - switch (parser.getCurrentName()) { - case "defaultLib": - defaultLib = parser.getValueAsString(); - break; - case "libs": - libs = deserializeLibsMap(parser); - break; - default: - throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); + private static ModelConfigs parseModelConfigs(JsonParser parser) { + var parsingContext = new Object() { + String defaultLib = null; + final Map libs = new HashMap<>(); + }; + JsonUtil.parseObject(parser, name -> + switch (name) { + case "defaultLib" -> { + parsingContext.defaultLib = parser.nextTextValue(); + yield true; + } + case "libs" -> { + JsonUtil.parseObjectArray(parser, mc -> parsingContext.libs.put(mc.name(), mc), ModelConfigsJsonDeserializer::parseModelConfig); + yield true; + } + default -> false; } - } - return new ModelConfigs(libs, defaultLib); + ); + return new ModelConfigs(parsingContext.libs, parsingContext.defaultLib); } - private Map deserializeLibsMap(JsonParser parser) throws IOException { - Map libs = new HashMap<>(); - while (parser.nextToken() != JsonToken.END_ARRAY) { - parser.nextToken(); + private static ModelConfig parseModelConfig(JsonParser parser) { + var parsingContext = new Object() { String lib = null; String alias = null; String internalModelPrefix = null; List properties = Collections.emptyList(); - while (parser.nextToken() != JsonToken.END_OBJECT) { - switch (parser.getCurrentName()) { - case "lib": - lib = parser.getValueAsString(); - break; - case "properties": - properties = deserializeProperties(parser); - break; - case "internalModelPrefix": - internalModelPrefix = parser.getValueAsString(); - break; - case "alias": - alias = parser.getValueAsString(); - break; - default: - throw new IllegalStateException("Unexpected field: " + parser.getCurrentName()); + }; + JsonUtil.parseObject(parser, name -> + switch (parser.getCurrentName()) { + case "lib" -> { + parsingContext.lib = parser.nextTextValue(); + yield true; } + case "properties" -> { + parsingContext.properties = JsonUtil.parseStringArray(parser); + yield true; + } + case "internalModelPrefix" -> { + parsingContext.internalModelPrefix = parser.nextTextValue(); + yield true; + } + case "alias" -> { + parsingContext.alias = parser.nextTextValue(); + yield true; + } + default -> false; } - ModelConfig modelConfig = new ModelConfig(lib, alias, internalModelPrefix, properties); - libs.put(modelConfig.name(), modelConfig); - } - return libs; - } - - private List deserializeProperties(JsonParser parser) throws IOException { - List properties = new ArrayList<>(); - JsonToken token; - while ((token = parser.nextToken()) != JsonToken.END_ARRAY) { - if (token == VALUE_STRING) { - properties.add(parser.getValueAsString().toUpperCase()); - } - } - return properties; + ); + return new ModelConfig(parsingContext.lib, parsingContext.alias, parsingContext.internalModelPrefix, parsingContext.properties); } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelsHandler.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelsHandler.java index e7c4deba8..97ff99424 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelsHandler.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelsHandler.java @@ -38,9 +38,9 @@ public T getDefaultModel(Identifiable equipment, Class c return connectableClass.cast(defaultModel); } if (throwException) { - throw new PowsyblException("Default model " + defaultModel.getClass().getSimpleName() + " does not implement " + connectableClass.getSimpleName() + " interface"); + throw new PowsyblException("Default model " + defaultModel.getClass().getSimpleName() + " for " + equipment.getId() + " does not implement " + connectableClass.getSimpleName() + " interface"); } else { - LOGGER.warn("Default model {} does not implement {} interface", defaultModel.getClass().getSimpleName(), connectableClass.getSimpleName()); + LOGGER.warn("Default model {} for {} does not implement {} interface", defaultModel.getClass().getSimpleName(), equipment.getId(), connectableClass.getSimpleName()); return null; } } diff --git a/dynawaltz/src/main/resources/models.json b/dynawaltz/src/main/resources/models.json index 0f785ad16..36de2cb56 100644 --- a/dynawaltz/src/main/resources/models.json +++ b/dynawaltz/src/main/resources/models.json @@ -16,7 +16,7 @@ { "lib": "GeneratorSynchronousFourWindingsGoverPropVRPropInt", "properties": [ - "Controllable" + "CONTROLLABLE" ] }, { @@ -31,13 +31,13 @@ { "lib": "GeneratorSynchronousFourWindingsPmConstVRNordicTfo", "properties": [ - "Transformer" + "TRANSFORMER" ] }, { "lib": "GeneratorSynchronousFourWindingsProportionalRegulations", "properties": [ - "Controllable" + "CONTROLLABLE" ] }, { @@ -64,13 +64,13 @@ { "lib": "GeneratorSynchronousThreeWindingsGoverNordicVRNordicTfo", "properties": [ - "Transformer" + "TRANSFORMER" ] }, { "lib": "GeneratorSynchronousThreeWindingsGoverPropVRPropInt", "properties": [ - "Controllable" + "CONTROLLABLE" ] }, { @@ -79,13 +79,13 @@ { "lib": "GeneratorSynchronousThreeWindingsPmConstVRNordicTfo", "properties": [ - "Transformer" + "TRANSFORMER" ] }, { "lib": "GeneratorSynchronousThreeWindingsProportionalRegulations", "properties": [ - "Controllable" + "CONTROLLABLE" ] } ] @@ -99,7 +99,7 @@ { "lib": "GeneratorPV", "properties": [ - "Controllable" + "CONTROLLABLE" ] }, { @@ -140,25 +140,25 @@ { "lib": "HvdcPVDangling", "properties": [ - "Dangling" + "DANGLING" ] }, { "lib": "HvdcPVDanglingDiagramPQ", "properties": [ - "Dangling" + "DANGLING" ] }, { "lib": "HvdcPTanPhiDangling", "properties": [ - "Dangling" + "DANGLING" ] }, { "lib": "HvdcPTanPhiDanglingDiagramPQ", "properties": [ - "Dangling" + "DANGLING" ] } ] @@ -175,13 +175,13 @@ { "lib": "HvdcVSCDanglingP", "properties": [ - "Dangling" + "DANGLING" ] }, { "lib": "HvdcVSCDanglingUdc", "properties": [ - "Dangling" + "DANGLING" ] } ] @@ -214,7 +214,7 @@ { "lib": "LoadAlphaBeta", "properties": [ - "Controllable" + "CONTROLLABLE" ] }, { @@ -318,14 +318,14 @@ "lib": "WTG4AWeccCurrentSource", "internalModelPrefix": "WTG4A", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { "lib": "WTG4BWeccCurrentSource", "internalModelPrefix": "WTG4B", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { @@ -340,14 +340,14 @@ "lib": "PhotovoltaicsWeccCurrentSource", "internalModelPrefix": "photovoltaics", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { "lib": "PhotovoltaicsWeccVoltageSource", "internalModelPrefix": "photovoltaics", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] } ] @@ -358,19 +358,19 @@ { "lib": "GridFormingConverterDroopControl", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { "lib": "GridFormingConverterMatchingControl", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { "lib": "GridFormingConverterDispatchableVirtualOscillatorControl", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] } ] diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java index 7f2a4ba5d..68e334a32 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzProviderTest.java @@ -33,6 +33,7 @@ import java.util.concurrent.ForkJoinPool; import static com.powsybl.commons.report.ReportNode.NO_OP; +import static com.powsybl.dynamicsimulation.DynamicSimulationResult.Status.FAILURE; import static org.junit.jupiter.api.Assertions.*; /** @@ -146,7 +147,7 @@ void testFail() throws Exception { CurvesSupplier.empty(), network.getVariantManager().getWorkingVariantId(), computationManager, DynamicSimulationParameters.load(), NO_OP); assertNotNull(result); - assertFalse(result.isOk()); + assertEquals(FAILURE, result.getStatus()); } @Test @@ -160,7 +161,7 @@ void testWithoutCurves() throws Exception { new CurvesSupplierMock(), network.getVariantManager().getWorkingVariantId(), computationManager, DynamicSimulationParameters.load(), NO_OP); assertNotNull(result); - assertFalse(result.isOk()); + assertEquals(FAILURE, result.getStatus()); } @Test diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderTest.java index a5a1bb725..336014f43 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/builders/ModelConfigLoaderTest.java @@ -35,17 +35,17 @@ void loadConfigTest() throws IOException { "libs": [ { "lib": "PhotovoltaicsWeccCurrentSource", - "alias": "WeccCs", + "alias": "Wecc", "internalModelPrefix": "WTG4A", "properties": [ - "Synchronized" + "SYNCHRONIZED" ] }, { "lib": "WT4BWeccCurrentSource", "properties": [ - "Synchronized", - "Controllable" + "SYNCHRONIZED", + "CONTROLLABLE" ] }, { @@ -64,12 +64,12 @@ void loadConfigTest() throws IOException { assertThat(configs.keySet()).containsExactlyInAnyOrder("synchronousGenerators"); ModelConfigs synchroGens = configs.get("synchronousGenerators"); assertThat(synchroGens.getSupportedLibs()).containsExactlyInAnyOrder( - "WeccCs", + "Wecc", "WT4BWeccCurrentSource", "WT4AWeccCurrentSource"); ModelConfig defaultModel = new ModelConfig("WT4BWeccCurrentSource", null, null, List.of("SYNCHRONIZED", "CONTROLLABLE")); assertThat(listModelConfigs(synchroGens)).containsExactlyInAnyOrder( - new ModelConfig("PhotovoltaicsWeccCurrentSource", "WeccCs", "WTG4A", List.of("SYNCHRONIZED")), + new ModelConfig("PhotovoltaicsWeccCurrentSource", "Wecc", "WTG4A", List.of("SYNCHRONIZED")), defaultModel, new ModelConfig("WT4AWeccCurrentSource", null, null, Collections.emptyList())); assertEquals(defaultModel, synchroGens.getDefaultModelConfig()); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelHandlerTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelHandlerTest.java index d0d8fe2c9..edad8b862 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelHandlerTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelHandlerTest.java @@ -54,7 +54,7 @@ void noInterfaceImplementationLog() { void noInterfaceImplementationException() { Generator gen = network.getGenerator("GEN"); PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(gen, LoadModel.class, true)); - assertEquals("Default model DefaultGenerator does not implement LoadModel interface", pe.getMessage()); + assertEquals("Default model DefaultGenerator for GEN does not implement LoadModel interface", pe.getMessage()); } @Test diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java index bf9244c38..06755bfb1 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaFlowTest.java @@ -40,8 +40,8 @@ import java.util.List; import java.util.Objects; +import static com.powsybl.loadflow.LoadFlowResult.ComponentResult.Status.CONVERGED; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Geoffroy Jamgotchian {@literal } @@ -81,15 +81,15 @@ void testLf() throws IOException { LoadFlowResult result = loadFlowProvider.run(network, computationManager, VariantManagerConstants.INITIAL_VARIANT_ID, loadFlowParameters, reportNode) .join(); - assertTrue(result.isOk()); assertEquals(1, result.getComponentResults().size()); LoadFlowResult.ComponentResult componentResult = result.getComponentResults().get(0); - assertEquals(LoadFlowResult.ComponentResult.Status.CONVERGED, componentResult.getStatus()); - assertEquals("B4", componentResult.getSlackBusId()); + assertEquals(CONVERGED, componentResult.getStatus()); + assertEquals("B4", componentResult.getSlackBusResults().get(0).getId()); StringWriter sw = new StringWriter(); reportNode.print(sw); System.out.println(sw); + InputStream refStream = Objects.requireNonNull(getClass().getResourceAsStream("/loadflow_timeline_report.txt")); String refLogExport = TestUtil.normalizeLineSeparator(new String(ByteStreams.toByteArray(refStream), StandardCharsets.UTF_8)); String logExport = TestUtil.normalizeLineSeparator(sw.toString()); diff --git a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java index 88362c577..9c7d7f802 100644 --- a/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java +++ b/dynawo-integration-tests/src/test/java/com/powsybl/dynawo/it/DynaWaltzTest.java @@ -87,7 +87,7 @@ void testIeee14() { assertEquals(DynamicSimulationResult.Status.SUCCESS, result.getStatus()); assertTrue(result.getStatusText().isEmpty()); assertEquals(41, result.getCurves().size()); - DoubleTimeSeries ts1 = (DoubleTimeSeries) result.getCurve("_GEN____1_SM_generator_UStatorPu"); + DoubleTimeSeries ts1 = result.getCurve("_GEN____1_SM_generator_UStatorPu"); assertEquals("_GEN____1_SM_generator_UStatorPu", ts1.getMetadata().getName()); assertEquals(587, ts1.toArray().length); List timeLine = result.getTimeLine();