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

Add an implementation of GlskProvider that uses GlskDocument as data source #113

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions flow-decomposition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<groupId>com.powsybl</groupId>
<artifactId>powsybl-loadflow-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-glsk-document-api</artifactId>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-sensitivity-analysis-api</artifactId>
Expand All @@ -40,6 +44,16 @@
<artifactId>commons-csv</artifactId>
<version>${commonscsv.version}</version>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-glsk-document-io-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-glsk-document-ucte</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-iidm-impl</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.flow_decomposition.glsk_provider;

import com.powsybl.flow_decomposition.GlskProvider;
import com.powsybl.glsk.api.GlskDocument;
import com.powsybl.glsk.commons.CountryEICode;
import com.powsybl.glsk.commons.ZonalData;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import com.powsybl.sensitivity.SensitivityVariableSet;

import java.time.Instant;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
*/
public final class GlskDocumentBasedGlskProvider implements GlskProvider {
private final GlskDocument glskDocument;
private final Instant instant;
private final boolean timeSpecific;

private GlskDocumentBasedGlskProvider(GlskDocument glskDocument, Instant instant, boolean timeSpecific) {
this.glskDocument = glskDocument;
this.instant = instant;
this.timeSpecific = timeSpecific;
}

@Override
public Map<Country, Map<String, Double>> getGlsk(Network network) {
Map<Country, Map<String, Double>> perCountryGlsk = getDefaultGlsk(network);
updateWithGlskFromDocument(network, perCountryGlsk);
return perCountryGlsk;
}

private void updateWithGlskFromDocument(Network network, Map<Country, Map<String, Double>> perCountryGlsk) {
getSensitivityVariableSetZonalData(network).getDataPerZone().forEach((countryEicCode, glskData) -> perCountryGlsk.put(new CountryEICode(countryEicCode).getCountry(),
glskData.getVariablesById().entrySet().stream().collect(Collectors.toMap(
nodeFactorEntry -> nodeFactorEntry.getKey(),
nodeFactorEntry -> nodeFactorEntry.getValue().getWeight()
))));
}

private ZonalData<SensitivityVariableSet> getSensitivityVariableSetZonalData(Network network) {
if (timeSpecific) {
Instant glskInstant = Optional.ofNullable(instant).orElse(getNetworkInstant(network));
return glskDocument.getZonalGlsks(network, glskInstant);
} else {
return glskDocument.getZonalGlsks(network);
}
}

private Instant getNetworkInstant(Network network) {
return Instant.ofEpochMilli(network.getCaseDate().getMillis());
}

private Map<Country, Map<String, Double>> getDefaultGlsk(Network network) {
return new AutoGlskProvider().getGlsk(network);
}

public static GlskProvider notTimeSpecific(GlskDocument glskDocument) {
OpenSuze marked this conversation as resolved.
Show resolved Hide resolved
return new GlskDocumentBasedGlskProvider(glskDocument, null, false);
}

public static GlskProvider basedOnNetworkInstant(GlskDocument glskDocument) {
return new GlskDocumentBasedGlskProvider(glskDocument, null, true);
}

public static GlskProvider basedOnGivenInstant(GlskDocument glskDocument, Instant instant) {
return new GlskDocumentBasedGlskProvider(glskDocument, instant, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.flow_decomposition;

import com.powsybl.glsk.api.GlskDocument;
import com.powsybl.glsk.api.io.GlskDocumentImporters;
import com.powsybl.iidm.network.Bus;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.Terminal;
Expand All @@ -30,6 +32,11 @@ public static Network importNetwork(String networkResourcePath) {
return Network.read(networkName, TestUtils.class.getResourceAsStream(networkResourcePath));
}

public static GlskDocument importGlskDocument(String glskFileName) {
String glskName = Paths.get(glskFileName).getFileName().toString();
return GlskDocumentImporters.importGlsk(TestUtils.class.getResourceAsStream(glskName));
}

public static void assertCoherenceTotalFlow(boolean enableRescaledResults, FlowDecompositionResults flowDecompositionResults) {
for (String xnec : flowDecompositionResults.getDecomposedFlowMap().keySet()) {
DecomposedFlow decomposedFlow = flowDecompositionResults.getDecomposedFlowMap().get(xnec);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.flow_decomposition.glsk_provider;

import com.powsybl.flow_decomposition.GlskProvider;
import com.powsybl.glsk.api.GlskDocument;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.Map;

import static com.powsybl.flow_decomposition.TestUtils.importGlskDocument;
import static com.powsybl.flow_decomposition.TestUtils.importNetwork;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
*/
class GlskDocumentBasedGlskProviderTest {
private static final double EPSILON = 1e-3;

@Test
void testThatGlskProviderWithFirstInstantGetsCorrectFactors() {
String networkFileName = "testCase.xiidm";
String glskFileName = "GlskUcteFrUniqueInstant.xml";
Network network = importNetwork(networkFileName);
GlskDocument glskDocument = importGlskDocument(glskFileName);
GlskProvider glskProvider = GlskDocumentBasedGlskProvider.notTimeSpecific(glskDocument);
Map<Country, Map<String, Double>> glsks = glskProvider.getGlsk(network);
assertEquals(0.5, glsks.get(Country.FR).get("FFR1AA1 _generator"), EPSILON);
assertEquals(0.5, glsks.get(Country.FR).get("FFR2AA1 _generator"), EPSILON);
}

@Test
void testThatGlskProviderWithNetworkInstantGetsCorrectFactors() {
String networkFileName = "testCase.xiidm";
String glskFileName = "GlskUcteFrMultipleInstants.xml";
Network network = importNetwork(networkFileName);
GlskDocument glskDocument = importGlskDocument(glskFileName);
GlskProvider glskProvider = GlskDocumentBasedGlskProvider.basedOnNetworkInstant(glskDocument);
Map<Country, Map<String, Double>> glsks = glskProvider.getGlsk(network);
assertEquals(1, glsks.get(Country.FR).get("FFR1AA1 _generator"), EPSILON);
}

@Test
void testThatGlskProviderWithGivenInstantGetsCorrectFactors() {
String networkFileName = "testCase.xiidm";
String glskFileName = "GlskUcteFrMultipleInstants.xml";
Network network = importNetwork(networkFileName);
GlskDocument glskDocument = importGlskDocument(glskFileName);
GlskProvider glskProvider = GlskDocumentBasedGlskProvider.basedOnGivenInstant(glskDocument, Instant.parse("2014-01-16T21:00:00Z"));
Map<Country, Map<String, Double>> glsks = glskProvider.getGlsk(network);
assertEquals(1, glsks.get(Country.FR).get("FFR2AA1 _generator"), EPSILON);
}

@Test
void testThatCountriesNotIncludedInGlskDocumentHaveAutoGlskFactorsCalculated() {
String networkFileName = "testCase.xiidm";
String glskFileName = "GlskUcteFrMultipleInstants.xml";
Network network = importNetwork(networkFileName);
GlskDocument glskDocument = importGlskDocument(glskFileName);
GlskProvider glskProvider = GlskDocumentBasedGlskProvider.basedOnNetworkInstant(glskDocument);
Map<Country, Map<String, Double>> glsks = glskProvider.getGlsk(network);
assertEquals(0.214, glsks.get(Country.BE).get("BBE1AA1 _generator"), EPSILON);
assertEquals(0.429, glsks.get(Country.BE).get("BBE2AA1 _generator"), EPSILON);
assertEquals(0.357, glsks.get(Country.BE).get("BBE3AA1 _generator"), EPSILON);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<GSKDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" DtdVersion="1" DtdRelease="0" xsi:noNamespaceSchemaLocation="gsk-document.xsd">
<DocumentIdentification v="17XTSO-CS------W-20160729-F112"/>
<DocumentVersion v="1"/>
<DocumentType v="Z02"/>
<ProcessType v="Z02"/>
<SenderIdentification v="17XTSO-CS------W" codingScheme="A01"/>
<SenderRole v="A36"/>
<ReceiverIdentification v="10XFR-RTE------Q" codingScheme="A01"/>
<ReceiverRole v="A04"/>
<CreationDateTime v="2017-10-30T09:27:21Z"/>
<GSKTimeInterval v="2014-01-15T23:00Z/2014-01-16T23:00Z"/>
<Domain v="10YDOM-REGION-1V" codingScheme="A01"/>
<GSKSeries>
<TimeSeriesIdentification v="1"/>
<BusinessType v="Z02" share="100"/>
<Area v="10YFR-RTE------C" codingScheme="A01"/>
<ManualGSK_Block>
<GSK_Name v="FR"/>
<TimeInterval v="2014-01-15T23:00Z/2014-01-16T04:00Z"/>
<ManualNodes>
<NodeName v="FFR1AA1 "/>
<Factor v="0.5"/>
</ManualNodes>
<ManualNodes>
<NodeName v="FFR2AA1 "/>
<Factor v="0.5"/>
</ManualNodes>
</ManualGSK_Block>
<ManualGSK_Block>
<GSK_Name v="FR"/>
<TimeInterval v="2014-01-16T04:00Z/2014-01-16T16:00Z"/>
<ManualNodes>
<NodeName v="FFR1AA1 "/>
<Factor v="1"/>
</ManualNodes>
</ManualGSK_Block>
<ManualGSK_Block>
<GSK_Name v="FR"/>
<TimeInterval v="2014-01-16T16:00Z/2014-01-16T23:00Z"/>
<ManualNodes>
<NodeName v="FFR2AA1 "/>
<Factor v="1"/>
</ManualNodes>
</ManualGSK_Block>
</GSKSeries>
</GSKDocument>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<GSKDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" DtdVersion="1" DtdRelease="0" xsi:noNamespaceSchemaLocation="gsk-document.xsd">
<DocumentIdentification v="17XTSO-CS------W-20160729-F112"/>
<DocumentVersion v="1"/>
<DocumentType v="Z02"/>
<ProcessType v="Z02"/>
<SenderIdentification v="17XTSO-CS------W" codingScheme="A01"/>
<SenderRole v="A36"/>
<ReceiverIdentification v="10XFR-RTE------Q" codingScheme="A01"/>
<ReceiverRole v="A04"/>
<CreationDateTime v="2017-10-30T09:27:21Z"/>
<GSKTimeInterval v="2014-01-15T23:00Z/2014-01-16T23:00Z"/>
<Domain v="10YDOM-REGION-1V" codingScheme="A01"/>
<GSKSeries>
<TimeSeriesIdentification v="1"/>
<BusinessType v="Z02" share="100"/>
<Area v="10YFR-RTE------C" codingScheme="A01"/>
<ManualGSK_Block>
<GSK_Name v="FR"/>
<TimeInterval v="2014-01-15T23:00Z/2014-01-16T04:00Z"/>
<ManualNodes>
<NodeName v="FFR1AA1 "/>
<Factor v="0.5"/>
</ManualNodes>
<ManualNodes>
<NodeName v="FFR2AA1 "/>
<Factor v="0.5"/>
</ManualNodes>
</ManualGSK_Block>
</GSKSeries>
</GSKDocument>