Skip to content

Commit

Permalink
fixing HpModel to comply with integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Feb 16, 2025
1 parent fd4b0b3 commit b4c2389
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
38 changes: 30 additions & 8 deletions src/main/scala/edu/ie3/simona/model/participant/HpModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import edu.ie3.simona.model.thermal.ThermalGrid.{
ThermalDemandWrapper,
ThermalGridState,
}
import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageState
import edu.ie3.simona.model.thermal.{ThermalGrid, ThermalThreshold}
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptions
import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions
Expand Down Expand Up @@ -150,7 +151,14 @@ final case class HpModel(

// Updating the HpState
val updatedHpState =
calcState(lastHpState, relevantData, turnOn, false, thermalDemandWrapper)
calcState(
lastHpState,
relevantData,
turnOn,
false,
thermalDemandWrapper,
currentThermalGridState,
)
(canOperate, canBeOutOfOperation, updatedHpState)
}

Expand Down Expand Up @@ -227,24 +235,37 @@ final case class HpModel(
isRunning: Boolean,
useUpperTempBoundaryForFlexibility: Boolean,
demandWrapper: ThermalDemandWrapper,
currentThermalGridState: ThermalGridState,
): HpState = {
val lastStateStorageQDot = lastState.thermalGridState.storageState
.map(_.qDot)
.getOrElse(zeroKW)
val lastStateStorage = lastState.thermalGridState.storageState
// Todo: Maybe throw exception would be a better option here?
.getOrElse(ThermalStorageState(-1, zeroKWh, zeroKW))

val currentEnergyOfThermalStorage = currentThermalGridState.storageState
.map(_.storedEnergy)
.getOrElse(zeroKWh)

val (newActivePowerHp, newThermalPowerHp, qDotIntoGrid) = {
if (isRunning)
(pRated, pThermal, pThermal)
else if (lastStateStorageQDot < zeroKW)
(zeroKW, zeroKW, lastStateStorageQDot * (-1))
// If the house has required demand and storage isn't empty, we can heat the house from storage.
else if (
lastStateStorageQDot == zeroKW && (demandWrapper.houseDemand.hasRequiredDemand || demandWrapper.heatStorageDemand.hasRequiredDemand)
currentEnergyOfThermalStorage > zeroKWh && demandWrapper.houseDemand.hasRequiredDemand
)
(
zeroKW,
zeroKW,
thermalGrid.storage.map(_.getChargingPower: squants.Power).get,
)
// If the house has any demand, was heated from storage in last state and storage isn't empty, we can continue heating the house from storage.
else if (
currentEnergyOfThermalStorage > zeroKWh && lastStateStorage.qDot < zeroKW && demandWrapper.houseDemand.hasAdditionalDemand
)
(
zeroKW,
zeroKW,
lastStateStorage.qDot * -1,
)
else (zeroKW, zeroKW, zeroKW)
}

Expand Down Expand Up @@ -329,7 +350,7 @@ final case class HpModel(

val (
thermalDemandWrapper,
_,
updatedThermalGridState,
) =
thermalGrid.energyDemandAndUpdatedState(
relevantData,
Expand All @@ -343,6 +364,7 @@ final case class HpModel(
turnOn,
useUpperTempBoundaryForFlexibility,
thermalDemandWrapper,
updatedThermalGridState,
)

(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class ThermalGridIT
scheduler.expectMessage(Completion(heatPumpAgent, Some(21600)))

/* TICK 21600
House would reach lowerTempBoundary at tick 50797
House would reach lowerTempBoundary at tick 50797,
but now it's getting colder which should decrease inner temp of house faster
House demand heating : requiredDemand = 0.0 kWh, possibleDemand = 11.9 kWh
ThermalStorage : requiredDemand = 0.0 kWh, possibleDemand = 0.0 kWh
Expand Down

0 comments on commit b4c2389

Please sign in to comment.