Skip to content

Commit

Permalink
Merge branch 'dev' into df/#878-thermalGridIT
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala
  • Loading branch information
danielfeismann committed Nov 15, 2024
2 parents 6631b67 + 9d780a7 commit 97b4a15
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rewrote StorageModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)
- Updated `ExtEvSimulationClasses` [#898](https://github.com/ie3-institute/simona/issues/898)
- Refactoring of `ThermalGrid.energyGrid` to distinguish between demand of house and storage [#928](https://github.com/ie3-institute/simona/issues/928)
- Refactoring to use zeroKW and zeroKWH in thermal grid unit tests [#1023](https://github.com/ie3-institute/simona/issues/1023)

### Fixed
- Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final case class ChpModel(
chpData: ChpRelevantData
): ChpRelevantData => ChpState = {
val isRunning = chpData.chpState.isRunning
val hasDemand = chpData.heatDemand > DefaultQuantities.zeroKWH
val hasDemand = chpData.heatDemand > DefaultQuantities.zeroKWh
val isCovered = isDemandCovered(chpData)

(isRunning, hasDemand, isCovered) match {
Expand All @@ -145,7 +145,7 @@ final case class ChpModel(
isRunning = false,
chpData.currentTimeTick,
DefaultQuantities.zeroKW,
DefaultQuantities.zeroKWH,
DefaultQuantities.zeroKWh,
)

/** The demand cannot be covered, therefore this function sets storage level
Expand Down Expand Up @@ -182,7 +182,7 @@ final case class ChpModel(
isRunning = false,
chpData.currentTimeTick,
DefaultQuantities.zeroKW,
DefaultQuantities.zeroKWH,
DefaultQuantities.zeroKWh,
)
}

Expand All @@ -199,7 +199,7 @@ final case class ChpModel(
chpData: ChpRelevantData
): ChpState = {
val differenceEnergy = chpEnergy(chpData) - chpData.heatDemand
if (differenceEnergy < zeroKWH) {
if (differenceEnergy < zeroKWh) {
// Returned lack is always zero, because demand is covered.
storage.tryToTakeAndReturnLack(differenceEnergy * -1)
calculateStateRunningSurplus(chpData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ final case class HpModel(
val noThermalStorageOrThermalStorageIsEmpty: Boolean =
updatedGridState.storageState.isEmpty || updatedGridState.storageState
.exists(
_.storedEnergy =~ zeroKWH
_.storedEnergy =~ zeroKWh
)

val houseDemand =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final case class StorageModel(
cosPhiRated,
) {

private val minEnergy = zeroKWH
private val minEnergy = zeroKWh

/** Tolerance for power comparisons. With very small (dis-)charging powers,
* problems can occur when calculating the future tick at which storage is
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ final case class EvcsModel(
tickStop > lastSchedulingTick && tickStart < currentTick
}
.sortBy(_.tickStart)
.foldLeft(zeroKWH) { case (accumulatedEnergy, scheduleEntry) =>
.foldLeft(zeroKWh) { case (accumulatedEnergy, scheduleEntry) =>
/* Only the timeframe from the start of last scheduling update and current tick must be considered */
val trimmedEntry = trimScheduleEntry(
scheduleEntry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final case class CylindricalThermalStorage(
override def tryToStoreAndReturnRemainder(
addedEnergy: Energy
): Option[Energy] = {
if (addedEnergy > zeroKWH) {
if (addedEnergy > zeroKWh) {
_storedEnergy = _storedEnergy + addedEnergy
if (_storedEnergy > maxEnergyThreshold) {
val surplus = _storedEnergy - maxEnergyThreshold
Expand All @@ -158,7 +158,7 @@ final case class CylindricalThermalStorage(
override def tryToTakeAndReturnLack(
takenEnergy: Energy
): Option[Energy] = {
if (takenEnergy > zeroKWH) {
if (takenEnergy > zeroKWh) {
_storedEnergy = _storedEnergy - takenEnergy
if (_storedEnergy < minEnergyThreshold) {
val lack = minEnergyThreshold - _storedEnergy
Expand All @@ -185,7 +185,7 @@ object CylindricalThermalStorage {
*/
def apply(
input: CylindricalStorageInput,
initialStoredEnergy: Energy = DefaultQuantities.zeroKWH,
initialStoredEnergy: Energy = DefaultQuantities.zeroKWh,
): CylindricalThermalStorage = {
val minEnergyThreshold: Energy =
CylindricalThermalStorage.volumeToEnergy(
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ final case class ThermalGrid(
storage.getMaxEnergyThreshold - storedEnergy

} else {
zeroMWH
zeroMWh
}
}

Expand All @@ -130,7 +130,7 @@ final case class ThermalGrid(

}
.getOrElse(
ThermalEnergyDemand(zeroMWH, zeroMWH),
ThermalEnergyDemand(zeroMWh, zeroMWh),
None,
)
}
Expand Down Expand Up @@ -771,7 +771,7 @@ object ThermalGrid {
possible + rhs.possible,
)

def hasRequiredDemand: Boolean = required > zeroMWH
def hasRequiredDemand: Boolean = required > zeroMWh

def hasAdditionalDemand: Boolean = possible > zeroMWH
}
Expand Down Expand Up @@ -801,8 +801,8 @@ object ThermalGrid {
}

def noDemand: ThermalEnergyDemand = ThermalEnergyDemand(
zeroMWH,
zeroMWH,
zeroMWh,
zeroMWh,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ final case class ThermalHouse(
)
) energy(targetTemperature, currentInnerTemp)
else
zeroMWH
zeroMWh

val possibleEnergy =
if (!isInnerTemperatureTooHigh(currentInnerTemp)) {
// if upper boundary has not been reached,
// there is an amount of optional energy that could be stored
energy(upperBoundaryTemperature, currentInnerTemp)
} else
zeroMWH
zeroMWh
ThermalEnergyDemand(requiredEnergy, possibleEnergy)
}

Expand Down Expand Up @@ -323,7 +323,7 @@ final case class ThermalHouse(
qDot: Power,
): Option[Long] = {
val flexibleEnergy = energy(higherTemperature, lowerTemperature)
if (flexibleEnergy < zeroMWH)
if (flexibleEnergy < zeroMWh)
None
else {
val duration = Math.round(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ object DefaultQuantities {
val zeroKVAr: ReactivePower = Kilovars(0d)
val zeroMVAr: ReactivePower = Megavars(0d)

val zeroKWH: Energy = KilowattHours(0d)
val zeroMWH: Energy = MegawattHours(0d)
val zeroKWh: Energy = KilowattHours(0d)
val zeroMWh: Energy = MegawattHours(0d)

val zeroPU: Dimensionless = Each(0d)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{
HouseTemperatureLowerBoundaryReached,
HouseTemperatureUpperBoundaryReached,
}
import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWh}
import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageState
import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageThreshold.{
StorageEmpty,
Expand Down Expand Up @@ -103,15 +104,15 @@ class ThermalGridWithHouseAndStorageSpec
testGridAmbientTemperature,
ThermalGrid.startingState(thermalGrid),
)
houseDemand.required should approximate(KilowattHours(0d))
houseDemand.required should approximate(zeroKWh)
houseDemand.possible should approximate(KilowattHours(31.05009722d))
storageDemand.required should approximate(KilowattHours(1150d))
storageDemand.possible should approximate(KilowattHours(1150d))
updatedThermalGridState.houseState shouldBe Some(
ThermalHouseState(10800, Kelvin(292.0799935185185), Kilowatts(0d))
ThermalHouseState(10800, Kelvin(292.0799935185185), zeroKW)
)
updatedThermalGridState.storageState shouldBe Some(
ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d))
ThermalStorageState(10800, zeroKWh, zeroKW)
)
}

Expand All @@ -136,10 +137,10 @@ class ThermalGridWithHouseAndStorageSpec
storageDemand.required should approximate(KilowattHours(1150d))
storageDemand.possible should approximate(KilowattHours(1150d))
updatedThermalGridState.houseState shouldBe Some(
ThermalHouseState(10800, Celsius(15.959996296296296), Kilowatts(0d))
ThermalHouseState(10800, Celsius(15.959996296296296), zeroKW)
)
updatedThermalGridState.storageState shouldBe Some(
ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d))
ThermalStorageState(10800, zeroKWh, zeroKW)
)
}
}
Expand All @@ -159,7 +160,7 @@ class ThermalGridWithHouseAndStorageSpec
storageState.copy(storedEnergy = initialLoading)
)
)
val externalQDot = Kilowatts(0d)
val externalQDot = zeroKW

val (updatedGridState, reachedThreshold) =
thermalGrid invokePrivate handleConsumption(
Expand Down Expand Up @@ -216,7 +217,7 @@ class ThermalGridWithHouseAndStorageSpec
) =>
houseTick shouldBe 0L
innerTemperature should approximate(Celsius(18.9999d))
qDotHouse should approximate(Kilowatts(0d))
qDotHouse should approximate(zeroKW)

storageTick shouldBe 0L
storedEnergy should approximate(initialLoading)
Expand All @@ -228,7 +229,7 @@ class ThermalGridWithHouseAndStorageSpec
}

"revising infeed from storage to house" should {
val zeroInflux = Kilowatts(0d)
val zeroInflux = zeroKW
val tick = 3600L
val ambientTemperature = Celsius(14d)
"hand back unaltered information if needed information is missing" in {
Expand Down Expand Up @@ -371,7 +372,7 @@ class ThermalGridWithHouseAndStorageSpec
(
ThermalStorageState(
tick,
KilowattHours(0d),
zeroKWh,
testGridQDotInfeed,
),
Some(StorageEmpty(tick)),
Expand Down Expand Up @@ -519,7 +520,7 @@ class ThermalGridWithHouseAndStorageSpec
.getOrElse(fail("No initial storage state found"))
)

qDotStorage should approximate(Kilowatts(0d))
qDotStorage should approximate(zeroKW)

case _ => fail("Thermal grid state has been calculated wrong.")
}
Expand Down Expand Up @@ -558,7 +559,7 @@ class ThermalGridWithHouseAndStorageSpec
) =>
houseTick shouldBe 0L
innerTemperature should approximate(Celsius(20.99999167d))
qDotHouse should approximate(Kilowatts(0d))
qDotHouse should approximate(zeroKW)

storageTick shouldBe 0L
storedEnergy should approximate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{
HouseTemperatureLowerBoundaryReached,
HouseTemperatureUpperBoundaryReached,
}
import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWh}
import edu.ie3.simona.test.common.UnitSpec
import squants.energy._
import squants.thermal.Celsius
Expand Down Expand Up @@ -90,10 +91,10 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {

houseDemand.required should approximate(expectedHouseDemand.required)
houseDemand.possible should approximate(expectedHouseDemand.possible)
storageDemand.required should approximate(KilowattHours(0d))
storageDemand.possible should approximate(KilowattHours(0d))
storageDemand.required should approximate(zeroKWh)
storageDemand.possible should approximate(zeroKWh)
updatedThermalGridState.houseState shouldBe Some(
ThermalHouseState(10800, Kelvin(292.0799935185185), Kilowatts(0d))
ThermalHouseState(10800, Kelvin(292.0799935185185), zeroKW)
)
updatedThermalGridState.storageState shouldBe None
}
Expand All @@ -108,7 +109,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {
"deliver the house state by just letting it cool down, if just no infeed is given" in {
val tick = 0L
val gridState = ThermalGrid.startingState(thermalGrid)
val externalQDot = Megawatts(0d)
val externalQDot = zeroKW

val (updatedGridState, reachedThreshold) =
thermalGrid invokePrivate handleConsumption(
Expand Down Expand Up @@ -154,7 +155,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {
) =>
tick shouldBe 0L
innerTemperature should approximate(Celsius(18.9999d))
qDot should approximate(Megawatts(0d))
qDot should approximate(zeroKW)
case _ => fail("Thermal grid state has been calculated wrong.")
}
reachedThreshold shouldBe Some(
Expand Down Expand Up @@ -245,7 +246,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {
) =>
tick shouldBe 0L
innerTemperature should approximate(Celsius(18.9999d))
qDot should approximate(Megawatts(0d))
qDot should approximate(zeroKW)
thresholdTick shouldBe 154285L
case _ => fail("Thermal grid state updated failed")
}
Expand All @@ -258,7 +259,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {
testGridAmbientTemperature,
testGridAmbientTemperature,
isNotRunning,
Megawatts(0d),
zeroKW,
onlyThermalDemandOfHouse,
) match {
case (
Expand All @@ -270,7 +271,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData {
) =>
tick shouldBe 0L
innerTemperature should approximate(Celsius(18.9999d))
qDot should approximate(Kilowatts(0d))
qDot should approximate(zeroKW)
thresholdTick shouldBe 154285L
case _ => fail("Thermal grid state updated failed")
}
Expand Down
Loading

0 comments on commit 97b4a15

Please sign in to comment.