Skip to content

Commit

Permalink
Merge branch 'refs/heads/dev' into ms/#1186-add-congestion-detection
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/main/scala/edu/ie3/simona/agent/grid/DBFSAlgorithm.scala
#	src/main/scala/edu/ie3/simona/agent/grid/GridAgent.scala
  • Loading branch information
staudtMarius committed Feb 19, 2025
2 parents 0dd4f62 + 5f0fc63 commit abc3a2a
Show file tree
Hide file tree
Showing 32 changed files with 548 additions and 161 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `VoltageLimits` [#1133](https://github.com/ie3-institute/simona/issues/1133)
- Introducing new ParticipantAgent and ParticipantModel [#1134](https://github.com/ie3-institute/simona/issues/1134)
- Using new `ParticipantAgent.Request` messages everywhere [#1195](https://github.com/ie3-institute/simona/issues/1195)
- Implementing consideration of `NotifierConfig` into new participant [#1200](https://github.com/ie3-institute/simona/issues/1200)
- Added congestion detection [#1186](https://github.com/ie3-institute/simona/issues/1186)

### Changed
Expand Down Expand Up @@ -134,6 +135,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Removing generated methods and cleaning up in config [#1170](https://github.com/ie3-institute/simona/issues/1170)
- Changed `pvInput` values in `PvInputTestData` to more realistic values [#1144](https://github.com/ie3-institute/simona/issues/1144)
- Refactor `RuntimeConfig` [#1172](https://github.com/ie3-institute/simona/issues/1172)
- Renamed some methods and variables within `ThermalGrid` and `ThermalHouse` [#1193](https://github.com/ie3-institute/simona/issues/1193)
- Replaced Java Durations with Scala Durations [#1068](https://github.com/ie3-institute/simona/issues/1068)

### Fixed
- Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505)
Expand Down Expand Up @@ -182,6 +185,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactoring of `ThermalGrid.handleInfeed` to fix thermal storage recharge correctly when empty [#930](https://github.com/ie3-institute/simona/issues/930)
- Move `ScheduleServiceActivation` out of `RegistrationResponseMessage` [#1143](https://github.com/ie3-institute/simona/issues/1143)
- Check for runningHp when handling infeed to thermalGrid [#1167](https://github.com/ie3-institute/simona/issues/1167)
- Send `FlexResult` to EM [#1202](https://github.com/ie3-institute/simona/issues/1202)

## [3.0.0] - 2023-08-07

Expand Down
17 changes: 9 additions & 8 deletions src/main/scala/edu/ie3/simona/agent/grid/DBFSAlgorithm.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ import org.apache.pekko.actor.typed.scaladsl.{
StashBuffer,
}
import org.apache.pekko.actor.typed.{ActorRef, ActorSystem, Behavior, Scheduler}
import org.apache.pekko.util.{Timeout => PekkoTimeout}
import org.apache.pekko.util.Timeout
import squants.Each

import java.time.Duration
import java.time.ZonedDateTime
import java.util.UUID
import scala.concurrent.duration.FiniteDuration
import scala.concurrent.{ExecutionContext, Future}

/** Trait that is normally mixed into every [[GridAgent]] to enable distributed
Expand Down Expand Up @@ -1088,13 +1089,13 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
sweepValueStore: Option[SweepValueStore],
nodeToAssetAgents: Map[UUID, Set[ActorRef[ParticipantAgent.Request]]],
refSystem: RefSystem,
askTimeout: Duration,
askTimeout: FiniteDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
implicit val ec: ExecutionContext = ctx.executionContext

implicit val timeout: PekkoTimeout = PekkoTimeout.create(askTimeout)
implicit val timeout: Timeout = Timeout(askTimeout)
implicit val system: ActorSystem[_] = ctx.system

ctx.log.debug(s"asking assets for power values: {}", nodeToAssetAgents)
Expand Down Expand Up @@ -1172,11 +1173,11 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
private def askInferiorGridsForPowers(
currentSweepNo: Int,
inferiorGridRefs: Map[ActorRef[GridAgent.Request], Seq[UUID]],
askTimeout: Duration,
askTimeout: FiniteDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
implicit val timeout: PekkoTimeout = PekkoTimeout.create(askTimeout)
implicit val timeout: Timeout = Timeout(askTimeout)
implicit val ec: ExecutionContext = ctx.executionContext
implicit val scheduler: Scheduler = ctx.system.scheduler

Expand Down Expand Up @@ -1229,11 +1230,11 @@ trait DBFSAlgorithm extends PowerFlowSupport with GridResultsSupport {
private def askSuperiorGridsForSlackVoltages(
currentSweepNo: Int,
superiorGridRefs: Map[ActorRef[GridAgent.Request], Seq[UUID]],
askTimeout: Duration,
askTimeout: FiniteDuration,
)(implicit
ctx: ActorContext[GridAgent.Request]
): Boolean = {
implicit val timeout: PekkoTimeout = PekkoTimeout.create(askTimeout)
implicit val timeout: Timeout = Timeout(askTimeout)
implicit val ec: ExecutionContext = ctx.executionContext
implicit val scheduler: Scheduler = ctx.system.scheduler

Expand Down
15 changes: 7 additions & 8 deletions src/main/scala/edu/ie3/simona/agent/grid/GridAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ import org.apache.pekko.actor.typed.{ActorRef, Behavior, Scheduler}
import org.apache.pekko.util.Timeout
import org.slf4j.Logger

import java.time.temporal.ChronoUnit
import java.time.{Duration, ZonedDateTime}
import java.time.ZonedDateTime
import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}
import scala.language.postfixOps
import scala.language.{implicitConversions, postfixOps}
import scala.util.{Failure, Success}

object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
Expand Down Expand Up @@ -79,9 +78,9 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
context.messageAdapter[Activation](msg => WrappedActivation(msg))

// val initialization
val resolution: Long = simonaConfig.simona.powerflow.resolution.get(
ChronoUnit.SECONDS
) // this determines the agents regular time bin it wants to be triggered e.g. one hour

// this determines the agents regular time bin it wants to be triggered e.g. one hour
val resolution: Long = simonaConfig.simona.powerflow.resolution.toSeconds

val simStartTime: ZonedDateTime = TimeUtil.withDefaults
.toZonedDateTime(simonaConfig.simona.time.startDateTime)
Expand Down Expand Up @@ -374,12 +373,12 @@ object GridAgent extends DBFSAlgorithm with DCMAlgorithm {
askMsgBuilder: ActorRef[GridAgent.Request] => Request,
resMsgBuilder: Vector[(ActorRef[GridAgent.Request], T)] => InternalReply,
ctx: ActorContext[GridAgent.Request],
)(implicit timeout: Duration): Unit = {
)(implicit timeout: FiniteDuration): Unit = {
if (inferiorGridRefs.nonEmpty) {
// creating implicit vals
implicit val ec: ExecutionContext = ctx.executionContext
implicit val scheduler: Scheduler = ctx.system.scheduler
implicit val askTimeout: Timeout = Timeout.create(timeout)
implicit val askTimeout: Timeout = Timeout(timeout)

// asking process
val future = Future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

package edu.ie3.simona.agent.grid

import java.time.Duration
import scala.concurrent.duration.FiniteDuration

/** Holds all power flow configuration parameters used in
* [[edu.ie3.simona.agent.grid]]
Expand All @@ -29,6 +29,6 @@ final case class PowerFlowParams(
maxSweepPowerDeviation: Double,
epsilon: Vector[Double],
maxIterations: Int,
sweepTimeout: Duration,
sweepTimeout: FiniteDuration,
stopOnFailure: Boolean,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import edu.ie3.simona.agent.participant.data.Data.{
PrimaryData,
PrimaryDataExtra,
}
import edu.ie3.simona.event.ResultEvent
import edu.ie3.simona.event.ResultEvent.ParticipantResultEvent
import edu.ie3.simona.exceptions.CriticalFailureException
import edu.ie3.simona.model.participant2.ParticipantModelShell
import edu.ie3.simona.ontology.messages.SchedulerMessage.Completion
Expand Down Expand Up @@ -227,7 +225,7 @@ object ParticipantAgent {
modelShell: ParticipantModelShell[_, _],
inputHandler: ParticipantInputHandler,
gridAdapter: ParticipantGridAdapter,
resultListener: Iterable[ActorRef[ResultEvent]],
resultHandler: ParticipantResultHandler,
parentData: Either[SchedulerData, FlexControlledData],
): Behavior[Request] =
Behaviors.receivePartial {
Expand All @@ -244,7 +242,7 @@ object ParticipantAgent {
updatedShell,
inputHandler,
gridAdapter,
resultListener,
resultHandler,
parentData,
)

Expand All @@ -256,15 +254,15 @@ object ParticipantAgent {
modelShell,
coreWithActivation,
gridAdapter,
resultListener,
resultHandler,
parentData,
)

ParticipantAgent(
updatedShell,
updatedInputHandler,
updatedGridAdapter,
resultListener,
resultHandler,
parentData,
)

Expand All @@ -276,15 +274,15 @@ object ParticipantAgent {
modelShell,
inputHandlerWithData,
gridAdapter,
resultListener,
resultHandler,
parentData,
)

ParticipantAgent(
updatedShell,
updatedInputHandler,
updatedGridAdapter,
resultListener,
resultHandler,
parentData,
)

Expand Down Expand Up @@ -334,7 +332,7 @@ object ParticipantAgent {
modelShell,
inputHandler,
updatedGridAdapter,
resultListener,
resultHandler,
parentData,
)

Expand All @@ -348,15 +346,15 @@ object ParticipantAgent {
modelShell,
inputHandler,
gridAdapterFinished,
resultListener,
resultHandler,
parentData,
)

ParticipantAgent(
updatedShell,
updatedInputHandler,
updatedGridAdapter,
resultListener,
resultHandler,
parentData,
)
}
Expand All @@ -373,8 +371,8 @@ object ParticipantAgent {
* The [[ParticipantInputHandler]].
* @param gridAdapter
* The [[ParticipantGridAdapter]].
* @param listener
* The result listeners.
* @param resultHandler
* The [[ParticipantResultHandler]].
* @param parentData
* The parent of this [[ParticipantAgent]].
* @return
Expand All @@ -385,7 +383,7 @@ object ParticipantAgent {
modelShell: ParticipantModelShell[_, _],
inputHandler: ParticipantInputHandler,
gridAdapter: ParticipantGridAdapter,
listener: Iterable[ActorRef[ResultEvent]],
resultHandler: ParticipantResultHandler,
parentData: Either[SchedulerData, FlexControlledData],
): (
ParticipantModelShell[_, _],
Expand Down Expand Up @@ -418,9 +416,7 @@ object ParticipantAgent {
val results =
newShell.determineResults(tick, gridAdapter.nodalVoltage)

results.modelResults.foreach { res =>
listener.foreach(_ ! ParticipantResultEvent(res))
}
results.modelResults.foreach(resultHandler.maybeSend)

val newGridAdapter =
gridAdapter.storePowerValue(results.totalPower, tick)
Expand Down Expand Up @@ -450,7 +446,11 @@ object ParticipantAgent {
case Flex(FlexActivation(tick)) =>
val shellWithFlex =
if (isCalculationRequired(shell, inputHandler)) {
shell.updateFlexOptions(tick)
val newShell = shell.updateFlexOptions(tick)
resultHandler.maybeSend(
newShell.determineFlexOptionsResult(tick)
)
newShell
} else
shell

Expand All @@ -468,15 +468,12 @@ object ParticipantAgent {
val shellWithOP = shell.updateOperatingPoint(flexControl)

// todo we determine results even if no new data arrived, and EM is also activated...
val results =
shellWithOP.determineResults(
flexControl.tick,
gridAdapter.nodalVoltage,
)
val results = shellWithOP.determineResults(
flexControl.tick,
gridAdapter.nodalVoltage,
)

results.modelResults.foreach { res =>
listener.foreach(_ ! ParticipantResultEvent(res))
}
results.modelResults.foreach(resultHandler.maybeSend)

val gridAdapterWithResult =
gridAdapter.storePowerValue(
Expand All @@ -494,11 +491,17 @@ object ParticipantAgent {
throw new CriticalFailureException(
"Received issue flex control while not controlled by EM"
),
_.emAgent ! FlexCompletion(
shellWithOP.uuid,
changeIndicator.changesAtNextActivation,
changeIndicator.changesAtTick,
),
flexData => {
flexData.emAgent ! FlexResult(
shellWithOP.uuid,
results.totalPower,
)
flexData.emAgent ! FlexCompletion(
shellWithOP.uuid,
changeIndicator.changesAtNextActivation,
changeIndicator.changesAtTick,
)
},
)

(shellWithOP, gridAdapterWithResult)
Expand Down
Loading

0 comments on commit abc3a2a

Please sign in to comment.