Skip to content

Commit

Permalink
Merge branch 'refs/heads/df/#930-refactor-handleInfeed' into df/#878-…
Browse files Browse the repository at this point in the history
…thermalGridIT

# Conflicts:
#	CHANGELOG.md
#	src/main/scala/edu/ie3/simona/model/participant/HpModel.scala
#	src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridTestData.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala
  • Loading branch information
danielfeismann committed Nov 15, 2024
2 parents f33fc1a + 95d0562 commit 6b74778
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 130 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed ThermalStorageResults having multiple entries [#924](https://github.com/ie3-institute/simona/issues/924)
- Fix filter for thermal result checking for lastTick not for currentTick [#1008](https://github.com/ie3-institute/simona/issues/1008)
- Fixed `CHANGELOG` entry for issue ([#103](https://github.com/ie3-institute/simona/issues/103)) [#941](https://github.com/ie3-institute/simona/issues/941)
- 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)
- Refactoring of `ThermalGrid.handleInfeed` to fix thermal storage recharge correctly when empty [#930](https://github.com/ie3-institute/simona/issues/930)

## [3.0.0] - 2023-08-07

Expand Down
119 changes: 37 additions & 82 deletions src/main/scala/edu/ie3/simona/model/participant/HpModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import edu.ie3.simona.model.SystemComponent
import edu.ie3.simona.model.participant.HpModel.{HpRelevantData, HpState}
import edu.ie3.simona.model.participant.control.QControl
import edu.ie3.simona.model.thermal.ThermalGrid.{
ThermalDemandIndicator,
ThermalEnergyDemand,
ThermalGridState,
}
Expand Down Expand Up @@ -150,7 +151,7 @@ final case class HpModel(
)

// Determining the operation point and limitations at this tick
val (turnOn, canOperate, canBeOutOfOperation) =
val (turnOn, canOperate, canBeOutOfOperation, demandIndicator) =
operatesInNextState(
lastHpState,
currentThermalGridState,
Expand All @@ -161,7 +162,7 @@ final case class HpModel(

// Updating the HpState
val updatedState =
calcState(lastHpState, relevantData, turnOn)
calcState(lastHpState, relevantData, turnOn, demandIndicator)
(canOperate, canBeOutOfOperation, updatedState)
}

Expand All @@ -183,55 +184,19 @@ final case class HpModel(
* ThermalEnergyDemand of the thermal storage
* @return
* boolean defining if heat pump runs in next time step, if it can be in
* operation and out of operation plus the demand of house and storage
* operation and can be out of operation plus the
* [[ThermalDemandIndicator]] of the thermal units
*/
private def operatesInNextState(
lastState: HpState,
currentThermalGridState: ThermalGridState,
relevantData: HpRelevantData,
demandHouse: ThermalEnergyDemand,
demandThermalStorage: ThermalEnergyDemand,
): (Boolean, Boolean, Boolean, Boolean, Boolean) = {

//FIXME
/*
val (demandHouse, demandThermalStorage, updatedState) =
thermalGrid.energyDemandAndUpdatedState(
relevantData.currentTick,
state.ambientTemperature.getOrElse(relevantData.ambientTemperature),
relevantData.ambientTemperature,
state.thermalGridState,
)
val (
houseDemand,
heatStorageDemand,
noThermalStorageOrThermalStorageIsEmpty,
) = determineDemandBooleans(
state,
updatedState,
demandHouse,
demandThermalStorage,
)
val turnHpOn: Boolean =
houseDemand || heatStorageDemand
val canOperate =
demandHouse.hasRequiredDemand || demandHouse.hasAdditionalDemand ||
demandThermalStorage.hasRequiredDemand || demandThermalStorage.hasAdditionalDemand
val canBeOutOfOperation =
!(demandHouse.hasRequiredDemand && noThermalStorageOrThermalStorageIsEmpty)
(turnHpOn, canOperate, canBeOutOfOperation, houseDemand, heatStorageDemand)
}
*/

/*
): (Boolean, Boolean, Boolean, ThermalDemandIndicator) = {

val (
houseHasDemand,
heatStorageHasDemand,
demandIndicator,
noThermalStorageOrThermalStorageIsEmpty,
) = determineDemandBooleans(
lastState,
Expand All @@ -240,18 +205,21 @@ final case class HpModel(
demandThermalStorage,
)

val turnHpOn: Boolean =
houseHasDemand || heatStorageHasDemand
val turnHpOn =
demandIndicator.houseDemand || demandIndicator.heatStorageDemand

val canOperate =
demandHouse.hasRequiredDemand || demandHouse.hasAdditionalDemand ||
demandThermalStorage.hasRequiredDemand || demandThermalStorage.hasAdditionalDemand
val canBeOutOfOperation =
!(demandHouse.hasRequiredDemand && noThermalStorageOrThermalStorageIsEmpty)

(turnHpOn, canOperate, canBeOutOfOperation)
*/

(
turnHpOn,
canOperate,
canBeOutOfOperation,
demandIndicator,
)
}

/** This method will return booleans whether there is a heat demand of house
Expand All @@ -273,11 +241,11 @@ final case class HpModel(
*/

private def determineDemandBooleans(
lastHpState: HpState,
updatedGridState: ThermalGridState,
demandHouse: ThermalEnergyDemand,
demandThermalStorage: ThermalEnergyDemand,
): (Boolean, Boolean, Boolean) = {
lastHpState: HpState,
updatedGridState: ThermalGridState,
demandHouse: ThermalEnergyDemand,
demandThermalStorage: ThermalEnergyDemand,
): (ThermalDemandIndicator, Boolean) = {
implicit val tolerance: Energy = KilowattHours(1e-3)
val noThermalStorageOrThermalStorageIsEmpty: Boolean =
updatedGridState.storageState.isEmpty || updatedGridState.storageState
Expand All @@ -289,7 +257,9 @@ final case class HpModel(
(demandHouse.hasRequiredDemand && noThermalStorageOrThermalStorageIsEmpty) || (lastHpState.isRunning && demandHouse.hasAdditionalDemand)
val heatStorageDemand =
demandThermalStorage.hasRequiredDemand || (lastHpState.isRunning && demandThermalStorage.hasAdditionalDemand)
(houseDemand, heatStorageDemand, noThermalStorageOrThermalStorageIsEmpty)

val demandIndicator = ThermalDemandIndicator(houseDemand, heatStorageDemand)
(demandIndicator, noThermalStorageOrThermalStorageIsEmpty)
}

/** Calculate state depending on whether heat pump is needed or not. Also
Expand All @@ -302,19 +272,17 @@ final case class HpModel(
* data of heat pump including state of the heat pump
* @param isRunning
* determines whether the heat pump is running or not
* @param houseDemand
* determines if the thermal house has heat demand
* @param storageDemand
* determines if the thermal storage has heat demand
* @param demandIndicator
* determines if the thermal units (house, storage) having some heat demand
* or not
* @return
* next [[HpState]]
*/
private def calcState(
lastState: HpState,
relevantData: HpRelevantData,
isRunning: Boolean,
houseDemand: Boolean,
storageDemand: Boolean,
demandIndicator: ThermalDemandIndicator,
): HpState = {
val lastStateStorageQDot = lastState.thermalGridState.storageState
.map(_.qDot)
Expand All @@ -336,8 +304,7 @@ final case class HpModel(
relevantData.ambientTemperature,
isRunning,
newThermalPower,
houseDemand,
storageDemand,
demandIndicator,
)

HpState(
Expand Down Expand Up @@ -400,18 +367,9 @@ final case class HpModel(
lastState: HpState,
setPower: Power,
): (HpState, FlexChangeIndicator) = {
/* If the setpoint value is above 50 % of the electrical power, turn on the heat pump otherwise turn it off */
/* If the set point value is above 50 % of the electrical power, turn on the heat pump otherwise turn it off */
val turnOn = setPower > (sRated * cosPhiRated * 0.5)

// FIXME
/* val updatedHpState = calcState(
lastState,
data,
turnOn,
)
*/

val (
thermalEnergyDemandHouse,
thermalEnergyDemandStorage,
Expand All @@ -425,24 +383,21 @@ final case class HpModel(
)

val (
houseDemand,
heatStorageDemand,
noThermalStorageOrThermalStorageIsEmpty,
demandIndicator,
_,
) = determineDemandBooleans(
lastState,
updatedThermalGridState,
thermalEnergyDemandHouse,
thermalEnergyDemandStorage,
)

val updatedHpState: HpState =
calcState(
lastState,
data,
turnOn,
houseDemand,
heatStorageDemand,
)
val updatedHpState = calcState(
lastState,
data,
turnOn,
demandIndicator,
)

(
updatedHpState,
Expand Down
Loading

0 comments on commit 6b74778

Please sign in to comment.