Skip to content

Commit

Permalink
Merge pull request #877 from ie3-institute/pp/#646-thermal-convert-gr…
Browse files Browse the repository at this point in the history
…oovy-tests-to-scalatest-remove-groovy

Rewrote ThermalHouseTest from groovy to scala
  • Loading branch information
danielfeismann authored Aug 12, 2024
2 parents 2268691 + 6e4ae75 commit 24100a7
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 136 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rewrote SystemComponentTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)
- Converting remaining rst files to markdown [#838](https://github.com/ie3-institute/simona/issues/838)
- Merging both `FixedFeedInModelSpec` tests [#870](https://github.com/ie3-institute/simona/issues/870)
- Rewrote ThermalHouseTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)
- Updated dependabot reviewers [#888](https://github.com/ie3-institute/simona/issues/888)
- Merged `HpModelTestData` with `HpTestData` to `HpInputTestData` [#872](https://github.com/ie3-institute/simona/issues/872)

Expand Down
12 changes: 6 additions & 6 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ final case class ThermalHouse(
* @return
* new inner temperature
*/
private def newInnerTemperature(
def newInnerTemperature(
thermalPower: Power,
duration: Time,
currentInnerTemperature: Temperature,
Expand Down Expand Up @@ -221,7 +221,7 @@ final case class ThermalHouse(
* @return
* new inner temperature
*/
private def calcNewInnerTemperature(
def calcNewInnerTemperature(
oldInnerTemperature: Temperature,
temperatureChange: Temperature,
): Temperature =
Expand All @@ -235,7 +235,7 @@ final case class ThermalHouse(
* @return
* temperature change
*/
private def calcInnerTemperatureChange(
def calcInnerTemperatureChange(
thermalEnergyChange: Energy
): Temperature = {
thermalEnergyChange / ethCapa
Expand All @@ -250,7 +250,7 @@ final case class ThermalHouse(
* @return
* thermal energy change
*/
private def calcThermalEnergyChange(
def calcThermalEnergyChange(
thermalEnergyGain: Energy,
thermalEnergyLoss: Energy,
): Energy =
Expand All @@ -265,7 +265,7 @@ final case class ThermalHouse(
* @return
* resulting thermal energy gain
*/
private def calcThermalEnergyGain(
def calcThermalEnergyGain(
pThermal: Power,
time: Time,
): Energy = pThermal * time
Expand All @@ -282,7 +282,7 @@ final case class ThermalHouse(
* @return
* resulting thermal energy loss
*/
private def calcThermalEnergyLoss(
def calcThermalEnergyLoss(
innerTemperature: Temperature,
ambientTemperature: Temperature,
time: Time,
Expand Down
129 changes: 0 additions & 129 deletions src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy

This file was deleted.

123 changes: 123 additions & 0 deletions src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

package edu.ie3.simona.model.thermal

import edu.ie3.simona.test.common.UnitSpec
import edu.ie3.simona.test.common.input.HpInputTestData
import edu.ie3.util.scala.quantities.WattsPerKelvin
import org.scalatest.prop.TableFor3
import squants.energy._
import squants.thermal._
import squants.time._
import squants.{Energy, Temperature}

class ThermalHouseSpec extends UnitSpec with HpInputTestData {

implicit val tolerance: Temperature = Celsius(1e-4)
implicit val energyTolerance: Energy = KilowattHours(1e-4)

"ThermalHouse" should {
"Functions testing inner temperature work as expected" in {

val thermalHouseTest = thermalHouse(18, 22)

val testCases: TableFor3[Double, Boolean, Boolean] = Table(
("Inner Temperature (C)", "Is Too High", "Is Too Low"),
(17d, false, true),
(17.98d, false, true),
(18d, false, true),
(20d, false, false),
(22d, true, false),
(22.02d, true, false),
(23d, true, false),
)

testCases.foreach { case (innerTemperature, isTooHigh, isTooLow) =>
val innerTemp = Temperature(innerTemperature, Celsius)
val isHigher = thermalHouseTest.isInnerTemperatureTooHigh(innerTemp)
val isLower = thermalHouseTest.isInnerTemperatureTooLow(innerTemp)

isHigher shouldBe isTooHigh
isLower shouldBe isTooLow
}
}

"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)
val duration = Seconds(3600)
val currentInnerTemperature = Temperature(20, Celsius)
val ambientTemperature = Temperature(10, Celsius)

val newInnerTemperature = thermalHouseTest.newInnerTemperature(
thermalPower,
duration,
currentInnerTemperature,
ambientTemperature,
)

newInnerTemperature should approximate(Temperature(29, Celsius))
}

"Check build method" in {

val thermalTestHouse = thermalHouse(18, 22)
val thermalHouseInput = defaultThermalHouse

thermalTestHouse.id shouldBe thermalHouseInput.getId
thermalTestHouse.operatorInput shouldBe thermalHouseInput.getOperator
thermalTestHouse.operationTime shouldBe thermalHouseInput.getOperationTime
thermalTestHouse.bus shouldBe null
thermalTestHouse.ethLosses shouldBe WattsPerKelvin(1000.0)
(thermalTestHouse.ethCapa * Temperature(
1,
Kelvin,
)) shouldBe KilowattHours(10.0)
thermalTestHouse.lowerBoundaryTemperature should approximate(
Temperature(
18,
Celsius,
)
)
thermalTestHouse.upperBoundaryTemperature should approximate(
Temperature(
22,
Celsius,
)
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ trait HpInputTestData extends NodeInputTestData with ThermalGridTestData {
)
protected val defaultThermalHouse = new ThermalHouseInput(
UUID.fromString("91940626-bdd0-41cf-96dd-47c94c86b20e"),
"thermal house",
"Thermal house",
thermalBusInput,
Quantities.getQuantity(0.325, StandardUnits.THERMAL_TRANSMISSION),
Quantities.getQuantity(75, StandardUnits.HEAT_CAPACITY),
Expand Down

0 comments on commit 24100a7

Please sign in to comment.