Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into df/#924-ThermalStorageResults-have…
Browse files Browse the repository at this point in the history
…-multiple-entries

# Conflicts:
#	CHANGELOG.md
  • Loading branch information
danielfeismann committed Sep 19, 2024
2 parents e438ca0 + bf68de1 commit d941b31
Show file tree
Hide file tree
Showing 29 changed files with 209 additions and 271 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated AUTHORS.md [#905](https://github.com/ie3-institute/simona/issues/905)
- Rewrote BMModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646)
- Refactoring EM messages [#947](https://github.com/ie3-institute/simona/issues/947)
- Simplifying ThermalHouse [#940](https://github.com/ie3-institute/simona/issues/940)
- Prepare ThermalStorageTestData for Storage without storageVolumeLvlMin [#894](https://github.com/ie3-institute/simona/issues/894)
- Renamed `ActivityStartTrigger`, `ScheduleTriggerMessage`, `CompletionMessage` in UML Diagrams[#675](https://github.com/ie3-institute/simona/issues/675)

### Fixed
- Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658)
Expand Down Expand Up @@ -107,6 +110,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix determineState of ThermalHouse [#926](https://github.com/ie3-institute/simona/issues/926)
- Fix activation of Hp when not under control of an EM [#922](https://github.com/ie3-institute/simona/issues/922)
- Fix expected secondaryData in baseStateData [#955](https://github.com/ie3-institute/simona/issues/955)
- Improve code quality in fixedloadmodelspec and other tests [#919](https://github.com/ie3-institute/simona/issues/919)
- Fix power flow calculation with em agents [#962](https://github.com/ie3-institute/simona/issues/962)
- Fixed ThermalStorageResults having multiple entries [#924](https://github.com/ie3-institute/simona/issues/924)

## [3.0.0] - 2023-08-07
Expand Down
2 changes: 1 addition & 1 deletion docs/uml/main/ExtEvSimulationClasses.puml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ package simona-api {

interface ExtTriggerResponse
class CompletionMessage {
- List<Long> newTriggers
- Optional<Long> nextActivation
}
CompletionMessage --|> ExtTriggerResponse

Expand Down
2 changes: 1 addition & 1 deletion docs/uml/main/ParticipantInheritance.puml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
+ getAndCheckNodalVoltage(...): ComparableQuantity[Dimensionless]
+ initializeParticipant(...): FSM.State[AgentState, ParticipantStateData]
+ {abstract} determineBaseStateData(...): BaseStateData[ApparentPower]
+ determineTriggersThroughoutSimulation(...): Option[List[ScheduleTriggerMessage]]
+ determineTriggersThroughoutSimulation(...): Option[List[ScheduleActivation]]
+ baseStateDataForExternalDataProvision(...): FromOutsideBaseStateData
+ queryPrimaryDataAndChangeState(...): FSM.State[AgentState, ParticipantStateData]
+ querySecondaryDataAndChangeState(...): FSM.State[AgentState, ParticipantStateData]
Expand Down
4 changes: 2 additions & 2 deletions docs/uml/protocol/ExtEvSimulationSequence.puml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ Scheduler -> ExtEvDataService: <font color=red>!</font> Activation(t1)
deactivate Scheduler
activate ExtEvDataService

ExtSimulation -> ExtSimAdapter: <font color=red>!</font> CompletionMessage(newTriggers)
ExtSimulation -> ExtSimAdapter: <font color=red>!</font> CompletionMessage(newTick)
deactivate ExtSimulation
activate ExtSimAdapter

ExtSimAdapter -> Scheduler: <font color=red>!</font> <font color=green>Completion(newTriggers)</font>
ExtSimAdapter -> Scheduler: <font color=red>!</font> <font color=green>Completion(newTick)</font>
deactivate ExtSimAdapter

ExtEvDataService -> EvcsAgent1: <font color=red>!</font> RegistrationSuccessfulMessage(t1)
Expand Down
28 changes: 14 additions & 14 deletions docs/uml/protocol/InitializationPhase.puml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
@startuml
MainController -> Listener: create()
MainController -> SimScheduler: create()
MainController -> Services: create()
MainController -> SimScheduler: <font color=red>!</font> ScheduleTriggerMessage(\n\tInitializeServiceTrigger(0),\n\tweatherActorRef)
MainController -> GridAgents: create()
MainController -> SimScheduler: <font color=red>!</font> ScheduleTriggerMessage(\n\tInitializeGridAgentTrigger(0),\n\tgridAgentInitData,\n\tgridAgentRef)
MainController -> SimScheduler: <font color=red>?</font> StartScheduleMessage()
SimScheduler -> Services: <font color=red>!</font> TriggerWithIdMessage(\n\tInitializeServiceTrigger(_),\n\ttriggerId,\n\t_)
Services --> SimScheduler: <font color=red>!</font> CompletionMessage(\n\ttriggerId,\n\tScheduleTriggerMessage[...])
SimScheduler -> GridAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tInitializeGridAgentTrigger(_),\n\ttriggerId,\n\t_)
GridAgents -> SimScheduler: <font color=red>!</font> ScheduleTriggerMessage(\n\tInitializeSystemComponentsTrigger(0),\n\tassetAgentRef)
GridAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, ScheduleTriggerMessage[...])
SimScheduler -> ParticipantAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tIInitializeSystemComponentsTrigger(_),\n\ttriggerId,\n\t_)
SimonaSim -> Listener: create()
SimonaSim -> Scheduler: create()
SimonaSim -> Services: create()
Services -> Scheduler: <font color=red>!</font> ScheduleActivation(\n\tweatherActorRef, \n\tINIT_SIM_TICK)
SimonaSim -> GridAgents: create()
GridAgents -> Scheduler: <font color=red>!</font> ScheduleActivation(\n\tgridAgentRef, \n\tINIT_SIM_TICK)
SimonaSim -> Scheduler: <font color=red>?</font> StartScheduleMessage()
Scheduler -> Services: <font color=red>!</font> Activation(\n\tINIT_SIM_TICK)
Services --> Scheduler: <font color=red>!</font> Completion(\n\tweatherActorRef, \n\ttick)
Scheduler -> GridAgents: <font color=red>!</font> Activation(\n\tINIT_SIM_TICK)
GridAgents -> Scheduler: <font color=red>!</font> ScheduleActivation(\n\tassetAgentRef, \n\tINIT_SIM_TICK)
GridAgents --> Scheduler: <font color=red>!</font> Completion(\n\tgridAgentRef,\n\ttick)
Scheduler -> ParticipantAgents: <font color=red>!</font> Activation(\n\tINIT_SIM_TICK)
ParticipantAgents -> Services: <font color=red>!</font> RegisterForWeatherMessage(lat, lon)
ParticipantAgents -> Services: <font color=red>!</font> RegisterFor...
Services --> ParticipantAgents: <font color=red>!</font> RegistrationResponseMessages
ParticipantAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(\n\ttriggerId,\n\tScheduleTriggerMessage[\n\t\tActivityStartTrigger(tick)\n\t])
ParticipantAgents --> Scheduler: <font color=red>!</font> Completion(\n\tassetAgentRef,\n\ttick)
@enduml
8 changes: 4 additions & 4 deletions docs/uml/protocol/ParticipantTriggeredByItself.puml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@startuml
SimScheduler -> ParticipantAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tIInitializeSystemComponentsTrigger(_),\n\ttriggerId,\n\t_)
ParticipantAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, ScheduleTriggerMessage[...])
SimScheduler -> ParticipantAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tActivityStartTrigger(tick),\n\t_,\n\t_)
ParticipantAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, None)
Scheduler -> ParticipantAgents: <font color=red>!</font> Activation(\n\tINIT_SIM_TICK)
ParticipantAgents --> Scheduler: <font color=red>!</font> Completion(\n\tactor, tick)
Scheduler -> ParticipantAgents: <font color=red>!</font> Activation(\n\ttick)
ParticipantAgents --> Scheduler: <font color=red>!</font> Completion(\n\tactor, newTick)
@enduml
8 changes: 4 additions & 4 deletions docs/uml/protocol/ParticipantTriggeredByPrimaryData.puml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@startuml
SimScheduler -> PrimaryServiceWorker: <font color=red>!</font> TriggerWithIdMessage(\n\tActivityStartTrigger(tick),\n\t_,\n\t_)
Scheduler -> PrimaryServiceWorker: <font color=red>!</font> Activation(\n\tInit_SIM_TICK)
PrimaryServiceWorker -> ParticipantAgents: <font color=red>!</font> <i>ProvisionMessage</i>
PrimaryServiceWorker --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, None)
SimScheduler -> ParticipantAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tActivityStartTrigger(tick),\n\t_,\n\t_)
ParticipantAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, None)
PrimaryServiceWorker --> Scheduler: <font color=red>!</font> Completion(\n\tactor,None)
Scheduler -> ParticipantAgents: <font color=red>!</font> Activation(\n\ttick)
ParticipantAgents --> Scheduler: <font color=red>!</font> Completion(\n\tactor, newTick)
@enduml
8 changes: 4 additions & 4 deletions docs/uml/protocol/ParticipantTriggeredBySecondaryData.puml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@startuml
SimScheduler -> Services: <font color=red>!</font> TriggerWithIdMessage(\n\tActivityStartTrigger(tick),\n\t_,\n\t_)
Scheduler -> Services: <font color=red>!</font> Activation(\n\tINIT_SIM_TICK)
Services -> ParticipantAgents: <font color=red>!</font> ProvideWeatherMessage(\n\ttick,\n\tweatherData,\n\tnextDataTick)
SimScheduler -> ParticipantAgents: <font color=red>!</font> TriggerWithIdMessage(\n\tActivityStartTrigger(tick),\n\t_,\n\t_)
Scheduler -> ParticipantAgents: <font color=red>!</font> Activation(\n\ttick)
Services -> ParticipantAgents: <font color=red>!</font> <i>ProvisionMessage</i>
Services -> ParticipantAgents: <font color=red>!</font> <i>ProvisionMessage</i>
Services --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, None)
Services --> Scheduler: <font color=red>!</font> Completion(\n\tactor, None)
ParticipantAgents -> ParticipantAgents: <font color=red>!</font> StartCalculationTrigger(tick)
ParticipantAgents --> SimScheduler: <font color=red>!</font> CompletionMessage(triggerId, None)
ParticipantAgents --> Scheduler: <font color=red>!</font> Completion(\n\tactor, newTick)
@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ protected trait ParticipantAgentFundamentals[
awaitRegistrationResponsesFrom,
)
} else {
/* Determine the next activation tick, create a ScheduleTriggerMessage and remove the recently triggered tick */
/* Determine the next activation tick, create a ScheduleActivation and remove the recently triggered tick */
val (newTick, nextBaseStateData) = popNextActivationTrigger(
baseStateData
)
Expand Down Expand Up @@ -808,6 +808,7 @@ protected trait ParticipantAgentFundamentals[
nextActivation,
)

unstashAll()
stay() using stateDataFinal
}

