Skip to content

Commit

Permalink
Merge pull request #1123 from ie3-institute/ms/#1122-check-number-of-…
Browse files Browse the repository at this point in the history
…slack-nodes

Checking the number of slack nodes.
  • Loading branch information
danielfeismann authored Jan 28, 2025
2 parents 68dba92 + eeca079 commit e88e8f9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/main/scala/edu/ie3/simona/io/grid/GridProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit e88e8f9

Please sign in to comment.