diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractIeeeTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractIeeeTest.java index 180551c8a..90adebf3c 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractIeeeTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/AbstractIeeeTest.java @@ -14,9 +14,9 @@ import com.powsybl.computation.local.LocalComputationManager; import com.powsybl.dynamicsimulation.*; import com.powsybl.dynamicsimulation.groovy.*; -import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.DynaWaltzProvider; +import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Network; import org.junit.jupiter.api.AfterEach; @@ -51,20 +51,14 @@ void tearDown() throws IOException { public abstract String getWorkingDirName(); - protected void setup(String parametersFile, String networkParametersFile, String solverParametersFile, String networkFile, - String dynamicModelsFile, String eventModelsFile, String curvesFile, String parametersJson) throws IOException { + protected void setup(String parametersFile, String networkParametersFile, String networkParametersId, String solverParametersFile, String solverParametersId, String networkFile, + String dynamicModelsFile, String eventModelsFile, String curvesFile, int startTime, int stopTime) throws IOException { // The parameter files are copied into the PlatformConfig filesystem, // that filesystem is the one that DynaWaltzContext and ParametersXml will use to read the parameters fileSystem = PlatformConfig.defaultConfig().getConfigDir().map(Path::getFileSystem).orElseThrow(AssertionError::new); workingDir = Files.createDirectory(fileSystem.getPath(getWorkingDirName())); - // Copy parameter files - Path configDir = Files.createDirectory(workingDir.resolve("config")); - Files.copy(getClass().getResourceAsStream(parametersFile), configDir.resolve("models.par")); - Files.copy(getClass().getResourceAsStream(networkParametersFile), configDir.resolve("network.par")); - Files.copy(getClass().getResourceAsStream(solverParametersFile), configDir.resolve("solvers.par")); - // Load network Files.copy(getClass().getResourceAsStream(networkFile), workingDir.resolve("network.iidm")); network = Network.read(workingDir.resolve("network.iidm")); @@ -96,9 +90,15 @@ protected void setup(String parametersFile, String networkParametersFile, String curvesSupplier = CurvesSupplier.empty(); } - // Parameters - Files.copy(getClass().getResourceAsStream(parametersJson), workingDir.resolve("dynaWaltzParameters.json")); - parameters = JsonDynamicSimulationParameters.read(workingDir.resolve("dynaWaltzParameters.json")); + parameters = new DynamicSimulationParameters() + .setStartTime(startTime) + .setStopTime(stopTime); + DynaWaltzParameters dynaWaltzParameters = new DynaWaltzParameters(); + parameters.addExtension(DynaWaltzParameters.class, dynaWaltzParameters); + dynaWaltzParameters.setModelsParameters(ParametersXml.load(getClass().getResourceAsStream(parametersFile))) + .setNetworkParameters(ParametersXml.load(getClass().getResourceAsStream(networkParametersFile), networkParametersId)) + .setSolverParameters(ParametersXml.load(getClass().getResourceAsStream(solverParametersFile), solverParametersId)) + .setSolverType(DynaWaltzParameters.SolverType.IDA); } protected DynaWaltzParameters getDynaWaltzSimulationParameters(DynamicSimulationParameters parameters) { diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java index 9937dce72..a4811b00b 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee/DynaWaltzLocalCommandExecutor.java @@ -53,9 +53,9 @@ protected void validateInputs(Path workingDir) throws IOException { compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.xiidm"), Files.newInputStream(workingDir.resolve(NETWORK_FILENAME))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.jobs"), Files.newInputStream(workingDir.resolve(JOBS_FILENAME))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.dyd"), Files.newInputStream(workingDir.resolve(DYD_FILENAME))); - compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getNetwork().getParametersFile()).getFileName().toString()))); - compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(dynaWaltzParameters.getSolver().getParametersFile()).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/models.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(DynaWaltzParameters.MODELS_OUTPUT_PARAMETERS_FILE).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/network.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(DynaWaltzParameters.NETWORK_OUTPUT_PARAMETERS_FILE).getFileName().toString()))); + compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/solvers.par"), Files.newInputStream(workingDir.resolve(fileSystem.getPath(DynaWaltzParameters.SOLVER_OUTPUT_PARAMETERS_FILE).getFileName().toString()))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/" + networkId + ".par"), Files.newInputStream(workingDir.resolve(networkId + ".par"))); compareXml(getClass().getResourceAsStream("/" + baseDirName + "/dynawaltz-inputs/powsybl_dynawaltz.crv"), Files.newInputStream(workingDir.resolve(CRV_FILENAME))); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java index 7a521179d..7cc5e8e9e 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14CurrentLimitAutomatonTest.java @@ -25,13 +25,13 @@ class Ieee14CurrentLimitAutomatonTest extends AbstractIeeeTest { void setup() throws IOException { super.setup( "/ieee14-currentlimitautomaton/config/models.par", - "/ieee14-currentlimitautomaton/config/network.par", - "/ieee14-currentlimitautomaton/config/solvers.par", + "/ieee14-currentlimitautomaton/config/network.par", "8", + "/ieee14-currentlimitautomaton/config/solvers.par", "2", "/ieee14-currentlimitautomaton/powsybl-inputs/IEEE14.iidm", "/ieee14-currentlimitautomaton/powsybl-inputs/dynamicModels.groovy", "/ieee14-currentlimitautomaton/powsybl-inputs/eventModels.groovy", "/ieee14-currentlimitautomaton/powsybl-inputs/curves.groovy", - "/ieee14-currentlimitautomaton/powsybl-inputs/dynaWaltzParameters.json" + 0, 50 ); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java index 70551bbca..fe6913b9d 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14DisconnectLineTest.java @@ -25,13 +25,13 @@ class Ieee14DisconnectLineTest extends AbstractIeeeTest { public void setup() throws IOException { super.setup( "/ieee14-disconnectline/config/models.par", - "/ieee14-disconnectline/config/network.par", - "/ieee14-disconnectline/config/solvers.par", + "/ieee14-disconnectline/config/network.par", "8", + "/ieee14-disconnectline/config/solvers.par", "2", "/ieee14-disconnectline/powsybl-inputs/IEEE14.iidm", "/ieee14-disconnectline/powsybl-inputs/dynamicModels.groovy", "/ieee14-disconnectline/powsybl-inputs/eventModels.groovy", "/ieee14-disconnectline/powsybl-inputs/curves.groovy", - "/ieee14-disconnectline/powsybl-inputs/dynaWaltzParameters.json"); + 0, 30); } @Test diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java index 5abc923eb..0ec4fcf26 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee14/Ieee14MacroConnectsTest.java @@ -25,13 +25,13 @@ class Ieee14MacroConnectsTest extends AbstractIeeeTest { void setup() throws IOException { super.setup( "/ieee14-macroconnects/config/models.par", - "/ieee14-macroconnects/config/network.par", - "/ieee14-macroconnects/config/solvers.par", + "/ieee14-macroconnects/config/network.par", "8", + "/ieee14-macroconnects/config/solvers.par", "2", "/ieee14-macroconnects/powsybl-inputs/IEEE14.iidm", "/ieee14-macroconnects/powsybl-inputs/dynamicModels.groovy", null, "/ieee14-macroconnects/powsybl-inputs/curves.groovy", - "/ieee14-macroconnects/powsybl-inputs/dynaWaltzParameters.json" + 0, 100 ); } diff --git a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java index a9608434b..9c5d12c6d 100644 --- a/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java +++ b/dynawaltz-dsl/src/test/java/com/powsybl/dynawaltz/dsl/ieee57/Ieee57DisconnectGeneratorTest.java @@ -25,13 +25,13 @@ class Ieee57DisconnectGeneratorTest extends AbstractIeeeTest { void setup() throws IOException { super.setup( "/ieee57-disconnectgenerator/config/models.par", - "/ieee57-disconnectgenerator/config/network.par", - "/ieee57-disconnectgenerator/config/solvers.par", + "/ieee57-disconnectgenerator/config/network.par", "51", + "/ieee57-disconnectgenerator/config/solvers.par", "2", "/ieee57-disconnectgenerator/powsybl-inputs/IEEE57.iidm", "/ieee57-disconnectgenerator/powsybl-inputs/dynamicModels.groovy", "/ieee57-disconnectgenerator/powsybl-inputs/eventModels.groovy", "/ieee57-disconnectgenerator/powsybl-inputs/curves.groovy", - "/ieee57-disconnectgenerator/powsybl-inputs/dynaWaltzParameters.json"); + 0, 30); } @Test diff --git a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/solvers.par b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/solvers.par index c74be67d1..88b2f92db 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/solvers.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/dynawaltz-inputs/solvers.par @@ -1,15 +1,5 @@ - - - - - - - - - - @@ -18,37 +8,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/powsybl-inputs/dynaWaltzParameters.json b/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/powsybl-inputs/dynaWaltzParameters.json deleted file mode 100644 index fed757f65..000000000 --- a/dynawaltz-dsl/src/test/resources/ieee14-currentlimitautomaton/powsybl-inputs/dynaWaltzParameters.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version" : "1.0", - "startTime" : 0, - "stopTime" : 50, - "extensions" : { - "DynaWaltzParameters" : { - "parametersFile" : "ieee14-currentlimitautomaton/config/models.par", - "network" : { - "parametersFile" : "ieee14-currentlimitautomaton/config/network.par", - "parametersId" : "8" - }, - "solver" : { - "type" : "IDA", - "parametersFile" : "ieee14-currentlimitautomaton/config/solvers.par", - "parametersId" : "2" - } - } - } -} diff --git a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/solvers.par b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/solvers.par index c74be67d1..88b2f92db 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/solvers.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/dynawaltz-inputs/solvers.par @@ -1,15 +1,5 @@ - - - - - - - - - - @@ -18,37 +8,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/powsybl-inputs/dynaWaltzParameters.json b/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/powsybl-inputs/dynaWaltzParameters.json deleted file mode 100644 index 7ec13fcc9..000000000 --- a/dynawaltz-dsl/src/test/resources/ieee14-disconnectline/powsybl-inputs/dynaWaltzParameters.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version" : "1.0", - "startTime" : 0, - "stopTime" : 30, - "extensions" : { - "DynaWaltzParameters" : { - "parametersFile" : "ieee14-disconnectline/config/models.par", - "network" : { - "parametersFile" : "ieee14-disconnectline/config/network.par", - "parametersId" : "8" - }, - "solver" : { - "type" : "IDA", - "parametersFile" : "ieee14-disconnectline/config/solvers.par", - "parametersId" : "2" - } - } - } -} \ No newline at end of file diff --git a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/solvers.par b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/solvers.par index c74be67d1..88b2f92db 100644 --- a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/solvers.par +++ b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/dynawaltz-inputs/solvers.par @@ -1,15 +1,5 @@ - - - - - - - - - - @@ -18,37 +8,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/powsybl-inputs/dynaWaltzParameters.json b/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/powsybl-inputs/dynaWaltzParameters.json deleted file mode 100644 index b7514c62f..000000000 --- a/dynawaltz-dsl/src/test/resources/ieee14-macroconnects/powsybl-inputs/dynaWaltzParameters.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version" : "1.0", - "startTime" : 0, - "stopTime" : 100, - "extensions" : { - "DynaWaltzParameters" : { - "parametersFile" : "ieee14-macroconnects/config/models.par", - "network" : { - "parametersFile" : "ieee14-macroconnects/config/network.par", - "parametersId" : "8" - }, - "solver" : { - "type" : "IDA", - "parametersFile" : "ieee14-macroconnects/config/solvers.par", - "parametersId" : "2" - } - } - } -} diff --git a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/solvers.par b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/solvers.par index c74be67d1..08be7a9bd 100644 --- a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/solvers.par +++ b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/dynawaltz-inputs/solvers.par @@ -1,14 +1,5 @@ - - - - - - - - - @@ -18,37 +9,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/powsybl-inputs/dynaWaltzParameters.json b/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/powsybl-inputs/dynaWaltzParameters.json deleted file mode 100644 index af15fd5c7..000000000 --- a/dynawaltz-dsl/src/test/resources/ieee57-disconnectgenerator/powsybl-inputs/dynaWaltzParameters.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version" : "1.0", - "startTime" : 0, - "stopTime" : 30, - "extensions" : { - "DynaWaltzParameters" : { - "parametersFile" : "ieee57-disconnectgenerator/config/models.par", - "network" : { - "parametersFile" : "ieee57-disconnectgenerator/config/network.par", - "parametersId" : "51" - }, - "solver" : { - "type" : "IDA", - "parametersFile" : "ieee57-disconnectgenerator/config/solvers.par", - "parametersId" : "2" - } - } - } -} \ No newline at end of file diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java index 48c5bc64d..385d4bf0f 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzContext.java @@ -7,7 +7,6 @@ package com.powsybl.dynawaltz; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.config.PlatformConfig; import com.powsybl.dynamicsimulation.Curve; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.models.*; @@ -16,9 +15,6 @@ import com.powsybl.iidm.network.Identifiable; import com.powsybl.iidm.network.Network; -import java.nio.file.FileSystem; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -34,7 +30,6 @@ public class DynaWaltzContext { private final String workingVariantId; private final DynamicSimulationParameters parameters; private final DynaWaltzParameters dynaWaltzParameters; - private final DynaWaltzParametersDatabase parametersDatabase; private final List dynamicModels; private final List eventModels; private final Map staticIdBlackBoxModelMap; @@ -45,16 +40,9 @@ public class DynaWaltzContext { private final NetworkModel networkModel = new NetworkModel(); private final OmegaRef omegaRef; - private final PlatformConfig platformConfig; public DynaWaltzContext(Network network, String workingVariantId, List dynamicModels, List eventModels, List curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters) { - this(network, workingVariantId, dynamicModels, eventModels, curves, parameters, dynaWaltzParameters, PlatformConfig.defaultConfig()); - } - - public DynaWaltzContext(Network network, String workingVariantId, List dynamicModels, List eventModels, - List curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters, - PlatformConfig platformConfig) { this.network = Objects.requireNonNull(network); this.workingVariantId = Objects.requireNonNull(workingVariantId); this.dynamicModels = Objects.requireNonNull(dynamicModels); @@ -66,8 +54,6 @@ public DynaWaltzContext(Network network, String workingVariantId, List getMacroStaticReferences() { return macroStaticReferences.values(); } @@ -228,26 +210,7 @@ public boolean withCurves() { return !curves.isEmpty(); } - private static FileSystem getFileSystem(PlatformConfig platformConfig) { - return platformConfig.getConfigDir() - .map(Path::getFileSystem) - .orElseThrow(() -> new PowsyblException("A configuration directory should be defined")); - } - - private static DynaWaltzParametersDatabase loadDatabase(String filename, PlatformConfig platformConfig) { - FileSystem fs = getFileSystem(platformConfig); - return DynaWaltzParametersDatabase.load(fs.getPath(filename)); - } - - public String getParFile() { - return Paths.get(getDynaWaltzParameters().getParametersFile()).getFileName().toString(); - } - public String getSimulationParFile() { return getNetwork().getId() + ".par"; } - - public PlatformConfig getPlatformConfig() { - return platformConfig; - } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java index 8e8d8a68a..c213ebfb6 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParameters.java @@ -6,16 +6,23 @@ */ package com.powsybl.dynawaltz; -import java.util.Objects; -import java.util.Optional; - +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonSetter; import com.powsybl.commons.config.ModuleConfig; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.extensions.AbstractExtension; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.xml.ParametersXml; + +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Path; +import java.util.*; /** * @author Marcos de Miguel + * @author Florian Dupuy */ public class DynaWaltzParameters extends AbstractExtension { @@ -23,89 +30,23 @@ public class DynaWaltzParameters extends AbstractExtension modelsParameters = new LinkedHashMap<>(); + private ParametersSet networkParameters; + private ParametersSet solverParameters; + private SolverType solverType; + private boolean mergeLoads; /** * Loads parameters from the default platform configuration. @@ -118,13 +59,21 @@ public static DynaWaltzParameters load() { * Load parameters from a provided platform configuration. */ public static DynaWaltzParameters load(PlatformConfig platformConfig) { + return load(platformConfig, FileSystems.getDefault()); + } + + public static DynaWaltzParameters load(PlatformConfig platformConfig, FileSystem fileSystem) { 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_PARAMETERS_FILE); + 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_NETWORK_PARAMETERS_FILE); + 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 networkParametersId = config.flatMap(c -> c.getOptionalStringProperty("network.parametersId")).orElse(DEFAULT_NETWORK_PAR_ID); @@ -135,7 +84,9 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig) { 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_SOLVER_PARAMETERS_FILE); + 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); @@ -143,23 +94,17 @@ public static DynaWaltzParameters load(PlatformConfig platformConfig) { // If merging loads on each bus to simplify dynawo's analysis boolean mergeLoads = config.flatMap(c -> c.getOptionalBooleanProperty("mergeLoads")).orElse(DEFAULT_MERGE_LOADS); - return new DynaWaltzParameters(parametersFile, networkParametersFile, networkParametersId, solverType, solverParametersFile, solverParametersId, mergeLoads); - } - - private String parametersFile; - private Network network; - private Solver solver; - private boolean mergeLoads; + // Load xml files + List modelsParameters = ParametersXml.load(parametersPath); + ParametersSet networkParameters = ParametersXml.load(networkParametersPath, networkParametersId); + ParametersSet solverParameters = ParametersXml.load(solverParametersPath, solverParametersId); - public DynaWaltzParameters() { - } - - public DynaWaltzParameters(String parametersFile, String networkParametersFile, String networkParametersId, SolverType solverType, String solverParametersFile, - String solverParametersId, boolean mergeLoads) { - this.parametersFile = Objects.requireNonNull(parametersFile); - this.network = new Network(networkParametersFile, networkParametersId); - this.solver = new Solver(solverType, solverParametersFile, solverParametersId); - this.mergeLoads = mergeLoads; + return new DynaWaltzParameters() + .setModelsParameters(modelsParameters) + .setNetworkParameters(networkParameters) + .setSolverParameters(solverParameters) + .setSolverType(solverType) + .setMergeLoads(mergeLoads); } @Override @@ -167,38 +112,55 @@ public String getName() { return "DynaWaltzParameters"; } - public String getParametersFile() { - return parametersFile; + public ParametersSet getModelParameters(String parameterSetId) { + return modelsParameters.get(parameterSetId); + } + + @JsonGetter("modelsParameters") + public Collection getModelParameters() { + return modelsParameters.values(); } - public DynaWaltzParameters setParametersFile(String parametersFile) { - this.parametersFile = Objects.requireNonNull(parametersFile); + @JsonSetter("modelsParameters") + public DynaWaltzParameters setModelsParameters(Collection parametersSets) { + modelsParameters = new LinkedHashMap<>(); + parametersSets.forEach(parametersSet -> modelsParameters.put(parametersSet.getId(), parametersSet)); return this; } - public Network getNetwork() { - return network; + public DynaWaltzParameters setNetworkParameters(ParametersSet networkParameters) { + this.networkParameters = Objects.requireNonNull(networkParameters); + return this; } - public DynaWaltzParameters setNetwork(Network network) { - this.network = Objects.requireNonNull(network); + public ParametersSet getNetworkParameters() { + return networkParameters; + } + + public DynaWaltzParameters setSolverParameters(ParametersSet solverParameters) { + this.solverParameters = Objects.requireNonNull(solverParameters); return this; } - public Solver getSolver() { - return solver; + public ParametersSet getSolverParameters() { + return solverParameters; } - public DynaWaltzParameters setSolver(Solver solver) { - this.solver = Objects.requireNonNull(solver); + public DynaWaltzParameters setSolverType(SolverType solverType) { + this.solverType = solverType; return this; } + public SolverType getSolverType() { + return solverType; + } + public boolean isMergeLoads() { return mergeLoads; } - public void setMergeLoads(boolean mergeLoads) { + public DynaWaltzParameters setMergeLoads(boolean mergeLoads) { this.mergeLoads = mergeLoads; + return this; } } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabase.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabase.java deleted file mode 100644 index c3c5479b4..000000000 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabase.java +++ /dev/null @@ -1,196 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz; - -import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.exceptions.UncheckedXmlStreamException; -import com.powsybl.commons.xml.XmlUtil; - -import javax.xml.XMLConstants; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import java.io.IOException; -import java.io.Reader; -import java.io.UncheckedIOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; - -/** - * @author Marcos de Miguel - */ -public final class DynaWaltzParametersDatabase { - - public enum ParameterType { - DOUBLE, - INT, - BOOL, - STRING; - } - - public static class Parameter { - - public Parameter(String name, ParameterType type, String value) { - this.name = Objects.requireNonNull(name); - this.type = Objects.requireNonNull(type); - this.value = Objects.requireNonNull(value); - } - - public String getName() { - return name; - } - - public ParameterType getType() { - return type; - } - - public String getValue() { - return value; - } - - private final String name; - private final ParameterType type; - private final String value; - } - - public static class ParameterSet { - - public ParameterSet() { - this.parameters = new HashMap<>(); - } - - public void addParameter(String name, ParameterType type, String value) { - parameters.put(name, new Parameter(name, type, value)); - } - - public Parameter getParameter(String name) { - return parameters.get(name); - } - - private final Map parameters; - - } - - public static DynaWaltzParametersDatabase load(Path parametersFile) { - return read(parametersFile); - } - - private DynaWaltzParametersDatabase() { - this.parameterSets = new HashMap<>(); - } - - private void addParameterSet(String parameterSetId, ParameterSet parameterSet) { - parameterSets.put(parameterSetId, parameterSet); - } - - public boolean getBool(String parameterSetId, String parameterName) { - Parameter parameter = getParameter(parameterSetId, parameterName, ParameterType.BOOL); - return Boolean.parseBoolean(parameter.getValue()); - } - - public double getDouble(String parameterSetId, String parameterName) { - Parameter parameter = getParameter(parameterSetId, parameterName, ParameterType.DOUBLE); - return Double.parseDouble(parameter.getValue()); - } - - public int getInt(String parameterSetId, String parameterName) { - Parameter parameter = getParameter(parameterSetId, parameterName, ParameterType.INT); - return Integer.parseInt(parameter.getValue()); - } - - public String getString(String parameterSetId, String parameterName) { - Parameter parameter = getParameter(parameterSetId, parameterName, ParameterType.STRING); - return parameter.getValue(); - } - - public ParameterSet getParameterSet(String parameterSetId) { - ParameterSet parameterSet = parameterSets.get(parameterSetId); - if (parameterSet == null) { - throw new IllegalArgumentException("ParameterSet not found: " + parameterSetId); - } - return parameterSet; - } - - public Parameter getParameter(String parameterSetId, String parameterName) { - ParameterSet parameterSet = getParameterSet(parameterSetId); - - Parameter parameter = parameterSet.getParameter(parameterName); - if (parameter == null) { - throw new IllegalArgumentException("Parameter not found: " + parameterSetId + "." + parameterName); - } - return parameter; - } - - private Parameter getParameter(String parameterSetId, String parameterName, ParameterType type) { - Parameter parameter = getParameter(parameterSetId, parameterName); - if (parameter.getType() != type) { - throw new PowsyblException("Invalid parameter type: " + parameter.getType() + " (" + type + " expected)"); - } - return parameter; - } - - private static DynaWaltzParametersDatabase read(Path parametersFile) { - Objects.requireNonNull(parametersFile); - - DynaWaltzParametersDatabase parametersDatabase = new DynaWaltzParametersDatabase(); - try (Reader reader = Files.newBufferedReader(parametersFile, StandardCharsets.UTF_8)) { - XMLInputFactory factory = XMLInputFactory.newInstance(); - factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); - factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); - XMLStreamReader xmlReader = factory.createXMLStreamReader(reader); - try { - read(xmlReader, parametersDatabase); - } finally { - xmlReader.close(); - } - } catch (IOException e) { - throw new UncheckedIOException(e); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - return parametersDatabase; - } - - private static void read(XMLStreamReader xmlReader, DynaWaltzParametersDatabase parametersDatabase) { - try { - int state = xmlReader.next(); - while (state == XMLStreamConstants.COMMENT) { - state = xmlReader.next(); - } - XmlUtil.readUntilEndElement("parametersSet", xmlReader, () -> { - if (xmlReader.getLocalName().equals("set")) { - String parameterSetId = xmlReader.getAttributeValue(null, "id"); - ParameterSet parameterSet = new ParameterSet(); - XmlUtil.readUntilEndElement("set", xmlReader, () -> { - String name = xmlReader.getAttributeValue(null, "name"); - ParameterType type = ParameterType.valueOf(xmlReader.getAttributeValue(null, "type")); - if (xmlReader.getLocalName().equals("par")) { - String value = xmlReader.getAttributeValue(null, "value"); - parameterSet.addParameter(name, type, value); - } else if (xmlReader.getLocalName().equals("reference")) { - // Not supported - } else { - throw new PowsyblException("Unexpected element: " + xmlReader.getLocalName()); - } - }); - parametersDatabase.addParameterSet(parameterSetId, parameterSet); - } else { - throw new PowsyblException("Unexpected element: " + xmlReader.getLocalName()); - } - }); - } catch (XMLStreamException e) { - throw new UncheckedXmlStreamException(e); - } - } - - private final Map parameterSets; -} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java index 9e346adff..93eaca26a 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/DynaWaltzProvider.java @@ -51,8 +51,6 @@ public class DynaWaltzProvider implements DynamicSimulationProvider { private static final String WORKING_DIR_PREFIX = "powsybl_dynawaltz_"; private static final String OUTPUT_IIDM_FILENAME = "outputIIDM.xml"; - private final PlatformConfig platformConfig; - private final DynaWaltzConfig dynaWaltzConfig; public DynaWaltzProvider() { @@ -60,11 +58,10 @@ public DynaWaltzProvider() { } public DynaWaltzProvider(PlatformConfig platformConfig) { - this(platformConfig, DynaWaltzConfig.load(platformConfig)); + this(DynaWaltzConfig.load(platformConfig)); } - public DynaWaltzProvider(PlatformConfig platformConfig, DynaWaltzConfig dynawoConfig) { - this.platformConfig = Objects.requireNonNull(platformConfig); + public DynaWaltzProvider(DynaWaltzConfig dynawoConfig) { this.dynaWaltzConfig = Objects.requireNonNull(dynawoConfig); } @@ -138,7 +135,7 @@ private CompletableFuture run(Network network, DynamicM .filter(BlackBoxModel.class::isInstance) .map(BlackBoxModel.class::cast) .collect(Collectors.toList()); - DynaWaltzContext context = new DynaWaltzContext(network, workingVariantId, blackBoxModels, blackBoxEventModels, curvesSupplier.get(network), parameters, dynaWaltzParameters, platformConfig); + DynaWaltzContext context = new DynaWaltzContext(network, workingVariantId, blackBoxModels, blackBoxEventModels, curvesSupplier.get(network), parameters, dynaWaltzParameters); return computationManager.execute(execEnv, new DynaWaltzHandler(context)); } diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java index a5242e02d..0fb174e8f 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/AbstractBlackBoxModel.java @@ -7,6 +7,7 @@ package com.powsybl.dynawaltz.models; import com.powsybl.dynawaltz.DynaWaltzContext; +import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.iidm.network.Identifiable; import javax.xml.stream.XMLStreamException; @@ -63,7 +64,7 @@ public List getMacroConnectToAttributes() { @Override public String getParFile(DynaWaltzContext context) { - return context.getParFile(); + return DynaWaltzParameters.MODELS_OUTPUT_PARAMETERS_FILE; } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java index 16f1f3cf5..a8224e14b 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/OmegaRef.java @@ -8,7 +8,7 @@ import com.powsybl.commons.PowsyblException; import com.powsybl.dynawaltz.DynaWaltzContext; -import com.powsybl.dynawaltz.DynaWaltzParametersDatabase; +import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.models.buses.BusModel; import com.powsybl.dynawaltz.models.generators.GeneratorSynchronousModel; import com.powsybl.dynawaltz.models.generators.OmegaRefGeneratorModel; @@ -19,8 +19,8 @@ import java.util.Collections; import java.util.List; -import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.DOUBLE; -import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.INT; +import static com.powsybl.dynawaltz.parameters.ParameterType.DOUBLE; +import static com.powsybl.dynawaltz.parameters.ParameterType.INT; import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; /** @@ -55,7 +55,7 @@ public String getLib() { @Override public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { - DynaWaltzParametersDatabase parDB = context.getParametersDatabase(); + DynaWaltzParameters dynaWaltzParameters = context.getDynaWaltzParameters(); writer.writeStartElement(DYN_URI, "set"); writer.writeAttribute("id", getParameterSetId()); @@ -66,8 +66,8 @@ public void writeParameters(XMLStreamWriter writer, DynaWaltzContext context) th for (OmegaRefGeneratorModel generator : omegaRefGenerators) { double weightGen = 0; if (generator instanceof GeneratorSynchronousModel) { - double h = parDB.getDouble(generator.getParameterSetId(), "generator_H"); - double snom = parDB.getDouble(generator.getParameterSetId(), "generator_SNom"); + double h = dynaWaltzParameters.getModelParameters(generator.getParameterSetId()).getDouble("generator_H"); + double snom = dynaWaltzParameters.getModelParameters(generator.getParameterSetId()).getDouble("generator_SNom"); weightGen = h * snom; } ParametersXml.writeParameter(writer, DOUBLE, "weight_gen_" + index, Double.toString(weightGen)); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/AbstractEventModel.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/AbstractEventModel.java index 70acdd758..143ba2e52 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/AbstractEventModel.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/AbstractEventModel.java @@ -16,7 +16,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.DOUBLE; +import static com.powsybl.dynawaltz.parameters.ParameterType.DOUBLE; import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; /** diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventInjectionDisconnection.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventInjectionDisconnection.java index 1551324dc..40c7a72d0 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventInjectionDisconnection.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventInjectionDisconnection.java @@ -8,6 +8,7 @@ import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.models.VarConnection; +import com.powsybl.dynawaltz.parameters.ParameterType; import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Load; @@ -16,8 +17,6 @@ import javax.xml.stream.XMLStreamWriter; import java.util.List; -import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.BOOL; - /** * @author Mathieu BAGUE {@literal } * @author Laurent Issertial @@ -63,7 +62,7 @@ public void createMacroConnections(DynaWaltzContext context) { @Override protected void writeEventSpecificParameters(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { - ParametersXml.writeParameter(writer, BOOL, "event_stateEvent1", Boolean.toString(disconnect)); + ParametersXml.writeParameter(writer, ParameterType.BOOL, "event_stateEvent1", Boolean.toString(disconnect)); } @Override diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventQuadripoleDisconnection.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventQuadripoleDisconnection.java index a63f86613..9b178f646 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventQuadripoleDisconnection.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/models/events/EventQuadripoleDisconnection.java @@ -15,7 +15,7 @@ import javax.xml.stream.XMLStreamWriter; import java.util.List; -import static com.powsybl.dynawaltz.DynaWaltzParametersDatabase.ParameterType.BOOL; +import static com.powsybl.dynawaltz.parameters.ParameterType.BOOL; /** * @author Marcos de Miguel diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Parameter.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Parameter.java new file mode 100644 index 000000000..5fccebf0a --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Parameter.java @@ -0,0 +1,44 @@ +/** + * 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.parameters; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +/** + * @author Marcos de Miguel + * @author Florian Dupuy + */ +public class Parameter { + + private final String name; + private final ParameterType type; + private final String value; + + public Parameter(@JsonProperty("name") String name, + @JsonProperty("type") ParameterType type, + @JsonProperty("value") String value) { + this.name = Objects.requireNonNull(name); + this.type = Objects.requireNonNull(type); + this.value = Objects.requireNonNull(value); + } + + public String getName() { + return name; + } + + public ParameterType getType() { + return type; + } + + public String getValue() { + return value; + } + +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParameterType.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParameterType.java new file mode 100644 index 000000000..d4da347a9 --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParameterType.java @@ -0,0 +1,19 @@ +/** + * 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.parameters; + +/** + * @author Marcos de Miguel + * @author Florian Dupuy + */ +public enum ParameterType { + DOUBLE, + INT, + BOOL, + STRING; +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParametersSet.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParametersSet.java new file mode 100644 index 000000000..2b5f9c57a --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/ParametersSet.java @@ -0,0 +1,88 @@ +/** + * 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.parameters; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.powsybl.commons.PowsyblException; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +/** + * @author Marcos de Miguel + * @author Florian Dupuy + */ +public class ParametersSet { + + private final Map parameters = new LinkedHashMap<>(); + + private final List references = new ArrayList<>(); + private final String id; + + public ParametersSet(@JsonProperty("id") String id) { + this.id = id; + } + + public void addParameter(String name, ParameterType type, String value) { + parameters.put(name, new Parameter(name, type, value)); + } + + public void addReference(String name, ParameterType type, String origData, String origName) { + references.add(new Reference(name, type, origData, origName)); + } + + public String getId() { + return id; + } + + public Map getParameters() { + return parameters; + } + + public List getReferences() { + return references; + } + + public boolean getBool(String parameterName) { + Parameter parameter = getParameter(parameterName, ParameterType.BOOL); + return Boolean.parseBoolean(parameter.getValue()); + } + + public double getDouble(String parameterName) { + Parameter parameter = getParameter(parameterName, ParameterType.DOUBLE); + return Double.parseDouble(parameter.getValue()); + } + + public int getInt(String parameterName) { + Parameter parameter = getParameter(parameterName, ParameterType.INT); + return Integer.parseInt(parameter.getValue()); + } + + public String getString(String parameterName) { + Parameter parameter = getParameter(parameterName, ParameterType.STRING); + return parameter.getValue(); + } + + public Parameter getParameter(String parameterName) { + Parameter parameter = parameters.get(parameterName); + if (parameter == null) { + throw new IllegalArgumentException("Parameter " + parameterName + " not found in set " + id); + } + return parameter; + } + + private Parameter getParameter(String parameterName, ParameterType type) { + Parameter parameter = getParameter(parameterName); + if (parameter.getType() != type) { + throw new PowsyblException("Invalid parameter type: " + parameter.getType() + " (" + type + " expected)"); + } + return parameter; + } +} diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Reference.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Reference.java new file mode 100644 index 000000000..88b6dc7af --- /dev/null +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/parameters/Reference.java @@ -0,0 +1,49 @@ +/** + * 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.parameters; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.Objects; + +/** + * @author Florian Dupuy + */ +public class Reference { + + private final String name; + private final ParameterType type; + private final String origData; + private final String origName; + + public Reference(@JsonProperty("name") String name, + @JsonProperty("type") ParameterType type, + @JsonProperty("origData") String origData, + @JsonProperty("origName") String origName) { + this.name = Objects.requireNonNull(name); + this.type = Objects.requireNonNull(type); + this.origData = Objects.requireNonNull(origData); + this.origName = Objects.requireNonNull(origName); + } + + public String getName() { + return name; + } + + public ParameterType getType() { + return type; + } + + public String getOrigData() { + return origData; + } + + public String getOrigName() { + return origName; + } +} 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 69d55d3af..11897e83e 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/JobsXml.java @@ -14,7 +14,6 @@ import javax.xml.stream.XMLStreamWriter; import java.io.IOException; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Objects; import static com.powsybl.dynawaltz.xml.DynaWaltzConstants.*; @@ -48,9 +47,9 @@ private static void write(XMLStreamWriter writer, DynaWaltzContext context) thro private static void writeSolver(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { DynaWaltzParameters parameters = context.getDynaWaltzParameters(); writer.writeEmptyElement(DYN_URI, "solver"); - writer.writeAttribute("lib", parameters.getSolver().getType().equals(SolverType.IDA) ? "dynawo_SolverIDA" : "dynawo_SolverSIM"); - writer.writeAttribute("parFile", Paths.get(parameters.getSolver().getParametersFile()).getFileName().toString()); - writer.writeAttribute("parId", parameters.getSolver().getParametersId()); + writer.writeAttribute("lib", parameters.getSolverType().equals(SolverType.IDA) ? "dynawo_SolverIDA" : "dynawo_SolverSIM"); + writer.writeAttribute("parFile", DynaWaltzParameters.SOLVER_OUTPUT_PARAMETERS_FILE); + writer.writeAttribute("parId", parameters.getSolverParameters().getId()); } private static void writeModeler(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { @@ -60,8 +59,8 @@ private static void writeModeler(XMLStreamWriter writer, DynaWaltzContext contex writer.writeEmptyElement(DYN_URI, "network"); writer.writeAttribute("iidmFile", NETWORK_FILENAME); - writer.writeAttribute("parFile", Paths.get(parameters.getNetwork().getParametersFile()).getFileName().toString()); - writer.writeAttribute("parId", parameters.getNetwork().getParametersId()); + writer.writeAttribute("parFile", DynaWaltzParameters.NETWORK_OUTPUT_PARAMETERS_FILE); + writer.writeAttribute("parId", parameters.getNetworkParameters().getId()); writer.writeEmptyElement(DYN_URI, "dynModels"); writer.writeAttribute("dydFile", DYD_FILENAME); diff --git a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java index a9f35df4b..417d19180 100644 --- a/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java +++ b/dynawaltz/src/main/java/com/powsybl/dynawaltz/xml/ParametersXml.java @@ -8,54 +8,163 @@ package com.powsybl.dynawaltz.xml; import com.powsybl.commons.PowsyblException; -import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.commons.exceptions.UncheckedXmlStreamException; import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; -import com.powsybl.dynawaltz.DynaWaltzParametersDatabase; import com.powsybl.dynawaltz.models.BlackBoxModel; +import com.powsybl.dynawaltz.parameters.Parameter; +import com.powsybl.dynawaltz.parameters.ParameterType; +import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.parameters.Reference; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.file.FileSystem; +import javax.xml.XMLConstants; +import javax.xml.stream.*; +import java.io.*; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.util.Objects; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; import static com.powsybl.dynawaltz.xml.DynaWaltzXmlConstants.DYN_URI; /** * @author Marcos de Miguel + * @author Florian Dupuy */ public final class ParametersXml { + public static final String PARAMETERS_SET_ELEMENT_NAME = "parametersSet"; + private ParametersXml() { } + public static List load(InputStream parametersFile) { + try { + XMLStreamReader xmlReader = createXmlInputFactory().createXMLStreamReader(parametersFile); + return readAndClose(xmlReader); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); + } + } + + public static ParametersSet load(InputStream parametersFile, String parameterSetId) { + try { + XMLStreamReader xmlReader = createXmlInputFactory().createXMLStreamReader(parametersFile); + return readOneSetAndClose(xmlReader, parameterSetId); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); + } + } + + public static List load(Path parametersFile) { + try (Reader reader = Files.newBufferedReader(parametersFile, StandardCharsets.UTF_8)) { + XMLStreamReader xmlReader = createXmlInputFactory().createXMLStreamReader(reader); + return readAndClose(xmlReader); + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); + } + } + + public static ParametersSet load(Path parametersFile, String parameterSetId) { + try (Reader reader = Files.newBufferedReader(parametersFile, StandardCharsets.UTF_8)) { + XMLStreamReader xmlReader = createXmlInputFactory().createXMLStreamReader(reader); + return readOneSetAndClose(xmlReader, parameterSetId); + } catch (IOException e) { + throw new UncheckedIOException(e); + } catch (XMLStreamException e) { + throw new UncheckedXmlStreamException(e); + } + } + + private static List readAndClose(XMLStreamReader xmlReader) throws XMLStreamException { + List parametersSets = new ArrayList<>(); + skipComments(xmlReader); + com.powsybl.commons.xml.XmlUtil.readUntilEndElement(PARAMETERS_SET_ELEMENT_NAME, xmlReader, () -> { + if (!xmlReader.getLocalName().equals("set")) { + closeAndThrowException(xmlReader, xmlReader.getLocalName()); + } + String parameterSetIdRead = xmlReader.getAttributeValue(null, "id"); + ParametersSet parametersSet = new ParametersSet(parameterSetIdRead); + fillParametersSet(xmlReader, parametersSet); + parametersSets.add(parametersSet); + }); + xmlReader.close(); + return parametersSets; + } + + private static ParametersSet readOneSetAndClose(XMLStreamReader xmlReader, String parameterSetId) throws XMLStreamException { + ParametersSet parametersSet = new ParametersSet(parameterSetId); + AtomicBoolean found = new AtomicBoolean(false); + skipComments(xmlReader); + com.powsybl.commons.xml.XmlUtil.readUntilEndElement(PARAMETERS_SET_ELEMENT_NAME, xmlReader, () -> { + if (found.get()) { + return; + } + if (!xmlReader.getLocalName().equals("set")) { + closeAndThrowException(xmlReader, xmlReader.getLocalName()); + } + if (xmlReader.getAttributeValue(null, "id").equals(parameterSetId)) { + fillParametersSet(xmlReader, parametersSet); + found.set(true); + } else { + com.powsybl.commons.xml.XmlUtil.readUntilEndElement("set", xmlReader, () -> { + }); + } + }); + xmlReader.close(); + return parametersSet; + } + + private static void fillParametersSet(XMLStreamReader xmlReader, ParametersSet parametersSet) throws XMLStreamException { + com.powsybl.commons.xml.XmlUtil.readUntilEndElement("set", xmlReader, () -> { + String name = xmlReader.getAttributeValue(null, "name"); + ParameterType type = ParameterType.valueOf(xmlReader.getAttributeValue(null, "type")); + if (xmlReader.getLocalName().equals("par")) { + String value = xmlReader.getAttributeValue(null, "value"); + parametersSet.addParameter(name, type, value); + } else if (xmlReader.getLocalName().equals("reference")) { + String origData = xmlReader.getAttributeValue(null, "origData"); + String origName = xmlReader.getAttributeValue(null, "origName"); + parametersSet.addReference(name, type, origData, origName); + } else { + closeAndThrowException(xmlReader, xmlReader.getLocalName()); + } + }); + } + + private static XMLInputFactory createXmlInputFactory() { + XMLInputFactory factory = XMLInputFactory.newInstance(); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, ""); + factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, ""); + return factory; + } + + private static void skipComments(XMLStreamReader xmlReader) throws XMLStreamException { + int state = xmlReader.next(); + while (state == XMLStreamConstants.COMMENT) { + state = xmlReader.next(); + } + } + + private static void closeAndThrowException(XMLStreamReader xmlReader, String unexpectedElement) throws XMLStreamException { + xmlReader.close(); + throw new PowsyblException("Unexpected element: " + unexpectedElement); + } + public static void write(Path workingDir, DynaWaltzContext context) throws IOException, XMLStreamException { Objects.requireNonNull(workingDir); DynaWaltzParameters parameters = context.getDynaWaltzParameters(); - copy(parameters.getParametersFile(), workingDir, context.getPlatformConfig()); - copy(parameters.getNetwork().getParametersFile(), workingDir, context.getPlatformConfig()); - copy(parameters.getSolver().getParametersFile(), workingDir, context.getPlatformConfig()); + write(parameters.getModelParameters(), DynaWaltzParameters.MODELS_OUTPUT_PARAMETERS_FILE, workingDir); + write(List.of(parameters.getNetworkParameters()), DynaWaltzParameters.NETWORK_OUTPUT_PARAMETERS_FILE, workingDir); + write(List.of(parameters.getSolverParameters()), DynaWaltzParameters.SOLVER_OUTPUT_PARAMETERS_FILE, workingDir); // Write parameterSet that needs to be generated (OmegaRef...) Path file = workingDir.resolve(context.getSimulationParFile()); - XmlUtil.write(file, context, "parametersSet", ParametersXml::write); - } - - private static void copy(String filename, Path workingDir, PlatformConfig platformConfig) throws IOException { - FileSystem fs = platformConfig.getConfigDir() - .map(Path::getFileSystem) - .orElseThrow(() -> new PowsyblException("A configuration directory should be defined")); - Path source = fs.getPath(filename); - if (!Files.exists(source)) { - throw new FileNotFoundException("File not found: " + filename); - } - Files.copy(source, workingDir.resolve(source.getFileName().toString()), StandardCopyOption.REPLACE_EXISTING); + XmlUtil.write(file, context, PARAMETERS_SET_ELEMENT_NAME, ParametersXml::write); } private static void write(XMLStreamWriter writer, DynaWaltzContext context) throws XMLStreamException { @@ -64,10 +173,50 @@ private static void write(XMLStreamWriter writer, DynaWaltzContext context) thro } } - public static void writeParameter(XMLStreamWriter writer, DynaWaltzParametersDatabase.ParameterType type, String name, String value) throws XMLStreamException { + private static void write(Collection parametersSets, String filename, Path workingDir) throws IOException, XMLStreamException { + Path parametersPath = workingDir.resolve(filename); + try (Writer writer = Files.newBufferedWriter(parametersPath, StandardCharsets.UTF_8)) { + XMLStreamWriter xmlWriter = XmlStreamWriterFactory.newInstance(writer); + try { + xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0"); + xmlWriter.setPrefix("", DYN_URI); + xmlWriter.writeStartElement(DYN_URI, PARAMETERS_SET_ELEMENT_NAME); + xmlWriter.writeNamespace("", DYN_URI); + for (ParametersSet parametersSet : parametersSets) { + writeParametersSet(xmlWriter, parametersSet); + } + xmlWriter.writeEndElement(); + xmlWriter.writeEndDocument(); + } finally { + xmlWriter.close(); + } + } + } + + private static void writeParametersSet(XMLStreamWriter xmlWriter, ParametersSet parametersSet) throws XMLStreamException { + xmlWriter.writeStartElement(DYN_URI, "set"); + xmlWriter.writeAttribute("id", parametersSet.getId()); + for (Parameter par : parametersSet.getParameters().values()) { + ParametersXml.writeParameter(xmlWriter, par.getType(), par.getName(), par.getValue()); + } + for (Reference par : parametersSet.getReferences()) { + ParametersXml.writeReference(xmlWriter, par.getType(), par.getName(), par.getOrigData(), par.getOrigName()); + } + xmlWriter.writeEndElement(); + } + + public static void writeParameter(XMLStreamWriter writer, ParameterType type, String name, String value) throws XMLStreamException { writer.writeEmptyElement(DYN_URI, "par"); writer.writeAttribute("type", type.toString()); writer.writeAttribute("name", name); writer.writeAttribute("value", value); } + + public static void writeReference(XMLStreamWriter writer, ParameterType type, String name, String origData, String origName) throws XMLStreamException { + writer.writeEmptyElement(DYN_URI, "reference"); + writer.writeAttribute("type", type.toString()); + writer.writeAttribute("name", name); + writer.writeAttribute("origData", origData); + writer.writeAttribute("origName", origName); + } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabaseTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabaseTest.java index 7e171d59e..29cb4bd4e 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabaseTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersDatabaseTest.java @@ -9,6 +9,8 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; import com.powsybl.commons.PowsyblException; +import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.xml.ParametersXml; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -18,6 +20,7 @@ import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -42,28 +45,33 @@ void tearDown() throws IOException { @Test void checkParameters() { - DynaWaltzParametersDatabase parametersDatabase = DynaWaltzParametersDatabase.load(fileSystem.getPath("/models.par")); - assertNotNull(parametersDatabase.getParameterSet("LoadAlphaBeta")); - assertEquals(1.5, parametersDatabase.getDouble("LoadAlphaBeta", "load_alpha"), 1e-6); - assertEquals(2.5, parametersDatabase.getDouble("LoadAlphaBeta", "load_beta"), 1e-6); - assertNotNull(parametersDatabase.getParameterSet("GeneratorSynchronousFourWindingsProportionalRegulations")); - assertEquals(5.4, parametersDatabase.getDouble("GeneratorSynchronousFourWindingsProportionalRegulations", "generator_H"), 1e-6); - assertEquals(1, parametersDatabase.getInt("GeneratorSynchronousFourWindingsProportionalRegulations", "generator_ExcitationPu")); - assertTrue(parametersDatabase.getBool("test", "boolean")); - assertEquals("aString", parametersDatabase.getString("test", "string")); + List setsMap = ParametersXml.load(fileSystem.getPath("/models.par")); + DynaWaltzParameters dParameters = new DynaWaltzParameters().setModelsParameters(setsMap); + + ParametersSet set1 = dParameters.getModelParameters("LoadAlphaBeta"); + assertEquals(1.5, set1.getDouble("load_alpha"), 1e-6); + assertEquals(2.5, set1.getDouble("load_beta"), 1e-6); + + ParametersSet set2 = dParameters.getModelParameters("GeneratorSynchronousFourWindingsProportionalRegulations"); + assertEquals(5.4, set2.getDouble("generator_H"), 1e-6); + assertEquals(1, set2.getInt("generator_ExcitationPu")); + + ParametersSet set3 = dParameters.getModelParameters("test"); + assertTrue(set3.getBool("boolean")); + assertEquals("aString", set3.getString("string")); } @Test void checkParametersMisspelled() { Path path = fileSystem.getPath("/models_misspelled.par"); - PowsyblException e = assertThrows(PowsyblException.class, () -> DynaWaltzParametersDatabase.load(path)); + PowsyblException e = assertThrows(PowsyblException.class, () -> ParametersXml.load(path)); assertEquals("Unexpected element: sett", e.getMessage()); } @Test void checkParametersNotFound() { Path path = fileSystem.getPath("/file.par"); - UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> DynaWaltzParametersDatabase.load(path)); + UncheckedIOException e = assertThrows(UncheckedIOException.class, () -> ParametersXml.load(path)); assertEquals("java.nio.file.NoSuchFileException: /file.par", e.getMessage()); } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java index c3c3ce441..63afea746 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/DynaWaltzParametersTest.java @@ -6,84 +6,154 @@ */ package com.powsybl.dynawaltz; -import com.google.common.jimfs.Configuration; -import com.google.common.jimfs.Jimfs; import com.powsybl.commons.config.InMemoryPlatformConfig; import com.powsybl.commons.config.MapModuleConfig; -import com.powsybl.commons.config.ModuleConfig; +import com.powsybl.commons.test.AbstractConverterTest; +import com.powsybl.dynamicsimulation.DynamicSimulationParameters; +import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzParameters.SolverType; -import org.junit.jupiter.api.AfterEach; +import com.powsybl.dynawaltz.parameters.Parameter; +import com.powsybl.dynawaltz.parameters.ParameterType; +import com.powsybl.dynawaltz.parameters.ParametersSet; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.IOException; -import java.nio.file.FileSystem; -import java.util.Optional; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Objects; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Marcos de Miguel */ -class DynaWaltzParametersTest { +class DynaWaltzParametersTest extends AbstractConverterTest { - private final String parametersFile = "/home/user/parametersFile"; - private final String networkParametersFile = "/home/user/networkParametersFile"; - private final String solverParametersFile = "/home/user/solverParametersFile"; - private final boolean mergeLoads = true; + public static final String USER_HOME = "/home/user/"; private InMemoryPlatformConfig platformConfig; - private FileSystem fileSystem; @BeforeEach - void setUp() { - fileSystem = Jimfs.newFileSystem(Configuration.unix()); + public void setUp() throws IOException { + super.setUp(); platformConfig = new InMemoryPlatformConfig(fileSystem); - MapModuleConfig moduleConfig = platformConfig.createModuleConfig("dynawaltz-default-parameters"); - moduleConfig.setStringProperty("parametersFile", parametersFile); - moduleConfig.setStringProperty("network.parametersFile", networkParametersFile); - moduleConfig.setStringProperty("solver.parametersFile", solverParametersFile); - moduleConfig.setStringProperty("mergeLoads", String.valueOf(mergeLoads)); } - @AfterEach - void tearDown() throws IOException { - fileSystem.close(); + private void copyFile(String name, String parametersFile) throws IOException { + Path path = platformConfig.getConfigDir() + .map(cd -> cd.resolve(fileSystem.getPath(parametersFile))) + .orElse(fileSystem.getPath(parametersFile)); + Objects.requireNonNull(getClass().getResourceAsStream(name)) + .transferTo(Files.newOutputStream(path)); } @Test - void checkParameters() { + void checkParameters() throws IOException { String networkParametersId = "networkParametersId"; SolverType solverType = SolverType.IDA; String solverParametersId = "solverParametersId"; + boolean mergeLoads = true; + initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads); + + DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig, fileSystem); + + checModelParameters(parameters); + + assertEquals(networkParametersId, parameters.getNetworkParameters().getId()); + ParametersSet networkParameters = parameters.getNetworkParameters(); + Parameter loadTp = networkParameters.getParameter("load_Tp"); + assertEquals("90", loadTp.getValue()); + assertEquals("load_Tp", loadTp.getName()); + assertEquals(ParameterType.DOUBLE, loadTp.getType()); + Parameter loadControllable = networkParameters.getParameter("load_isControllable"); + assertEquals("false", loadControllable.getValue()); + assertEquals("load_isControllable", loadControllable.getName()); + assertEquals(ParameterType.BOOL, loadControllable.getType()); + + ParametersSet solverParameters = parameters.getSolverParameters(); + assertEquals(solverParametersId, solverParameters.getId()); + assertEquals(solverType, parameters.getSolverType()); + Parameter order = solverParameters.getParameter("order"); + assertEquals("1", order.getValue()); + assertEquals("order", order.getName()); + assertEquals(ParameterType.INT, order.getType()); + Parameter absAccuracy = solverParameters.getParameter("absAccuracy"); + assertEquals("1e-4", absAccuracy.getValue()); + assertEquals("absAccuracy", absAccuracy.getName()); + assertEquals(ParameterType.DOUBLE, absAccuracy.getType()); - Optional moduleConfig = platformConfig.getOptionalModuleConfig("dynawaltz-default-parameters"); - moduleConfig.filter(MapModuleConfig.class::isInstance).map(MapModuleConfig.class::cast).ifPresent(c -> { - c.setStringProperty("network.parametersId", networkParametersId); - c.setStringProperty("solver.type", solverType.toString()); - c.setStringProperty("solver.parametersId", solverParametersId); - }); - - DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig); - assertEquals(parametersFile, parameters.getParametersFile()); - assertEquals(networkParametersFile, parameters.getNetwork().getParametersFile()); - assertEquals(networkParametersId, parameters.getNetwork().getParametersId()); - assertEquals(solverType, parameters.getSolver().getType()); - assertEquals(solverParametersFile, parameters.getSolver().getParametersFile()); - assertEquals(solverParametersId, parameters.getSolver().getParametersId()); assertEquals(mergeLoads, parameters.isMergeLoads()); } @Test - void checkDefaultParameters() { - - DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig); - assertEquals(parametersFile, parameters.getParametersFile()); - assertEquals(networkParametersFile, parameters.getNetwork().getParametersFile()); - assertEquals(DynaWaltzParameters.DEFAULT_NETWORK_PAR_ID, parameters.getNetwork().getParametersId()); - assertEquals(DynaWaltzParameters.DEFAULT_SOLVER_TYPE, parameters.getSolver().getType()); - assertEquals(solverParametersFile, parameters.getSolver().getParametersFile()); - assertEquals(DynaWaltzParameters.DEFAULT_SOLVER_PAR_ID, parameters.getSolver().getParametersId()); + void roundTripParametersSerializing() throws IOException { + String networkParametersId = "networkParametersId"; + SolverType solverType = SolverType.IDA; + String solverParametersId = "solverParametersId"; + boolean mergeLoads = false; + initPlatformConfig(networkParametersId, solverType, solverParametersId, mergeLoads); + + DynamicSimulationParameters dynamicSimulationParameters = new DynamicSimulationParameters() + .setStartTime(0) + .setStopTime(3600); + DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(platformConfig); + dynamicSimulationParameters.addExtension(DynaWaltzParameters.class, dynawoParameters); + roundTripTest(dynamicSimulationParameters, JsonDynamicSimulationParameters::write, + JsonDynamicSimulationParameters::read, "/DynaWaltzParameters.json"); + } + + private void initPlatformConfig(String networkParametersId, SolverType solverType, String solverParametersId, boolean mergeLoads) throws IOException { + String parametersFile = USER_HOME + "parametersFile"; + String networkParametersFile = USER_HOME + "networkParametersFile"; + String solverParametersFile = USER_HOME + "solverParametersFile"; + + MapModuleConfig moduleConfig = platformConfig.createModuleConfig("dynawaltz-default-parameters"); + moduleConfig.setStringProperty("parametersFile", parametersFile); + moduleConfig.setStringProperty("network.parametersFile", networkParametersFile); + moduleConfig.setStringProperty("solver.parametersFile", solverParametersFile); + moduleConfig.setStringProperty("mergeLoads", String.valueOf(mergeLoads)); + moduleConfig.setStringProperty("network.parametersId", networkParametersId); + moduleConfig.setStringProperty("solver.type", solverType.toString()); + moduleConfig.setStringProperty("solver.parametersId", solverParametersId); + + Files.createDirectories(fileSystem.getPath(USER_HOME)); + copyFile("/parametersSet/models.par", parametersFile); + copyFile("/parametersSet/network.par", networkParametersFile); + copyFile("/parametersSet/solvers.par", solverParametersFile); + } + + @Test + void checkDefaultParameters() throws IOException { + Files.createDirectories(fileSystem.getPath(USER_HOME)); + copyFile("/parametersSet/models.par", DynaWaltzParameters.DEFAULT_INPUT_PARAMETERS_FILE); + copyFile("/parametersSet/network.par", DynaWaltzParameters.DEFAULT_INPUT_NETWORK_PARAMETERS_FILE); + copyFile("/parametersSet/solvers.par", DynaWaltzParameters.DEFAULT_INPUT_SOLVER_PARAMETERS_FILE); + + DynaWaltzParameters parameters = DynaWaltzParameters.load(platformConfig, fileSystem); + checModelParameters(parameters); + + assertEquals(DynaWaltzParameters.DEFAULT_NETWORK_PAR_ID, parameters.getNetworkParameters().getId()); + assertTrue(parameters.getNetworkParameters().getParameters().isEmpty()); + assertTrue(parameters.getNetworkParameters().getReferences().isEmpty()); + + assertEquals(DynaWaltzParameters.DEFAULT_SOLVER_TYPE, parameters.getSolverType()); + assertEquals(DynaWaltzParameters.DEFAULT_SOLVER_PAR_ID, parameters.getSolverParameters().getId()); + assertTrue(parameters.getSolverParameters().getParameters().isEmpty()); + assertTrue(parameters.getSolverParameters().getReferences().isEmpty()); + assertEquals(DynaWaltzParameters.DEFAULT_MERGE_LOADS, parameters.isMergeLoads()); } + + private static void checModelParameters(DynaWaltzParameters dynaWaltzParameters) { + Parameter booleanParameter = dynaWaltzParameters.getModelParameters("test").getParameter("boolean"); + assertEquals("true", booleanParameter.getValue()); + assertEquals("boolean", booleanParameter.getName()); + assertEquals(ParameterType.BOOL, booleanParameter.getType()); + Parameter stringParameter = dynaWaltzParameters.getModelParameters("test").getParameter("string"); + assertEquals("aString", stringParameter.getValue()); + assertEquals("string", stringParameter.getName()); + assertEquals(ParameterType.STRING, stringParameter.getType()); + } } diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/json/DynaWaltzParametersSerializerTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/json/DynaWaltzParametersSerializerTest.java deleted file mode 100644 index a480fcebf..000000000 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/json/DynaWaltzParametersSerializerTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (c) 2020, 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/. - */ -package com.powsybl.dynawaltz.json; - -import com.powsybl.commons.config.InMemoryPlatformConfig; -import com.powsybl.commons.config.MapModuleConfig; -import com.powsybl.commons.test.AbstractConverterTest; -import com.powsybl.dynamicsimulation.DynamicSimulationParameters; -import com.powsybl.dynamicsimulation.json.JsonDynamicSimulationParameters; -import com.powsybl.dynawaltz.DynaWaltzParameters; -import org.junit.jupiter.api.Test; - -import java.io.IOException; - -/** - * @author Marcos de Miguel - */ -class DynaWaltzParametersSerializerTest extends AbstractConverterTest { - - @Test - void roundTripParameters() throws IOException { - String parametersFile = "/home/user/parametersFile"; - String networkParametersFile = "/home/user/networkParametersFile"; - String solverParametersFile = "/home/user/solverParametersFile"; - boolean mergeLoads = false; - InMemoryPlatformConfig platformConfig = new InMemoryPlatformConfig(fileSystem); - MapModuleConfig moduleConfig = platformConfig.createModuleConfig("dynawaltz-default-parameters"); - moduleConfig.setStringProperty("parametersFile", parametersFile); - moduleConfig.setStringProperty("network.parametersFile", networkParametersFile); - moduleConfig.setStringProperty("solver.parametersFile", solverParametersFile); - moduleConfig.setStringProperty("mergeLoads", String.valueOf(mergeLoads)); - - DynamicSimulationParameters dynamicSimulationParameters = new DynamicSimulationParameters() - .setStartTime(0) - .setStopTime(3600); - DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(platformConfig); - dynamicSimulationParameters.addExtension(DynaWaltzParameters.class, dynawoParameters); - roundTripTest(dynamicSimulationParameters, JsonDynamicSimulationParameters::write, - JsonDynamicSimulationParameters::read, "/DynaWaltzParameters.json"); - } -} diff --git a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java index 8270e6530..9939d8979 100644 --- a/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java +++ b/dynawaltz/src/test/java/com/powsybl/dynawaltz/xml/ParametersXmlTest.java @@ -6,6 +6,7 @@ */ package com.powsybl.dynawaltz.xml; +import com.powsybl.commons.config.PlatformConfig; import com.powsybl.dynamicsimulation.DynamicSimulationParameters; import com.powsybl.dynawaltz.DynaWaltzContext; import com.powsybl.dynawaltz.DynaWaltzParameters; @@ -23,7 +24,7 @@ class ParametersXmlTest extends DynaWaltzTestUtil { @Test void writeOmegaRef() throws SAXException, IOException, XMLStreamException { DynamicSimulationParameters parameters = DynamicSimulationParameters.load(); - DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(); + DynaWaltzParameters dynawoParameters = DynaWaltzParameters.load(PlatformConfig.defaultConfig(), fileSystem); DynaWaltzContext context = new DynaWaltzContext(network, network.getVariantManager().getWorkingVariantId(), dynamicModels, eventModels, curves, parameters, dynawoParameters); DydXml.write(tmpDir, context); diff --git a/dynawaltz/src/test/resources/DynaWaltzParameters.json b/dynawaltz/src/test/resources/DynaWaltzParameters.json index 80ae87d67..67147940a 100644 --- a/dynawaltz/src/test/resources/DynaWaltzParameters.json +++ b/dynawaltz/src/test/resources/DynaWaltzParameters.json @@ -4,17 +4,56 @@ "stopTime" : 3600, "extensions" : { "DynaWaltzParameters" : { - "parametersFile" : "/home/user/parametersFile", - "network" : { - "parametersFile" : "/home/user/networkParametersFile", - "parametersId" : "1" + "networkParameters" : { + "id" : "networkParametersId", + "parameters" : { + "load_Tp" : { + "name" : "load_Tp", + "type" : "DOUBLE", + "value" : "90" + }, + "load_isControllable" : { + "name" : "load_isControllable", + "type" : "BOOL", + "value" : "false" + } + }, + "references" : [ ] }, - "solver" : { - "type" : "SIM", - "parametersFile" : "/home/user/solverParametersFile", - "parametersId" : "1" + "solverParameters" : { + "id" : "solverParametersId", + "parameters" : { + "order" : { + "name" : "order", + "type" : "INT", + "value" : "1" + }, + "absAccuracy" : { + "name" : "absAccuracy", + "type" : "DOUBLE", + "value" : "1e-4" + } + }, + "references" : [ ] }, - "mergeLoads" : false + "solverType" : "IDA", + "mergeLoads" : false, + "modelsParameters" : [ { + "id" : "test", + "parameters" : { + "boolean" : { + "name" : "boolean", + "type" : "BOOL", + "value" : "true" + }, + "string" : { + "name" : "string", + "type" : "STRING", + "value" : "aString" + } + }, + "references" : [ ] + } ] } } } \ No newline at end of file diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/config.yml b/dynawaltz/src/test/resources/com/powsybl/config/test/config.yml index bd7f0b050..11eab076f 100644 --- a/dynawaltz/src/test/resources/com/powsybl/config/test/config.yml +++ b/dynawaltz/src/test/resources/com/powsybl/config/test/config.yml @@ -7,10 +7,10 @@ dynawaltz: debug: false dynawaltz-default-parameters: - parametersFile: /work/unittests/models.par - network.parametersFile: /work/unittests/network.par + parametersFile: /work/unittests/configModels.par + network.parametersFile: /work/unittests/configNetwork.par network.parametersId: "1" solver.type: IDA - solver.parametersFile: /work/unittests/solver.par + solver.parametersFile: /work/unittests/configSolver.par solver.parametersId: "1" diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/models.par b/dynawaltz/src/test/resources/com/powsybl/config/test/configModels.par similarity index 100% rename from dynawaltz/src/test/resources/com/powsybl/config/test/models.par rename to dynawaltz/src/test/resources/com/powsybl/config/test/configModels.par diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/configNetwork.par b/dynawaltz/src/test/resources/com/powsybl/config/test/configNetwork.par new file mode 100644 index 000000000..293a375c4 --- /dev/null +++ b/dynawaltz/src/test/resources/com/powsybl/config/test/configNetwork.par @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/configSolver.par b/dynawaltz/src/test/resources/com/powsybl/config/test/configSolver.par new file mode 100644 index 000000000..c6f9674e6 --- /dev/null +++ b/dynawaltz/src/test/resources/com/powsybl/config/test/configSolver.par @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/filelist.txt b/dynawaltz/src/test/resources/com/powsybl/config/test/filelist.txt index 08737a402..430d456a6 100644 --- a/dynawaltz/src/test/resources/com/powsybl/config/test/filelist.txt +++ b/dynawaltz/src/test/resources/com/powsybl/config/test/filelist.txt @@ -1,4 +1,4 @@ config.yml -models.par -network.par -solver.par +configModels.par +configNetwork.par +configSolver.par diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/network.par b/dynawaltz/src/test/resources/com/powsybl/config/test/network.par deleted file mode 100644 index e69de29bb..000000000 diff --git a/dynawaltz/src/test/resources/com/powsybl/config/test/solver.par b/dynawaltz/src/test/resources/com/powsybl/config/test/solver.par deleted file mode 100644 index e69de29bb..000000000 diff --git a/dynawaltz/src/test/resources/jobs.xml b/dynawaltz/src/test/resources/jobs.xml index ba4ff2d06..f450aac74 100644 --- a/dynawaltz/src/test/resources/jobs.xml +++ b/dynawaltz/src/test/resources/jobs.xml @@ -1,7 +1,7 @@ - + diff --git a/dynawaltz/src/test/resources/parametersSet/models.par b/dynawaltz/src/test/resources/parametersSet/models.par new file mode 100644 index 000000000..be611df2b --- /dev/null +++ b/dynawaltz/src/test/resources/parametersSet/models.par @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dynawaltz/src/test/resources/parametersSet/network.par b/dynawaltz/src/test/resources/parametersSet/network.par new file mode 100644 index 000000000..293a375c4 --- /dev/null +++ b/dynawaltz/src/test/resources/parametersSet/network.par @@ -0,0 +1,7 @@ + + + + + + + diff --git a/dynawaltz/src/test/resources/parametersSet/solvers.par b/dynawaltz/src/test/resources/parametersSet/solvers.par new file mode 100644 index 000000000..c6f9674e6 --- /dev/null +++ b/dynawaltz/src/test/resources/parametersSet/solvers.par @@ -0,0 +1,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 8e23f4275..3d2556f0e 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 @@ -6,7 +6,6 @@ */ package com.powsybl.dynawo.it; -import com.powsybl.commons.config.PlatformConfig; import com.powsybl.commons.datasource.ResourceDataSource; import com.powsybl.commons.datasource.ResourceSet; import com.powsybl.dynamicsimulation.*; @@ -14,6 +13,8 @@ import com.powsybl.dynawaltz.DynaWaltzConfig; import com.powsybl.dynawaltz.DynaWaltzParameters; import com.powsybl.dynawaltz.DynaWaltzProvider; +import com.powsybl.dynawaltz.parameters.ParametersSet; +import com.powsybl.dynawaltz.xml.ParametersXml; import com.powsybl.iidm.network.Network; import com.powsybl.iidm.network.VariantManagerConstants; import com.powsybl.iidm.network.test.SvcTestCaseFactory; @@ -22,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.IOException; -import java.nio.file.Files; import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -43,7 +42,7 @@ class DynaWaltzTest extends AbstractDynawoTest { @BeforeEach void setUp() throws Exception { super.setUp(); - provider = new DynaWaltzProvider(PlatformConfig.defaultConfig(), new DynaWaltzConfig("/dynawo", false)); + provider = new DynaWaltzProvider(new DynaWaltzConfig("/dynawo", false)); parameters = new DynamicSimulationParameters() .setStartTime(1) .setStopTime(100); @@ -52,7 +51,7 @@ void setUp() throws Exception { } @Test - void testIeee14() throws IOException { + void testIeee14() { Network network = Network.read(new ResourceDataSource("IEEE14", new ResourceSet("/ieee14", "IEEE14.iidm"))); GroovyDynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier( @@ -67,20 +66,13 @@ void testIeee14() throws IOException { getResourceAsStream("/ieee14/disconnectline/curves.groovy"), GroovyExtension.find(CurveGroovyExtension.class, DynaWaltzProvider.NAME)); - // FIXME waiting for being able to pass parameters as an input stream - for (String parFileName : List.of("models.par", "network.par", "solvers.par")) { - Files.copy(getResourceAsStream("/ieee14/disconnectline/" + parFileName), localDir.resolve(parFileName)); - } - - // FIXME this should not be dependent of the run, all par file should be provider through an input stream - dynaWaltzParameters.setParametersFile(localDir.resolve("models.par").toString()) - .setNetwork(new DynaWaltzParameters.Network() - .setParametersId("8") - .setParametersFile(localDir.resolve("network.par").toString())) - .setSolver(new DynaWaltzParameters.Solver() - .setType(DynaWaltzParameters.SolverType.IDA) - .setParametersId("2") - .setParametersFile(localDir.resolve("solvers.par").toString())); + List modelsParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/models.par")); + ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/network.par"), "8"); + ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/ieee14/disconnectline/solvers.par"), "2"); + dynaWaltzParameters.setModelsParameters(modelsParameters) + .setNetworkParameters(networkParameters) + .setSolverParameters(solverParameters) + .setSolverType(DynaWaltzParameters.SolverType.IDA); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, eventModelsSupplier, curvesSupplier, VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) @@ -97,27 +89,20 @@ void testIeee14() throws IOException { } @Test - void testSvc() throws IOException { + void testSvc() { Network network = SvcTestCaseFactory.create(); GroovyDynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier( getResourceAsStream("/svc/dynamicModels.groovy"), GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME)); - // FIXME waiting for being able to pass parameters as an input stream - for (String parFileName : List.of("models.par", "network.par", "solvers.par")) { - Files.copy(getResourceAsStream("/svc/" + parFileName), localDir.resolve(parFileName)); - } - - // FIXME this should not be dependent of the run, all par file should be provider through an input stream - dynaWaltzParameters.setParametersFile(localDir.resolve("models.par").toString()) - .setNetwork(new DynaWaltzParameters.Network() - .setParametersId("8") - .setParametersFile(localDir.resolve("network.par").toString())) - .setSolver(new DynaWaltzParameters.Solver() - .setType(DynaWaltzParameters.SolverType.IDA) - .setParametersId("2") - .setParametersFile(localDir.resolve("solvers.par").toString())); + List modelsParameters = ParametersXml.load(getResourceAsStream("/svc/models.par")); + ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/svc/network.par"), "8"); + ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/svc/solvers.par"), "2"); + dynaWaltzParameters.setModelsParameters(modelsParameters) + .setNetworkParameters(networkParameters) + .setSolverParameters(solverParameters) + .setSolverType(DynaWaltzParameters.SolverType.IDA); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, EventModelsSupplier.empty(), CurvesSupplier.empty(), VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters) @@ -131,27 +116,20 @@ void testSvc() throws IOException { } @Test - void testHvdc() throws IOException { + void testHvdc() { Network network = Network.read(new ResourceDataSource("HvdcPowerTransfer", new ResourceSet("/hvdc", "HvdcPowerTransfer.iidm"))); GroovyDynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier( getResourceAsStream("/hvdc/dynamicModels.groovy"), GroovyExtension.find(DynamicModelGroovyExtension.class, DynaWaltzProvider.NAME)); - // FIXME waiting for being able to pass parameters as an input stream - for (String parFileName : List.of("models.par", "network.par", "solvers.par")) { - Files.copy(getResourceAsStream("/hvdc/" + parFileName), localDir.resolve(parFileName)); - } - - // FIXME this should not be dependent of the run, all par file should be provider through an input stream - dynaWaltzParameters.setParametersFile(localDir.resolve("models.par").toString()) - .setNetwork(new DynaWaltzParameters.Network() - .setParametersId("8") - .setParametersFile(localDir.resolve("network.par").toString())) - .setSolver(new DynaWaltzParameters.Solver() - .setType(DynaWaltzParameters.SolverType.IDA) - .setParametersId("2") - .setParametersFile(localDir.resolve("solvers.par").toString())); + List modelsParameters = ParametersXml.load(getResourceAsStream("/hvdc/models.par")); + ParametersSet networkParameters = ParametersXml.load(getResourceAsStream("/hvdc/network.par"), "8"); + ParametersSet solverParameters = ParametersXml.load(getResourceAsStream("/hvdc/solvers.par"), "2"); + dynaWaltzParameters.setModelsParameters(modelsParameters) + .setNetworkParameters(networkParameters) + .setSolverParameters(solverParameters) + .setSolverType(DynaWaltzParameters.SolverType.IDA); DynamicSimulationResult result = provider.run(network, dynamicModelsSupplier, EventModelsSupplier.empty(), CurvesSupplier.empty(), VariantManagerConstants.INITIAL_VARIANT_ID, computationManager, parameters)