Expand Down Expand Up @@ -906,7 +907,7 @@ protected trait ParticipantAgentFundamentals[
updatedState,
)

/* In this case, without secondary data, the agent has been triggered by an ActivityStartTrigger by itself,
/* In this case, without secondary data, the agent has been triggered by an Activation(tick) by itself,
* therefore pop the next one */
val baseStateDataWithUpdatedResultStore =
baseStateData.copy(
Expand Down
102 changes: 12 additions & 90 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,100 +199,22 @@ final case class ThermalHouse(
currentInnerTemperature: Temperature,
ambientTemperature: Temperature,
): Temperature = {
val thermalEnergyChange = calcThermalEnergyChange(
calcThermalEnergyGain(thermalPower, duration),
calcThermalEnergyLoss(
currentInnerTemperature,
ambientTemperature,
duration,
),
)
calcNewInnerTemperature(
val thermalEnergyGain = thermalPower * duration

// thermal energy loss due to the deviation between outside and inside temperature
val thermalEnergyLoss = ethLosses.calcThermalEnergyChange(
currentInnerTemperature,
calcInnerTemperatureChange(thermalEnergyChange),
ambientTemperature,
duration,
)
}

/** Calculate the new inner temperature of the thermal house
*
* @param oldInnerTemperature
* previous inner temperature
* @param temperatureChange
* temperature change
* @return
* new inner temperature
*/
def calcNewInnerTemperature(
oldInnerTemperature: Temperature,
temperatureChange: Temperature,
): Temperature =
oldInnerTemperature + temperatureChange
val energyChange = thermalEnergyGain - thermalEnergyLoss

/** Calculate the temperature change for the thermal house form the thermal
* energy change
*
* @param thermalEnergyChange
* thermal energy change (e.g. through heat pump)
* @return
* temperature change
*/
def calcInnerTemperatureChange(
thermalEnergyChange: Energy
): Temperature = {
thermalEnergyChange / ethCapa
}

/** Calculate the thermal energy change combining the added and lost energy
*
* @param thermalEnergyGain
* thermal energy added
* @param thermalEnergyLoss
* thermal energy lost
* @return
* thermal energy change
*/
def calcThermalEnergyChange(
thermalEnergyGain: Energy,
thermalEnergyLoss: Energy,
): Energy =
thermalEnergyGain - thermalEnergyLoss
// temperature change calculated from energy change(WattHours) and thermal capacity(Joules per Kelvin)
val temperatureChange = energyChange / ethCapa

/** Calculate the thermal energy gain, e.g. due to a running heat pump
*
* @param pThermal
* added thermal power (e.g. of heat pump)
* @param time
* time step length in which thermal power is added
* @return
* resulting thermal energy gain
*/
def calcThermalEnergyGain(
pThermal: Power,
time: Time,
): Energy = pThermal * time

/** Calculate the thermal energy loss due to the temperature deviation over
* the time step
*
* @param innerTemperature
* previous inner temperature
* @param ambientTemperature
* ambient temperature of thermal house
* @param time
* time step length
* @return
* resulting thermal energy loss
*/
def calcThermalEnergyLoss(
innerTemperature: Temperature,
ambientTemperature: Temperature,
time: Time,
): Energy = {
ethLosses.thermalConductanceToEnergy(
innerTemperature,
ambientTemperature,
time,
)
// return value new inner temperature
currentInnerTemperature + temperatureChange
}

/** Update the current state of the house
Expand Down Expand Up @@ -358,7 +280,7 @@ final case class ThermalHouse(
ambientTemperature: Temperature,
): Option[ThermalThreshold] = {
val artificialDuration = Hours(1d)
val loss = calcThermalEnergyLoss(
val loss = ethLosses.calcThermalEnergyChange(
innerTemperature,
ambientTemperature,
artificialDuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class ThermalConductance private (
* Time duration
* @return
*/
def thermalConductanceToEnergy(
def calcThermalEnergyChange(
temperatureInner: Temperature,
temperatureOuter: Temperature,
time: squants.Time,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(900L)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]

evcsAgent.stateName shouldBe Idle
Expand Down Expand Up @@ -434,7 +434,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(0)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)
/* State data is tested in another test */
Expand Down Expand Up @@ -568,7 +568,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(0)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)
/* State data is tested in another test */
Expand Down Expand Up @@ -699,7 +699,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(10800)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)

Expand Down Expand Up @@ -744,7 +744,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(0)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the CompletionM */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)

Expand Down Expand Up @@ -825,7 +825,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(0)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)

Expand Down Expand Up @@ -903,7 +903,7 @@ class EvcsAgentModelCalculationSpec
RegistrationSuccessfulMessage(evService.ref, Some(0)),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(evcsAgent.stateName shouldBe Idle)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class FixedFeedInAgentModelCalculationSpec
RegistrationFailedMessage(primaryServiceProxy.ref),
)

/* I'm not interested in the content of the CompletionMessage */
/* I'm not interested in the content of the Completion */
scheduler.expectMsgType[Completion]

fixedFeedAgent.stateName shouldBe Idle
Expand Down Expand Up @@ -305,7 +305,7 @@ class FixedFeedInAgentModelCalculationSpec
RegistrationFailedMessage(primaryServiceProxy.ref),
)

/* I am not interested in the CompletionMessage */
/* I am not interested in the Completion */
scheduler.expectMsgType[Completion]
awaitAssert(fixedFeedAgent.stateName shouldBe Idle)
/* State data is tested in another test */
Expand Down
Loading

0 comments on commit d941b31

Please sign in to comment.