Skip to content

Commit

Permalink
Refactoring EM messages
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Peter <sebastian.peter@tu-dortmund.de>
  • Loading branch information
sebastian-peter committed Sep 3, 2024
1 parent fdb836b commit 9f8a46a
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 92 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
- 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)

### Fixed
- Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658)
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 having been 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
10 changes: 5 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 Down Expand Up @@ -101,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 Down
4 changes: 2 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 Down
8 changes: 4 additions & 4 deletions src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,10 @@ 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)
}

newCore.fold(
Expand Down Expand Up @@ -371,7 +371,7 @@ object EmAgent {
updatedCore,
)

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

updatedCore
Expand Down Expand Up @@ -436,7 +436,7 @@ object EmAgent {
schedulerData.activationAdapter,
inactiveCore.nextActiveTick,
),
_.emAgent ! FlexCtrlCompletion(
_.emAgent ! FlexCompletion(
modelShell.uuid,
inactiveCore.hasFlexWithNext,
inactiveCore.nextActiveTick,
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ object EmDataCore {
* on critical error
*/
def handleCompletion(
completion: FlexCtrlCompletion
completion: FlexCompletion
): AwaitingCompletions = {
if (!awaitedCompletions.contains(completion.modelUuid))
throw new CriticalFailureException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import edu.ie3.simona.ontology.messages.Activation
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{
FlexResponse,
IssueFlexControl,
RequestFlexOptions,
FlexActivation,
}
import edu.ie3.simona.ontology.messages.services.ServiceMessage.RegistrationResponseMessage.RegistrationSuccessfulMessage
import edu.ie3.simona.ontology.messages.services.ServiceMessage.{
Expand Down Expand Up @@ -221,7 +221,7 @@ abstract class ParticipantAgent[
finalizeTickAfterPF(baseStateData, tick)

case Event(
RequestFlexOptions(tick),
FlexActivation(tick),
baseStateData: ParticipantModelBaseStateData[PD, CD, MS, M],
) =>
val expectedSenders = baseStateData.foreseenDataTicks
Expand Down Expand Up @@ -336,7 +336,7 @@ abstract class ParticipantAgent[
)(stateData.baseStateData.outputConfig)

case Event(
RequestFlexOptions(tick),
FlexActivation(tick),
stateData: DataCollectionStateData[PD],
) =>
checkForExpectedDataAndChangeState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ protected trait ParticipantAgentFundamentals[
result.primaryData.toApparentPower,
)

flexStateData.emAgent ! FlexCtrlCompletion(
flexStateData.emAgent ! FlexCompletion(
baseStateData.modelUuid,
flexChangeIndicator.changesAtNextActivation,
nextActivation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ object FlexibilityMessage {
* @param tick
* The tick to request flex options for
*/
final case class RequestFlexOptions(override val tick: Long)
extends FlexRequest
final case class FlexActivation(override val tick: Long) extends FlexRequest

/** Message that provides flex options to an
* [[edu.ie3.simona.agent.em.EmAgent]] after they have been requested via
* [[RequestFlexOptions]]
* [[FlexActivation]]
*/
trait ProvideFlexOptions extends FlexResponse

Expand Down Expand Up @@ -117,8 +116,8 @@ object FlexibilityMessage {
extends IssueFlexControl

/** Message sent by flex options providers that transports the result after
* flex control has been handled. Has to be sent before
* [[FlexCtrlCompletion]], but is not required during initialization.
* flex control has been handled. Has to be sent before [[FlexCompletion]],
* but is not required during initialization.
*
* @param modelUuid
* The UUID of the flex options provider asset model
Expand Down Expand Up @@ -147,7 +146,7 @@ object FlexibilityMessage {
* i.e. the tick at which the flex options provider would like to be
* activated at the latest.
*/
final case class FlexCtrlCompletion(
final case class FlexCompletion(
override val modelUuid: UUID,
requestAtNextActivation: Boolean = false,
requestAtTick: Option[Long] = None,
Expand Down
Loading

0 comments on commit 9f8a46a

Please sign in to comment.