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

Write ThermalHouse results when em controlled #845

Merged
merged 19 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ee76ddc
enhance results as AccompaniedSimulationResult
danielfeismann Jul 3, 2024
739e823
Merge branch 'refs/heads/df/#841_fix_em' into df/#844_fix_thermal_hou…
danielfeismann Jul 3, 2024
e662ee1
fix handleCalculatedResult
danielfeismann Jul 4, 2024
61323f6
changelog
danielfeismann Jul 4, 2024
d5d9950
fix fill level calculation of cylindrical thermal storages
danielfeismann Jul 4, 2024
26e0688
Merge branch 'dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 5, 2024
c6ed34d
Merge branch 'refs/heads/dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 11, 2024
81d9458
adapt StorageAgentFundamentals
danielfeismann Jul 12, 2024
4b49f45
fix StorageAgentFundamentals to comply with ParticipantAgentFundamentals
danielfeismann Jul 12, 2024
905cd20
Merge branch 'refs/heads/dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 17, 2024
2a94bba
Merge branch 'dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 22, 2024
bbde5c5
Merge branch 'refs/heads/dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 24, 2024
af3eb81
refactoring to comply with quality gateway
danielfeismann Jul 24, 2024
727f53b
more refactoring on code smell
danielfeismann Jul 24, 2024
2ca7c21
Merge branch 'refs/heads/dev' into df/#844_fix_thermal_house_results
danielfeismann Jul 25, 2024
361965d
remove imports
danielfeismann Jul 25, 2024
df7363c
Revert "remove imports"
danielfeismann Jul 25, 2024
43d5e17
Revert "more refactoring on code smell"
danielfeismann Jul 25, 2024
3bac8e7
Revert "refactoring to comply with quality gateway"
danielfeismann Jul 25, 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 @@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Simulation stopping at unhandled messages in `DBFSAlgorithm` [#821](https://github.com/ie3-institute/simona/issues/821)
- Not stopping correctly on failed power flow if configured to stop [#800](https://github.com/ie3-institute/simona/issues/800)
- Finally fixing `RuntimeEventListenerSpec` [#849](https://github.com/ie3-institute/simona/issues/849)
- Fixed result output for thermal houses and cylindrical storages [#844](https://github.com/ie3-institute/simona/issues/844)

## [3.0.0] - 2023-08-07

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import edu.ie3.simona.agent.{SimonaAgent, ValueStore}
import edu.ie3.simona.config.SimonaConfig
import edu.ie3.simona.event.notifier.NotifierConfig
import edu.ie3.simona.exceptions.agent.InconsistentStateException
import edu.ie3.simona.io.result.AccompaniedSimulationResult
import edu.ie3.simona.model.participant.ModelState.ConstantState
import edu.ie3.simona.model.participant.{
CalcRelevantData,
Expand Down Expand Up @@ -799,7 +800,7 @@ abstract class ParticipantAgent[
data: CD,
lastState: MS,
setPower: squants.Power,
): (MS, PD, FlexChangeIndicator)
): (MS, AccompaniedSimulationResult[PD], FlexChangeIndicator)

/** Determining the reply to an [[RequestAssetPowerMessage]], send this answer
* and stay in the current state. If no reply can be determined (because an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ protected trait ParticipantAgentFundamentals[

flexStateData.emAgent ! FlexCtrlCompletion(
baseStateData.modelUuid,
result.toApparentPower,
result.primaryData.toApparentPower,
flexChangeIndicator.changesAtNextActivation,
nextActivation,
)
Expand All @@ -854,22 +854,22 @@ protected trait ParticipantAgentFundamentals[
*/
protected def handleCalculatedResult(
baseStateData: ParticipantModelBaseStateData[PD, CD, MS, M],
result: PD,
result: AccompaniedSimulationResult[PD],
currentTick: Long,
): ParticipantModelBaseStateData[PD, CD, MS, M] = {

// announce last result to listeners
announceSimulationResult(
baseStateData,
currentTick,
AccompaniedSimulationResult(result),
result,
)(baseStateData.outputConfig)

baseStateData.copy(
resultValueStore = ValueStore.updateValueStore(
baseStateData.resultValueStore,
currentTick,
result,
result.primaryData,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.evcs

import edu.ie3.datamodel.models.input.system.EvcsInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
EvcsResult,
SystemParticipantResult,
Expand Down Expand Up @@ -39,6 +40,7 @@ import edu.ie3.simona.exceptions.agent.{
InconsistentStateException,
InvalidRequestException,
}
import edu.ie3.simona.io.result.AccompaniedSimulationResult
import edu.ie3.simona.model.participant.FlexChangeIndicator
import edu.ie3.simona.model.participant.evcs.EvcsModel
import edu.ie3.simona.model.participant.evcs.EvcsModel.{
Expand All @@ -59,7 +61,7 @@ import org.apache.pekko.actor.typed.scaladsl.adapter.ClassicActorRefOps
import org.apache.pekko.actor.typed.{ActorRef => TypedActorRef}
import org.apache.pekko.actor.{ActorRef, FSM}
import squants.energy.Megawatts
import squants.{Dimensionless, Each}
import squants.{Dimensionless, Each, Power}

import java.time.ZonedDateTime
import java.util.UUID
Expand Down Expand Up @@ -243,16 +245,23 @@ protected trait EvcsAgentFundamentals
],
data: EvcsRelevantData,
lastState: EvcsState,
setPower: squants.Power,
): (EvcsState, ApparentPower, FlexChangeIndicator) = {
setPower: Power,
): (
EvcsState,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
/* Calculate the power */
val voltage = getAndCheckNodalVoltage(baseStateData, tick)

val reactivePower = baseStateData.model.calculateReactivePower(
setPower,
voltage,
)
val result = ApparentPower(setPower, reactivePower)
val result = AccompaniedSimulationResult(
ApparentPower(setPower, reactivePower),
Seq.empty[ResultEntity],
)

/* Handle the request within the model */
val (updatedState, flexChangeIndicator) =
Expand Down Expand Up @@ -674,7 +683,7 @@ protected trait EvcsAgentFundamentals
EvcsState,
EvcsModel,
],
result: ApparentPower,
result: AccompaniedSimulationResult[ApparentPower],
currentTick: Long,
): ParticipantModelBaseStateData[
ApparentPower,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.fixedfeedin

import edu.ie3.datamodel.models.input.system.FixedFeedInInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
FixedFeedInResult,
SystemParticipantResult,
Expand Down Expand Up @@ -34,6 +35,7 @@ import edu.ie3.simona.exceptions.agent.{
InconsistentStateException,
InvalidRequestException,
}
import edu.ie3.simona.io.result.AccompaniedSimulationResult
import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData
import edu.ie3.simona.model.participant.ModelState.ConstantState
import edu.ie3.simona.model.participant.{
Expand Down Expand Up @@ -231,15 +233,22 @@ protected trait FixedFeedInAgentFundamentals
data: FixedRelevantData.type,
lastState: ConstantState.type,
setPower: squants.Power,
): (ConstantState.type, ApparentPower, FlexChangeIndicator) = {
): (
ConstantState.type,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
/* Calculate result */
val voltage = getAndCheckNodalVoltage(baseStateData, tick)

val reactivePower = baseStateData.model.calculateReactivePower(
setPower,
voltage,
)
val result = ApparentPower(setPower, reactivePower)
val result = AccompaniedSimulationResult(
ApparentPower(setPower, reactivePower),
Seq.empty[ResultEntity],
)

/* Handle the request within the model */
val (updatedState, flexChangeIndicator) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import edu.ie3.simona.ontology.messages.services.WeatherMessage.WeatherData
import edu.ie3.util.quantities.PowerSystemUnits.PU
import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble
import edu.ie3.util.scala.quantities.DefaultQuantities._
import edu.ie3.util.scala.quantities.{Megavars, ReactivePower}
import edu.ie3.util.scala.quantities.ReactivePower
import org.apache.pekko.actor.typed.scaladsl.adapter.ClassicActorRefOps
import org.apache.pekko.actor.typed.{ActorRef => TypedActorRef}
import org.apache.pekko.actor.{ActorRef, FSM}
Expand Down Expand Up @@ -147,7 +147,11 @@ trait HpAgentFundamentals
data: HpRelevantData,
lastState: HpState,
setPower: squants.Power,
): (HpState, ApparentPowerAndHeat, FlexChangeIndicator) = {
): (
HpState,
AccompaniedSimulationResult[ApparentPowerAndHeat],
FlexChangeIndicator,
) = {
/* Determine needed information */
val voltage =
getAndCheckNodalVoltage(baseStateData, tick)
Expand Down Expand Up @@ -176,13 +180,18 @@ trait HpAgentFundamentals
.handleControlledPowerChange(relevantData, modelState, setPower)

/* Calculate power results */
val result = baseStateData.model.calculatePower(
val power = baseStateData.model.calculatePower(
tick,
voltage,
updatedState,
relevantData,
)

val accompanyingResults = baseStateData.model.thermalGrid.results(
updatedState.thermalGridState
)(baseStateData.startDate)
val result = AccompaniedSimulationResult(power, accompanyingResults)

(updatedState, result, flexChangeIndicator)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.load

import edu.ie3.datamodel.models.input.system.LoadInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
LoadResult,
SystemParticipantResult,
Expand All @@ -31,6 +32,7 @@ import edu.ie3.simona.agent.state.AgentState.Idle
import edu.ie3.simona.config.SimonaConfig.LoadRuntimeConfig
import edu.ie3.simona.event.notifier.NotifierConfig
import edu.ie3.simona.exceptions.agent.InconsistentStateException
import edu.ie3.simona.io.result.AccompaniedSimulationResult
import edu.ie3.simona.model.SystemComponent
import edu.ie3.simona.model.participant.CalcRelevantData.LoadRelevantData
import edu.ie3.simona.model.participant.ModelState.ConstantState
Expand Down Expand Up @@ -261,15 +263,22 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[
data: LD,
lastState: ConstantState.type,
setPower: squants.Power,
): (ConstantState.type, ApparentPower, FlexChangeIndicator) = {
): (
ConstantState.type,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
/* Calculate result */
val voltage = getAndCheckNodalVoltage(baseStateData, tick)

val reactivePower = baseStateData.model.calculateReactivePower(
setPower,
voltage,
)
val result = ApparentPower(setPower, reactivePower)
val result = AccompaniedSimulationResult(
ApparentPower(setPower, reactivePower),
Seq.empty[ResultEntity],
)

/* Handle the request within the model */
val (updatedState, flexChangeIndicator) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.pv

import edu.ie3.datamodel.models.input.system.PvInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
PvResult,
SystemParticipantResult,
Expand Down Expand Up @@ -270,15 +271,22 @@ protected trait PvAgentFundamentals
data: PvRelevantData,
lastState: ConstantState.type,
setPower: squants.Power,
): (ConstantState.type, ApparentPower, FlexChangeIndicator) = {
): (
ConstantState.type,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
/* Calculate result */
val voltage = getAndCheckNodalVoltage(baseStateData, tick)

val reactivePower = baseStateData.model.calculateReactivePower(
setPower,
voltage,
)
val result = ApparentPower(setPower, reactivePower)
val result = AccompaniedSimulationResult(
ApparentPower(setPower, reactivePower),
Seq.empty[ResultEntity],
)

/* Handle the request within the model */
val (updatedState, flexChangeIndicator) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.storage

import edu.ie3.datamodel.models.input.system.StorageInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
StorageResult,
SystemParticipantResult,
Expand Down Expand Up @@ -36,6 +37,7 @@ import edu.ie3.simona.exceptions.agent.{
AgentInitializationException,
InvalidRequestException,
}
import edu.ie3.simona.io.result.AccompaniedSimulationResult
import edu.ie3.simona.model.participant.StorageModel.{
StorageRelevantData,
StorageState,
Expand Down Expand Up @@ -259,15 +261,14 @@ trait StorageAgentFundamentals
StorageState,
StorageModel,
],
result: ApparentPower,
result: AccompaniedSimulationResult[ApparentPower],
currentTick: Long,
): ParticipantModelBaseStateData[
ApparentPower,
StorageRelevantData,
StorageState,
StorageModel,
] = {

// announce last result to listeners
if (baseStateData.outputConfig.simulationResultInfo) {
val uuid = baseStateData.modelUuid
Expand All @@ -289,8 +290,8 @@ trait StorageAgentFundamentals
val storageResult = new StorageResult(
dateTime,
uuid,
result.p.toMegawatts.asMegaWatt,
result.q.toMegavars.asMegaVar,
result.primaryData.p.toMegawatts.asMegaWatt,
result.primaryData.q.toMegavars.asMegaVar,
soc,
)

Expand All @@ -301,7 +302,7 @@ trait StorageAgentFundamentals
resultValueStore = ValueStore.updateValueStore(
baseStateData.resultValueStore,
currentTick,
result,
result.primaryData,
)
)
}
Expand Down Expand Up @@ -332,7 +333,11 @@ trait StorageAgentFundamentals
data: StorageRelevantData,
lastState: StorageState,
setPower: Power,
): (StorageState, ApparentPower, FlexChangeIndicator) = {
): (
StorageState,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
val (updatedState, flexChangeIndicator) =
baseStateData.model.handleControlledPowerChange(data, lastState, setPower)
// In edge cases, the model does not accept the given set power
Expand All @@ -345,11 +350,13 @@ trait StorageAgentFundamentals
voltage,
)

(
updatedState,
ApparentPower(updatedSetPower, reactivePower),
flexChangeIndicator,
)
val apparentPower = ApparentPower(updatedSetPower, reactivePower)

val result: AccompaniedSimulationResult[ApparentPower] =
AccompaniedSimulationResult(apparentPower, Seq.empty[ResultEntity])

(updatedState, result, flexChangeIndicator)

}

/** Update the last known model state with the given external, relevant data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.agent.participant.wec

import edu.ie3.datamodel.models.input.system.WecInput
import edu.ie3.datamodel.models.result.ResultEntity
import edu.ie3.datamodel.models.result.system.{
SystemParticipantResult,
WecResult,
Expand Down Expand Up @@ -246,15 +247,22 @@ protected trait WecAgentFundamentals
data: WecRelevantData,
lastState: ConstantState.type,
setPower: squants.Power,
): (ConstantState.type, ApparentPower, FlexChangeIndicator) = {
): (
ConstantState.type,
AccompaniedSimulationResult[ApparentPower],
FlexChangeIndicator,
) = {
/* Calculate result */
val voltage = getAndCheckNodalVoltage(baseStateData, tick)

val reactivePower = baseStateData.model.calculateReactivePower(
setPower,
voltage,
)
val result = ApparentPower(setPower, reactivePower)
val result = AccompaniedSimulationResult(
ApparentPower(setPower, reactivePower),
Seq.empty[ResultEntity],
)

/* Handle the request within the model */
val (updatedState, flexChangeIndicator) =
Expand Down
Loading