diff --git a/CHANGELOG.md b/CHANGELOG.md index 5902f1cb01..ea1a2f31cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 5af1b68236..56bd446412 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -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 { @@ -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 @@ -182,7 +182,7 @@ final case class ChpModel( isRunning = false, chpData.currentTimeTick, DefaultQuantities.zeroKW, - DefaultQuantities.zeroKWH, + DefaultQuantities.zeroKWh, ) } @@ -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) diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index bc413ba76b..564d31980c 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -243,7 +243,7 @@ final case class HpModel( val noThermalStorageOrThermalStorageIsEmpty: Boolean = updatedGridState.storageState.isEmpty || updatedGridState.storageState .exists( - _.storedEnergy =~ zeroKWH + _.storedEnergy =~ zeroKWh ) val houseDemand = diff --git a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala index 02f82d2670..742f5d8f68 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala @@ -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 diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index a1d21252ec..4f0e4d9730 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -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, diff --git a/src/main/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorage.scala b/src/main/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorage.scala index fedea75204..7640505bb1 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorage.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/CylindricalThermalStorage.scala @@ -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 @@ -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 @@ -185,7 +185,7 @@ object CylindricalThermalStorage { */ def apply( input: CylindricalStorageInput, - initialStoredEnergy: Energy = DefaultQuantities.zeroKWH, + initialStoredEnergy: Energy = DefaultQuantities.zeroKWh, ): CylindricalThermalStorage = { val minEnergyThreshold: Energy = CylindricalThermalStorage.volumeToEnergy( diff --git a/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala b/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala index 956af27cd4..67904dde23 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala @@ -115,7 +115,7 @@ final case class ThermalGrid( storage.getMaxEnergyThreshold - storedEnergy } else { - zeroMWH + zeroMWh } } @@ -130,7 +130,7 @@ final case class ThermalGrid( } .getOrElse( - ThermalEnergyDemand(zeroMWH, zeroMWH), + ThermalEnergyDemand(zeroMWh, zeroMWh), None, ) } @@ -771,7 +771,7 @@ object ThermalGrid { possible + rhs.possible, ) - def hasRequiredDemand: Boolean = required > zeroMWH + def hasRequiredDemand: Boolean = required > zeroMWh def hasAdditionalDemand: Boolean = possible > zeroMWH } @@ -801,8 +801,8 @@ object ThermalGrid { } def noDemand: ThermalEnergyDemand = ThermalEnergyDemand( - zeroMWH, - zeroMWH, + zeroMWh, + zeroMWh, ) } } diff --git a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala index 71e992c4e0..aaae60aeab 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -123,7 +123,7 @@ final case class ThermalHouse( ) ) energy(targetTemperature, currentInnerTemp) else - zeroMWH + zeroMWh val possibleEnergy = if (!isInnerTemperatureTooHigh(currentInnerTemp)) { @@ -131,7 +131,7 @@ final case class ThermalHouse( // there is an amount of optional energy that could be stored energy(upperBoundaryTemperature, currentInnerTemp) } else - zeroMWH + zeroMWh ThermalEnergyDemand(requiredEnergy, possibleEnergy) } @@ -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( diff --git a/src/main/scala/edu/ie3/util/scala/quantities/DefaultQuantities.scala b/src/main/scala/edu/ie3/util/scala/quantities/DefaultQuantities.scala index ac401db84c..698f757eff 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/DefaultQuantities.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/DefaultQuantities.scala @@ -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) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala index ce58b6a52a..2351774f20 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala @@ -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, @@ -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) ) } @@ -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) ) } } @@ -159,7 +160,7 @@ class ThermalGridWithHouseAndStorageSpec storageState.copy(storedEnergy = initialLoading) ) ) - val externalQDot = Kilowatts(0d) + val externalQDot = zeroKW val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( @@ -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) @@ -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 { @@ -371,7 +372,7 @@ class ThermalGridWithHouseAndStorageSpec ( ThermalStorageState( tick, - KilowattHours(0d), + zeroKWh, testGridQDotInfeed, ), Some(StorageEmpty(tick)), @@ -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.") } @@ -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( diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala index 39a614e92c..0c61b79ba8 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -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 @@ -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 } @@ -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( @@ -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( @@ -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") } @@ -258,7 +259,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { testGridAmbientTemperature, testGridAmbientTemperature, isNotRunning, - Megawatts(0d), + zeroKW, onlyThermalDemandOfHouse, ) match { case ( @@ -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") } diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala index c2c1880fef..d8b622e78c 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala @@ -17,6 +17,7 @@ import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageThreshold.{ StorageFull, } import edu.ie3.simona.test.common.UnitSpec +import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWh} import squants.energy._ import squants.thermal.Celsius import squants.{Energy, Power, Temperature} @@ -88,13 +89,13 @@ class ThermalGridWithStorageOnlySpec ThermalGrid.startingState(thermalGrid), ) - houseDemand.required should approximate(KilowattHours(0d)) - houseDemand.possible should approximate(KilowattHours(0d)) + houseDemand.required should approximate(zeroKWh) + houseDemand.possible should approximate(zeroKWh) storageDemand.required should approximate(KilowattHours(1150d)) storageDemand.possible should approximate(KilowattHours(1150d)) updatedThermalGridState.houseState shouldBe None updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d)) + ThermalStorageState(10800, zeroKWh, zeroKW) ) } @@ -108,17 +109,17 @@ class ThermalGridWithStorageOnlySpec testGridAmbientTemperature, ThermalGridState( None, - Some(ThermalStorageState(0L, KilowattHours(575d), Kilowatts(0d))), + Some(ThermalStorageState(0L, KilowattHours(575d), zeroKW)), ), ) - houseDemand.required should approximate(KilowattHours(0d)) - houseDemand.possible should approximate(KilowattHours(0d)) - storageDemand.required should approximate(KilowattHours(0d)) + houseDemand.required should approximate(zeroKWh) + houseDemand.possible should approximate(zeroKWh) + storageDemand.required should approximate(zeroKWh) storageDemand.possible should approximate(KilowattHours(575d)) updatedThermalGridState.houseState shouldBe None updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800L, KilowattHours(575d), Kilowatts(0d)) + ThermalStorageState(10800L, KilowattHours(575d), zeroKW) ) } } @@ -138,7 +139,7 @@ class ThermalGridWithStorageOnlySpec ThermalStorageState( 0L, KilowattHours(200d), - Kilowatts(0d), + zeroKW, ) ) ) @@ -193,7 +194,7 @@ class ThermalGridWithStorageOnlySpec Some(ThermalStorageState(tick, storedEnergy, qDot)), ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) + storedEnergy should approximate(zeroKWh) qDot should approximate(testGridQDotInfeed) case _ => fail("Thermal grid state has been calculated wrong.") } @@ -221,7 +222,7 @@ class ThermalGridWithStorageOnlySpec Some(ThermalStorageState(tick, storedEnergy, qDot)), ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) + storedEnergy should approximate(zeroKWh) qDot should approximate(testGridQDotInfeed) case _ => fail("Thermal grid state updated failed") } @@ -237,7 +238,7 @@ class ThermalGridWithStorageOnlySpec ThermalStorageState( 0L, KilowattHours(200d), - Kilowatts(0d), + zeroKW, ) ) ), @@ -269,7 +270,7 @@ class ThermalGridWithStorageOnlySpec testGridAmbientTemperature, testGridAmbientTemperature, isRunning, - Kilowatts(0d), + zeroKW, noThermalDemand, ) updatedState match { @@ -281,8 +282,8 @@ class ThermalGridWithStorageOnlySpec None, ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) - qDot should approximate(Megawatts(0d)) + storedEnergy should approximate(zeroKWh) + qDot should approximate(zeroKW) case _ => fail("Thermal grid state updated failed") }