Skip to content

Commit

Permalink
Merge pull request #259 from ie3-institute/ms/#67-reduce-memory-usage
Browse files Browse the repository at this point in the history
Reduce memory usage.
  • Loading branch information
danielfeismann authored Jan 7, 2025
2 parents 60ce749 + bfedaf0 commit fc33fbf
Show file tree
Hide file tree
Showing 12 changed files with 265 additions and 139 deletions.
8 changes: 4 additions & 4 deletions src/main/scala/edu/ie3/simbench/convert/GridConverter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ case object GridConverter extends LazyLogging {
removeSwitches: Boolean
): (
JointGridContainer,
Vector[IndividualTimeSeries[_ <: PValue]],
Set[IndividualTimeSeries[_ <: PValue]],
Seq[MappingEntry],
Vector[NodeResult]
) = {
Expand Down Expand Up @@ -610,7 +610,7 @@ case object GridConverter extends LazyLogging {
nodeConversion: Map[Node, NodeInput]
): (
SystemParticipants,
Vector[IndividualTimeSeries[_ <: PValue]],
Set[IndividualTimeSeries[_ <: PValue]],
Seq[MappingEntry]
) = {
/* Convert all participant groups */
Expand Down Expand Up @@ -640,8 +640,8 @@ case object GridConverter extends LazyLogging {
timeSeries.getUuid
)
}.toSeq
val timeSeries: Vector[IndividualTimeSeries[_ >: SValue <: PValue]] =
participantsToTimeSeries.map(_._2).toVector
val timeSeries: Set[IndividualTimeSeries[_ <: PValue]] =
participantsToTimeSeries.map(_._2).toSet

(
new SystemParticipants(
Expand Down
48 changes: 26 additions & 22 deletions src/main/scala/edu/ie3/simbench/convert/LoadConverter.scala
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
package edu.ie3.simbench.convert

import java.util.{Locale, UUID}
import com.typesafe.scalalogging.LazyLogging
import edu.ie3.datamodel.models.OperationTime
import edu.ie3.datamodel.models.input.system.LoadInput
import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed
import edu.ie3.datamodel.models.input.{EmInput, NodeInput, OperatorInput}
import edu.ie3.datamodel.models.input.{NodeInput, OperatorInput}
import edu.ie3.datamodel.models.profile.LoadProfile.DefaultLoadProfiles
import edu.ie3.datamodel.models.timeseries.individual.IndividualTimeSeries
import edu.ie3.datamodel.models.value.SValue
import edu.ie3.simbench.convert.profiles.PowerProfileConverter
import edu.ie3.simbench.model.datamodel.profiles.{LoadProfile, LoadProfileType}
import edu.ie3.simbench.model.datamodel.{Load, Node}
import edu.ie3.util.quantities.PowerSystemUnits.{
KILOWATTHOUR,
MEGAVAR,
MEGAVOLTAMPERE,
MEGAWATT
}
import edu.ie3.util.quantities.PowerSystemUnits.{KILOWATTHOUR, MEGAVOLTAMPERE}
import tech.units.indriya.quantity.Quantities

import java.util.{Locale, UUID}
import scala.collection.parallel.CollectionConverters._

case object LoadConverter extends ShuntConverter {
case object LoadConverter extends ShuntConverter with LazyLogging {
def convert(
loads: Vector[Load],
nodes: Map[Node, NodeInput],
profiles: Map[LoadProfileType, LoadProfile]
): Map[LoadInput, IndividualTimeSeries[SValue]] =
): Map[LoadInput, IndividualTimeSeries[SValue]] = {

val modelScalings = loads
.map { input =>
input.profile -> (input.pLoad, input.qLoad)
}
.groupBy(_._1)
.map { entry => entry._1 -> entry._2.map(_._2).toSet }

val convertedTimeSeries = PowerProfileConverter.convertS(
modelScalings,
profiles
)

logger.debug("Resulting load time series: {]", convertedTimeSeries.size)

loads.par
.map { load =>
val node = NodeConverter.getNode(load.node, nodes)
val profile = PowerProfileConverter.getProfile(load.profile, profiles)
convert(load, node, profile)
val series = convertedTimeSeries((load.profile, load.pLoad, load.qLoad))
convert(load, node) -> series
}
.seq
.toMap
}

/** Converts a single SimBench [[Load]] to ie3's [[LoadInput]]. Currently not
* sufficiently covered:
Expand All @@ -45,8 +57,6 @@ case object LoadConverter extends ShuntConverter {
* Input model
* @param node
* Node, the load is connected to
* @param profile
* SimBench load profile
* @param uuid
* UUID to use for the model generation (default: Random UUID)
* @return
Expand All @@ -55,20 +65,15 @@ case object LoadConverter extends ShuntConverter {
def convert(
input: Load,
node: NodeInput,
profile: LoadProfile,
uuid: UUID = UUID.randomUUID()
): (LoadInput, IndividualTimeSeries[SValue]) = {
): LoadInput = {
val id = input.id
val cosphi = cosPhi(input.pLoad, input.qLoad)
val varCharacteristicString =
"cosPhiFixed:{(0.0,%#.2f)}".formatLocal(Locale.ENGLISH, cosphi)
val eCons = Quantities.getQuantity(0d, KILOWATTHOUR)
val sRated = Quantities.getQuantity(input.sR, MEGAVOLTAMPERE)

val p = Quantities.getQuantity(input.pLoad, MEGAWATT)
val q = Quantities.getQuantity(input.qLoad, MEGAVAR)
val timeSeries = PowerProfileConverter.convert(profile, p, q)

new LoadInput(
uuid,
id,
Expand All @@ -82,7 +87,6 @@ case object LoadConverter extends ShuntConverter {
eCons,
sRated,
cosphi
) ->
timeSeries
)
}
}
41 changes: 27 additions & 14 deletions src/main/scala/edu/ie3/simbench/convert/PowerPlantConverter.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package edu.ie3.simbench.convert

import java.util.{Locale, UUID}
import com.typesafe.scalalogging.LazyLogging

import java.util.{Locale, UUID}
import edu.ie3.datamodel.models.OperationTime
import edu.ie3.datamodel.models.input.system.FixedFeedInInput
import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed
Expand All @@ -23,7 +24,7 @@ import tech.units.indriya.quantity.Quantities

import scala.collection.parallel.CollectionConverters._

case object PowerPlantConverter extends ShuntConverter {
case object PowerPlantConverter extends ShuntConverter with LazyLogging {

/** Convert a full set of power plants
*
Expand All @@ -41,16 +42,34 @@ case object PowerPlantConverter extends ShuntConverter {
powerPlants: Vector[PowerPlant],
nodes: Map[Node, NodeInput],
profiles: Map[PowerPlantProfileType, PowerPlantProfile]
): Map[FixedFeedInInput, IndividualTimeSeries[PValue]] =
): Map[FixedFeedInInput, IndividualTimeSeries[PValue]] = {

val modelScalings = powerPlants
.map { input =>
input.profile -> input.p
}
.groupBy(_._1)
.map { entry => entry._1 -> entry._2.map(_._2).toSet }

val convertedTimeSeries = PowerProfileConverter.convertP(
modelScalings,
profiles
)

logger.debug(
"Resulting power plant time series: {]",
convertedTimeSeries.size
)

powerPlants.par
.map { powerPlant =>
val node = NodeConverter.getNode(powerPlant.node, nodes)
val profile =
PowerProfileConverter.getProfile(powerPlant.profile, profiles)
convert(powerPlant, node, profile)
val series = convertedTimeSeries((powerPlant.profile, powerPlant.p))
convert(powerPlant, node) -> series
}
.seq
.toMap
}

/** Converts a single power plant model to a fixed feed in model, as the power
* system data model does not reflect power plants, yet. Voltage regulation
Expand All @@ -60,8 +79,6 @@ case object PowerPlantConverter extends ShuntConverter {
* Input model
* @param node
* Node, the power plant is connected to
* @param profile
* SimBench power plant profile
* @param uuid
* Option to a specific uuid
* @return
Expand All @@ -70,9 +87,8 @@ case object PowerPlantConverter extends ShuntConverter {
def convert(
input: PowerPlant,
node: NodeInput,
profile: PowerPlantProfile,
uuid: Option[UUID] = None
): (FixedFeedInInput, IndividualTimeSeries[PValue]) = {
): FixedFeedInInput = {
val p = Quantities.getQuantity(input.p, MEGAWATT)
val q = input.q match {
case Some(value) => Quantities.getQuantity(value, MEGAVAR)
Expand All @@ -83,9 +99,6 @@ case object PowerPlantConverter extends ShuntConverter {
"cosPhiFixed:{(0.0,%#.2f)}".formatLocal(Locale.ENGLISH, cosphi)
val sRated = Quantities.getQuantity(input.sR, MEGAVOLTAMPERE)

/* Flip the sign, as infeed is negative in PowerSystemDataModel */
val timeSeries = PowerProfileConverter.convert(profile, p.multiply(-1))

new FixedFeedInInput(
uuid.getOrElse(UUID.randomUUID()),
input.id,
Expand All @@ -96,6 +109,6 @@ case object PowerPlantConverter extends ShuntConverter {
null,
sRated,
cosphi
) -> timeSeries
)
}
}
39 changes: 24 additions & 15 deletions src/main/scala/edu/ie3/simbench/convert/ResConverter.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package edu.ie3.simbench.convert

import java.util.{Locale, UUID}

import com.typesafe.scalalogging.LazyLogging
import edu.ie3.datamodel.models.OperationTime
import edu.ie3.datamodel.models.input.system.FixedFeedInInput
import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed
Expand All @@ -18,9 +17,10 @@ import edu.ie3.util.quantities.PowerSystemUnits.{
}
import tech.units.indriya.quantity.Quantities

import java.util.{Locale, UUID}
import scala.collection.parallel.CollectionConverters._

case object ResConverter extends ShuntConverter {
case object ResConverter extends ShuntConverter with LazyLogging {

/** Convert a full set of renewable energy source system
*
Expand All @@ -38,16 +38,31 @@ case object ResConverter extends ShuntConverter {
res: Vector[RES],
nodes: Map[Node, NodeInput],
profiles: Map[ResProfileType, ResProfile]
): Map[FixedFeedInInput, IndividualTimeSeries[PValue]] =
): Map[FixedFeedInInput, IndividualTimeSeries[PValue]] = {

val modelScalings = res
.map { input =>
input.profile -> input.p
}
.groupBy(_._1)
.map { entry => entry._1 -> entry._2.map(_._2).toSet }

val convertedTimeSeries = PowerProfileConverter.convertP(
modelScalings,
profiles
)

logger.debug("Resulting RES time series: {]", convertedTimeSeries.size)

res.par
.map { plant =>
val node = NodeConverter.getNode(plant.node, nodes)
val profile =
PowerProfileConverter.getProfile(plant.profile, profiles)
convert(plant, node, profile)
val series = convertedTimeSeries((plant.profile, plant.p))
convert(plant, node) -> series
}
.seq
.toMap
}

/** Converts a single renewable energy source system to a fixed feed in model
* due to lacking information to sophistically guess typical types of assets.
Expand All @@ -57,8 +72,6 @@ case object ResConverter extends ShuntConverter {
* Input model
* @param node
* Node, the renewable energy source system is connected to
* @param profile
* SimBench renewable energy source system profile
* @param uuid
* Option to a specific uuid
* @return
Expand All @@ -67,19 +80,15 @@ case object ResConverter extends ShuntConverter {
def convert(
input: RES,
node: NodeInput,
profile: ResProfile,
uuid: Option[UUID] = None
): (FixedFeedInInput, IndividualTimeSeries[PValue]) = {
): FixedFeedInInput = {
val p = Quantities.getQuantity(input.p, MEGAWATT)
val q = Quantities.getQuantity(input.q, MEGAVAR)
val cosphi = cosPhi(p.getValue.doubleValue(), q.getValue.doubleValue())
val varCharacteristicString =
"cosPhiFixed:{(0.0,%#.2f)}".formatLocal(Locale.ENGLISH, cosphi)
val sRated = Quantities.getQuantity(input.sR, MEGAVOLTAMPERE)

/* Flip the sign, as infeed is negative in PowerSystemDataModel */
val timeSeries = PowerProfileConverter.convert(profile, p.multiply(-1))

new FixedFeedInInput(
uuid.getOrElse(UUID.randomUUID()),
input.id + "_" + input.resType.toString,
Expand All @@ -90,6 +99,6 @@ case object ResConverter extends ShuntConverter {
null,
sRated,
cosphi
) -> timeSeries
)
}
}
Loading

0 comments on commit fc33fbf

Please sign in to comment.