Skip to content

Commit

Permalink
Fix dsl unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Apr 21, 2023
1 parent b782912 commit 07e2fdb
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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.iidm.network.Network;
Expand Down Expand Up @@ -51,20 +50,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("parametersSet/network.par"));
Files.copy(getClass().getResourceAsStream(solverParametersFile), configDir.resolve("parametersSet/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 +89,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(getClass().getResourceAsStream(parametersFile))
.setNetworkParameters(getClass().getResourceAsStream(networkParametersFile), networkParametersId)
.setSolverParameters(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 @@ -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.

Original file line number Diff line number Diff line change
@@ -1,14 +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"/>
Expand All @@ -18,37 +9,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>
Loading

0 comments on commit 07e2fdb

Please sign in to comment.