From 5280971ae9fb4f262c7f5d5ad1d9d3aabc9c9930 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Sun, 24 Nov 2024 11:05:19 +0100 Subject: [PATCH 1/5] Refactor thermal calcRelevantData --- CHANGELOG.md | 1 + .../simona/model/participant/HpModel.scala | 6 +- .../simona/model/thermal/ThermalGrid.scala | 93 ++++++++----------- .../simona/model/thermal/ThermalHouse.scala | 34 +++---- .../ThermalGridWithHouseAndStorageSpec.scala | 78 +++++++++------- .../ThermalGridWithHouseOnlySpec.scala | 23 ++--- .../ThermalGridWithStorageOnlySpec.scala | 29 +++--- 7 files changed, 129 insertions(+), 135 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44290c1dd2..e8c5efd272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Refactor `ResultFileHierarchy` [#1031](https://github.com/ie3-institute/simona/issues/1031) - Removing logs in `logs/simona` [#1017](https://github.com/ie3-institute/simona/issues/1017) - Fix implausible test cases of HpModelSpec [#1042](https://github.com/ie3-institute/simona/issues/1042) +- Refactor thermal calcRelevantData [#1051](https://github.com/ie3-institute/simona/issues/1051) ### 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/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index 98d18d9ce3..860a1efe72 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -134,11 +134,10 @@ final case class HpModel( // Use lastHpState and relevantData to update state of thermalGrid to the current tick val (demandHouse, demandThermalStorage, currentThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - relevantData.currentTick, + relevantData, lastHpState.ambientTemperature.getOrElse( relevantData.ambientTemperature ), - relevantData.ambientTemperature, lastHpState.thermalGridState, ) @@ -279,10 +278,9 @@ final case class HpModel( /* Push thermal energy to the thermal grid and get its updated state in return */ val (thermalGridState, maybeThreshold) = thermalGrid.updateState( - relevantData.currentTick, + relevantData, lastState.thermalGridState, lastState.ambientTemperature.getOrElse(relevantData.ambientTemperature), - relevantData.ambientTemperature, newThermalPower, ) 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 50f56e1849..ff9339c2b8 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala @@ -14,6 +14,7 @@ import edu.ie3.datamodel.models.result.thermal.{ ThermalHouseResult, } import edu.ie3.simona.exceptions.agent.InconsistentStateException +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalGrid.{ ThermalEnergyDemand, ThermalGridState, @@ -44,13 +45,10 @@ final case class ThermalGrid( /** Determine the energy demand of the total grid at the given instance in * time and returns it including the updatedState - * - * @param tick - * Questioned instance in time + * @param relevantData + * data of heat pump including state of the heat pump * @param lastAmbientTemperature * Ambient temperature until this tick - * @param ambientTemperature - * Ambient temperature in the instance in question * @param state * Currently applicable state of the thermal grid * @return @@ -58,10 +56,9 @@ final case class ThermalGrid( * [[ThermalGridState]] */ def energyDemandAndUpdatedState( - tick: Long, + relevantData: HpRelevantData, // FIXME this is also in state lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, state: ThermalGridState, ): (ThermalEnergyDemand, ThermalEnergyDemand, ThermalGridState) = { /* First get the energy demand of the houses but only if inner temperature is below target temperature */ @@ -71,10 +68,9 @@ final case class ThermalGrid( case Some((thermalHouse, lastHouseState)) => val (updatedHouseState, _) = thermalHouse.determineState( - tick, + relevantData, lastHouseState, lastAmbientTemperature, - ambientTemperature, lastHouseState.qDot, ) if ( @@ -83,8 +79,7 @@ final case class ThermalGrid( ) { ( thermalHouse.energyDemand( - tick, - ambientTemperature, + relevantData, updatedHouseState, ), Some(updatedHouseState), @@ -105,7 +100,7 @@ final case class ThermalGrid( .zip(state.storageState) .map { case (storage, state) => val (updatedStorageState, _) = - storage.updateState(tick, state.qDot, state) + storage.updateState(relevantData.currentTick, state.qDot, state) val storedEnergy = updatedStorageState.storedEnergy val soc = storedEnergy / storage.getMaxEnergyThreshold val storageRequired = { @@ -148,32 +143,28 @@ final case class ThermalGrid( /** Update the current state of the grid * - * @param tick - * Instance in time + * @param relevantData + * data of heat pump including state of the heat pump * @param state * Currently applicable state * @param lastAmbientTemperature * Ambient temperature valid up until (not including) the current tick - * @param ambientTemperature - * Current ambient temperature * @param qDot * Thermal energy balance * @return * The updated state of the grid */ def updateState( - tick: Long, + relevantData: HpRelevantData, state: ThermalGridState, lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, qDot: Power, ): (ThermalGridState, Option[ThermalThreshold]) = if (qDot > zeroKW) - handleInfeed(tick, lastAmbientTemperature, ambientTemperature, state, qDot) + handleInfeed(relevantData, lastAmbientTemperature, state, qDot) else handleConsumption( - tick, + relevantData, lastAmbientTemperature, - ambientTemperature, state, qDot, ) @@ -181,12 +172,10 @@ final case class ThermalGrid( /** Handles the case, when a grid has infeed. First, heat up all the houses to * their maximum temperature, then fill up the storages * - * @param tick - * Current tick + * @param relevantData + * data of heat pump including state of the heat pump * @param lastAmbientTemperature * Ambient temperature valid up until (not including) the current tick - * @param ambientTemperature - * Current ambient temperature * @param state * Current state of the houses * @param qDot @@ -195,9 +184,8 @@ final case class ThermalGrid( * Updated thermal grid state */ private def handleInfeed( - tick: Long, + relevantData: HpRelevantData, lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, state: ThermalGridState, qDot: Power, ): (ThermalGridState, Option[ThermalThreshold]) = @@ -210,7 +198,7 @@ final case class ThermalGrid( Some( thermalStorage .updateState( - tick, + relevantData.currentTick, zeroKW, storageState, ) @@ -221,10 +209,9 @@ final case class ThermalGrid( val (updatedHouseState, maybeHouseThreshold) = thermalHouse.determineState( - tick, + relevantData, lastHouseState, lastAmbientTemperature, - ambientTemperature, qDot, ) @@ -236,16 +223,19 @@ final case class ThermalGrid( /* The house is already heated up fully, set back the infeed and put it into storage, if available */ val (fullHouseState, maybeFullHouseThreshold) = thermalHouse.determineState( - tick, + relevantData, lastHouseState, lastAmbientTemperature, - ambientTemperature, zeroKW, ) storage.zip(updatedStorageState) match { case Some((thermalStorage, storageState)) => val (updatedStorageState, maybeStorageThreshold) = - thermalStorage.updateState(tick, qDot, storageState) + thermalStorage.updateState( + relevantData.currentTick, + qDot, + storageState, + ) /* Both house and storage are updated. Determine what reaches the next threshold */ val nextThreshold = determineMostRecentThreshold( @@ -279,7 +269,11 @@ final case class ThermalGrid( storage.zip(state.storageState) match { case Some((thermalStorage, storageState)) => val (updatedStorageState, maybeStorageThreshold) = - thermalStorage.updateState(tick, qDot, storageState) + thermalStorage.updateState( + relevantData.currentTick, + qDot, + storageState, + ) ( state.copy(storageState = Some(updatedStorageState)), maybeStorageThreshold, @@ -308,12 +302,10 @@ final case class ThermalGrid( /** Handle consumption (or no infeed) from thermal grid * - * @param tick - * Current tick + * @param relevantData + * data of heat pump including state of the heat pump * @param lastAmbientTemperature * Ambient temperature valid up until (not including) the current tick - * @param ambientTemperature - * Current ambient temperature * @param state * Current state of the houses * @param qDot @@ -322,9 +314,8 @@ final case class ThermalGrid( * Updated thermal grid state */ private def handleConsumption( - tick: Long, + relevantData: HpRelevantData, lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, state: ThermalGridState, qDot: Power, ): (ThermalGridState, Option[ThermalThreshold]) = { @@ -332,10 +323,9 @@ final case class ThermalGrid( val maybeUpdatedHouseState = house.zip(state.houseState).map { case (house, houseState) => house.determineState( - tick, + relevantData, houseState, lastAmbientTemperature, - ambientTemperature, zeroMW, ) } @@ -343,18 +333,17 @@ final case class ThermalGrid( /* Update the state of the storage */ val maybeUpdatedStorageState = storage.zip(state.storageState).map { case (storage, storageState) => - storage.updateState(tick, qDot, storageState) + storage.updateState(relevantData.currentTick, qDot, storageState) } val (revisedHouseState, revisedStorageState) = reviseInfeedFromStorage( - tick, + relevantData, maybeUpdatedHouseState, maybeUpdatedStorageState, state.houseState, state.storageState, lastAmbientTemperature, - ambientTemperature, qDot, ) @@ -377,8 +366,8 @@ final case class ThermalGrid( * is no infeed from external and
  • the storage is not empty * itself
  • * - * @param tick - * The current tick + * @param relevantData + * data of heat pump including state of the heat pump * @param maybeHouseState * Optional thermal house state * @param maybeStorageState @@ -389,15 +378,13 @@ final case class ThermalGrid( * Previous thermal storage state before a first update was performed * @param lastAmbientTemperature * Ambient temperature valid up until (not including) the current tick - * @param ambientTemperature - * Current ambient temperature * @param qDot * Thermal influx * @return * Options to revised thermal house and storage state */ def reviseInfeedFromStorage( - tick: Long, + relevantData: HpRelevantData, maybeHouseState: Option[(ThermalHouseState, Option[ThermalThreshold])], maybeStorageState: Option[ (ThermalStorageState, Option[ThermalThreshold]) @@ -405,7 +392,6 @@ final case class ThermalGrid( formerHouseState: Option[ThermalHouseState], formerStorageState: Option[ThermalStorageState], lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, qDot: Power, ): ( Option[(ThermalHouseState, Option[ThermalThreshold])], @@ -423,7 +409,7 @@ final case class ThermalGrid( ) && !thermalStorage.isEmpty(storageState.storedEnergy) => /* Storage is meant to heat the house only, if there is no infeed from external (+/- 10 W) and the house is cold */ val revisedStorageState = thermalStorage.updateState( - tick, + relevantData.currentTick, thermalStorage.getChargingPower * -1, formerStorageState.getOrElse( throw new InconsistentStateException( @@ -432,14 +418,13 @@ final case class ThermalGrid( ), ) val revisedHouseState = thermalHouse.determineState( - tick, + relevantData, formerHouseState.getOrElse( throw new InconsistentStateException( "Impossible to find no house state" ) ), lastAmbientTemperature, - ambientTemperature, thermalStorage.getChargingPower, ) (Some(revisedHouseState), Some(revisedStorageState)) 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 e0fd7024f7..4296efa1ae 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -12,6 +12,7 @@ import edu.ie3.datamodel.models.input.thermal.{ ThermalBusInput, ThermalHouseInput, } +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalGrid.ThermalEnergyDemand import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{ HouseTemperatureLowerBoundaryReached, @@ -82,27 +83,24 @@ final case class ThermalHouse( * determining the thermal demand, a change in external infeed will take * place. * - * @param tick - * Questionable tick - * @param ambientTemperature - * Ambient temperature in the instance in question + * @param relevantData + * data of heat pump including state of the heat pump * @param state * most recent state, that is valid for this model * @return * the needed energy in the questioned tick */ def energyDemand( - tick: Long, - ambientTemperature: Temperature, + relevantData: HpRelevantData, state: ThermalHouseState, ): ThermalEnergyDemand = { /* Calculate the inner temperature of the house, at the questioned instance in time */ - val duration = Seconds(tick - state.tick) + val duration = Seconds(relevantData.currentTick - state.tick) val currentInnerTemp = newInnerTemperature( state.qDot, duration, state.innerTemperature, - ambientTemperature, + relevantData.ambientTemperature, ) /* Determine, which temperature boundary triggers a needed energy to reach the temperature constraints */ @@ -219,27 +217,24 @@ final case class ThermalHouse( /** Update the current state of the house * - * @param tick - * Current instance in time + * @param relevantData + * data of heat pump including state of the heat pump * @param state * Currently applicable state * @param lastAmbientTemperature * Ambient temperature valid up until (not including) the current tick - * @param ambientTemperature - * Current ambient temperature * @param qDot * New thermal influx * @return * Updated state and the tick in which the next threshold is reached */ def determineState( - tick: Long, + relevantData: HpRelevantData, state: ThermalHouseState, lastAmbientTemperature: Temperature, - ambientTemperature: Temperature, qDot: Power, ): (ThermalHouseState, Option[ThermalThreshold]) = { - val duration = Seconds(tick - state.tick) + val duration = Seconds(relevantData.currentTick - state.tick) val updatedInnerTemperature = newInnerTemperature( state.qDot, duration, @@ -249,11 +244,16 @@ final case class ThermalHouse( /* Calculate the next given threshold */ val threshold = - nextThreshold(tick, qDot, updatedInnerTemperature, ambientTemperature) + nextThreshold( + relevantData.currentTick, + qDot, + updatedInnerTemperature, + relevantData.ambientTemperature, + ) ( state.copy( - tick = tick, + tick = relevantData.currentTick, innerTemperature = updatedInnerTemperature, qDot = qDot, ), 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 7d8d2c27f1..19ba70f680 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala @@ -7,6 +7,7 @@ package edu.ie3.simona.model.thermal import edu.ie3.datamodel.models.input.thermal.ThermalStorageInput +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalGrid.ThermalGridState import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseState import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{ @@ -95,12 +96,13 @@ class ThermalGridWithHouseAndStorageSpec "determining the energy demand" should { "deliver the house demand (no demand) with added flexibility by storage" in { - val tick = 10800 // after three hours - + val relevantData = HpRelevantData( + 10800, // after three hours + testGridAmbientTemperature, + ) val (houseDemand, storageDemand, updatedThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, ThermalGrid.startingState(thermalGrid), ) @@ -117,13 +119,15 @@ class ThermalGridWithHouseAndStorageSpec } "deliver the correct house and storage demand" in { - val tick = 10800 // after three hours + val relevantData = HpRelevantData( + 10800, // after three hours + testGridAmbientTemperature, + ) val startingState = ThermalGrid.startingState(thermalGrid) val (houseDemand, storageDemand, updatedThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, startingState.copy(houseState = startingState.houseState.map( @@ -189,7 +193,10 @@ class ThermalGridWithHouseAndStorageSpec } "take energy from storage, if there is actual consumption" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val initialGridState = ThermalGrid.startingState(thermalGrid) val initialLoading = KilowattHours(200d) val gridState = initialGridState.copy(storageState = @@ -201,8 +208,7 @@ class ThermalGridWithHouseAndStorageSpec val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, externalQDot, @@ -230,13 +236,16 @@ class ThermalGridWithHouseAndStorageSpec "revising infeed from storage to house" should { val zeroInflux = zeroKW - val tick = 3600L + val relevantData = HpRelevantData( + 3600, + testGridAmbientTemperature, + ) val ambientTemperature = Celsius(14d) "hand back unaltered information if needed information is missing" in { val maybeHouseState = Some( ( ThermalHouseState( - tick, + relevantData.currentTick, Celsius( thermalHouseInput.getTargetTemperature .to(Units.CELSIUS) @@ -251,13 +260,12 @@ class ThermalGridWithHouseAndStorageSpec val maybeStorageState = None thermalGrid.reviseInfeedFromStorage( - tick, + relevantData, maybeHouseState, maybeStorageState, maybeHouseState.map(_._1), None, testGridAmbientTemperature, - testGridAmbientTemperature, testGridQDotConsumption, ) match { case (maybeRevisedHouseState, maybeRevisedStorageState) => @@ -270,7 +278,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeHouseState = Some( ( ThermalHouseState( - tick, + relevantData.currentTick, Celsius( thermalHouseInput.getTargetTemperature .to(Units.CELSIUS) @@ -285,7 +293,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeStorageState = Some( ( ThermalStorageState( - tick, + relevantData.currentTick, KilowattHours(50d), zeroInflux, ), @@ -294,13 +302,12 @@ class ThermalGridWithHouseAndStorageSpec ) thermalGrid.reviseInfeedFromStorage( - tick, + relevantData, maybeHouseState, maybeStorageState, maybeHouseState.map(_._1), maybeStorageState.map(_._1), ambientTemperature, - ambientTemperature, zeroInflux, ) match { case (maybeRevisedHouseState, maybeRevisedStorageState) => @@ -313,7 +320,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeHouseState = Some( ( ThermalHouseState( - tick, + relevantData.currentTick, Celsius( thermalHouseInput.getTargetTemperature .to(Units.CELSIUS) @@ -328,7 +335,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeStorageState = Some( ( ThermalStorageState( - tick, + relevantData.currentTick, KilowattHours(50d), zeroInflux, ), @@ -337,13 +344,12 @@ class ThermalGridWithHouseAndStorageSpec ) thermalGrid.reviseInfeedFromStorage( - tick, + relevantData, maybeHouseState, maybeStorageState, maybeHouseState.map(_._1), maybeStorageState.map(_._1), ambientTemperature, - ambientTemperature, testGridQDotInfeed, ) match { case (maybeRevisedHouseState, maybeRevisedStorageState) => @@ -356,7 +362,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeHouseState = Some( ( ThermalHouseState( - tick, + relevantData.currentTick, Celsius( thermalHouseInput.getLowerTemperatureLimit .to(Units.CELSIUS) @@ -365,28 +371,29 @@ class ThermalGridWithHouseAndStorageSpec ), zeroInflux, ), - Some(HouseTemperatureLowerBoundaryReached(tick)), + Some( + HouseTemperatureLowerBoundaryReached(relevantData.currentTick) + ), ) ) val maybeStorageState = Some( ( ThermalStorageState( - tick, + relevantData.currentTick, zeroKWh, testGridQDotInfeed, ), - Some(StorageEmpty(tick)), + Some(StorageEmpty(relevantData.currentTick)), ) ) thermalGrid.reviseInfeedFromStorage( - tick, + relevantData, maybeHouseState, maybeStorageState, maybeHouseState.map(_._1), maybeStorageState.map(_._1), ambientTemperature, - ambientTemperature, zeroInflux, ) match { case (maybeRevisedHouseState, maybeRevisedStorageState) => @@ -399,7 +406,7 @@ class ThermalGridWithHouseAndStorageSpec val maybeHouseState = Some( ( ThermalHouseState( - tick, + relevantData.currentTick, Celsius( thermalHouseInput.getLowerTemperatureLimit .to(Units.CELSIUS) @@ -408,13 +415,15 @@ class ThermalGridWithHouseAndStorageSpec ), zeroInflux, ), - Some(HouseTemperatureLowerBoundaryReached(tick)), + Some( + HouseTemperatureLowerBoundaryReached(relevantData.currentTick) + ), ) ) val maybeStorageState = Some( ( ThermalStorageState( - tick, + relevantData.currentTick, KilowattHours(20d), testGridQDotInfeed, ), @@ -442,13 +451,12 @@ class ThermalGridWithHouseAndStorageSpec ) thermalGrid.reviseInfeedFromStorage( - tick, + relevantData, maybeHouseState, maybeStorageState, formerHouseState, formerStorageState, ambientTemperature, - ambientTemperature, zeroInflux, ) match { case ( @@ -465,8 +473,8 @@ class ThermalGridWithHouseAndStorageSpec ) ), ) => - houseTick shouldBe tick - storageTick shouldBe tick + houseTick shouldBe relevantData.currentTick + storageTick shouldBe relevantData.currentTick revisedQDotHouse should approximate(thermalStorage.chargingPower) revisedQDotStorage 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 6b14ee3780..b1c96ca41f 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -7,6 +7,7 @@ package edu.ie3.simona.model.thermal import edu.ie3.datamodel.models.input.thermal.ThermalStorageInput +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalGrid.ThermalGridState import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseState import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{ @@ -74,17 +75,18 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { "determining the energy demand" should { "exactly be the demand of the house" in { - val tick = 10800 // after three hours - val expectedHouseDemand = thermalHouse.energyDemand( - tick, + val relevantData = HpRelevantData( + 10800, // after three hours testGridAmbientTemperature, + ) + val expectedHouseDemand = thermalHouse.energyDemand( + relevantData, expectedHouseStartingState, ) val (houseDemand, storageDemand, updatedThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, ThermalGrid.startingState(thermalGrid), ) @@ -200,12 +202,13 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { } "updating the grid state dependent on the given thermal infeed" should { + val relevantData = HpRelevantData(0, testGridAmbientTemperature) "deliver proper result, if energy is fed into the grid" in { + thermalGrid.updateState( - 0L, + relevantData, ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, - testGridAmbientTemperature, testGridQDotInfeed, ) match { case ( @@ -225,10 +228,9 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { "deliver proper result, if energy is consumed from the grid" in { thermalGrid.updateState( - 0L, + relevantData, ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, - testGridAmbientTemperature, testGridQDotConsumption, ) match { case ( @@ -248,10 +250,9 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { "deliver proper result, if energy is neither consumed from nor fed into the grid" in { thermalGrid.updateState( - 0L, + relevantData, ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, - testGridAmbientTemperature, zeroKW, ) match { case ( 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 ead1ff6b03..e686dfa7f2 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala @@ -10,6 +10,7 @@ import edu.ie3.datamodel.models.input.thermal.{ ThermalHouseInput, ThermalStorageInput, } +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalGrid.ThermalGridState import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageState import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageThreshold.{ @@ -79,12 +80,13 @@ class ThermalGridWithStorageOnlySpec "determining the energy demand" should { "deliver the capabilities of the storage" in { - val tick = 10800 // after three hours - + val relevantData = HpRelevantData( + 10800, // after three hours + testGridAmbientTemperature, + ) val (houseDemand, storageDemand, updatedThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, ThermalGrid.startingState(thermalGrid), ) @@ -100,12 +102,13 @@ class ThermalGridWithStorageOnlySpec } "deliver the capabilities of a half full storage" in { - val tick = 10800 // after three hours - + val relevantData = HpRelevantData( + 10800, // after three hours + testGridAmbientTemperature, + ) val (houseDemand, storageDemand, updatedThermalGridState) = thermalGrid.energyDemandAndUpdatedState( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, ThermalGridState( None, @@ -201,12 +204,12 @@ class ThermalGridWithStorageOnlySpec } "updating the grid state dependent on the given thermal infeed" should { + val relevantData = HpRelevantData(0, testGridAmbientTemperature) "deliver proper result, if energy is fed into the grid" in { val (updatedState, nextThreshold) = thermalGrid.updateState( - 0L, + relevantData, ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, - testGridAmbientTemperature, testGridQDotInfeed, ) @@ -226,7 +229,7 @@ class ThermalGridWithStorageOnlySpec "deliver proper result, if energy is consumed from the grid" in { thermalGrid.updateState( - 0L, + relevantData, ThermalGrid .startingState(thermalGrid) .copy(storageState = @@ -239,7 +242,6 @@ class ThermalGridWithStorageOnlySpec ) ), testGridAmbientTemperature, - testGridAmbientTemperature, testGridQDotConsumptionHigh, ) match { case ( @@ -259,10 +261,9 @@ class ThermalGridWithStorageOnlySpec "deliver proper result, if energy is neither consumed from nor fed into the grid" in { val updatedState = thermalGrid.updateState( - 0L, + relevantData, ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, - testGridAmbientTemperature, zeroKW, ) updatedState match { From 47e38dd01000f11239c2be6b1ae860ab60af256d Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Sun, 24 Nov 2024 11:13:01 +0100 Subject: [PATCH 2/5] fix ThermalHouseSpec --- .../edu/ie3/simona/model/thermal/ThermalHouseSpec.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala index f4a7c97574..4438036f06 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -6,6 +6,7 @@ package edu.ie3.simona.model.thermal +import edu.ie3.simona.model.participant.HpModel.HpRelevantData import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.HouseTemperatureLowerBoundaryReached import edu.ie3.simona.model.thermal.ThermalHouse.{ ThermalHouseState, @@ -71,16 +72,16 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { } "Check for the correct state of house when ambient temperature changes" in { + val ambientTemperature = Temperature(-20, Celsius) + val relevantData = HpRelevantData(3600, ambientTemperature) val house = thermalHouse(18, 22) val initialHousestate = startingState(house) val lastAmbientTemperature = Temperature(15, Celsius) - val ambientTemperature = Temperature(-20, Celsius) val (thermalHouseState, threshold) = house.determineState( - 3600L, + relevantData, initialHousestate, lastAmbientTemperature, - ambientTemperature, zeroKW, ) From 2000e2cc48ecedb31ed5ffc637280fcd8fcecfbf Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Sun, 24 Nov 2024 11:20:35 +0100 Subject: [PATCH 3/5] fix tests --- .../ThermalGridWithHouseAndStorageSpec.scala | 24 ++++++++++++------- .../ThermalGridWithHouseOnlySpec.scala | 24 ++++++++++++------- .../ThermalGridWithStorageOnlySpec.scala | 16 ++++++++----- 3 files changed, 40 insertions(+), 24 deletions(-) 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 19ba70f680..bdd6ba22da 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala @@ -156,7 +156,10 @@ class ThermalGridWithHouseAndStorageSpec ) "return house threshold, if storage is in balance" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val initialGridState = ThermalGrid.startingState(thermalGrid) val initialLoading = KilowattHours(430d) val gridState = initialGridState.copy(storageState = @@ -168,8 +171,7 @@ class ThermalGridWithHouseAndStorageSpec val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, externalQDot, @@ -495,14 +497,16 @@ class ThermalGridWithHouseAndStorageSpec ) "heat the house, if the upper temperature in the house is not reached" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val initialGridState = ThermalGrid.startingState(thermalGrid) val externalQDot = testGridQDotInfeed val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleInfeed( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, initialGridState, externalQDot, @@ -536,7 +540,10 @@ class ThermalGridWithHouseAndStorageSpec } "load the storage, if the upper temperature in the house is reached" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val initialGridState = ThermalGrid.startingState(thermalGrid) val gridState = initialGridState.copy(houseState = initialGridState.houseState.map( @@ -547,8 +554,7 @@ class ThermalGridWithHouseAndStorageSpec val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleInfeed( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, externalQDot, 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 b1c96ca41f..f1593c5d40 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -109,14 +109,16 @@ 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 relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val gridState = ThermalGrid.startingState(thermalGrid) val externalQDot = zeroKW val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, externalQDot, @@ -138,13 +140,15 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { } "not withdraw energy from the house, if actual consumption is given" in { - val tick = 0L // after three hours + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val gridState = ThermalGrid.startingState(thermalGrid) val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, testGridQDotConsumption, @@ -173,13 +177,15 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ) "solely heat up the house" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val gridState = ThermalGrid.startingState(thermalGrid) val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleInfeed( - tick, - testGridAmbientTemperature, + relevantData, testGridAmbientTemperature, gridState, testGridQDotInfeed, 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 e686dfa7f2..8c9357ebba 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala @@ -134,7 +134,10 @@ class ThermalGridWithStorageOnlySpec ) "properly take the energy from storage" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val gridState = ThermalGrid .startingState(thermalGrid) .copy(storageState = @@ -149,8 +152,7 @@ class ThermalGridWithStorageOnlySpec val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( - tick, - testGridAmbientTemperature, +relevantData, testGridAmbientTemperature, gridState, testGridQDotConsumptionHigh, @@ -177,13 +179,15 @@ class ThermalGridWithStorageOnlySpec ) "properly put energy to storage" in { - val tick = 0L + val relevantData = HpRelevantData( + 0L, + testGridAmbientTemperature, + ) val gridState = ThermalGrid.startingState(thermalGrid) val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleInfeed( - tick, - testGridAmbientTemperature, +relevantData, testGridAmbientTemperature, gridState, testGridQDotInfeed, From bb0763357815d7968f1d2ebbc5678f03d0b52c51 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Sun, 24 Nov 2024 11:20:46 +0100 Subject: [PATCH 4/5] fmt --- .../simona/model/thermal/ThermalGridWithStorageOnlySpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 8c9357ebba..79f9f82ad9 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala @@ -152,7 +152,7 @@ class ThermalGridWithStorageOnlySpec val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( -relevantData, + relevantData, testGridAmbientTemperature, gridState, testGridQDotConsumptionHigh, @@ -187,7 +187,7 @@ relevantData, val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleInfeed( -relevantData, + relevantData, testGridAmbientTemperature, gridState, testGridQDotInfeed, From 511add9d92e2e67519cf0a781bc88aa8a857579d Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Mon, 25 Nov 2024 14:22:10 +0100 Subject: [PATCH 5/5] fix after merge conflicts --- .../scala/edu/ie3/simona/model/thermal/ThermalGrid.scala | 4 +++- .../simona/model/thermal/ThermalGridWithHouseOnlySpec.scala | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) 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 2c3a6f4cc4..2e6e684947 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala @@ -67,7 +67,9 @@ final case class ThermalGrid( thermalHouse.determineState( relevantData, lastHouseState, - lastAmbientTemperature, + lastHpState.ambientTemperature.getOrElse( + relevantData.ambientTemperature + ), lastHouseState.qDot, ) if ( 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 44ae8caa95..d1e00e1c8d 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -88,10 +88,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ThermalGrid.startingState(thermalGrid), None, ) - val expectedHouseDemand = thermalHouse.energyDemand( - relevantData.currentTick, - testGridAmbientTemperature, - ) + val expectedHouseDemand = thermalHouse.energyDemand( relevantData, expectedHouseStartingState,