Skip to content

Commit

Permalink
Fixed lineType mismatch issue. Each lineType can now be mapped to mor…
Browse files Browse the repository at this point in the history
…e than one rated voltage.
  • Loading branch information
Utkarsha-dev05 committed Dec 6, 2021
1 parent 2a33252 commit bdc3824
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 66 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.0] - 2021-08-03
### Added
- Basic functionality to convert SimBench data sets to [PowerSystemDataModel](https://github.com/ie3-institute/powersystemdatamodel)

### Changed
- Line type can be mapped to more than one vRated voltage.

[Unreleased]: https://github.com/ie3-institute/simbench2psdm/compare/v1.0...HEAD
[1.0.0]: https://github.com/ie3-institute/simbench2psdm/releases/tag/1.0
2 changes: 1 addition & 1 deletion inputData/config/EHV.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ io {
simbenchCodes = [
"1-EHVHV-mixed-all-0-no_sw"
]
}
}
12 changes: 7 additions & 5 deletions src/main/scala/edu/ie3/simbench/convert/LineConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import edu.ie3.datamodel.utils.GridAndGeoUtils
import edu.ie3.simbench.exception.ConversionException
import edu.ie3.simbench.model.datamodel.types.LineType
import edu.ie3.simbench.model.datamodel.{Line, Node}
import edu.ie3.util.quantities.PowerSystemUnits.KILOMETRE
import edu.ie3.util.quantities.PowerSystemUnits.{KILOMETRE,KILOVOLT}
import javax.measure.quantity.ElectricPotential
import tech.units.indriya.ComparableQuantity
import tech.units.indriya.quantity.Quantities

case object LineConverter extends LazyLogging {
Expand All @@ -26,16 +28,16 @@ case object LineConverter extends LazyLogging {
* @return A [[Vector]] of [[LineInput]]s
*/
def convert(
inputs: Vector[Line[_ <: LineType]],
types: Map[LineType, LineTypeInput],
nodes: Map[Node, NodeInput]
inputs: Vector[Line[_ <: LineType]],
types: Map[(LineType,ComparableQuantity[ElectricPotential]), LineTypeInput],
nodes: Map[Node, NodeInput]
): Vector[LineInput] =
inputs.flatMap {
case acLine: Line.ACLine =>
val (nodeA, nodeB) =
NodeConverter.getNodes(acLine.nodeA, acLine.nodeB, nodes)
val lineType = types.getOrElse(
acLine.lineType,
(acLine.lineType,Quantities.getQuantity(acLine.nodeA.vmR,KILOVOLT)),
throw ConversionException(
s"Cannot find conversion result for line type ${acLine.lineType.id}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,15 @@ case object LineTypeConverter extends LazyLogging {
* @return A [[Vector]] of [[LineTypeInput]]s
*/
def convert(
lines: Vector[Line[_ <: LineType]]
): Map[LineType, LineTypeInput] = {
val ratedVoltageMapping = getRatedVoltages(lines)
val lineTypes = lines.map(line => line.lineType).distinct

lineTypes
.map(
lineType =>
lineType -> convert(
lineType,
ratedVoltageMapping.getOrElse(
lineType,
throw SimbenchDataModelException(
s"Cannot find the rated voltage vor line type ${lineType}"
)
)
)
)
.toMap
lines: Vector[Line[_ <: LineType]]
): Map[(LineType, ComparableQuantity[ElectricPotential]), LineTypeInput] = {
assignRatedVoltages(lines).map {
case pair @ (lineType, vRated) =>
pair -> convert(
lineType,
vRated
)
}.toMap
}

/**
Expand Down Expand Up @@ -91,42 +81,10 @@ case object LineTypeConverter extends LazyLogging {
* @param lines [[Vector]] of [[Line]]s
* @return Mapping of [[LineType]] to [[ComparableQuantity]] of type [[ElectricPotential]]
*/
def getRatedVoltages(
lines: Vector[Line[_ <: LineType]]
): Map[LineType, ComparableQuantity[ElectricPotential]] = {
val rawMapping = lines
.distinctBy(line => line.lineType)
.map(line => determineRatedVoltage(line))
.groupMap(_._1)(_._2)

/* Sanity check, that there is no ambiguous mapping */
rawMapping.find {
case (_, ratedVoltages) if ratedVoltages.length > 1 =>
true
case _ =>
false
} match {
case Some(ambiguousEntry) =>
throw SimbenchDataModelException(
s"Found ambiguous rated voltages for at least one entry: $ambiguousEntry"
)
case None =>
logger.debug(
"Great! Found only unambiguous line type to rated voltage mappings."
)
}

/* Mapping the line type to the rated voltage of the first entry of the Vector of each raw mapping. That nothing
* is missed is ensured by the sanity check beforehand */
rawMapping.map {
case (lineType, lineTypeVRatedVector) =>
lineType -> lineTypeVRatedVector.headOption.getOrElse(
throw SimbenchDataModelException(
s"Cannot receive rated voltage for line type '$lineType'."
)
)
}
}
def assignRatedVoltages(
lines: Vector[Line[_ <: LineType]]
): Vector[(LineType, ComparableQuantity[ElectricPotential])] =
lines.map(line => determineRatedVoltage(line)).distinct

/**
* Maps the [[LineType]] of the specific line to it's rated voltage based on the line's nodes' rated voltages
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simbench/io/SimbenchReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ final case class SimbenchReader(
read(clazz, fields)
}
),
Duration("10 s")
Duration("100 s")
)
.toMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class LineTypeConverterSpec extends UnitSpec with ConverterTestData {
}

"build line type to rated voltage mapping correctly" in {
val actual = LineTypeConverter.getRatedVoltages(lineVec)
val actual = LineTypeConverter.assignRatedVoltages(lineVec)
val expected = Map(
getACLineTypes("NAYY 4x150SE 0.6/1kV")._1 -> Quantities
.getQuantity(0.4, KILOVOLT),
Expand Down

0 comments on commit bdc3824

Please sign in to comment.