Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into df/#856-tap-water
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
danielfeismann committed Sep 17, 2024
2 parents eca2902 + 87836de commit f915164
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 123 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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)
- Prepare ThermalStorageTestData for Storage without storageVolumeLvlMin [#894](https://github.com/ie3-institute/simona/issues/894)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
102 changes: 12 additions & 90 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -409,100 +409,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

/** 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
val energyChange = 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
// temperature change calculated from energy change(WattHours) and thermal capacity(Joules per Kelvin)
val temperatureChange = energyChange / ethCapa

/** 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
Expand Down Expand Up @@ -568,7 +490,7 @@ final case class ThermalHouse(
ambientTemperature: Temperature,
): Option[ThermalThreshold] = {
val artificialDuration = Hours(1d)
val loss = calcThermalEnergyLoss(
val loss = ethLosses.calcThermalEnergyChange(
innerTemperature,
ambientTemperature,
artificialDuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class ThermalConductance private (
* Time duration
* @return
*/
def thermalConductanceToEnergy(
def calcThermalEnergyChange(
temperatureInner: Temperature,
temperatureOuter: Temperature,
time: squants.Time,
Expand Down
29 changes: 0 additions & 29 deletions src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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),
) should be(KilowattHours(50d))
}

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),
Expand Down

0 comments on commit f915164

Please sign in to comment.