Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into df/#878-thermalGridIT
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala
  • Loading branch information
danielfeismann committed Sep 19, 2024
2 parents 3df14e4 + bf68de1 commit ae87f53
Show file tree
Hide file tree
Showing 36 changed files with 697 additions and 621 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update RTD references and bibliography [#868](https://github.com/ie3-institute/simona/issues/868)
- Add gradle application plugin for command line execution with gradle run [#890](https://github.com/ie3-institute/simona/issues/890)
- Additional tests to check flexibility options of thermal house and storage [#729](https://github.com/ie3-institute/simona/issues/729)
- EmAgents should be able to handle initialization [#945](https://github.com/ie3-institute/simona/issues/945)
- Integration test for thermal grids [#878](https://github.com/ie3-institute/simona/issues/878)

### Changed
Expand Down Expand Up @@ -79,6 +80,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated `Gradle` to version V8.10 [#829](https://github.com/ie3-institute/simona/issues/829)
- 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)
- Prepare ThermalStorageTestData for Storage without storageVolumeLvlMin [#894](https://github.com/ie3-institute/simona/issues/894)

### Fixed
Expand Down Expand Up @@ -106,6 +111,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Handle MobSim requests for current prices [#892](https://github.com/ie3-institute/simona/issues/892)
- 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 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)

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ ext {

scalaVersion = '2.13'
scalaBinaryVersion = '2.13.14'
pekkoVersion = '1.0.3'
jtsVersion = '1.19.0'
pekkoVersion = '1.1.1'
jtsVersion = '1.20.0'
confluentKafkaVersion = '7.4.0'
tscfgVersion = '1.1.3'
scapegoatVersion = '3.0.0'
Expand Down Expand Up @@ -98,7 +98,7 @@ dependencies {

/* logging */
implementation "com.typesafe.scala-logging:scala-logging_${scalaVersion}:3.9.5" // pekko scala logging
implementation "ch.qos.logback:logback-classic:1.5.7"
implementation "ch.qos.logback:logback-classic:1.5.8"

/* testing */
testImplementation 'org.spockframework:spock-core:2.3-groovy-4.0'
Expand Down
6 changes: 3 additions & 3 deletions docs/readthedocs/models/em.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Energy Management Agents (EmAgents) control power feed-in and load of system par

## Protocol

During simulation, EmAgents send `RequestFlexOptions` and `IssueFlexControl` messages and receive `ProvideFlexOptions` and `FlexCompletion` messages.
After having been requested to calculate flex options via `RequestFlexOptions`, controllable assets send back their flex options to the controlling unit using `ProvideFlexOptions`.
During simulation, EmAgents send `FlexActivation` and `IssueFlexControl` messages and receive `ProvideFlexOptions` and `FlexCompletion` messages.
After being requested to calculate flex options via `FlexActivation`, controllable assets send back their flex options to the controlling unit using `ProvideFlexOptions`.
Eventually the controlling EmAgent responds with some type of `IssueFlexControl` messages, setting a power set point for operation.
The asset then tries to realize the set power as best as it can and replies with a `FlexCompletion` messages.
If an EmAgent is itself controlled by another EmAgent, it also behaves like a system participant (sends `RequestFlexOptions` and `IssueFlexControl` messages etc.).
If an EmAgent is itself controlled by another EmAgent, it also behaves like a system participant (sends `FlexActivation` and `IssueFlexControl` messages etc.).


Every EmAgent aggregates flex options and power of its connected assets and disaggregates flex control among the connected assets.
Expand Down
6 changes: 3 additions & 3 deletions docs/readthedocs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Sphinx==7.3.7
Sphinx==7.4.7
sphinx-rtd-theme==2.0.0
sphinxcontrib-plantuml==0.30
myst-parser==4.0.0
markdown-it-py==3.0.0
sphinx-hoverxref==1.4.0
sphinxcontrib-bibtex==2.6.2
sphinx-hoverxref==1.4.1
sphinxcontrib-bibtex==2.6.3
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
15 changes: 10 additions & 5 deletions docs/uml/protocol/em/ControlledEm.puml
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ deactivate WeatherService
Scheduler -> EmAgent1: Activation(tick=0)
activate EmAgent1

EmAgent1 -> EmAgent2: RequestFlexOptions(tick=0)
EmAgent1 -> EmAgent2: FlexActivation(tick=0)
activate EmAgent2

EmAgent2 -> StorageAgent: RequestFlexOptions(tick=0)
EmAgent2 -> StorageAgent: FlexActivation(tick=0)
activate StorageAgent

EmAgent2 -> PvAgent: RequestFlexOptions(tick=0)
EmAgent2 -> PvAgent: FlexActivation(tick=0)
activate PvAgent

PvAgent -> EmAgent2: ProvideFlexOptions
Expand All @@ -81,12 +81,15 @@ activate PvAgent
EmAgent2 -> StorageAgent: IssuePowerControl(tick=0)
activate StorageAgent

PvAgent -> EmAgent2: FlexResult
PvAgent -> EmAgent2: FlexCompletion(nextTick=3600)
deactivate PvAgent

StorageAgent -> EmAgent2: FlexResult
StorageAgent -> EmAgent2: FlexCompletion(nextTick=1805)
deactivate StorageAgent

EmAgent2 -> EmAgent1: FlexResult
EmAgent2 -> EmAgent1: FlexCompletion(nextTick=1805)
deactivate EmAgent2

Expand All @@ -98,10 +101,10 @@ deactivate EmAgent1
Scheduler -> EmAgent1: Activation(tick=1805)
activate EmAgent1

EmAgent1 -> EmAgent2: RequestFlexOptions(tick=1805)
EmAgent1 -> EmAgent2: FlexActivation(tick=1805)
activate EmAgent2

EmAgent2 -> StorageAgent: RequestFlexOptions(tick=1805)
EmAgent2 -> StorageAgent: FlexActivation(tick=1805)
activate StorageAgent

StorageAgent -> EmAgent2: ProvideFlexOptions
Expand All @@ -116,9 +119,11 @@ activate EmAgent2
EmAgent2 -> StorageAgent: IssuePowerControl(tick=1805)
activate StorageAgent

StorageAgent -> EmAgent2: FlexResult
StorageAgent -> EmAgent2: FlexCompletion(nextTick=10800)
deactivate StorageAgent

EmAgent2 -> EmAgent1: FlexResult
EmAgent2 -> EmAgent1: FlexCompletion(nextTick=3600)
deactivate EmAgent2

Expand Down
6 changes: 4 additions & 2 deletions docs/uml/protocol/em/UncontrolledEm.puml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ deactivate WeatherService
Scheduler -> EmAgent: Activation(tick=0)
activate EmAgent

EmAgent -> StorageAgent: RequestFlexOptions(tick=0)
EmAgent -> StorageAgent: FlexActivation(tick=0)
activate StorageAgent

EmAgent -> PvAgent: RequestFlexOptions(tick=0)
EmAgent -> PvAgent: FlexActivation(tick=0)
activate PvAgent

PvAgent -> EmAgent: ProvideFlexOptions
Expand All @@ -68,9 +68,11 @@ activate PvAgent
EmAgent -> StorageAgent: IssuePowerControl(tick=0)
activate StorageAgent

PvAgent -> EmAgent: FlexResult
PvAgent -> EmAgent: FlexCompletion(nextTick=3600)
deactivate PvAgent

StorageAgent -> EmAgent: FlexResult
StorageAgent -> EmAgent: FlexCompletion(nextTick=8400)
deactivate StorageAgent

Expand Down
62 changes: 38 additions & 24 deletions src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,16 @@ object EmAgent {
val flexOptionsCore = core.activate(msg.tick)

msg match {
case Flex(_: RequestFlexOptions) | EmActivation(_) =>
case Flex(_: FlexActivation) | EmActivation(_) =>
val (toActivate, newCore) = flexOptionsCore.takeNewFlexRequests()
toActivate.foreach {
_ ! RequestFlexOptions(msg.tick)
_ ! FlexActivation(msg.tick)
}

awaitingFlexOptions(emData, modelShell, newCore)
newCore.fold(
awaitingFlexOptions(emData, modelShell, _),
awaitingCompletions(emData, modelShell, _),
)

case Flex(_: IssueFlexControl) =>
// We got sent a flex control message instead of a flex request,
Expand Down Expand Up @@ -359,8 +362,16 @@ object EmAgent {
modelShell: EmModelShell,
core: EmDataCore.AwaitingCompletions,
): Behavior[Request] = Behaviors.receiveMessagePartial {
// Completions and results
case completion: FlexCtrlCompletion =>
case result: FlexResult =>
val updatedCore = core.handleResult(result)

awaitingCompletions(
emData,
modelShell,
updatedCore,
)

case completion: FlexCompletion =>
val updatedCore = core.handleCompletion(completion)

updatedCore
Expand All @@ -385,34 +396,38 @@ object EmAgent {

}

/** Completions have all been received, possibly send results and report to
* parent
*/
private def sendCompletionCommunication(
emData: EmData,
modelShell: EmModelShell,
inactiveCore: EmDataCore.Inactive,
lastActiveTick: Long,
): Unit = {
// calc result
val result = inactiveCore.getResults
// Sum up resulting power, if applicable.
// After initialization, there are no results yet.
val maybeResult = inactiveCore.getResults
.reduceOption { (power1, power2) =>
ApparentPower(power1.p + power2.p, power1.q + power2.q)
}
.getOrElse(
ApparentPower(
zeroMW,
zeroMVAr,
)
)

emData.listener.foreach {
_ ! ParticipantResultEvent(
new EmResult(
lastActiveTick
.toDateTime(emData.simulationStartDate),
modelShell.uuid,
result.p.toMegawatts.asMegaWatt,
result.q.toMegavars.asMegaVar,
maybeResult.foreach { result =>
emData.listener.foreach {
_ ! ParticipantResultEvent(
new EmResult(
lastActiveTick
.toDateTime(emData.simulationStartDate),
modelShell.uuid,
result.p.toMegawatts.asMegaWatt,
result.q.toMegavars.asMegaVar,
)
)
)
}

emData.parentData.foreach {
_.emAgent ! FlexResult(modelShell.uuid, result)
}
}

emData.parentData.fold(
Expand All @@ -421,9 +436,8 @@ object EmAgent {
schedulerData.activationAdapter,
inactiveCore.nextActiveTick,
),
_.emAgent ! FlexCtrlCompletion(
_.emAgent ! FlexCompletion(
modelShell.uuid,
result,
inactiveCore.hasFlexWithNext,
inactiveCore.nextActiveTick,
),
Expand Down
Loading

0 comments on commit ae87f53

Please sign in to comment.