-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an implementation of GlskProvider that uses GlskDocument as data …
…source (#113) Signed-off-by: Sébastien Murgey <sebastien.murgey@rte-france.com>
- Loading branch information
Showing
6 changed files
with
254 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
80 changes: 80 additions & 0 deletions
80
...main/java/com/powsybl/flow_decomposition/glsk_provider/GlskDocumentBasedGlskProvider.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,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) { | ||
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); | ||
} | ||
} |
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
75 changes: 75 additions & 0 deletions
75
.../java/com/powsybl/flow_decomposition/glsk_provider/GlskDocumentBasedGlskProviderTest.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,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); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...position/src/test/resources/com/powsybl/flow_decomposition/GlskUcteFrMultipleInstants.xml
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,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> |
31 changes: 31 additions & 0 deletions
31
...composition/src/test/resources/com/powsybl/flow_decomposition/GlskUcteFrUniqueInstant.xml
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,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> |