diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 6b222641c..aa2a54f9e 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -26,7 +26,7 @@ jobs: uses: actions/checkout@v4 with: repository: powsybl/powsybl-core - ref: refs/heads/sa_runner_parameter + ref: refs/heads/main path: powsybl-core - name: Set up JDK 17 diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DumpFileParameters.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DumpFileParameters.java index c3186a6d4..e270426a9 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DumpFileParameters.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DumpFileParameters.java @@ -8,7 +8,11 @@ package com.powsybl.dynawaltz; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.powsybl.commons.PowsyblException; +import com.powsybl.commons.config.ModuleConfig; +import java.nio.file.FileSystem; +import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; @@ -22,6 +26,7 @@ public record DumpFileParameters(boolean exportDumpFile, boolean useDumpFile, Pa public static final boolean DEFAULT_USE_DUMP = false; public static final String DEFAULT_DUMP_FOLDER = null; public static final String DEFAULT_DUMP_NAME = null; + public static final DumpFileParameters DEFAULT_DUMP_FILE_PARAMETERS = new DumpFileParameters(DEFAULT_EXPORT_DUMP, DEFAULT_USE_DUMP, null, DEFAULT_DUMP_NAME); public DumpFileParameters { if (useDumpFile) { @@ -33,7 +38,7 @@ public record DumpFileParameters(boolean exportDumpFile, boolean useDumpFile, Pa } public static DumpFileParameters createDefaultDumpFileParameters() { - return new DumpFileParameters(DEFAULT_EXPORT_DUMP, DEFAULT_USE_DUMP, null, DEFAULT_DUMP_NAME); + return DEFAULT_DUMP_FILE_PARAMETERS; } public static DumpFileParameters createExportDumpFileParameters(Path dumpFileFolder) { @@ -48,6 +53,22 @@ public static DumpFileParameters createImportExportDumpFileParameters(Path dumpF return new DumpFileParameters(true, true, dumpFileFolder, dumpFile); } + public static DumpFileParameters createDumpFileParametersFromConfig(ModuleConfig config, FileSystem fileSystem) { + boolean exportDumpFile = config.getOptionalBooleanProperty("dump.export").orElse(DumpFileParameters.DEFAULT_EXPORT_DUMP); + String exportDumpFileFolder = config.getOptionalStringProperty("dump.exportFolder").orElse(DumpFileParameters.DEFAULT_DUMP_FOLDER); + Path exportDumpFileFolderPath = exportDumpFileFolder != null ? fileSystem.getPath(exportDumpFileFolder) : null; + boolean exportFolderNotFound = exportDumpFileFolderPath == null || !Files.exists(exportDumpFileFolderPath); + if (exportDumpFile && exportFolderNotFound) { + throw new PowsyblException("Folder " + exportDumpFileFolder + " set in 'dumpFileFolder' property cannot be found"); + } + boolean useDumpFile = config.getOptionalBooleanProperty("dump.useAsInput").orElse(DumpFileParameters.DEFAULT_USE_DUMP); + String dumpFile = config.getOptionalStringProperty("dump.fileName").orElse(DumpFileParameters.DEFAULT_DUMP_NAME); + if (useDumpFile && (exportFolderNotFound || dumpFile == null || !Files.exists(exportDumpFileFolderPath.resolve(dumpFile)))) { + throw new PowsyblException("File " + dumpFile + " set in 'dumpFile' property cannot be found"); + } + return new DumpFileParameters(exportDumpFile, useDumpFile, exportDumpFileFolderPath, dumpFile); + } + public Path getDumpFilePath() { return dumpFileFolder != null ? dumpFileFolder.resolve(dumpFile) diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java index faecedf39..6443dab19 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java @@ -18,7 +18,6 @@ import java.nio.file.FileSystem; import java.nio.file.FileSystems; -import java.nio.file.Files; import java.nio.file.Path; import java.util.*; @@ -31,7 +30,7 @@ public class DynaWaltzParameters extends AbstractExtension modelsParameters = new LinkedHashMap<>(); private ParametersSet networkParameters; private ParametersSet solverParameters; - private SolverType solverType; - private boolean mergeLoads; + private SolverType solverType = DEFAULT_SOLVER_TYPE; + private boolean mergeLoads = DEFAULT_MERGE_LOADS; private boolean writeFinalState = DEFAULT_WRITE_FINAL_STATE; - private boolean useModelSimplifiers = USE_MODEL_SIMPLIFIERS; - private DumpFileParameters dumpFileParameters; + private boolean useModelSimplifiers = DEFAULT_USE_MODEL_SIMPLIFIERS; + private DumpFileParameters dumpFileParameters = DumpFileParameters.DEFAULT_DUMP_FILE_PARAMETERS; + private double precision = DEFAULT_PRECISION; + private ExportMode timelineExportMode = DEFAULT_TIMELINE_EXPORT_MODE; /** * Loads parameters from the default platform configuration. @@ -70,72 +98,36 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig) { } public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem fileSystem) { + DynaWaltzParameters parameters = new DynaWaltzParameters(); Optional config = platformConfig.getOptionalModuleConfig("dynawaltz-default-parameters"); - // File with all the dynamic models' parameters for the simulation - String parametersFile = config.map(c -> c.getStringProperty("parametersFile")).orElse(DEFAULT_INPUT_PARAMETERS_FILE); - Path parametersPath = platformConfig.getConfigDir().map(configDir -> configDir.resolve(parametersFile)) - .orElse(fileSystem.getPath(parametersFile)); - - // File with all the network's parameters for the simulation - String networkParametersFile = config.map(c -> c.getStringProperty("network.parametersFile")).orElse(DEFAULT_INPUT_NETWORK_PARAMETERS_FILE); - Path networkParametersPath = platformConfig.getConfigDir().map(configDir -> configDir.resolve(networkParametersFile)) - .orElse(fileSystem.getPath(networkParametersFile)); - - // Identifies the set of network parameters that will be used in the simulation. + String parametersFile = config.flatMap(c -> c.getOptionalStringProperty("parametersFile")).orElse(DEFAULT_INPUT_PARAMETERS_FILE); + String networkParametersFile = config.flatMap(c -> c.getOptionalStringProperty("network.parametersFile")).orElse(DEFAULT_INPUT_NETWORK_PARAMETERS_FILE); String networkParametersId = config.flatMap(c -> c.getOptionalStringProperty("network.parametersId")).orElse(DEFAULT_NETWORK_PAR_ID); - - // Information about the solver to use in the simulation, there are two options - // the simplified solver - // and the IDA solver - SolverType solverType = config.flatMap(c -> c.getOptionalEnumProperty("solver.type", SolverType.class)).orElse(DEFAULT_SOLVER_TYPE); - - // File with all the solvers' parameters for the simulation String solverParametersFile = config.flatMap(c -> c.getOptionalStringProperty("solver.parametersFile")).orElse(DEFAULT_INPUT_SOLVER_PARAMETERS_FILE); - Path solverParametersPath = platformConfig.getConfigDir().map(configDir -> configDir.resolve(solverParametersFile)) - .orElse(fileSystem.getPath(solverParametersFile)); - - // Identifies the set of solver parameters that will be used in the simulation String solverParametersId = config.flatMap(c -> c.getOptionalStringProperty("solver.parametersId")).orElse(DEFAULT_SOLVER_PAR_ID); + // File with all the dynamic models' parameters for the simulation + parameters.setModelsParameters(ParametersXml.load(resolveParameterPath(parametersFile, platformConfig, fileSystem))) + // File with all the network's parameters for the simulation + .setNetworkParameters(ParametersXml.load(resolveParameterPath(networkParametersFile, platformConfig, fileSystem), networkParametersId)) + // File with all the solvers' parameters for the simulation + .setSolverParameters(ParametersXml.load(resolveParameterPath(solverParametersFile, platformConfig, fileSystem), solverParametersId)); - // 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); - - boolean useModelSimplifiers = config.flatMap(c -> c.getOptionalBooleanProperty("useModelSimplifiers")).orElse(USE_MODEL_SIMPLIFIERS); - - // Dump file config - boolean exportDumpFile = config.flatMap(c -> c.getOptionalBooleanProperty("dump.export")).orElse(DumpFileParameters.DEFAULT_EXPORT_DUMP); - String exportDumpFileFolder = config.flatMap(c -> c.getOptionalStringProperty("dump.exportFolder")).orElse(DumpFileParameters.DEFAULT_DUMP_FOLDER); - Path exportDumpFileFolderPath = exportDumpFileFolder != null ? fileSystem.getPath(exportDumpFileFolder) : null; - boolean exportFolderNotFound = exportDumpFileFolderPath == null || !Files.exists(exportDumpFileFolderPath); - if (exportDumpFile && exportFolderNotFound) { - throw new PowsyblException("Folder " + exportDumpFileFolder + " set in 'dumpFileFolder' property cannot be found"); - } - boolean useDumpFile = config.flatMap(c -> c.getOptionalBooleanProperty("dump.useAsInput")).orElse(DumpFileParameters.DEFAULT_USE_DUMP); - String dumpFile = config.flatMap(c -> c.getOptionalStringProperty("dump.fileName")).orElse(DumpFileParameters.DEFAULT_DUMP_NAME); - if (useDumpFile && (exportFolderNotFound || dumpFile == null || !Files.exists(exportDumpFileFolderPath.resolve(dumpFile)))) { - throw new PowsyblException("File " + dumpFile + " set in 'dumpFile' property cannot be found"); - } - - DumpFileParameters dumpFileParameters = new DumpFileParameters(exportDumpFile, useDumpFile, exportDumpFileFolderPath, dumpFile); - - // Load xml files - List modelsParameters = ParametersXml.load(parametersPath); - ParametersSet networkParameters = ParametersXml.load(networkParametersPath, networkParametersId); - ParametersSet solverParameters = ParametersXml.load(solverParametersPath, solverParametersId); + config.ifPresent(c -> { + parameters.setDumpFileParameters(DumpFileParameters.createDumpFileParametersFromConfig(c, fileSystem)); + c.getOptionalEnumProperty("solver.type", SolverType.class).ifPresent(parameters::setSolverType); + // If merging loads on each bus to simplify dynawo's analysis + c.getOptionalBooleanProperty("mergeLoads").ifPresent(parameters::setMergeLoads); + c.getOptionalBooleanProperty("writeFinalState").ifPresent(parameters::setWriteFinalState); + c.getOptionalBooleanProperty("useModelSimplifiers").ifPresent(parameters::setUseModelSimplifiers); + c.getOptionalDoubleProperty("precision").ifPresent(parameters::setPrecision); + c.getOptionalEnumProperty("timeline.exportMode", ExportMode.class).ifPresent(parameters::setTimelineExportMode); + }); + return parameters; + } - return new DynaWaltzParameters() - .setModelsParameters(modelsParameters) - .setNetworkParameters(networkParameters) - .setSolverParameters(solverParameters) - .setSolverType(solverType) - .setMergeLoads(mergeLoads) - .setWriteFinalState(writeFinalState) - .setUseModelSimplifiers(useModelSimplifiers) - .setDumpFileParameters(dumpFileParameters); + private static Path resolveParameterPath(String fileName, PlatformConfig platformConfig, FileSystem fileSystem) { + return platformConfig.getConfigDir().map(configDir -> configDir.resolve(fileName)).orElse(fileSystem.getPath(fileName)); } @Override @@ -234,4 +226,22 @@ public DynaWaltzParameters setDefaultDumpFileParameters() { this.dumpFileParameters = DumpFileParameters.createDefaultDumpFileParameters(); return this; } + + public double getPrecision() { + return precision; + } + + public DynaWaltzParameters setPrecision(double precision) { + this.precision = precision; + return this; + } + + public ExportMode getTimelineExportMode() { + return timelineExportMode; + } + + public DynaWaltzParameters setTimelineExportMode(ExportMode timelineExportMode) { + this.timelineExportMode = timelineExportMode; + return this; + } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java index ccdbcb63a..69720ad2e 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java @@ -21,6 +21,8 @@ import com.powsybl.dynawo.commons.dynawologs.CsvLogParser; import com.powsybl.dynawo.commons.loadmerge.LoadsMerger; import com.powsybl.dynawo.commons.timeline.CsvTimeLineParser; +import com.powsybl.dynawo.commons.timeline.TimeLineParser; +import com.powsybl.dynawo.commons.timeline.XmlTimeLineParser; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.serde.NetworkSerDe; import com.powsybl.timeseries.DoubleTimeSeries; @@ -58,7 +60,7 @@ public class DynaWaltzProvider implements DynamicSimulationProvider { private static final String LOGS_FOLDER = "logs"; private static final String OUTPUT_IIDM_FILENAME = "outputIIDM.xml"; private static final String OUTPUT_DUMP_FILENAME = "outputState.dmp"; - private static final String TIMELINE_FILENAME = "timeline.log"; + private static final String TIMELINE_FILENAME = "timeline"; private static final String LOGS_FILENAME = "dynawaltz.log"; private static final String ERROR_FILENAME = "dyn_fs_0.err"; private static final String DYNAWO_ERROR_PATTERN = "DYN Error: "; @@ -253,10 +255,15 @@ private void setDumpFile(Path outputsFolder, Path dumpFileFolder, Path fileName) } private void setTimeline(Path outputsFolder) { - Path timelineFile = outputsFolder.resolve(DYNAWO_TIMELINE_FOLDER).resolve(TIMELINE_FILENAME); + DynaWaltzParameters.ExportMode exportMode = context.getDynaWaltzParameters().getTimelineExportMode(); + Path timelineFile = outputsFolder.resolve(DYNAWO_TIMELINE_FOLDER).resolve(TIMELINE_FILENAME + exportMode.getFileExtension()); if (Files.exists(timelineFile)) { - new CsvTimeLineParser().parse(timelineFile).forEach(e -> - timeline.add(new TimelineEvent(e.time(), e.modelName(), e.message()))); + TimeLineParser parser = switch (exportMode) { + case CSV -> new CsvTimeLineParser(';'); + case TXT -> new CsvTimeLineParser(); + case XML -> new XmlTimeLineParser(); + }; + parser.parse(timelineFile).forEach(e -> timeline.add(new TimelineEvent(e.time(), e.modelName(), e.message()))); } else { LOGGER.warn("Timeline file not found"); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/AbstractInjectionDefaultModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/AbstractInjectionDefaultModel.java index b5cdce475..d7362aac0 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/AbstractInjectionDefaultModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/AbstractInjectionDefaultModel.java @@ -7,10 +7,12 @@ */ package com.powsybl.dynawaltz.models.defaultmodels; +import com.powsybl.dynawaltz.models.InjectionModel; + /** * @author Laurent Issertial {@literal } */ -public abstract class AbstractInjectionDefaultModel extends AbstractDefaultModel { +public abstract class AbstractInjectionDefaultModel extends AbstractDefaultModel implements InjectionModel { protected AbstractInjectionDefaultModel(String staticId) { super(staticId); @@ -20,6 +22,7 @@ public String getStateValueVarName() { return "@NAME@_state_value"; } + @Override public String getSwitchOffSignalEventVarName() { return getStateValueVarName(); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelConfiguration.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelConfiguration.java index 6e7acc7c3..1bd1437f2 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelConfiguration.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/defaultmodels/DefaultModelConfiguration.java @@ -7,6 +7,7 @@ */ package com.powsybl.dynawaltz.models.defaultmodels; +import com.powsybl.dynawaltz.models.InjectionModel; import com.powsybl.dynawaltz.models.Model; import com.powsybl.dynawaltz.models.buses.*; import com.powsybl.dynawaltz.models.generators.DefaultGenerator; @@ -16,11 +17,9 @@ import com.powsybl.dynawaltz.models.lines.DefaultLine; import com.powsybl.dynawaltz.models.lines.LineModel; import com.powsybl.dynawaltz.models.loads.DefaultLoad; -import com.powsybl.dynawaltz.models.loads.LoadModel; import com.powsybl.dynawaltz.models.shunts.DefaultShunt; import com.powsybl.dynawaltz.models.shunts.ShuntModel; import com.powsybl.dynawaltz.models.svarcs.DefaultStaticVarCompensator; -import com.powsybl.dynawaltz.models.svarcs.StaticVarCompensatorModel; import com.powsybl.dynawaltz.models.transformers.DefaultTransformer; import com.powsybl.dynawaltz.models.transformers.TransformerModel; import com.powsybl.iidm.network.IdentifiableType; @@ -49,13 +48,13 @@ public enum DefaultModelConfiguration { LineModel.class, new DefaultModelFactory<>(DefaultLine::new)), LOAD(IdentifiableType.LOAD, - LoadModel.class, + InjectionModel.class, new DefaultModelFactory<>(DefaultLoad::new)), SHUNT_COMPENSATOR(IdentifiableType.SHUNT_COMPENSATOR, ShuntModel.class, new DefaultModelFactory<>(DefaultShunt::new)), STATIC_VAR_COMPENSATOR(IdentifiableType.STATIC_VAR_COMPENSATOR, - StaticVarCompensatorModel.class, + InjectionModel.class, new DefaultModelFactory<>(DefaultStaticVarCompensator::new)), TWO_WINDINGS_TRANSFORMER(IdentifiableType.TWO_WINDINGS_TRANSFORMER, TransformerModel.class, diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoad.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoad.java index bb9002ad9..d51bee59c 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoad.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/AbstractLoad.java @@ -7,6 +7,7 @@ package com.powsybl.dynawaltz.models.loads; import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; +import com.powsybl.dynawaltz.models.InjectionModel; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder; @@ -18,7 +19,7 @@ * @author Marcos de Miguel {@literal } * @author Laurent Issertial {@literal } */ -public abstract class AbstractLoad extends AbstractEquipmentBlackBoxModel implements LoadModel { +public abstract class AbstractLoad extends AbstractEquipmentBlackBoxModel implements InjectionModel { protected final String terminalVarName; diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/DefaultLoad.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/DefaultLoad.java index 93a287138..e7d14b433 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/DefaultLoad.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/DefaultLoad.java @@ -13,7 +13,7 @@ /** * @author Laurent Issertial {@literal } */ -public class DefaultLoad extends AbstractInjectionDefaultModel implements LoadModel, ControllableEquipment { +public class DefaultLoad extends AbstractInjectionDefaultModel implements ControllableEquipment { public DefaultLoad(String staticId) { super(staticId); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadModel.java deleted file mode 100644 index e3963228e..000000000 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/loads/LoadModel.java +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) 2023, RTE (http://www.rte-france.com) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * SPDX-License-Identifier: MPL-2.0 - */ -package com.powsybl.dynawaltz.models.loads; - -import com.powsybl.dynawaltz.models.InjectionModel; - -/** - * @author Laurent Issertial {@literal } - */ -public interface LoadModel extends InjectionModel { - -} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/BaseStaticVarCompensator.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/BaseStaticVarCompensator.java index 7e3dea5fc..7877f35c1 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/BaseStaticVarCompensator.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/BaseStaticVarCompensator.java @@ -8,10 +8,12 @@ package com.powsybl.dynawaltz.models.svarcs; import com.powsybl.dynawaltz.models.AbstractEquipmentBlackBoxModel; +import com.powsybl.dynawaltz.models.InjectionModel; import com.powsybl.dynawaltz.models.VarConnection; import com.powsybl.dynawaltz.models.VarMapping; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.macroconnections.MacroConnectionsAdder; +import com.powsybl.iidm.network.StaticVarCompensator; import com.powsybl.iidm.network.extensions.StandbyAutomaton; import java.util.List; @@ -19,7 +21,7 @@ /** * @author Laurent Issertial {@literal } */ -public class BaseStaticVarCompensator extends AbstractEquipmentBlackBoxModel implements StaticVarCompensatorModel { +public class BaseStaticVarCompensator extends AbstractEquipmentBlackBoxModel implements InjectionModel { private static final VarMapping P_MAPPING = new VarMapping("SVarC_injector_PInjPu", "p"); private static final VarMapping Q_MAPPING = new VarMapping("SVarC_injector_QInjPu", "q"); @@ -29,7 +31,7 @@ public class BaseStaticVarCompensator extends AbstractEquipmentBlackBoxModel VAR_MAPPING_NO_STANDBY_AUTOMATON = List.of(P_MAPPING, Q_MAPPING, STATE_MAPPING); private static final List VAR_MAPPING_WITH_STANDBY_AUTOMATON = List.of(P_MAPPING, Q_MAPPING, STATE_MAPPING, MODE_MAPPING); - protected BaseStaticVarCompensator(String dynamicModelId, com.powsybl.iidm.network.StaticVarCompensator svarc, String parameterSetId, String lib) { + protected BaseStaticVarCompensator(String dynamicModelId, StaticVarCompensator svarc, String parameterSetId, String lib) { super(dynamicModelId, parameterSetId, svarc, lib); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/DefaultStaticVarCompensator.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/DefaultStaticVarCompensator.java index 8082c52f7..ea0b5be15 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/DefaultStaticVarCompensator.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/DefaultStaticVarCompensator.java @@ -12,7 +12,7 @@ /** * @author Laurent Issertial {@literal } */ -public class DefaultStaticVarCompensator extends AbstractInjectionDefaultModel implements StaticVarCompensatorModel { +public class DefaultStaticVarCompensator extends AbstractInjectionDefaultModel { public DefaultStaticVarCompensator(String staticId) { super(staticId); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/StaticVarCompensatorModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/StaticVarCompensatorModel.java deleted file mode 100644 index 918bd4043..000000000 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/svarcs/StaticVarCompensatorModel.java +++ /dev/null @@ -1,13 +0,0 @@ -/** - * Copyright (c) 2023, RTE (http://www.rte-france.com/) - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * SPDX-License-Identifier: MPL-2.0 - */ -package com.powsybl.dynawaltz.models.svarcs; - -import com.powsybl.dynawaltz.models.InjectionModel; - -public interface StaticVarCompensatorModel extends InjectionModel { -} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java index 2dcf216b8..d0ec6e1fb 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java @@ -83,6 +83,7 @@ private static void writeSimulation(XMLStreamWriter writer, DynaWaltzContext con writer.writeEmptyElement(DYN_URI, "simulation"); writer.writeAttribute("startTime", Integer.toString(context.getParameters().getStartTime())); writer.writeAttribute("stopTime", Integer.toString(context.getParameters().getStopTime())); + writer.writeAttribute("precision", Double.toString(context.getDynaWaltzParameters().getPrecision())); } private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { @@ -94,7 +95,7 @@ private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context writer.writeAttribute("global", Boolean.toString(false)); writer.writeEmptyElement(DYN_URI, "timeline"); - writer.writeAttribute("exportMode", "TXT"); + writer.writeAttribute("exportMode", context.getDynaWaltzParameters().getTimelineExportMode().name()); writer.writeEmptyElement(DYN_URI, "finalState"); writer.writeAttribute("exportIIDMFile", Boolean.toString(context.getDynaWaltzParameters().isWriteFinalState())); @@ -103,7 +104,7 @@ private static void writeOutput(XMLStreamWriter writer, DynaWaltzContext context if (context.withCurves()) { writer.writeEmptyElement(DYN_URI, "curves"); writer.writeAttribute("inputFile", DynaWaltzConstants.CRV_FILENAME); - writer.writeAttribute("exportMode", "CSV"); + writer.writeAttribute("exportMode", DynaWaltzParameters.ExportMode.CSV.name()); } writer.writeStartElement(DYN_URI, "logs"); diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java index 3f3b26525..72aee8ae2 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java @@ -12,6 +12,7 @@ import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; +import com.powsybl.dynawaltz.DynaWaltzParameters.ExportMode; import com.powsybl.dynawaltz.DynaWaltzParameters.SolverType; import com.powsybl.dynawaltz.parameters.Parameter; import com.powsybl.dynawaltz.parameters.ParameterType; @@ -58,7 +59,9 @@ void checkParameters() throws IOException { String solverParametersId = "solverParametersId"; boolean mergeLoads = true; boolean useModelSimplifiers = true; - initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelSimplifiers); + double precision = 1e-8; + ExportMode timelinExportMode = ExportMode.XML; + initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, useModelSimplifiers, precision, timelinExportMode); DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig, fileSystem); @@ -89,6 +92,8 @@ void checkParameters() throws IOException { assertEquals(mergeLoads, parameters.isMergeLoads()); assertEquals(useModelSimplifiers, parameters.isUseModelSimplifiers()); + assertEquals(precision, parameters.getPrecision()); + assertEquals(timelinExportMode, parameters.getTimelineExportMode()); } @Test @@ -111,7 +116,7 @@ void roundTripParametersSerializing() throws IOException { SolverType solverType = SolverType.IDA; String solverParametersId = "solverParametersId"; boolean mergeLoads = false; - initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, false); + initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads, false, 1e-7, ExportMode.TXT); DynamicSimulationParameters dynamicSimulationParameters = new DynamicSimulationParameters() .setStartTime(0) @@ -122,7 +127,7 @@ void roundTripParametersSerializing() throws IOException { JsonDynamicSimulationParameters::read, "/DynaWaltzParameters.json"); } - private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelSimplifiers) throws IOException { + private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads, boolean useModelSimplifiers, double precision, ExportMode timelineExportMode) throws IOException { String parametersFile = USER_HOME + "parametersFile"; String networkParametersFile = USER_HOME + "networkParametersFile"; String solverParametersFile = USER_HOME + "solverParametersFile"; @@ -136,6 +141,8 @@ private void initPlatformConfig(String networkParametersId, SolverType solverTyp moduleConfig.setStringProperty("solver.type", solverType.toString()); moduleConfig.setStringProperty("solver.parametersId", solverParametersId); moduleConfig.setStringProperty("useModelSimplifiers", String.valueOf(useModelSimplifiers)); + moduleConfig.setStringProperty("precision", Double.toString(precision)); + moduleConfig.setStringProperty("timeline.exportMode", String.valueOf(timelineExportMode)); Files.createDirectories(fileSystem.getPath(USER_HOME)); copyFile("/parametersSet/models.par", parametersFile); @@ -182,7 +189,8 @@ void checkDefaultParameters() throws IOException { assertEquals("1", parameters.getSolverParameters().getId()); assertEquals(DynaWaltzParameters.DEFAULT_MERGE_LOADS, parameters.isMergeLoads()); - assertEquals(DynaWaltzParameters.USE_MODEL_SIMPLIFIERS, parameters.isUseModelSimplifiers()); + assertEquals(DynaWaltzParameters.DEFAULT_USE_MODEL_SIMPLIFIERS, parameters.isUseModelSimplifiers()); + assertEquals(DynaWaltzParameters.DEFAULT_TIMELINE_EXPORT_MODE, parameters.getTimelineExportMode()); } @Test 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 edad8b862..be049b2ab 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 @@ -11,7 +11,7 @@ import com.powsybl.dynawaltz.models.Model; import com.powsybl.dynawaltz.models.buses.EquipmentConnectionPoint; import com.powsybl.dynawaltz.models.generators.GeneratorModel; -import com.powsybl.dynawaltz.models.loads.LoadModel; +import com.powsybl.dynawaltz.models.shunts.ShuntModel; import com.powsybl.iidm.network.Bus; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Network; @@ -46,28 +46,28 @@ void getMultipleConfigDefaultModel() { @Test void noInterfaceImplementationLog() { Generator gen = network.getGenerator("GEN"); - Model model = defaultModelHandler.getDefaultModel(gen, LoadModel.class, false); + Model model = defaultModelHandler.getDefaultModel(gen, ShuntModel.class, false); assertNull(model); } @Test void noInterfaceImplementationException() { Generator gen = network.getGenerator("GEN"); - PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(gen, LoadModel.class, true)); - assertEquals("Default model DefaultGenerator for GEN does not implement LoadModel interface", pe.getMessage()); + PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(gen, ShuntModel.class, true)); + assertEquals("Default model DefaultGenerator for GEN does not implement ShuntModel interface", pe.getMessage()); } @Test void noDynamicModelException() { VoltageLevel vl = network.getVoltageLevel("VLGEN"); - PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(vl, LoadModel.class, true)); + PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(vl, ShuntModel.class, true)); assertEquals("No default model configuration for VOLTAGE_LEVEL", pe.getMessage()); } @Test void noMultipleDynamicModelException() { Bus bus = network.getBusBreakerView().getBus("NGEN"); - PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(bus, LoadModel.class, true)); - assertEquals("No default model configuration for BUS - LoadModel", pe.getMessage()); + PowsyblException pe = assertThrows(PowsyblException.class, () -> defaultModelHandler.getDefaultModel(bus, ShuntModel.class, true)); + assertEquals("No default model configuration for BUS - ShuntModel", pe.getMessage()); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/JobsXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/JobsXmlTest.java index 7880d7980..25a83d0bd 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/JobsXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/JobsXmlTest.java @@ -13,7 +13,6 @@ import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; -import javax.xml.stream.XMLStreamException; import java.io.IOException; import java.nio.file.Path; @@ -23,7 +22,7 @@ class JobsXmlTest extends DynaWaltzTestUtil { @Test - void writeJob() throws SAXException, IOException, XMLStreamException { + void writeJob() throws SAXException, IOException { DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(); DynaWaltzContext context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, eventModels, curves, parameters, dynawoParameters); @@ -33,7 +32,7 @@ void writeJob() throws SAXException, IOException, XMLStreamException { } @Test - void writeJobWithDumpFile() throws SAXException, IOException, XMLStreamException { + void writeJobWithDumpFile() throws SAXException, IOException { DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load() .setDumpFileParameters(DumpFileParameters.createImportExportDumpFileParameters(Path.of("/dumpFiles"), "dump.dmp")); diff --git a/dynawaltz/src/test/resources/DynaWaltzParameters.json b/dynawaltz/src/test/resources/DynaWaltzParameters.json index 8544c81e2..fdcdb051c 100644 --- a/dynawaltz/src/test/resources/DynaWaltzParameters.json +++ b/dynawaltz/src/test/resources/DynaWaltzParameters.json @@ -46,6 +46,8 @@ "dumpFileFolder" : null, "dumpFile" : null }, + "precision" : 1.0E-7, + "timelineExportMode" : "TXT", "modelsParameters" : [ { "id" : "test", "parameters" : { diff --git a/dynawaltz/src/test/resources/jobs.xml b/dynawaltz/src/test/resources/jobs.xml index f450aac74..363d4f347 100644 --- a/dynawaltz/src/test/resources/jobs.xml +++ b/dynawaltz/src/test/resources/jobs.xml @@ -8,7 +8,7 @@ - + diff --git a/dynawaltz/src/test/resources/jobsWithDump.xml b/dynawaltz/src/test/resources/jobsWithDump.xml index 22ecd4fb8..3456cb08c 100644 --- a/dynawaltz/src/test/resources/jobsWithDump.xml +++ b/dynawaltz/src/test/resources/jobsWithDump.xml @@ -9,7 +9,7 @@ - + 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 9c7d7f802..89a42100c 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 @@ -78,7 +78,8 @@ void testIeee14() { .setNetworkParameters(networkParameters) .setSolverParameters(solverParameters) .setSolverType(DynaWaltzParameters.SolverType.IDA) - .setDefaultDumpFileParameters(); + .setDefaultDumpFileParameters() + .setTimelineExportMode(DynaWaltzParameters.ExportMode.XML); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, NO_OP) @@ -162,7 +163,8 @@ void testSvc() { .setNetworkParameters(networkParameters) .setSolverParameters(solverParameters) .setSolverType(DynaWaltzParameters.SolverType.IDA) - .setDefaultDumpFileParameters(); + .setDefaultDumpFileParameters() + .setPrecision(10e-8); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, EventModelsSupplier.empty(), CurvesSupplier.empty(), VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters, NO_OP)