diff --git a/CHANGELOG.md b/CHANGELOG.md index c4030aa839..681b04b5dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated AUTHORS.md [#905](https://github.com/ie3-institute/simona/issues/905) - Rewrote BMModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Refactoring EM messages [#947](https://github.com/ie3-institute/simona/issues/947) +- Simplifying ThermalHouse [#940](https://github.com/ie3-institute/simona/issues/940) ### Fixed - Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658) 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 547a639d08..71e992c4e0 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -199,100 +199,22 @@ final case class ThermalHouse( currentInnerTemperature: Temperature, ambientTemperature: Temperature, ): Temperature = { - val thermalEnergyChange = calcThermalEnergyChange( - calcThermalEnergyGain(thermalPower, duration), - calcThermalEnergyLoss( - currentInnerTemperature, - ambientTemperature, - duration, - ), - ) - calcNewInnerTemperature( + val thermalEnergyGain = thermalPower * duration + + // thermal energy loss due to the deviation between outside and inside temperature + val thermalEnergyLoss = ethLosses.calcThermalEnergyChange( currentInnerTemperature, - calcInnerTemperatureChange(thermalEnergyChange), + ambientTemperature, + duration, ) - } - /** Calculate the new inner temperature of the thermal house - * - * @param oldInnerTemperature - * previous inner temperature - * @param temperatureChange - * temperature change - * @return - * new inner temperature - */ - def calcNewInnerTemperature( - oldInnerTemperature: Temperature, - temperatureChange: Temperature, - ): Temperature = - oldInnerTemperature + temperatureChange + val energyChange = thermalEnergyGain - thermalEnergyLoss - /** Calculate the temperature change for the thermal house form the thermal - * energy change - * - * @param thermalEnergyChange - * thermal energy change (e.g. through heat pump) - * @return - * temperature change - */ - def calcInnerTemperatureChange( - thermalEnergyChange: Energy - ): Temperature = { - thermalEnergyChange / ethCapa - } - - /** Calculate the thermal energy change combining the added and lost energy - * - * @param thermalEnergyGain - * thermal energy added - * @param thermalEnergyLoss - * thermal energy lost - * @return - * thermal energy change - */ - def calcThermalEnergyChange( - thermalEnergyGain: Energy, - thermalEnergyLoss: Energy, - ): Energy = - thermalEnergyGain - thermalEnergyLoss + // temperature change calculated from energy change(WattHours) and thermal capacity(Joules per Kelvin) + val temperatureChange = energyChange / ethCapa - /** Calculate the thermal energy gain, e.g. due to a running heat pump - * - * @param pThermal - * added thermal power (e.g. of heat pump) - * @param time - * time step length in which thermal power is added - * @return - * resulting thermal energy gain - */ - def calcThermalEnergyGain( - pThermal: Power, - time: Time, - ): Energy = pThermal * time - - /** Calculate the thermal energy loss due to the temperature deviation over - * the time step - * - * @param innerTemperature - * previous inner temperature - * @param ambientTemperature - * ambient temperature of thermal house - * @param time - * time step length - * @return - * resulting thermal energy loss - */ - def calcThermalEnergyLoss( - innerTemperature: Temperature, - ambientTemperature: Temperature, - time: Time, - ): Energy = { - ethLosses.thermalConductanceToEnergy( - innerTemperature, - ambientTemperature, - time, - ) + // return value new inner temperature + currentInnerTemperature + temperatureChange } /** Update the current state of the house @@ -358,7 +280,7 @@ final case class ThermalHouse( ambientTemperature: Temperature, ): Option[ThermalThreshold] = { val artificialDuration = Hours(1d) - val loss = calcThermalEnergyLoss( + val loss = ethLosses.calcThermalEnergyChange( innerTemperature, ambientTemperature, artificialDuration, diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ThermalConductance.scala b/src/main/scala/edu/ie3/util/scala/quantities/ThermalConductance.scala index ce8f9d4293..a5fa7648c4 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/ThermalConductance.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/ThermalConductance.scala @@ -33,7 +33,7 @@ final class ThermalConductance private ( * Time duration * @return */ - def thermalConductanceToEnergy( + def calcThermalEnergyChange( temperatureInner: Temperature, temperatureOuter: Temperature, time: squants.Time, 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 20131046bf..0a967553e2 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -52,35 +52,6 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { } } - "Calculation of thermal energy change and new inner temperature is performed correctly" in { - val thermalHouseTest = thermalHouse(18, 22) - val innerTemperature = Temperature(20, Celsius) - - val thermalEnergyGain = - thermalHouseTest.calcThermalEnergyGain(Kilowatts(100), Seconds(3600)) - val thermalEnergyLoss = thermalHouseTest.calcThermalEnergyLoss( - innerTemperature, - Temperature(10, Celsius), - Seconds(3600), - ) - val thermalEnergyChange = thermalHouseTest.calcThermalEnergyChange( - thermalEnergyGain, - thermalEnergyLoss, - ) - val innerTemperatureChange = - thermalHouseTest.calcInnerTemperatureChange(thermalEnergyChange) - val newInnerTemperature = thermalHouseTest.calcNewInnerTemperature( - innerTemperature, - innerTemperatureChange, - ) - - thermalEnergyGain should approximate(KilowattHours(100)) - thermalEnergyLoss should approximate(KilowattHours(10)) - thermalEnergyChange should approximate(KilowattHours(90)) - innerTemperatureChange should approximate(Kelvin(9.0)) - newInnerTemperature should approximate(Celsius(29.0)) - } - "Comprising function to calculate new inner temperature works as expected" in { val thermalHouseTest = thermalHouse(18, 22) val thermalPower = Kilowatts(100) diff --git a/src/test/scala/edu/ie3/util/quantities/ThermalConductanceSpec.scala b/src/test/scala/edu/ie3/util/quantities/ThermalConductanceSpec.scala index 7b71137d69..9b54c25a81 100644 --- a/src/test/scala/edu/ie3/util/quantities/ThermalConductanceSpec.scala +++ b/src/test/scala/edu/ie3/util/quantities/ThermalConductanceSpec.scala @@ -33,7 +33,7 @@ class ThermalConductanceSpec extends AnyFlatSpec with Matchers { } it should "return Energy when multiplied by Temperature in Kelvin and Time" in { - WattsPerKelvin(1000).thermalConductanceToEnergy( + WattsPerKelvin(1000).calcThermalEnergyChange( Kelvin(10), Kelvin(0), Hours(5), @@ -41,7 +41,7 @@ class ThermalConductanceSpec extends AnyFlatSpec with Matchers { } it should "return Energy when multiplied by Temperature in Celsius and Time" in { - WattsPerKelvin(1000).thermalConductanceToEnergy( + WattsPerKelvin(1000).calcThermalEnergyChange( Celsius(10), Celsius(0), Hours(5),