From d264397c9a370d04db5bf1e5f344ad8e97750ef8 Mon Sep 17 00:00:00 2001 From: Luma Date: Mon, 16 Dec 2024 17:46:30 +0100 Subject: [PATCH] control area net interchange tolerance is optional, no default value is used Signed-off-by: Luma --- .../elements/ControlAreaConversion.java | 5 ++--- .../export/SteadyStateHypothesisExport.java | 6 ++---- .../test/export/CgmesExportTest.java | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/ControlAreaConversion.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/ControlAreaConversion.java index db9518fe5ed..f61c4efc30c 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/ControlAreaConversion.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/elements/ControlAreaConversion.java @@ -36,11 +36,10 @@ public void convert() { .setName(p.getLocal("name")) .setInterchangeTarget(p.asDouble("netInterchange", Double.NaN)) .add(); - String pTolerance = "0"; if (p.containsKey(CgmesNames.P_TOLERANCE)) { - pTolerance = p.get(CgmesNames.P_TOLERANCE); + String pTolerance = p.get(CgmesNames.P_TOLERANCE); + area.setProperty(CgmesNames.P_TOLERANCE, pTolerance); } - area.setProperty(CgmesNames.P_TOLERANCE, pTolerance); if (p.containsKey(CgmesNames.ENERGY_IDENT_CODE_EIC)) { area.addAlias(p.get(CgmesNames.ENERGY_IDENT_CODE_EIC), CgmesNames.ENERGY_IDENT_CODE_EIC); } diff --git a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java index baa20aa21c2..200eaa22292 100644 --- a/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java +++ b/cgmes/cgmes-conversion/src/main/java/com/powsybl/cgmes/conversion/export/SteadyStateHypothesisExport.java @@ -866,11 +866,9 @@ private static void writeControlArea(Area controlArea, String cimNamespace, XMLS double pTolerance; if (controlArea.hasProperty("pTolerance")) { pTolerance = Double.parseDouble(controlArea.getProperty("pTolerance")); - } else { - pTolerance = Math.abs(0.01 * netInterchange); + writer.writeStartElement(cimNamespace, "ControlArea.pTolerance"); + writer.writeCharacters(CgmesExportUtil.format(pTolerance)); } - writer.writeStartElement(cimNamespace, "ControlArea.pTolerance"); - writer.writeCharacters(CgmesExportUtil.format(pTolerance)); writer.writeEndElement(); writer.writeEndElement(); } diff --git a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java index 023261f03a2..fe23770690c 100644 --- a/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java +++ b/cgmes/cgmes-conversion/src/test/java/com/powsybl/cgmes/conversion/test/export/CgmesExportTest.java @@ -692,12 +692,30 @@ void networkWithoutControlAreaInterchange() throws IOException { new CgmesExport().createDefaultControlAreaInterchange(network); // Check that exported files now have a control area definition + // No default value for tolerance Path tmpDirWithCA = tmpDir.resolve("network-with-ca"); Files.createDirectories(tmpDirWithCA); network.write("CGMES", null, tmpDirWithCA.resolve(baseName)); Network networkWithCA = Network.read(new GenericReadOnlyDataSource(tmpDirWithCA, baseName)); assertEquals(1, networkWithCA.getAreaCount()); - assertEquals(1, networkWithCA.getAreas().iterator().next().getAreaBoundaryStream().count()); + Area areaExported = networkWithCA.getAreas().iterator().next(); + assertEquals(1, areaExported.getAreaBoundaryStream().count()); + assertEquals(-50, areaExported.getInterchangeTarget().orElse(Double.NaN)); + // No default value for tolerance + assertNull(areaExported.getProperty(CgmesNames.P_TOLERANCE)); + + // Check that tolerance is exported only if explicitly defined + Area area = network.getAreas().iterator().next(); + area.setProperty(CgmesNames.P_TOLERANCE, "1.01"); + Path tmpDirWithCaTolerance = tmpDir.resolve("network-with-ca-tolerance"); + Files.createDirectories(tmpDirWithCaTolerance); + network.write("CGMES", null, tmpDirWithCaTolerance.resolve(baseName)); + Network networkWithCaTolerance = Network.read(new GenericReadOnlyDataSource(tmpDirWithCaTolerance, baseName)); + assertEquals(1, networkWithCaTolerance.getAreaCount()); + areaExported = networkWithCaTolerance.getAreas().iterator().next(); + assertEquals(1, areaExported.getAreaBoundaryStream().count()); + assertEquals(-50, areaExported.getInterchangeTarget().orElse(Double.NaN)); + assertEquals("1.01", areaExported.getProperty(CgmesNames.P_TOLERANCE)); } }