Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of ThermalGrid.handleInfeed to fix thermal storage recharge correctly when empty #931

Open
wants to merge 35 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
baabf85
Merge remote-tracking branch 'refs/remotes/origin/df/#926-Fix-determi…
danielfeismann Aug 24, 2024
7659750
Merge remote-tracking branch 'refs/remotes/origin/df/#924-ThermalStor…
danielfeismann Aug 24, 2024
0b1868d
Merge remote-tracking branch 'refs/remotes/origin/df/#922-Fix-activat…
danielfeismann Aug 24, 2024
e2d7133
Merge remote-tracking branch 'refs/remotes/origin/df/#928-Refactor-Th…
danielfeismann Aug 24, 2024
64a67ec
Refactoring of ThermalGrid.handleInfeed to fix thermal storage rechar…
danielfeismann Aug 24, 2024
cb34618
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Aug 29, 2024
9ce13f9
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Aug 29, 2024
1573bcc
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Sep 16, 2024
355d765
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Sep 17, 2024
c1e37ee
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Sep 17, 2024
47e4052
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Sep 26, 2024
de1b0c5
Merge branch 'refs/heads/dev' into df/#930-refactor-handleInfeed
danielfeismann Oct 1, 2024
b6c596f
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Oct 28, 2024
e1df392
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 1, 2024
339a020
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 7, 2024
20664ab
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 13, 2024
165371d
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 14, 2024
ba6b581
Merge branch 'df/#928-Refactor-ThermalGird-energyDemand' into df/#930…
danielfeismann Nov 14, 2024
441359c
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 14, 2024
a669b5b
remove double entry in changelog
danielfeismann Nov 14, 2024
7884541
Revert "remove double entry in changelog"
danielfeismann Nov 14, 2024
86b3256
remove correct double entry in changelog
danielfeismann Nov 14, 2024
f4fa810
reintroduce demand booleans indicating demand when handle thermal infeed
danielfeismann Nov 14, 2024
963670c
add some scala doc
danielfeismann Nov 14, 2024
bfd633b
handle sonar code smell
danielfeismann Nov 14, 2024
9eee886
Revert "handle sonar code smell"
danielfeismann Nov 14, 2024
122cb69
handle sonar code smell
danielfeismann Nov 14, 2024
eba3b89
fmt
danielfeismann Nov 15, 2024
1f6311f
fix scala doc
danielfeismann Nov 15, 2024
95d0562
refactor demand booleans of thermal units into ThermalDemandIndicator…
danielfeismann Nov 15, 2024
30e4318
Merge branch 'df/#1023-zeroKW-and-kWh-in-test' into df/#930-refactor-…
danielfeismann Nov 15, 2024
9fb1523
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 15, 2024
94397ee
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 15, 2024
7341e10
remove unnecessary value
danielfeismann Nov 15, 2024
b69dd06
Merge branch 'dev' into df/#930-refactor-handleInfeed
danielfeismann Nov 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- Fix grammar and spelling in docs and comments [#1022](https://github.com/ie3-institute/simona/issues/1022)
- 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
61 changes: 49 additions & 12 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 @@ -143,7 +144,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 @@ -154,7 +155,7 @@ final case class HpModel(

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

Expand All @@ -176,19 +177,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 can be out of operation
* 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, Boolean, ThermalDemandIndicator) = {

val (
houseHasDemand,
heatStorageHasDemand,
demandIndicator,
noThermalStorageOrThermalStorageIsEmpty,
) = determineDemandBooleans(
lastState,
Expand All @@ -197,16 +198,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 @@ -232,7 +238,7 @@ final case class HpModel(
updatedGridState: ThermalGridState,
demandHouse: ThermalEnergyDemand,
demandThermalStorage: ThermalEnergyDemand,
): (Boolean, Boolean, Boolean) = {
): (ThermalDemandIndicator, Boolean) = {
implicit val tolerance: Energy = KilowattHours(1e-3)
val noThermalStorageOrThermalStorageIsEmpty: Boolean =
updatedGridState.storageState.isEmpty || updatedGridState.storageState
Expand All @@ -244,7 +250,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 @@ -257,13 +265,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 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,
demandIndicator: ThermalDemandIndicator,
): HpState = {
val lastStateStorageQDot = lastState.thermalGridState.storageState
.map(_.qDot)
Expand All @@ -283,7 +295,9 @@ final case class HpModel(
lastState.thermalGridState,
lastState.ambientTemperature.getOrElse(relevantData.ambientTemperature),
relevantData.ambientTemperature,
isRunning,
newThermalPower,
demandIndicator,
)

HpState(
Expand Down Expand Up @@ -346,13 +360,36 @@ 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)

val (
thermalEnergyDemandHouse,
thermalEnergyDemandStorage,
updatedThermalGridState,
) =
thermalGrid.energyDemandAndUpdatedState(
data.currentTick,
lastState.ambientTemperature.getOrElse(data.ambientTemperature),
data.ambientTemperature,
lastState.thermalGridState,
)

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

val updatedHpState = calcState(
lastState,
data,
turnOn,
demandIndicator,
)

(
Expand Down
Loading