diff --git a/CHANGELOG.md b/CHANGELOG.md index c2b3f59b8a..b44a798be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - 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) - Added support for topologies without transformers and slack grids with multiple nodes [#1099](https://github.com/ie3-institute/simona/issues/1099) +- Checking the number of slack nodes [#1122](https://github.com/ie3-institute/simona/issues/1122) ### 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 b4998c78a1..8777c1a3e9 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 import edu.ie3.datamodel.io.naming.FileNamingStrategy import edu.ie3.datamodel.io.source.csv.{ CsvJointGridContainerSource, @@ -50,6 +51,22 @@ object GridProvider extends LazyLogging { // checks the grid container and throws exception if there is an error ValidationUtils.check(jointGridContainer) + // check number of slack nodes + val numberOfSlack = + jointGridContainer.getRawGrid.getNodes.asScala.filter(_.isSlack) + + numberOfSlack.size match { + case 0 => + throw new InvalidGridException( + "The grid does not contain any slack node!" + ) + case n if n > 1 => + throw new InvalidGridException( + s"The grid has $n slack nodes. This is currently not supported!" + ) + case 1 => + } + jointGridContainer case None => throw new RuntimeException(