-
Notifications
You must be signed in to change notification settings - Fork 77
UCTE-DEF import/export: use IIDM Transformer ratedS #4093
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
Draft
armic-artelys
wants to merge
6
commits into
main
Choose a base branch
from
feature/4073-ucte-export-rateds
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3023ca6
UCTE export - Use the standard `ratedS` field when exporting nominal …
armic-artelys 3a4f26f
Doc - Update UCTE export documentation for nominal power exported fro…
armic-artelys cc0d1ca
Apply review suggestion to `export.md` - more precise info on use of …
armic-artelys 8df033d
Apply review suggestion to `import.md` - clearer explanation for tran…
armic-artelys 7494d80
Fixes after review
armic-artelys fcfc7d6
Fixes after review
armic-artelys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -10,6 +10,10 @@ | |
| import com.powsybl.commons.report.ReportNode; | ||
| import com.powsybl.commons.report.TypedValue; | ||
|
|
||
| import java.text.DecimalFormat; | ||
| import java.text.DecimalFormatSymbols; | ||
| import java.util.Locale; | ||
|
|
||
| /** | ||
| * Message-templated {@link ReportNode} entries reported by {@link com.powsybl.ucte.converter.UcteExporter}. | ||
| * | ||
|
|
@@ -70,4 +74,29 @@ public static void switchCurrentLimitMissing(ReportNode reportNode, String switc | |
| .withSeverity(TypedValue.WARN_SEVERITY) | ||
| .add(); | ||
| } | ||
|
|
||
| public static void nominalPowerMissing(ReportNode reportNode, String transformerId, double nominalPowerNovalue) { | ||
| reportNode.newReportNode() | ||
| .withMessageTemplate("core.ucte.export.nominalPowerMissing") | ||
| .withUntypedValue("transformerId", transformerId) | ||
| // nominal power is exported in a 5 chars column | ||
| .withUntypedValue("nominalPowerNovalue", formatAsExported(nominalPowerNovalue, 5)) | ||
|
jeandemanged marked this conversation as resolved.
Outdated
|
||
| .withSeverity(TypedValue.WARN_SEVERITY) | ||
| .add(); | ||
| } | ||
|
|
||
| /** | ||
| * Formats a double value the same way {@link com.powsybl.ucte.network.io.UcteWriter} exports it: as a decimal | ||
| * string truncated to {@code fieldLength} characters. | ||
| */ | ||
| private static String formatAsExported(double value, int fieldLength) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is dead code, remove. |
||
| DecimalFormat numberFormatter = new DecimalFormat(); | ||
| numberFormatter.setGroupingUsed(false); | ||
| numberFormatter.setDecimalFormatSymbols(DecimalFormatSymbols.getInstance(Locale.US)); | ||
| numberFormatter.setMinimumIntegerDigits(1); | ||
| numberFormatter.setMinimumFractionDigits(1); | ||
| numberFormatter.setMaximumFractionDigits(fieldLength); | ||
| String formatted = numberFormatter.format(value); | ||
| return formatted.length() > fieldLength ? formatted.substring(0, fieldLength) : formatted; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,10 +11,12 @@ | |
| import com.powsybl.commons.PowsyblException; | ||
| import com.powsybl.commons.datasource.MemDataSource; | ||
| import com.powsybl.commons.datasource.ReadOnlyDataSource; | ||
| import com.powsybl.commons.datasource.ReadOnlyMemDataSource; | ||
| import com.powsybl.commons.datasource.ResourceDataSource; | ||
| import com.powsybl.commons.datasource.ResourceSet; | ||
| import com.powsybl.commons.test.AbstractSerDeTest; | ||
| import com.powsybl.iidm.network.*; | ||
| import com.powsybl.ucte.converter.util.UcteConverterConstants; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checkstyle error |
||
| import com.powsybl.iidm.network.regulation.RegulationMode; | ||
| import org.apache.commons.io.FilenameUtils; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
@@ -49,6 +51,18 @@ private static Network loadNetworkFromResourceFile(String filePath, Properties p | |
| return new UcteImporter().importData(dataSource, NetworkFactory.findDefault(), parameters); | ||
| } | ||
|
|
||
| /** | ||
| * Re-imports a network exported to a {@link MemDataSource}. A plain {@link MemDataSource} always stores its | ||
| * content under an empty base name, which {@link UcteImporter} would otherwise turn into an invalid empty | ||
| * network id, so the exported bytes are copied into a named {@link ReadOnlyMemDataSource} first. | ||
| */ | ||
| private static Network reimport(MemDataSource dataSource) { | ||
| byte[] exported = dataSource.getData(null, "uct"); | ||
| ReadOnlyMemDataSource namedDataSource = new ReadOnlyMemDataSource("network"); | ||
| namedDataSource.putData("network.uct", exported); | ||
| return new UcteImporter().importData(namedDataSource, NetworkFactory.findDefault(), null); | ||
| } | ||
|
|
||
| private static void testExporter(Network network, String reference) throws IOException { | ||
| testExporter(network, reference, new Properties()); | ||
| } | ||
|
|
@@ -261,6 +275,48 @@ void testTapChangers() { | |
| exportedNetwork.getTwoWindingsTransformer(ptcId2).getPhaseTapChanger().getCurrentStep().getAlpha(), 0.0001); | ||
| } | ||
|
|
||
| @Test | ||
| void testNominalPowerExportedFromRatedS() { | ||
| Network network = loadNetworkFromResourceFile("/expectedExport.uct"); | ||
| TwoWindingsTransformer transformer = network.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1"); | ||
| transformer.setRatedS(1234.5); | ||
|
|
||
| MemDataSource dataSource = new MemDataSource(); | ||
| new UcteExporter().export(network, new Properties(), dataSource); | ||
| Network reimported = reimport(dataSource); | ||
|
|
||
| // Here, we accept a difference of 1 (the exporter can only export 5 characters, so exported value is '1234.') | ||
| assertEquals(1234.5, reimported.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1").getRatedS(), 1); | ||
| } | ||
|
|
||
| @Test | ||
| void testNominalPowerExportedFromLegacyPropertyWhenRatedSMissing() { | ||
| Network network = loadNetworkFromResourceFile("/expectedExport.uct"); | ||
| TwoWindingsTransformer transformer = network.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1"); | ||
| transformer.setRatedS(Double.NaN); | ||
| transformer.setProperty(UcteConverterConstants.NOMINAL_POWER_KEY, "1200.0"); | ||
|
|
||
| MemDataSource dataSource = new MemDataSource(); | ||
| new UcteExporter().export(network, new Properties(), dataSource); | ||
| Network reimported = reimport(dataSource); | ||
|
|
||
| assertEquals(1200.0, reimported.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1").getRatedS()); | ||
| } | ||
|
|
||
| @Test | ||
| void testNominalPowerDefaultedWhenNotProvided() { | ||
| Network network = loadNetworkFromResourceFile("/expectedExport.uct"); | ||
| TwoWindingsTransformer transformer = network.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1"); | ||
| transformer.setRatedS(Double.NaN); | ||
|
|
||
| MemDataSource dataSource = new MemDataSource(); | ||
| new UcteExporter().export(network, new Properties(), dataSource); | ||
| Network reimported = reimport(dataSource); | ||
|
|
||
| assertEquals(UcteExporter.NOMINAL_POWER_NOVALUE, | ||
| reimported.getTwoWindingsTransformer("F_SU1_11 F_SU1_21 1").getRatedS()); | ||
| } | ||
|
|
||
| @Test | ||
| void roundTripOfCombineRtcAndPtc() throws IOException { | ||
| Properties parameters = new Properties(); | ||
|
|
||
This file contains hidden or 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 hidden or 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,15 @@ | ||
| ##C 2007.05.01 | ||
| Generated by powsybl, 2019.09.23 17:47 | ||
| Case date: 2019.09.24 19:30 | ||
| ##N | ||
| ##ZBE | ||
| B_SU1_11 Belgium Nod1 0 0 400.00 50.0000 0.00000 0.00000 0.00000 | ||
| B_SU1_21 Belgium Nod2 0 3 225.00 0.00000 0.00000 100.000 0.00000 | ||
| ##ZFR | ||
| F_SU1_11 France Node1 0 0 400.00 50.0000 0.00000 0.00000 0.00000 | ||
| F_SU1_21 France Node2 0 0 225.00 0.00000 0.00000 0.00000 0.00000 | ||
| ##L | ||
| ##T | ||
| F_SU1_11 F_SU1_21 1 0 400.0 225.0 5000. 0.5500 1.6800 132.5000 200.00 5000 Test 2WT 1 | ||
| B_SU1_11 B_SU1_21 1 0 400.0 225.0 0.5500 1.6800 13.25000 0.0000 5000 Test 2WT 2 | ||
| ##R |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.