Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into df/#856-tap-water
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
danielfeismann committed Sep 13, 2024
2 parents c0c2042 + f7f2e99 commit 547534c
Show file tree
Hide file tree
Showing 14 changed files with 531 additions and 374 deletions.
3 changes: 3 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,7 @@ 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)
- Prepare ThermalStorageTestData for Storage without storageVolumeLvlMin [#894](https://github.com/ie3-institute/simona/issues/894)

### Fixed
Expand Down Expand Up @@ -106,6 +108,7 @@ 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)
- 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.0'
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
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 547534c

Please sign in to comment.