Skip to content

Commit

Permalink
fix after merging dev
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfeismann committed Nov 26, 2024
1 parent 88c6e3a commit be3b094
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,14 @@ final case class ThermalGrid(
qDot: Power,
thermalDemands: ThermalDemandWrapper,
): (ThermalGridState, Option[ThermalThreshold]) = if (qDot > zeroKW)
handleInfeed(relevantData, lastAmbientTemperature, state, isRunning, qDot, thermalDemands)
handleInfeed(
relevantData,
lastAmbientTemperature,
state,
isRunning,
qDot,
thermalDemands,
)
else
handleConsumption(
relevantData,
Expand Down Expand Up @@ -223,9 +230,8 @@ final case class ThermalGrid(
) {
val (updatedHouseState, thermalHouseThreshold, remainingQDotHouse) =
handleInfeedHouse(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDotHouseLastState,
)
Expand All @@ -234,13 +240,13 @@ final case class ThermalGrid(
qDotStorageLastState >= zeroKW && remainingQDotHouse > qDotStorageLastState
) {
handleInfeedStorage(
tick,
relevantData.currentTick,
state,
remainingQDotHouse,
)
} else {
handleInfeedStorage(
tick,
relevantData.currentTick,
state,
qDotStorageLastState,
)
Expand All @@ -262,19 +268,17 @@ final case class ThermalGrid(
else if (qDotHouseLastState > zeroKW && qDotStorageLastState < zeroKW) {
if (isRunning) {
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDot,
zeroKW,
)
} else {

handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDotHouseLastState,
qDotStorageLastState,
Expand All @@ -284,19 +288,17 @@ final case class ThermalGrid(
// Handle edge case where house should be heated from storage
else if (!isRunning && qDot > zeroKW) {
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDot,
-qDot,
)
} else
handleFinaleInfeedCases(
thermalDemands,
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDot,
)
Expand Down Expand Up @@ -335,9 +337,8 @@ final case class ThermalGrid(
*/
private def handleFinaleInfeedCases(
thermalDemands: ThermalDemandWrapper,
tick: Long,
relevantData: HpRelevantData,
lastAmbientTemperature: Temperature,
ambientTemperature: Temperature,
state: ThermalGridState,
qDot: Power,
): (ThermalGridState, Option[ThermalThreshold]) = {
Expand All @@ -351,49 +352,44 @@ final case class ThermalGrid(
case (true, _, _, _) =>
// house first then heatStorage after heating House
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDot,
zeroKW,
)

case (_, _, true, _) =>
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
zeroKW,
qDot,
)

case (false, _, false, true) =>
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
zeroKW,
qDot,
)

case (_, true, false, false) =>
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDot,
zeroKW,
)

case (false, false, false, false) =>
handleCases(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
zeroKW,
zeroKW,
Expand All @@ -408,12 +404,10 @@ final case class ThermalGrid(
/** Handles the different cases, of thermal flows from and into the thermal
* grid.
*
* @param tick
* Current tick
* @param relevantData
* data of heat pump including state of the heat pump
* @param lastAmbientTemperature
* Ambient temperature until this tick
* @param ambientTemperature
* actual ambient temperature
* @param state
* Current state of the thermal grid
* @param qDotHouse
Expand All @@ -424,24 +418,22 @@ final case class ThermalGrid(
* Updated thermal grid state and the next threshold if there is one
*/
private def handleCases(
tick: Long,
relevantData: HpRelevantData,
lastAmbientTemperature: Temperature,
ambientTemperature: Temperature,
state: ThermalGridState,
qDotHouse: Power,
qDotHeatStorage: Power,
): (ThermalGridState, Option[ThermalThreshold]) = {
val (updatedHouseState, thermalHouseThreshold, _) =
handleInfeedHouse(
tick,
relevantData,
lastAmbientTemperature,
ambientTemperature,
state,
qDotHouse,
)

val (updatedStorageState, thermalStorageThreshold) =
handleInfeedStorage(tick, state, qDotHeatStorage)
handleInfeedStorage(relevantData.currentTick, state, qDotHeatStorage)

val nextThreshold = determineMostRecentThreshold(
thermalHouseThreshold,
Expand All @@ -460,12 +452,10 @@ final case class ThermalGrid(
/** Handles the case, when the house has heat demand and will be heated up
* here.
*
* @param tick
* Current tick
* @param relevantData
* data of heat pump including state of the heat pump
* @param lastAmbientTemperature
* Ambient temperature until this tick
* @param ambientTemperature
* actual ambient temperature
* @param state
* Current state of the houses
* @param qDot
Expand All @@ -474,19 +464,17 @@ final case class ThermalGrid(
* Updated thermal house state, a ThermalThreshold and the remaining qDot
*/
private def handleInfeedHouse(
tick: Long,
relevantData: HpRelevantData,
lastAmbientTemperature: Temperature,
ambientTemperature: Temperature,
state: ThermalGridState,
qDot: Power,
): (Option[ThermalHouseState], Option[ThermalThreshold], Power) = {
(house, state.houseState) match {
case (Some(thermalHouse), Some(lastHouseState)) =>
val (newState, threshold) = thermalHouse.determineState(
tick,
relevantData,
lastHouseState,
lastAmbientTemperature,
ambientTemperature,
qDot,
)
/* Check if house can handle the thermal feed in */
Expand Down

0 comments on commit be3b094

Please sign in to comment.