From 6a421448b421be6040cf4961e28cd36f46fe05a7 Mon Sep 17 00:00:00 2001 From: marvinheintze Date: Mon, 9 Sep 2024 16:05:40 +0200 Subject: [PATCH 1/4] Changed methods to values: calcNewTemperatureChange, calcInnerTemperatureChange, calcThermalEnergyChange and calcThermalEnergyGain --- .../simona/model/thermal/ThermalHouse.scala | 100 ++---------------- .../scala/quantities/ThermalConductance.scala | 2 +- .../model/thermal/ThermalHouseSpec.scala | 21 ++-- .../quantities/ThermalConductanceSpec.scala | 4 +- 4 files changed, 20 insertions(+), 107 deletions(-) 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..ac6b56a4c1 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -199,101 +199,19 @@ final case class ThermalHouse( currentInnerTemperature: Temperature, ambientTemperature: Temperature, ): Temperature = { - val thermalEnergyChange = calcThermalEnergyChange( - calcThermalEnergyGain(thermalPower, duration), - calcThermalEnergyLoss( - currentInnerTemperature, - ambientTemperature, - duration, - ), - ) - calcNewInnerTemperature( + val thermalEnergyGain = thermalPower * duration + + 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 temperatureChange = (thermalEnergyGain - thermalEnergyLoss) / ethCapa - /** 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 + currentInnerTemperature + temperatureChange } - /** 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 - - /** 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, - ) - } /** Update the current state of the house * @@ -358,11 +276,11 @@ final case class ThermalHouse( ambientTemperature: Temperature, ): Option[ThermalThreshold] = { val artificialDuration = Hours(1d) - val loss = calcThermalEnergyLoss( + val loss = ethLosses.calcThermalEnergyChange( innerTemperature, ambientTemperature, artificialDuration, - ) / artificialDuration + ) / artificialDuration val resultingQDot = qDotExternal - loss if ( resultingQDot < zeroMW && !isInnerTemperatureTooLow( 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..8422061cdc 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -56,23 +56,18 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { val thermalHouseTest = thermalHouse(18, 22) val innerTemperature = Temperature(20, Celsius) - val thermalEnergyGain = - thermalHouseTest.calcThermalEnergyGain(Kilowatts(100), Seconds(3600)) - val thermalEnergyLoss = thermalHouseTest.calcThermalEnergyLoss( + val thermalEnergyGain = KilowattHours(100) + val thermalEnergyLoss = thermalHouseTest.ethLosses.calcThermalEnergyChange( innerTemperature, Temperature(10, Celsius), Seconds(3600), ) - val thermalEnergyChange = thermalHouseTest.calcThermalEnergyChange( - thermalEnergyGain, - thermalEnergyLoss, - ) - val innerTemperatureChange = - thermalHouseTest.calcInnerTemperatureChange(thermalEnergyChange) - val newInnerTemperature = thermalHouseTest.calcNewInnerTemperature( - innerTemperature, - innerTemperatureChange, - ) + val thermalEnergyChange = thermalEnergyGain - thermalEnergyLoss + + val innerTemperatureChange = thermalEnergyChange/thermalHouseTest.ethCapa + + val newInnerTemperature = innerTemperature + innerTemperatureChange + thermalEnergyGain should approximate(KilowattHours(100)) thermalEnergyLoss should approximate(KilowattHours(10)) 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), From 25d2d35b7265852f2c60c959fd6ef219eb3b6dff Mon Sep 17 00:00:00 2001 From: marvinheintze Date: Tue, 10 Sep 2024 13:19:08 +0200 Subject: [PATCH 2/4] spotlessApply changes --- .../ie3/simona/model/thermal/ThermalHouse.scala | 3 +-- .../simona/model/thermal/ThermalHouseSpec.scala | 15 ++++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) 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 ac6b56a4c1..afc49ad5b3 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -212,7 +212,6 @@ final case class ThermalHouse( currentInnerTemperature + temperatureChange } - /** Update the current state of the house * * @param tick @@ -280,7 +279,7 @@ final case class ThermalHouse( innerTemperature, ambientTemperature, artificialDuration, - ) / artificialDuration + ) / artificialDuration val resultingQDot = qDotExternal - loss if ( resultingQDot < zeroMW && !isInnerTemperatureTooLow( 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 8422061cdc..7178db116b 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -57,18 +57,19 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { val innerTemperature = Temperature(20, Celsius) val thermalEnergyGain = KilowattHours(100) - val thermalEnergyLoss = thermalHouseTest.ethLosses.calcThermalEnergyChange( - innerTemperature, - Temperature(10, Celsius), - Seconds(3600), - ) + val thermalEnergyLoss = + thermalHouseTest.ethLosses.calcThermalEnergyChange( + innerTemperature, + Temperature(10, Celsius), + Seconds(3600), + ) val thermalEnergyChange = thermalEnergyGain - thermalEnergyLoss - val innerTemperatureChange = thermalEnergyChange/thermalHouseTest.ethCapa + val innerTemperatureChange = + thermalEnergyChange / thermalHouseTest.ethCapa val newInnerTemperature = innerTemperature + innerTemperatureChange - thermalEnergyGain should approximate(KilowattHours(100)) thermalEnergyLoss should approximate(KilowattHours(10)) thermalEnergyChange should approximate(KilowattHours(90)) From 6bc4ea82c40f277b3829ba39dbc7d1e80da29cdd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:19:50 +0000 Subject: [PATCH 3/4] Bump pekkoVersion from 1.1.0 to 1.1.1 (#957) --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index e1120357b7..b47bc21820 100644 --- a/build.gradle +++ b/build.gradle @@ -26,7 +26,7 @@ ext { scalaVersion = '2.13' scalaBinaryVersion = '2.13.14' - pekkoVersion = '1.1.0' + pekkoVersion = '1.1.1' jtsVersion = '1.20.0' confluentKafkaVersion = '7.4.0' tscfgVersion = '1.1.3' From 5c5c7a4f3a7d7ff4500e1b88ef7005d2fe281f8f Mon Sep 17 00:00:00 2001 From: marvinheintze Date: Mon, 16 Sep 2024 19:23:24 +0200 Subject: [PATCH 4/4] ThermalHouse tests and comments added, Changelog update --- CHANGELOG.md | 1 + .../simona/model/thermal/ThermalHouse.scala | 7 +++++- .../model/thermal/ThermalHouseSpec.scala | 25 ------------------- 3 files changed, 7 insertions(+), 26 deletions(-) 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 afc49ad5b3..71e992c4e0 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -201,14 +201,19 @@ final case class ThermalHouse( ): Temperature = { val thermalEnergyGain = thermalPower * duration + // thermal energy loss due to the deviation between outside and inside temperature val thermalEnergyLoss = ethLosses.calcThermalEnergyChange( currentInnerTemperature, ambientTemperature, duration, ) - val temperatureChange = (thermalEnergyGain - thermalEnergyLoss) / ethCapa + val energyChange = thermalEnergyGain - thermalEnergyLoss + // temperature change calculated from energy change(WattHours) and thermal capacity(Joules per Kelvin) + val temperatureChange = energyChange / ethCapa + + // return value new inner temperature currentInnerTemperature + temperatureChange } 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 7178db116b..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,31 +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 = KilowattHours(100) - val thermalEnergyLoss = - thermalHouseTest.ethLosses.calcThermalEnergyChange( - innerTemperature, - Temperature(10, Celsius), - Seconds(3600), - ) - val thermalEnergyChange = thermalEnergyGain - thermalEnergyLoss - - val innerTemperatureChange = - thermalEnergyChange / thermalHouseTest.ethCapa - - val newInnerTemperature = 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)