-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Defining the new dynamic simulation API (#983)
* dynamic simulation API Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * dynamic simulation parameters Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * test Async Simulation Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix empty catch Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * test tool Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * unused import Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * changed the default stopTime Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * moved items to the eclipse projects block Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * prepare next release v3.1.0-SNAPSHOT Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix PR review Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix coverage Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix year in Copyright information Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * remove unused import Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix tests Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * Small fixes Signed-off-by: Mathieu BAGUE <mathieu.bague@rte-france.com> * Add more unit tests Signed-off-by: Mathieu BAGUE <mathieu.bague@rte-france.com> * use dynamicsimulation in package naming Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * fix redundant import Signed-off-by: Marcos de Miguel <demiguelm@aia.es> * remove Metrics from Tools Signed-off-by: Marcos de Miguel <demiguelm@aia.es>
- Loading branch information
Showing
30 changed files
with
1,815 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2019, 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/. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.powsybl</groupId> | ||
<artifactId>powsybl-dynamic-simulation</artifactId> | ||
<version>3.1.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>powsybl-dynamic-simulation-api</artifactId> | ||
<name>Dynamic Simulation API</name> | ||
<description>An API and a tool to run dynamic simulation computations</description> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>com.powsybl.dynamic.simulation.api</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.gmavenplus</groupId> | ||
<artifactId>gmavenplus-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- Compilation dependencies --> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-computation</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-iidm-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-iidm-converter-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- Test dependencies --> | ||
<dependency> | ||
<groupId>com.google.jimfs</groupId> | ||
<artifactId>jimfs</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>log4j-over-slf4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-commons</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-config-test</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-iidm-impl</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-iidm-xml-converter</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>powsybl-tools</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
<type>test-jar</type> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
176 changes: 176 additions & 0 deletions
176
...dynamic-simulation-api/src/main/java/com/powsybl/dynamicsimulation/DynamicSimulation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
/** | ||
* Copyright (c) 2019, 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.dynamicsimulation; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.stream.Collectors; | ||
|
||
import com.google.common.base.Supplier; | ||
import com.google.common.base.Suppliers; | ||
import com.powsybl.commons.PowsyblException; | ||
import com.powsybl.commons.Versionable; | ||
import com.powsybl.commons.config.PlatformConfig; | ||
import com.powsybl.commons.util.ServiceLoaderCache; | ||
import com.powsybl.computation.ComputationManager; | ||
import com.powsybl.computation.local.LocalComputationManager; | ||
import com.powsybl.iidm.network.Network; | ||
|
||
/** | ||
* @author Marcos de Miguel <demiguelm at aia.es> | ||
*/ | ||
public final class DynamicSimulation { | ||
|
||
private DynamicSimulation() { | ||
} | ||
|
||
private static final Supplier<List<DynamicSimulationProvider>> PROVIDERS_SUPPLIERS = Suppliers | ||
.memoize(() -> new ServiceLoaderCache<>(DynamicSimulationProvider.class).getServices()); | ||
|
||
public static class Runner implements Versionable { | ||
|
||
private final DynamicSimulationProvider provider; | ||
|
||
public Runner(DynamicSimulationProvider provider) { | ||
this.provider = Objects.requireNonNull(provider); | ||
} | ||
|
||
public CompletableFuture<DynamicSimulationResult> runAsync(Network network, String workingStateId, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
Objects.requireNonNull(workingStateId); | ||
Objects.requireNonNull(parameters); | ||
return provider.run(network, computationManager, workingStateId, parameters); | ||
} | ||
|
||
public CompletableFuture<DynamicSimulationResult> runAsync(Network network, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
return runAsync(network, network.getVariantManager().getWorkingVariantId(), computationManager, parameters); | ||
} | ||
|
||
public CompletableFuture<DynamicSimulationResult> runAsync(Network network, | ||
DynamicSimulationParameters parameters) { | ||
return runAsync(network, LocalComputationManager.getDefault(), parameters); | ||
} | ||
|
||
public CompletableFuture<DynamicSimulationResult> runAsync(Network network) { | ||
return runAsync(network, DynamicSimulationParameters.load()); | ||
} | ||
|
||
public DynamicSimulationResult run(Network network, String workingStateId, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
Objects.requireNonNull(workingStateId); | ||
Objects.requireNonNull(parameters); | ||
return provider.run(network, computationManager, workingStateId, parameters).join(); | ||
} | ||
|
||
public DynamicSimulationResult run(Network network, ComputationManager computationManager, | ||
DynamicSimulationParameters parameters) { | ||
return run(network, network.getVariantManager().getWorkingVariantId(), computationManager, parameters); | ||
} | ||
|
||
public DynamicSimulationResult run(Network network, DynamicSimulationParameters parameters) { | ||
return run(network, LocalComputationManager.getDefault(), parameters); | ||
} | ||
|
||
public DynamicSimulationResult run(Network network) { | ||
return run(network, DynamicSimulationParameters.load()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return provider.getName(); | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return provider.getVersion(); | ||
} | ||
} | ||
|
||
public static Runner find(String name) { | ||
return find(name, PROVIDERS_SUPPLIERS.get(), PlatformConfig.defaultConfig()); | ||
} | ||
|
||
public static Runner find() { | ||
return find(null); | ||
} | ||
|
||
public static Runner find(String name, List<DynamicSimulationProvider> providers, PlatformConfig platformConfig) { | ||
Objects.requireNonNull(providers); | ||
Objects.requireNonNull(platformConfig); | ||
|
||
if (providers.isEmpty()) { | ||
throw new PowsyblException("No dynamic simulation providers found"); | ||
} | ||
|
||
// if no dynamic simulation implementation name is provided through the API we | ||
// look for information in platform configuration | ||
String dynamicSimulatorName = name != null ? name | ||
: platformConfig.getOptionalModuleConfig("dynamic-simulation") | ||
.flatMap(mc -> mc.getOptionalStringProperty("default")) | ||
.orElse(null); | ||
DynamicSimulationProvider provider; | ||
if (providers.size() == 1 && dynamicSimulatorName == null) { | ||
// no information to select the implementation but only one provider, so we can | ||
// use it by default (that is be the most common use case) | ||
provider = providers.get(0); | ||
} else { | ||
if (providers.size() > 1 && dynamicSimulatorName == null) { | ||
// several providers and no information to select which one to choose, we can | ||
// only throw an exception | ||
List<String> dynamicSimulatorNames = providers.stream().map(DynamicSimulationProvider::getName) | ||
.collect(Collectors.toList()); | ||
throw new PowsyblException("Several dynamic simulation implementations found (" + dynamicSimulatorNames | ||
+ "), you must add configuration to select the implementation"); | ||
} | ||
provider = providers.stream() | ||
.filter(p -> p.getName().equals(dynamicSimulatorName)) | ||
.findFirst() | ||
.orElseThrow(() -> new PowsyblException("Dynamic simulation '" + dynamicSimulatorName + "' not found")); | ||
} | ||
|
||
return new Runner(provider); | ||
} | ||
|
||
public static CompletableFuture<DynamicSimulationResult> runAsync(Network network, String workingStateId, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
return find().runAsync(network, workingStateId, computationManager, parameters); | ||
} | ||
|
||
public static CompletableFuture<DynamicSimulationResult> runAsync(Network network, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
return find().runAsync(network, computationManager, parameters); | ||
} | ||
|
||
public static CompletableFuture<DynamicSimulationResult> runAsync(Network network, | ||
DynamicSimulationParameters parameters) { | ||
return find().runAsync(network, parameters); | ||
} | ||
|
||
public static CompletableFuture<DynamicSimulationResult> runAsync(Network network) { | ||
return find().runAsync(network); | ||
} | ||
|
||
public static DynamicSimulationResult run(Network network, String workingStateId, | ||
ComputationManager computationManager, DynamicSimulationParameters parameters) { | ||
return find().run(network, workingStateId, computationManager, parameters); | ||
} | ||
|
||
public static DynamicSimulationResult run(Network network, ComputationManager computationManager, | ||
DynamicSimulationParameters parameters) { | ||
return find().run(network, computationManager, parameters); | ||
} | ||
|
||
public static DynamicSimulationResult run(Network network, DynamicSimulationParameters parameters) { | ||
return find().run(network, parameters); | ||
} | ||
|
||
public static DynamicSimulationResult run(Network network) { | ||
return find().run(network); | ||
} | ||
} |
Oops, something went wrong.