From b2f6bcc56fea8506c0e789301a37ae4d28af5bb8 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 9 Jan 2025 16:32:57 +0100 Subject: [PATCH 1/2] Throw exception if the slack node is not directly conected to a transformer. --- CHANGELOG.md | 1 + .../edu/ie3/simona/io/grid/GridProvider.scala | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 416c701666..a8f233e5f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Create `CITATION.cff` [#1035](https://github.com/ie3-institute/simona/issues/1035) - Introduce ThermalDemandWrapper [#1049](https://github.com/ie3-institute/simona/issues/1049) - Added Marius Staudt to list of reviewers [#1057](https://github.com/ie3-institute/simona/issues/1057) +- Throw exception if the slack node is not directly conected to a transformer. [#525](https://github.com/ie3-institute/simona/issues/525) ### Changed - Adapted to changed data source in PSDM [#435](https://github.com/ie3-institute/simona/issues/435) diff --git a/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala b/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala index 3dda241c4d..efde83abb0 100644 --- a/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala +++ b/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala @@ -7,6 +7,7 @@ package edu.ie3.simona.io.grid import com.typesafe.scalalogging.LazyLogging +import edu.ie3.datamodel.exceptions.{InvalidGridException, SourceException} import edu.ie3.datamodel.io.naming.FileNamingStrategy import edu.ie3.datamodel.io.source.csv.{ CsvJointGridContainerSource, @@ -51,6 +52,27 @@ object GridProvider extends LazyLogging { // checks the grid container and throws exception if there is an error ValidationUtils.check(jointGridContainer) + // check slack node location + val slackSubGrid = jointGridContainer.getSubGridTopologyGraph + .vertexSet() + .asScala + .filter(_.getRawGrid.getNodes.asScala.exists(_.isSlack)) + .maxByOption( + _.getPredominantVoltageLevel.getNominalVoltage.getValue + .doubleValue() + ) + .getOrElse( + throw new InvalidGridException( + "There is no slack node present in the grid." + ) + ) + + if (slackSubGrid.getRawGrid.getNodes.size() > 1) { + throw new SourceException( + "There are too many nodes the the slack grid. This is currently not support." + ) + } + jointGridContainer case None => throw new RuntimeException( From c6a5d24cacba0ff47de37b343d64e4508dbc009a Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Fri, 10 Jan 2025 10:46:48 +0100 Subject: [PATCH 2/2] Fix exception message. --- src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala b/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala index efde83abb0..0b11d732ca 100644 --- a/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala +++ b/src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala @@ -69,7 +69,7 @@ object GridProvider extends LazyLogging { if (slackSubGrid.getRawGrid.getNodes.size() > 1) { throw new SourceException( - "There are too many nodes the the slack grid. This is currently not support." + "There are too many nodes in the slack grid. This is currently not support." ) }