Skip to content
Draft

ReCoDe #1223

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
167 commits
Select commit Hold shift + click to select a range
e316d88
Adding services.
staudtMarius Feb 24, 2025
893eec2
Fixing some bugs.
staudtMarius Feb 24, 2025
7be910e
Fixing config.
staudtMarius Feb 24, 2025
7a337fb
Merge branch 'dev' into ms/ReCoDe
staudtMarius Feb 24, 2025
9dfdf97
Merge branch 'dev' into ms/ReCoDe
staudtMarius Feb 27, 2025
0e455c2
Adapting tests.
staudtMarius Feb 27, 2025
e855008
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 4, 2025
9f80d80
Some adaptions.
staudtMarius Mar 4, 2025
34679c3
Updating to PSDM version `6.0.0`.
staudtMarius Mar 4, 2025
8175369
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 5, 2025
ff6f739
Adapting some parts.
staudtMarius Mar 5, 2025
9d40d87
Refactoring external data connections.
staudtMarius Mar 6, 2025
1ea5a83
Adding `EmDataService` to `EmAgent`.
staudtMarius Mar 7, 2025
901605c
Merge branch 'refs/heads/dev' into ms/ReCoDe
staudtMarius Mar 10, 2025
e37f50c
Refactoring `EmAgent`. Adding some tests for em agents with em service.
staudtMarius Mar 10, 2025
95cd561
Adding test for `ExtEmDataService`. Fixing some issues.
staudtMarius Mar 10, 2025
6b84f50
Adding test for `ExtEmDataService`.
staudtMarius Mar 11, 2025
0611bd8
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 11, 2025
6648588
Adapting to changes in `dev`.
staudtMarius Mar 11, 2025
369c691
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 12, 2025
3eadcc4
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 13, 2025
0fa60f7
Adapting to changes in SIMONA's `dev` branch.
staudtMarius Mar 13, 2025
b6ab770
Merge branch 'refs/heads/dev' into ms/ReCoDe
staudtMarius Mar 14, 2025
69d62ae
Merge branch 'refs/heads/dev' into ms/ReCoDe
staudtMarius Mar 18, 2025
74c290d
Saving changes.
staudtMarius Mar 18, 2025
7db942e
Saving changes.
staudtMarius Mar 19, 2025
01beeab
Saving changes.
staudtMarius Mar 20, 2025
02ae5af
Saving changes.
staudtMarius Mar 21, 2025
7aea7c6
Saving changes.
staudtMarius Mar 21, 2025
1cef155
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 21, 2025
d026dbc
Saving changes.
staudtMarius Mar 21, 2025
cca2dd6
Saving changes.
staudtMarius Mar 24, 2025
0fc9188
Saving changes.
staudtMarius Mar 25, 2025
5d5109e
Adapted to typed actor in simonaAPI
staudtMarius Mar 26, 2025
47f0fde
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 26, 2025
42fb9c3
Adapt to changes in `dev`.
staudtMarius Mar 26, 2025
6c59247
Saving changes.
staudtMarius Mar 27, 2025
ef0c089
Saving changes.
staudtMarius Mar 28, 2025
d874ba7
Saving changes.
staudtMarius Mar 31, 2025
911b671
Saving changes.
staudtMarius Mar 31, 2025
936e729
Merge branch 'dev' into ms/#1311-adapt-simona-to-typed-actors-in-api
staudtMarius Apr 1, 2025
137e31d
Adapting to API changes.
staudtMarius Apr 1, 2025
7cbdc04
Merge remote-tracking branch 'refs/remotes/origin/ms/#1311-adapt-simo…
staudtMarius Apr 1, 2025
7ec8414
Saving changes.
staudtMarius Apr 1, 2025
f7c6921
Saving changes.
staudtMarius Apr 10, 2025
af367ec
Saving changes.
staudtMarius Apr 10, 2025
c8cb333
Refactoring em messages.
staudtMarius Apr 11, 2025
f20bc8a
Saving changes.
staudtMarius Apr 15, 2025
08df66f
Enhancing `ExtEmCommunicationIT`.
staudtMarius Apr 15, 2025
d42baee
Saving changes.
staudtMarius Apr 15, 2025
336fcd9
Saving changes.
staudtMarius Apr 16, 2025
95f8846
Fixing some issues.
staudtMarius Apr 16, 2025
03df72e
Saving changes.
staudtMarius Apr 17, 2025
d3fca3c
Merge branch 'dev' into ms/ReCoDe
staudtMarius Apr 17, 2025
309d1ea
Saving changes.
staudtMarius Apr 17, 2025
a3080cc
Merge branch 'dev' into ms/ReCoDe
staudtMarius Apr 17, 2025
230dd0b
Saving changes.
staudtMarius Apr 17, 2025
bf24993
fmt
staudtMarius Apr 17, 2025
8609ff0
Merge branch 'dev' into ms/ReCoDe
staudtMarius Apr 25, 2025
26317b2
Improving `EmServiceBaseCore`.
staudtMarius Apr 28, 2025
5d5a947
Saving changes.
staudtMarius Apr 28, 2025
6216df5
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 6, 2025
de9e575
Saving changes.
staudtMarius May 6, 2025
d8b1bcf
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 7, 2025
ef51784
Saving changes.
staudtMarius May 7, 2025
a0cdff6
Saving changes.
staudtMarius May 7, 2025
b0ecf1c
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 9, 2025
27fa1d7
Merge remote-tracking branch 'origin/ms/#53-upgrate-to-scala3' into m…
staudtMarius May 12, 2025
05afd8f
Small adaptions, due to scala3 update.
staudtMarius May 12, 2025
5d131e3
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 12, 2025
fc2198d
Added parsing of flex message delay.
staudtMarius May 12, 2025
a3a5ce3
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 15, 2025
d415a1c
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 20, 2025
9dc67a6
Saving congestion result fixes.
staudtMarius May 20, 2025
1ccbd03
Saving changes.
staudtMarius May 21, 2025
4a51822
Saving changes.
staudtMarius May 21, 2025
d87abe8
Adding scaling for primary participant model.
staudtMarius May 22, 2025
de3fabe
Clean up.
staudtMarius May 22, 2025
9420777
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 26, 2025
26318bd
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 2, 2025
3e95c6b
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 4, 2025
0401b74
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 11, 2025
b5bcbef
Merge branch 'refs/heads/dev' into ms/ReCoDe
staudtMarius Jun 11, 2025
122dc0c
Saving changes.
staudtMarius Jun 11, 2025
ada78e9
Saving changes.
staudtMarius Jun 12, 2025
23609db
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 18, 2025
636cad0
Adapting to changes in `dev`.
staudtMarius Jun 18, 2025
7714450
Fixing bugs.
staudtMarius Jun 18, 2025
fc40745
fmt
staudtMarius Jun 18, 2025
bb53e9f
Saving changes.
staudtMarius Jun 24, 2025
110737e
Adapting to changes in `simonaAPI`.
staudtMarius Jun 25, 2025
61c3f25
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 25, 2025
5b89eeb
Adapting to changes in `simonaAPI`.
staudtMarius Jun 26, 2025
bf434e2
Saving changes.
staudtMarius Jun 26, 2025
c6e4c63
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 7, 2025
86f5216
ReCoDE InfluxDB.
staudtMarius Jul 7, 2025
bf653bf
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 8, 2025
50bc386
Merge remote-tracking branch 'origin/ms/#1436-refactor-LoadModel' int…
staudtMarius Jul 8, 2025
628b291
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 9, 2025
1cd430d
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 16, 2025
ba424c3
Merge remote-tracking branch 'origin/ms/#1413-enhance-config-with-mor…
staudtMarius Jul 16, 2025
b5197e8
Updating to PSDM version 8.0
staudtMarius Jul 22, 2025
19423e5
Merge branch 'refs/heads/dev' into ms/ReCoDe
staudtMarius Jul 22, 2025
578361f
Adding `ExtResultEventListener` and function to request last result f…
staudtMarius Jul 22, 2025
df09d49
Saving changes.
staudtMarius Jul 22, 2025
e032291
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 29, 2025
83a6515
Saving changes.
staudtMarius Jul 29, 2025
5d5c6a8
Adding new external result event handling.
staudtMarius Aug 8, 2025
23005d4
Update to java21.
staudtMarius Aug 13, 2025
9a87d0f
Update result handling.
staudtMarius Aug 19, 2025
ed072a4
Adapting code. Fixing bugs.
staudtMarius Aug 20, 2025
15f31de
Saving changes.
staudtMarius Aug 20, 2025
198f8b5
Merge remote-tracking branch 'origin/ms/ReCoDe' into ms/ReCoDe
staudtMarius Aug 20, 2025
aaa8b03
Refactor result handling.
staudtMarius Aug 25, 2025
da2b2ce
Merge branch 'dev' into ms/ReCoDe
staudtMarius Aug 25, 2025
7de8b79
Saving changes.
staudtMarius Aug 25, 2025
5c42c0f
Saving changes.
staudtMarius Aug 26, 2025
a95a808
Saving changes.
staudtMarius Aug 27, 2025
9455d8e
Saving changes.
staudtMarius Sep 1, 2025
90015dd
Saving changes.
staudtMarius Sep 1, 2025
c2b54ed
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 1, 2025
3a234e0
fmt
staudtMarius Sep 1, 2025
b071c24
Saving changes.
staudtMarius Sep 1, 2025
fdaae67
Saving changes.
staudtMarius Sep 1, 2025
6adbb93
Adapting to changes in API.
staudtMarius Sep 3, 2025
d065ee5
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 4, 2025
edaf634
Adapting to changes.
staudtMarius Sep 9, 2025
8e3f07d
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 9, 2025
1a764fd
Saving changes.
staudtMarius Sep 10, 2025
6598bb5
Saving changes.
staudtMarius Sep 11, 2025
dcbd78d
Added external result provider
staudtMarius Sep 12, 2025
c3d83f8
Merge branch 'dev' into ms/#1530-add-external-data-provider
staudtMarius Sep 15, 2025
db9c8c1
Saving changes.
staudtMarius Sep 15, 2025
113c8f9
Merge branch 'dev' into ms/#1530-add-external-data-provider
staudtMarius Sep 16, 2025
147c858
Adding test for `ResultServiceProxy` and `ExtResultProvider`.
staudtMarius Sep 16, 2025
a06c9dc
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 16, 2025
4c318b5
Saving changes.
staudtMarius Sep 16, 2025
34611ec
Merge branch 'dev' into ms/#1530-add-external-data-provider
staudtMarius Sep 16, 2025
38cc896
Saving changes.
staudtMarius Sep 19, 2025
f178fe1
Merge branch 'dev' into ms/#1530-add-external-data-provider
staudtMarius Sep 22, 2025
f4c0271
Merge branch 'dev' into ms/#1530-add-external-data-provider
staudtMarius Sep 23, 2025
0c786d0
Fixing bugs.
staudtMarius Sep 24, 2025
e053568
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 24, 2025
82314fe
Merge remote-tracking branch 'origin/ms/#1530-add-external-data-provi…
staudtMarius Sep 24, 2025
b623dd6
Saving changes.
staudtMarius Sep 24, 2025
0fcd0e0
Saving changes.
staudtMarius Sep 24, 2025
28d8b1c
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 30, 2025
7a6c1bf
Saving changes.
staudtMarius Sep 30, 2025
ad7dd09
Saving changes.
staudtMarius Sep 30, 2025
cdb7517
Saving changes.
staudtMarius Sep 30, 2025
46def68
Saving changes.
staudtMarius Oct 1, 2025
cb417c2
Saving changes.
staudtMarius Oct 13, 2025
8044a10
Saving changes.
staudtMarius Oct 14, 2025
4f1fbb5
Saving changes.
staudtMarius Oct 15, 2025
7fc1584
Refactoring em communication.
staudtMarius Oct 17, 2025
2adda4a
Saving changes.
staudtMarius Oct 21, 2025
c0f360c
Merge branch 'dev' into ms/ReCoDe
staudtMarius Oct 24, 2025
32f0aa4
Saving changes.
staudtMarius Oct 24, 2025
f5498df
Saving changes.
staudtMarius Oct 24, 2025
d00beff
Saving changes.
staudtMarius Oct 27, 2025
172e110
Saving changes.
staudtMarius Oct 27, 2025
99d0078
Saving changes.
staudtMarius Oct 28, 2025
dbe4295
Merge branch 'dev' into ms/ReCoDe
staudtMarius Nov 3, 2025
6c1081a
Saving changes.
staudtMarius Nov 4, 2025
a216a09
Saving changes.
staudtMarius Nov 4, 2025
bb20d92
Saving changes.
staudtMarius Nov 11, 2025
b17c30a
Saving changes.
staudtMarius Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated docker documentation [#488](https://github.com/ie3-institute/simona/issues/488)
- Added support classes for transformer tap position calculation [#1543](https://github.com/ie3-institute/simona/issues/1543)
- Added basic external em service [#1566](https://github.com/ie3-institute/simona/issues/1566)
- Added external result provider [#1530](https://github.com/ie3-institute/simona/issues/1530)

### Changed
- Upgraded `scala2` to `scala3` [#53](https://github.com/ie3-institute/simona/issues/53)
Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ tasks.shadowJar {
tasks.withType(ScalaCompile).configureEach {
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/src/",
"-P:scapegoat:disabledInspections:TryGet"
]
scalaCompileOptions.forkOptions.jvmArgs = [
'-Xss2m',
Expand All @@ -219,8 +217,6 @@ tasks.withType(ScalaCompile).configureEach {
compileTestScala {
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/testsrc/",
"-P:scapegoat:disabledInspections:TryGet"
]
}

Expand Down
6 changes: 3 additions & 3 deletions input/samples/vn_simona/vn_simona.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ simona.time.schedulerReadyCheckWindow = 900
# Input Parameters
##################################################################
simona.input.primary.csvParams = {
directoryPath: "input/samples/vn_simona/fullGrid"
directoryPath: "simona/input/samples/vn_simona/fullGridEm"
csvSep: ","
isHierarchic: false
}
simona.input.grid.datasource.id = "csv"
simona.input.grid.datasource.csvParams = {
directoryPath: "input/samples/vn_simona/fullGrid"
directoryPath: "simona/input/samples/vn_simona/fullGridEm"
csvSep: ","
isHierarchic: false
}
Expand All @@ -44,7 +44,7 @@ simona.input.weather.datasource = {
##################################################################
# Output Parameters
##################################################################
simona.output.base.dir = "output/vn_simona"
simona.output.base.dir = "simona/output/vn_simonaEM"
simona.output.base.addTimestampToOutputDir = true

simona.output.sink.csv {
Expand Down
1,531 changes: 1,531 additions & 0 deletions src/main/resources/reference.conf

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/main/scala/edu/ie3/simona/agent/EnvironmentRefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import edu.ie3.simona.event.RuntimeEvent
import edu.ie3.simona.ontology.messages.{SchedulerMessage, ServiceMessage}
import edu.ie3.simona.service.em.ExtEmDataService
import edu.ie3.simona.service.ev.ExtEvDataService
import edu.ie3.simona.service.results.ResultServiceProxy
import org.apache.pekko.actor.typed.ActorRef

/** Container class, that gather together reference to relevant entities, that
Expand All @@ -21,6 +22,8 @@ import org.apache.pekko.actor.typed.ActorRef
* Reference to the runtime event listener.
* @param primaryServiceProxy
* Reference to the primary service proxy.
* @param resultProxy
* Reference to the result service proxy.
* @param weather
* Reference to the service, that provides weather information.
* @param loadProfiles
Expand All @@ -34,6 +37,7 @@ final case class EnvironmentRefs(
scheduler: ActorRef[SchedulerMessage],
runtimeEventListener: ActorRef[RuntimeEvent],
primaryServiceProxy: ActorRef[ServiceMessage],
resultProxy: ActorRef[ResultServiceProxy.Message],
weather: ActorRef[ServiceMessage],
loadProfiles: ActorRef[ServiceMessage],
emDataService: Option[ActorRef[ExtEmDataService.Message]],
Expand Down
51 changes: 31 additions & 20 deletions src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object EmAgent {
* agent is em-controlled, or a [[Left]] with a reference to the scheduler
* that is activating this agent.
* @param listener
* A collection of result event listeners.
* A listener for result events.
* @param emDataService
* An energy management service.
*/
Expand All @@ -74,8 +74,8 @@ object EmAgent {
modelStrategy: String,
simulationStartDate: ZonedDateTime,
parent: Either[ActorRef[SchedulerMessage], ActorRef[FlexResponse]],
listener: Iterable[ActorRef[ResultEvent]],
emDataService: Option[ActorRef[ExtEmDataService.Message]] = None,
listener: ActorRef[ResultEvent],
emDataService: Option[ActorRef[ExtEmDataService.Message]],
): Behavior[Message] = Behaviors.setup[Message] { ctx =>

val parentData = emDataService match {
Expand Down Expand Up @@ -200,8 +200,18 @@ object EmAgent {
case (_, msg: Activation) =>
activate(emData, modelShell, core, msg.tick)

case (_, msg: FlexActivation) =>
activate(emData, modelShell, core, msg.tick)
case (ctx, msg: FlexActivation) =>
val tick = msg.tick
ctx.log.info(s"EmAgent (${modelShell.uuid}) activated for tick $tick")

activate(emData, modelShell, core, tick)

case (ctx, msg: FlexShiftActivation) =>
val tick = msg.tick
ctx.log.info(
s"EmAgent (${modelShell.uuid}) activated by service for tick $tick"
)
activate(emData, modelShell, core.gotoTick(tick), tick)

case (ctx, msg: IssueFlexControl) =>
val flexOptionsCore = core.activate(msg.tick)
Expand Down Expand Up @@ -265,9 +275,7 @@ object EmAgent {
)
)

emData.listener.foreach {
_ ! FlexOptionsResultEvent(flexResult)
}
emData.listener ! FlexOptionsResultEvent(flexResult)
}

emData.parent match {
Expand Down Expand Up @@ -392,6 +400,11 @@ object EmAgent {
inactiveCore,
lastActiveTick = updatedCore.activeTick,
)(using ctx.self)

ctx.log.info(
s"${modelShell.uuid} -> inactive, next tick ${completion.requestAtTick}"
)

inactive(emData, modelShell, inactiveCore)
}
.getOrElse {
Expand Down Expand Up @@ -422,17 +435,15 @@ object EmAgent {
}

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

emData.parent.foreach {
_ ! FlexResult(modelShell.uuid, result)
Expand Down Expand Up @@ -463,13 +474,13 @@ object EmAgent {
* agent is em-controlled, or a [[Left]] with a reference to the scheduler
* that is activating this agent.
* @param listener
* A collection of result event listeners.
* A listener for result events.
*/
private final case class EmData(
outputConfig: NotifierConfig,
simulationStartDate: ZonedDateTime,
parent: Either[ActorRef[SchedulerMessage], ActorRef[FlexResponse]],
listener: Iterable[ActorRef[ResultEvent]],
listener: ActorRef[ResultEvent],
)

/** The existence of this data object indicates that the corresponding agent
Expand Down
12 changes: 12 additions & 0 deletions src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ object EmDataCore {
modelToActor = modelToActor.updated(asset, actor)
)

def gotoTick(newTick: Long): Inactive = {
// remove the activations
activationQueue.headKeyOption.foreach { nextScheduledTick =>
if newTick > nextScheduledTick then {
val toActivate = activationQueue.getAndRemoveSet(nextScheduledTick)
activationQueue.set(newTick, toActivate)
}
}

this
}

/** Tries to handle an activation of the EmAgent for given tick. If the
* activation for the tick is not valid, a [[CriticalFailureException]] is
* thrown. If successful, an [[AwaitingFlexOptions]] data core is returned
Expand Down
20 changes: 17 additions & 3 deletions src/main/scala/edu/ie3/simona/agent/grid/GridAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import edu.ie3.simona.ontology.messages.SchedulerMessage.{
Completion,
ScheduleActivation,
}
import edu.ie3.simona.service.results.ResultServiceProxy.ExpectResult
import edu.ie3.simona.util.TickUtil.TickLong
import edu.ie3.util.TimeUtil
import edu.ie3.simona.util.TickUtil.{RichZonedDateTime, TickLong}
import org.apache.pekko.actor.typed.scaladsl.AskPattern.Askable
import org.apache.pekko.actor.typed.scaladsl.{
ActorContext,
Expand Down Expand Up @@ -68,7 +71,6 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
def apply(
environmentRefs: EnvironmentRefs,
simonaConfig: SimonaConfig,
listener: Iterable[ActorRef[ResultEvent]],
): Behavior[Message] = Behaviors.withStash(100) { buffer =>
val cfg = simonaConfig.simona

Expand All @@ -83,7 +85,6 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
val agentValues = GridAgentConstantData(
environmentRefs,
simonaConfig,
listener,
resolution,
simStartTime,
simEndTime,
Expand Down Expand Up @@ -229,6 +230,13 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
ctx.self,
Some(activation.tick),
)

// inform the result proxy that this grid agent will send new results
constantData.environmentRefs.resultProxy ! ExpectResult(
gridAgentBaseData.assets,
activation.tick,
)

buffer.unstashAll(simulateGrid(gridAgentBaseData, activation.tick))

case (_, msg: Message) =>
Expand Down Expand Up @@ -279,7 +287,13 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {

// check if congestion management is enabled
if gridAgentBaseData.congestionManagementParams.detectionEnabled then {
startCongestionManagement(gridAgentBaseData, currentTick, results, ctx)
startCongestionManagement(
gridAgentBaseData,
currentTick,
nextTick,
results,
ctx,
)
} else {
// clean up agent and go back to idle
gotoIdle(gridAgentBaseData, nextTick, results, ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ object GridAgentBuilder {

given ParticipantRefs = ParticipantRefs(
gridAgentContext.self,
constantData.environmentRefs.primaryServiceProxy,
environmentRefs.primaryServiceProxy,
environmentRefs.resultProxy,
serviceMap,
constantData.listener,
)

given SimulationParameters = SimulationParameters(
Expand Down Expand Up @@ -488,7 +488,7 @@ object GridAgentBuilder {
maybeControllingEm.toRight(
constantData.environmentRefs.scheduler
),
constantData.listener,
constantData.environmentRefs.resultProxy,
emDataService,
),
actorName(classOf[EmAgent.type], emInput.getId),
Expand Down
18 changes: 11 additions & 7 deletions src/main/scala/edu/ie3/simona/agent/grid/GridAgentData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ object GridAgentData {
* the grid agent.
* @param simonaConfig
* Configuration of SIMONA, that is used for.
* @param listener
* A sequence of listeners, that will receive the results from the grid
* agent.
* @param resolution
* That is used for the power flow. If no power flow should be carried out,
* this value is set to [[Long.MaxValue]].
Expand All @@ -60,14 +57,12 @@ object GridAgentData {
final case class GridAgentConstantData(
environmentRefs: EnvironmentRefs,
simonaConfig: SimonaConfig,
listener: Iterable[ActorRef[ResultEvent]],
resolution: Long,
simStartTime: ZonedDateTime,
simEndTime: ZonedDateTime,
) {
def notifyListeners(event: ResultEvent): Unit = {
listener.foreach(_ ! event)
}
def notifyListeners(event: ResultEvent): Unit =
environmentRefs.resultProxy ! event

val participantConfigUtil: ParticipantConfigUtil =
ConfigUtil.ParticipantConfigUtil(simonaConfig.simona.runtime.participant)
Expand Down Expand Up @@ -323,6 +318,15 @@ object GridAgentData {
) extends GridAgentData
with GridAgentDataHelper {

val assets: Seq[UUID] = {
val components = gridEnv.gridModel.gridComponents
components.nodes.map(_.uuid) ++ components.lines.map(
_.uuid
) ++ components.switches.map(_.uuid) ++ components.transformers.map(
_.uuid
) ++ components.transformers3w.map(_.uuid)
}

override protected val subgridGates: Vector[SubGridGate] =
gridEnv.subgridGateToActorRef.keys.toVector
override protected val subgridId: Int = gridEnv.gridModel.subnetNo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,16 @@ private[grid] trait GridResultsSupport {
def createResultModels(
grid: GridModel,
sweepValueStore: SweepValueStore,
)(implicit timestamp: ZonedDateTime, log: Logger): PowerFlowResultEvent = {
)(using timestamp: ZonedDateTime, log: Logger): PowerFlowResultEvent = {
// no sanity check for duplicated uuid result data as we expect valid data at this point
implicit val sweepValueStoreData: Map[UUID, SweepValueStoreData] =
given sweepValueStoreData: Map[UUID, SweepValueStoreData] =
sweepValueStore.sweepData
.map(sweepValueStoreData =>
sweepValueStoreData.nodeUuid -> sweepValueStoreData
)
.toMap

implicit val iNominal: ElectricCurrent =
grid.mainRefSystem.nominalCurrent
given ElectricCurrent = grid.mainRefSystem.nominalCurrent

/* When creating node results, we have to consider two things:
* 1) The result of a two winding transformer's hv node is calculated twice. If this grid contains the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ trait DCMAlgorithm extends CongestionDetection {
private[grid] def startCongestionManagement(
gridAgentBaseData: GridAgentBaseData,
currentTick: Long,
nextTick: Long,
results: Option[PowerFlowResultEvent],
ctx: ActorContext[Message],
)(using
Expand All @@ -59,7 +60,7 @@ trait DCMAlgorithm extends CongestionDetection {
val congestionManagementData = results
.map(res => CongestionManagementData(gridAgentBaseData, currentTick, res))
.getOrElse(
CongestionManagementData.empty(gridAgentBaseData, currentTick)
CongestionManagementData.empty(gridAgentBaseData, currentTick, nextTick)
)

ctx.self ! StartStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ object CongestionManagementData {
def empty(
gridAgentBaseData: GridAgentBaseData,
currentTick: Long,
nextTick: Long,
): CongestionManagementData = apply(
gridAgentBaseData,
currentTick,
Expand Down
Loading
Loading