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 19, 2024
2 parents 9c1334a + bf68de1 commit a45a7b1
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix determineState of ThermalHouse [#926](https://github.com/ie3-institute/simona/issues/926)
- Fix activation of Hp when not under control of an EM [#922](https://github.com/ie3-institute/simona/issues/922)
- Fix expected secondaryData in baseStateData [#955](https://github.com/ie3-institute/simona/issues/955)
- Improve code quality in fixedloadmodelspec and other tests [#919](https://github.com/ie3-institute/simona/issues/919)
- Fix power flow calculation with em agents [#962](https://github.com/ie3-institute/simona/issues/962)
- Fixed Hp results leading to overheating house and other effects [#827](https://github.com/ie3-institute/simona/issues/827)
- Fixed thermal storage getting recharged when empty [#827](https://github.com/ie3-institute/simona/issues/827)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ protected trait ParticipantAgentFundamentals[
nextActivation,
)

unstashAll()
stay() using stateDataFinal
}

Expand Down
36 changes: 19 additions & 17 deletions src/test/scala/edu/ie3/simona/model/grid/SystemComponentSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class SystemComponentSpec extends UnitSpec with DefaultTestData {
val simulationEnd: ZonedDateTime =
TimeUtil.withDefaults.toZonedDateTime("2019-01-02T00:00:00Z")

val testCases = Seq(
val testCases = Table(
("operationStart", "operationEnd", "expectedInterval"),
(
Some(TimeUtil.withDefaults.toZonedDateTime("2019-01-01T00:00:00Z")),
Some(TimeUtil.withDefaults.toZonedDateTime("2019-01-02T00:00:00Z")),
Expand Down Expand Up @@ -103,22 +104,23 @@ class SystemComponentSpec extends UnitSpec with DefaultTestData {
),
)

for ((operationStart, operationEnd, expected) <- testCases) {
val operationTimeBuilder = setup()

operationStart.foreach(operationTimeBuilder.withStart)
operationEnd.foreach(operationTimeBuilder.withEnd)

val operationTime: OperationTime = operationTimeBuilder.build()

val interval: OperationInterval =
SystemComponent.determineOperationInterval(
defaultSimulationStart,
simulationEnd,
operationTime,
)

interval should be(expected)
forAll(testCases) {
(
operationStart: Option[ZonedDateTime],
operationEnd: Option[ZonedDateTime],
expected: OperationInterval,
) =>
val operationTimeBuilder = setup()
operationStart.foreach(operationTimeBuilder.withStart)
operationEnd.foreach(operationTimeBuilder.withEnd)
val operationTime: OperationTime = operationTimeBuilder.build()
val interval: OperationInterval =
SystemComponent.determineOperationInterval(
defaultSimulationStart,
simulationEnd,
operationTime,
)
interval should be(expected)
}
}

Expand Down
76 changes: 47 additions & 29 deletions src/test/scala/edu/ie3/simona/model/participant/WecModelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,38 +104,54 @@ class WecModelSpec extends UnitSpec with DefaultTestData {

"determine Betz coefficient correctly" in {
val wecModel = buildWecModel()
val velocities = Seq(2.0, 2.5, 18.0, 27.0, 34.0, 40.0)
val expectedBetzResults = Seq(0.115933516, 0.2010945555, 0.108671106,
0.032198846, 0.000196644, 0.0)
velocities.zip(expectedBetzResults).foreach {
case (velocity, betzResult) =>
val windVel = MetersPerSecond(velocity)
val betzFactor = wecModel.determineBetzCoefficient(windVel)
val expected = Each(betzResult)
betzFactor shouldEqual expected

val testCases = Table(
("velocity", "expectedBetzResult"),
(2.0, 0.115933516),
(2.5, 0.2010945555),
(18.0, 0.108671106),
(27.0, 0.032198846),
(34.0, 0.000196644),
(40.0, 0.0),
)

forAll(testCases) { case (velocity: Double, expectedBetzResult: Double) =>
val windVel = MetersPerSecond(velocity)
val betzFactor = wecModel.determineBetzCoefficient(windVel)

betzFactor shouldEqual Each(expectedBetzResult)
}
}

"calculate active power output depending on velocity" in {
val wecModel = buildWecModel()
val velocities =
Seq(1.0, 2.0, 3.0, 7.0, 9.0, 13.0, 15.0, 19.0, 23.0, 27.0, 34.0, 40.0)
val expectedPowers =
Seq(0, -2948.8095851378266, -24573.41320418286, -522922.2325710509,
-1140000, -1140000, -1140000, -1140000, -1140000, -1140000,
-24573.39638823692, 0)

velocities.zip(expectedPowers).foreach { case (velocity, power) =>
val wecData = new WecRelevantData(
val testCases = Table(
("velocity", "expectedPower"),
(1.0, 0.0),
(2.0, -2948.8095851378266),
(3.0, -24573.41320418286),
(7.0, -522922.2325710509),
(9.0, -1140000.0),
(13.0, -1140000.0),
(15.0, -1140000.0),
(19.0, -1140000.0),
(23.0, -1140000.0),
(27.0, -1140000.0),
(34.0, -24573.39638823692),
(40.0, 0.0),
)

forAll(testCases) { (velocity: Double, expectedPower: Double) =>
val wecData = WecRelevantData(
MetersPerSecond(velocity),
Celsius(20),
Some(Pascals(101325d)),
)
val result =
wecModel.calculateActivePower(ModelState.ConstantState, wecData)
val expectedPower = Watts(power)
val expectedPowerInWatts = Watts(expectedPower)

result should be(expectedPower)
result should be(expectedPowerInWatts)
}
}

Expand Down Expand Up @@ -170,21 +186,23 @@ class WecModelSpec extends UnitSpec with DefaultTestData {

"calculate active power output depending on temperature" in {
val wecModel = buildWecModel()
val temperatures = Seq(35.0, 20.0, -25.0)
val expectedPowers =
Seq(-23377.23862017266, -24573.41320418286, -29029.60338829823)
val testCases = Table(
("temperature", "expectedPower"),
(35.0, -23377.23862017266),
(20.0, -24573.41320418286),
(-25.0, -29029.60338829823),
)

temperatures.zip(expectedPowers).foreach { case (temperature, power) =>
val wecData = new WecRelevantData(
forAll(testCases) { (temperature: Double, expectedPower: Double) =>
val wecData = WecRelevantData(
MetersPerSecond(3.0),
Celsius(temperature),
Some(Pascals(101325d)),
)
val result = {
val result =
wecModel.calculateActivePower(ModelState.ConstantState, wecData)
}
val expectedPower = Watts(power)
result shouldBe expectedPower
val expectedPowerInWatts = Watts(expectedPower)
result shouldBe expectedPowerInWatts
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,12 @@ class FixedLoadModelSpec
reference,
)

for (_ <- 0 until 10000) {
(1 to 10000).foreach { _ =>
val calculatedPower = dut
.calculateActivePower(
ModelState.ConstantState,
FixedLoadModel.FixedLoadRelevantData,
)

calculatedPower should approximate(expectedPower)
}
}
Expand All @@ -116,8 +115,10 @@ class FixedLoadModelSpec
forAll(testData) { (reference, expectedPower: Power) =>
val relevantData = FixedLoadModel.FixedLoadRelevantData

var scale = 0.0
while (scale <= 2) {
val scales: LazyList[Double] =
LazyList.iterate(0.0)(_ + 0.1).takeWhile(_ <= 2.0)

scales.foreach { scale =>
val scaledSRated = Kilowatts(
loadInput.getsRated
.to(PowerSystemUnits.KILOWATT)
Expand All @@ -142,8 +143,6 @@ class FixedLoadModelSpec
val expectedScaledPower = expectedPower * scale

calculatedPower should approximate(expectedScaledPower)

scale += 0.1
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData {
(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
forAll(testCases) {
(innerTemperature: Double, isTooHigh: Boolean, isTooLow: Boolean) =>
val innerTemp = Temperature(innerTemperature, Celsius)
val isHigher = thermalHouseTest.isInnerTemperatureTooHigh(innerTemp)
val isLower = thermalHouseTest.isInnerTemperatureTooLow(innerTemp)

isHigher shouldBe isTooHigh
isLower shouldBe isTooLow
}
}

Expand Down

0 comments on commit a45a7b1

Please sign in to comment.