Skip to content

Commit

Permalink
Refactor parameters input (#210)
Browse files Browse the repository at this point in the history
* Read parameters instead of just passing path
* Parameters files are in config dir if specified
* Write parameters and add references entries support
* Refactor inner classes into separate classes
* Delete ParametersSet class
* Delete Solver and Network classes
* Rename Set to ParametersSet
* Update unit tests

Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup authored Apr 21, 2023
1 parent 7a9e388 commit 45ce2e7
Show file tree
Hide file tree
Showing 46 changed files with 749 additions and 836 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<parametersSet xmlns="http://www.rte-france.com/dynawo">
<!-- IDA order 1 solver-->
<set id="1">
<par type="INT" name="order" value="1"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- IDA order 2 solver -->
<set id="2">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
Expand All @@ -18,37 +8,4 @@
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- Simplified solver without step recalculation -->
<set id="3">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="false"/>
</set>
<!-- Simplified solver with step recalculation -->
<set id="4">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="true"/>
</set>
<!-- IDA order 2 solver with higher accuracy requirements -->
<set id="5">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-6"/>
<par type="DOUBLE" name="relAccuracy" value="1e-6"/>
</set>
</parametersSet>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<parametersSet xmlns="http://www.rte-france.com/dynawo">
<!-- IDA order 1 solver-->
<set id="1">
<par type="INT" name="order" value="1"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- IDA order 2 solver -->
<set id="2">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
Expand All @@ -18,37 +8,4 @@
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- Simplified solver without step recalculation -->
<set id="3">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="false"/>
</set>
<!-- Simplified solver with step recalculation -->
<set id="4">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="true"/>
</set>
<!-- IDA order 2 solver with higher accuracy requirements -->
<set id="5">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-6"/>
<par type="DOUBLE" name="relAccuracy" value="1e-6"/>
</set>
</parametersSet>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
<?xml version='1.0' encoding='UTF-8'?>
<parametersSet xmlns="http://www.rte-france.com/dynawo">
<!-- IDA order 1 solver-->
<set id="1">
<par type="INT" name="order" value="1"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- IDA order 2 solver -->
<set id="2">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
Expand All @@ -18,37 +8,4 @@
<par type="DOUBLE" name="absAccuracy" value="1e-4"/>
<par type="DOUBLE" name="relAccuracy" value="1e-4"/>
</set>
<!-- Simplified solver without step recalculation -->
<set id="3">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="false"/>
</set>
<!-- Simplified solver with step recalculation -->
<set id="4">
<par type="DOUBLE" name="hMin" value="0.000001"/>
<par type="DOUBLE" name="hMax" value="1"/>
<par type="DOUBLE" name="kReduceStep" value="0.5"/>
<par type="INT" name="nEff" value="10"/>
<par type="INT" name="nDeadband" value="2"/>
<par type="INT" name="maxRootRestart" value="3"/>
<par type="INT" name="maxNewtonTry" value="10"/>
<par type="STRING" name="linearSolverName" value="KLU"/>
<par type="BOOL" name="recalculateStep" value="true"/>
</set>
<!-- IDA order 2 solver with higher accuracy requirements -->
<set id="5">
<par type="INT" name="order" value="2"/>
<par type="DOUBLE" name="initStep" value="0.000001"/>
<par type="DOUBLE" name="minStep" value="0.000001"/>
<par type="DOUBLE" name="maxStep" value="10"/>
<par type="DOUBLE" name="absAccuracy" value="1e-6"/>
<par type="DOUBLE" name="relAccuracy" value="1e-6"/>
</set>
</parametersSet>

This file was deleted.

Loading

0 comments on commit 45ce2e7

Please sign in to comment.