Skip to content

Commit

Permalink
Merge pull request #845 from ie3-institute/df/#844_fix_thermal_house_…
Browse files Browse the repository at this point in the history
…results

Write ThermalHouse results when em controlled
  • Loading branch information
danielfeismann authored Jul 25, 2024
2 parents b7d3a96 + 3bac8e7 commit bf12f50
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 37 deletions.
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

0 comments on commit bf12f50

Please sign in to comment.