Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests #140

Merged
merged 13 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Build with Maven
if: matrix.os == 'ubuntu-latest'
run: mvn --batch-mode -Pjacoco install
run: mvn --batch-mode -Pintegration-tests,jacoco install

- name: Build with Maven
if: matrix.os != 'ubuntu-latest'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To use DynaWaltz as your time domain engine, add the `com.powsybl:powsybl-dynawo
In `powsybl-dynawo`, the inputs can be configured using Groovy scripts. The simulation parameters can be configured either in the `config.yml` file or using a Json file.

```java
Network network = Importers.loadNetwork("/path/to/the/casefile.xiidm");
Network network = Network.read("/path/to/the/casefile.xiidm");

// Load the dynamic models mapping
GroovyDynamicModelsSupplier dynamicModelsSupplier = new GroovyDynamicModelsSupplier(
Expand Down
12 changes: 5 additions & 7 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
<artifactId>powsybl-iidm-api</artifactId>
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
Expand All @@ -54,6 +47,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand Down
12 changes: 5 additions & 7 deletions dynaflow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@
<artifactId>powsybl-dynawo-commons</artifactId>
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
Expand All @@ -76,6 +69,11 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-commons-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public class DynaFlowSecurityAnalysis {
private final List<SecurityAnalysisInterceptor> interceptors;

public DynaFlowSecurityAnalysis(Network network, LimitViolationDetector detector,
LimitViolationFilter filter, ComputationManager computationManager) {
LimitViolationFilter filter, ComputationManager computationManager,
Supplier<DynaFlowConfig> configSupplier) {
this.network = Objects.requireNonNull(network);
this.violationDetector = Objects.requireNonNull(detector);
this.violationFilter = Objects.requireNonNull(filter);
this.interceptors = new ArrayList<>();
this.computationManager = Objects.requireNonNull(computationManager);

interceptors.add(new CurrentLimitViolationInterceptor());
// TODO(Luma) Allow additional sources for configuration?
this.configSupplier = DynaFlowConfig::fromPropertyFile;
this.configSupplier = Objects.requireNonNull(configSupplier);
}

private static DynaFlowParameters getParametersExt(LoadFlowParameters parameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

/**
* @author Marcos de Miguel <demiguelm at aia.es>
Expand All @@ -33,6 +35,16 @@ public class DynaFlowSecurityAnalysisProvider implements SecurityAnalysisProvide
private static final String PROVIDER_NAME = "DynawoSecurityAnalysis";
private static final String PROVIDER_VERSION = "1.0";

private final Supplier<DynaFlowConfig> configSupplier;

public DynaFlowSecurityAnalysisProvider() {
this(DynaFlowConfig::fromPropertyFile);
}

public DynaFlowSecurityAnalysisProvider(Supplier<DynaFlowConfig> configSupplier) {
this.configSupplier = Objects.requireNonNull(configSupplier);
}

@Override
public CompletableFuture<SecurityAnalysisReport> run(Network network,
String workingVariantId,
Expand All @@ -58,7 +70,7 @@ public CompletableFuture<SecurityAnalysisReport> run(Network network,
if (actions != null && !actions.isEmpty()) {
LOG.error("Actions are not implemented in Dynaflow");
}
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, detector, filter, computationManager);
DynaFlowSecurityAnalysis securityAnalysis = new DynaFlowSecurityAnalysis(network, detector, filter, computationManager, configSupplier);
interceptors.forEach(securityAnalysis::addInterceptor);
return securityAnalysis.run(workingVariantId, parameters, contingenciesProvider);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import com.google.common.jimfs.Configuration;
import com.google.common.jimfs.Jimfs;
import com.powsybl.commons.test.AbstractConverterTest;
import com.powsybl.commons.config.InMemoryPlatformConfig;
import com.powsybl.commons.config.MapModuleConfig;
import com.powsybl.dynaflow.json.DynaFlowConfigSerializer;
import com.powsybl.dynaflow.DynaFlowConstants.OutputTypes;
import com.powsybl.commons.test.AbstractConverterTest;
import com.powsybl.dynaflow.DynaFlowConstants.ActivePowerCompensation;
import com.powsybl.dynaflow.DynaFlowConstants.OutputTypes;
import com.powsybl.dynaflow.DynaFlowConstants.StartingPointMode;
import com.powsybl.dynaflow.json.DynaFlowConfigSerializer;
import com.powsybl.loadflow.LoadFlowParameters;
import org.junit.After;
import org.junit.Before;
Expand All @@ -24,20 +24,11 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static com.powsybl.commons.test.ComparisonUtils.compareTxt;
import static com.powsybl.dynaflow.DynaFlowProvider.MODULE_SPECIFIC_PARAMETERS;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

/**
*
Expand Down
5 changes: 5 additions & 0 deletions dynawaltz-dsl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand Down
12 changes: 5 additions & 7 deletions dynawaltz/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@
<artifactId>powsybl-dynawo-commons</artifactId>
</dependency>

<!-- Runtime dependencies -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>com.google.jimfs</groupId>
Expand All @@ -89,6 +82,11 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,25 @@ public class DynaWaltzContext {
private final NetworkModel networkModel = new NetworkModel();

private final OmegaRef omegaRef;
private final PlatformConfig platformConfig;

public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxModel> dynamicModels, List<BlackBoxModel> eventModels,
List<Curve> curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters) {
this(network, workingVariantId, dynamicModels, eventModels, curves, parameters, dynaWaltzParameters, PlatformConfig.defaultConfig());
}

public DynaWaltzContext(Network network, String workingVariantId, List<BlackBoxModel> dynamicModels, List<BlackBoxModel> eventModels,
List<Curve> curves, DynamicSimulationParameters parameters, DynaWaltzParameters dynaWaltzParameters,
PlatformConfig platformConfig) {
this.network = Objects.requireNonNull(network);
this.workingVariantId = Objects.requireNonNull(workingVariantId);
this.dynamicModels = Objects.requireNonNull(dynamicModels);
this.eventModels = Objects.requireNonNull(eventModels);
this.curves = Objects.requireNonNull(curves);
this.parameters = Objects.requireNonNull(parameters);
this.dynaWaltzParameters = Objects.requireNonNull(dynaWaltzParameters);
this.parametersDatabase = loadDatabase(dynaWaltzParameters.getParametersFile());

this.platformConfig = Objects.requireNonNull(platformConfig);
this.parametersDatabase = loadDatabase(dynaWaltzParameters.getParametersFile(), platformConfig);
List<GeneratorSynchronousModel> synchronousGenerators = dynamicModels.stream()
.filter(GeneratorSynchronousModel.class::isInstance)
.map(GeneratorSynchronousModel.class::cast)
Expand Down Expand Up @@ -185,10 +192,14 @@ public boolean withCurves() {
return !curves.isEmpty();
}

private static DynaWaltzParametersDatabase loadDatabase(String filename) {
FileSystem fs = PlatformConfig.defaultConfig().getConfigDir()
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));
}

Expand All @@ -203,4 +214,8 @@ public String getParFile() {
public String getSimulationParFile() {
return getNetwork().getId() + ".par";
}

public PlatformConfig getPlatformConfig() {
return platformConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ public String getParametersFile() {
return parametersFile;
}

public void setParametersFile(String parametersFile) {
public Network setParametersFile(String parametersFile) {
this.parametersFile = Objects.requireNonNull(parametersFile);
return this;
}

public String getParametersId() {
return parametersId;
}

public void setParametersId(String parametersId) {
public Network setParametersId(String parametersId) {
this.parametersId = Objects.requireNonNull(parametersId);
return this;
}

private String parametersFile;
Expand All @@ -76,24 +78,27 @@ public SolverType getType() {
return type;
}

public void setType(SolverType type) {
public Solver setType(SolverType type) {
this.type = Objects.requireNonNull(type);
return this;
}

public String getParametersFile() {
return parametersFile;
}

public void setParametersFile(String parametersFile) {
public Solver setParametersFile(String parametersFile) {
this.parametersFile = Objects.requireNonNull(parametersFile);
return this;
}

public String getParametersId() {
return parametersId;
}

public void setParametersId(String parametersId) {
public Solver setParametersId(String parametersId) {
this.parametersId = Objects.requireNonNull(parametersId);
return this;
}

private SolverType type;
Expand Down Expand Up @@ -156,24 +161,27 @@ public String getParametersFile() {
return parametersFile;
}

public void setParametersFile(String parametersFile) {
public DynaWaltzParameters setParametersFile(String parametersFile) {
this.parametersFile = Objects.requireNonNull(parametersFile);
return this;
}

public Network getNetwork() {
return network;
}

public void setNetwork(Network network) {
public DynaWaltzParameters setNetwork(Network network) {
this.network = Objects.requireNonNull(network);
return this;
}

public Solver getSolver() {
return solver;
}

public void setSolver(Solver solver) {
public DynaWaltzParameters setSolver(Solver solver) {
this.solver = Objects.requireNonNull(solver);
return this;
}

private String parametersFile;
Expand Down
Loading