From ac50b98064dc53774665b94c7cc1cc1c893ae177 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 4 Jul 2024 13:27:01 +0200 Subject: [PATCH 01/22] Differentiate between different power types --- .../edu/ie3/simona/agent/em/EmAgent.scala | 8 +- .../edu/ie3/simona/agent/em/EmDataCore.scala | 6 +- .../agent/em/FlexCorrespondenceStore.scala | 8 +- .../ParticipantAgentFundamentals.scala | 22 ++--- .../agent/participant/evcs/EvcsAgent.scala | 20 ++--- .../evcs/EvcsAgentFundamentals.scala | 72 +++++++++-------- .../fixedfeedin/FixedFeedInAgent.scala | 12 +-- .../FixedFeedInAgentFundamentals.scala | 42 +++++----- .../simona/agent/participant/hp/HpAgent.scala | 12 +-- .../participant/hp/HpAgentFundamentals.scala | 40 ++++----- .../agent/participant/load/LoadAgent.scala | 18 +++-- .../load/LoadAgentFundamentals.scala | 54 ++++++------- .../simona/agent/participant/pv/PvAgent.scala | 12 +-- .../participant/pv/PvAgentFundamentals.scala | 40 ++++----- .../participant/statedata/BaseStateData.scala | 5 +- .../agent/participant/wec/WecAgent.scala | 12 +-- .../wec/WecAgentFundamentals.scala | 42 +++++----- .../simona/model/participant/BMModel.scala | 16 ++-- .../simona/model/participant/ChpModel.scala | 18 +++-- .../model/participant/FixedFeedInModel.scala | 14 ++-- .../simona/model/participant/HpModel.scala | 24 +++--- .../simona/model/participant/PvModel.scala | 19 ++--- .../model/participant/SystemParticipant.scala | 19 ++--- .../simona/model/participant/WecModel.scala | 15 ++-- .../participant/evcs/EvModelWrapper.scala | 7 +- .../model/participant/evcs/EvcsModel.scala | 21 ++--- .../participant/load/FixedLoadModel.scala | 8 +- .../model/participant/load/LoadModel.scala | 22 ++--- .../load/profile/LoadProfileStore.scala | 5 +- .../load/profile/ProfileLoadModel.scala | 5 +- .../load/random/RandomLoadModel.scala | 9 ++- .../messages/flex/FlexibilityMessage.scala | 6 +- .../services/PrimaryDataMessage.scala | 10 ++- .../util/scala/quantities/ApparentPower.scala | 81 +++++++++++++++++++ .../EvcsAgentModelCalculationSpec.scala | 24 +++--- .../ParticipantAgentFundamentalsSpec.scala | 23 +++--- .../ApparentPowerAndHeatSpec.scala | 13 ++- .../participant/FixedFeedInModelSpec.scala | 11 ++- .../model/participant/HpModelTestData.scala | 3 +- .../model/participant/PvModelSpec.scala | 5 ++ .../participant/evcs/EvcsModelSpec.scala | 2 +- .../MaximumPowerChargingSpec.scala | 2 +- .../participant/load/LoadModelSpec.scala | 31 ++++--- .../load/LoadProfileStoreSpec.scala | 3 +- .../load/ProfileLoadModelSpec.scala | 16 ++-- .../load/RandomLoadModelSpec.scala | 20 +++-- 46 files changed, 525 insertions(+), 352 deletions(-) create mode 100644 src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala diff --git a/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala b/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala index 06a7bf598a..3bbbef2382 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.em import edu.ie3.datamodel.models.input.EmInput import edu.ie3.datamodel.models.result.system.{EmResult, FlexOptionsResult} -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.statedata.BaseStateData.FlexControlledData import edu.ie3.simona.config.SimonaConfig.EmRuntimeConfig import edu.ie3.simona.event.ResultEvent @@ -394,10 +396,10 @@ object EmAgent { // calc result val result = inactiveCore.getResults .reduceOption { (power1, power2) => - ApparentPower(power1.p + power2.p, power1.q + power2.q) + ComplexPower(power1.p + power2.p, power1.q + power2.q) } .getOrElse( - ApparentPower( + ComplexPower( zeroMW, zeroMVAr, ) diff --git a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala index 3b46b176ee..8f6f3df941 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala @@ -7,7 +7,9 @@ package edu.ie3.simona.agent.em import edu.ie3.simona.exceptions.CriticalFailureException -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import EmAgent.Actor import FlexCorrespondenceStore.WithTime import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage._ @@ -162,7 +164,7 @@ object EmDataCore { /** Returns relevant results for all connected agents. */ - def getResults: Iterable[ApparentPower] = + def getResults: Iterable[ComplexPower] = correspondences.store.values.flatMap(_.receivedResult.map(_.get)) } diff --git a/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala b/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala index 5d69a5190a..aa4cca4b47 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala @@ -10,7 +10,9 @@ import edu.ie3.simona.agent.em.FlexCorrespondenceStore.{ FlexCorrespondence, WithTime, } -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{ IssueFlexControl, ProvideFlexOptions, @@ -88,7 +90,7 @@ final case class FlexCorrespondenceStore( */ def updateResult( modelUuid: UUID, - result: ApparentPower, + result: ComplexPower, tick: Long, ): FlexCorrespondenceStore = updateCorrespondence( @@ -124,7 +126,7 @@ object FlexCorrespondenceStore { final case class FlexCorrespondence( receivedFlexOptions: Option[WithTime[ProvideFlexOptions]] = None, issuedCtrlMsg: Option[WithTime[IssueFlexControl]] = None, - receivedResult: Option[WithTime[ApparentPower]] = None, + receivedResult: Option[WithTime[ComplexPower]] = None, ) /** Wrapper that allows storing a tick with an object diff --git a/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala index e636872833..6ffdd0a106 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala @@ -23,8 +23,8 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.StartCalculationTrigger import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals.RelevantResultValues import edu.ie3.simona.agent.participant.data.Data import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, - ApparentPowerAndHeat, + ApparentPower => ComplexPower, + ApparentPowerAndHeat => ComplexPowerAndHeat, EnrichableData, PrimaryDataWithApparentPower, } @@ -1768,7 +1768,7 @@ protected trait ParticipantAgentFundamentals[ ) averageResult.toApparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => stay() using nextStateData replying AssetPowerChangedMessage(p, q) } } @@ -2030,14 +2030,14 @@ object ParticipantAgentFundamentals { * The averaged apparent power */ def averageApparentPower( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, log: LoggingAdapter, - ): ApparentPower = { + ): ComplexPower = { val p = QuantityUtil.average[Power, Energy]( tickToResults.map { case (tick, pd) => tick -> pd.p @@ -2078,7 +2078,7 @@ object ParticipantAgentFundamentals { zeroMVAr } - ApparentPower(p, q) + ComplexPower(p, q) } /** Determine the average apparent power within the given tick window @@ -2095,20 +2095,20 @@ object ParticipantAgentFundamentals { * The averaged apparent power */ def averageApparentPowerAndHeat( - tickToResults: Map[Long, ApparentPowerAndHeat], + tickToResults: Map[Long, ComplexPowerAndHeat], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, log: LoggingAdapter, - ): ApparentPowerAndHeat = { + ): ComplexPowerAndHeat = { - val tickToResultsApparentPower: Map[Long, ApparentPower] = + val tickToResultsApparentPower: Map[Long, ComplexPower] = tickToResults.map { case (tick, pd) => ( tick, - ApparentPower(Megawatts(pd.p.toMegawatts), Megavars(pd.q.toMegavars)), + ComplexPower(Megawatts(pd.p.toMegawatts), Megavars(pd.q.toMegavars)), ) } @@ -2136,7 +2136,7 @@ object ParticipantAgentFundamentals { zeroMW } - ApparentPowerAndHeat(apparentPower.p, apparentPower.q, qDot) + ComplexPowerAndHeat(apparentPower.p, apparentPower.q, qDot) } } diff --git a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala index b2c428242d..8a675b90b6 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala @@ -8,7 +8,7 @@ package edu.ie3.simona.agent.participant.evcs import edu.ie3.datamodel.models.input.system.EvcsInput import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService @@ -41,7 +41,7 @@ object EvcsAgent { initStateData: ParticipantInitializeStateData[ EvcsInput, EvcsRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -63,26 +63,26 @@ class EvcsAgent( initStateData: ParticipantInitializeStateData[ EvcsInput, EvcsRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], EvcsInput, EvcsRuntimeConfig, EvcsModel, ](scheduler, initStateData) with EvcsAgentFundamentals { - override val alternativeResult: ApparentPower = ZERO_POWER + override val alternativeResult: ComplexPower = ZERO_POWER when(Idle) { case Event( EvFreeLotsRequest(tick), modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -94,7 +94,7 @@ class EvcsAgent( case Event( DepartingEvsRequest(tick, departingEvs), modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -119,13 +119,13 @@ class EvcsAgent( * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ], - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala index 941a86cb10..a92989bd98 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala @@ -15,7 +15,9 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.grid.GridAgentMessages.AssetPowerChangedMessage import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.data.Data.SecondaryData import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorEvMovementsService @@ -68,17 +70,17 @@ import scala.reflect.{ClassTag, classTag} protected trait EvcsAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], EvcsInput, EvcsRuntimeConfig, EvcsModel, ] { this: EvcsAgent => - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] /** Determines the needed base state data in dependence of the foreseen * simulation mode of the agent. @@ -115,7 +117,7 @@ protected trait EvcsAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -136,7 +138,7 @@ protected trait EvcsAgentFundamentals ) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -183,7 +185,7 @@ protected trait EvcsAgentFundamentals override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -197,7 +199,7 @@ protected trait EvcsAgentFundamentals override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -236,7 +238,7 @@ protected trait EvcsAgentFundamentals def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -244,7 +246,7 @@ protected trait EvcsAgentFundamentals data: EvcsRelevantData, lastState: EvcsState, setPower: squants.Power, - ): (EvcsState, ApparentPower, FlexChangeIndicator) = { + ): (EvcsState, ComplexPower, FlexChangeIndicator) = { /* Calculate the power */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -252,7 +254,7 @@ protected trait EvcsAgentFundamentals setPower, voltage, ) - val result = ApparentPower(setPower, reactivePower) + val result = ComplexPower(setPower, reactivePower) /* Handle the request within the model */ val (updatedState, flexChangeIndicator) = @@ -267,14 +269,14 @@ protected trait EvcsAgentFundamentals override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, ], EvcsState, Dimensionless, - ) => ApparentPower = + ) => ComplexPower = (_, _, _, _) => throw new InvalidRequestException( "Evcs model cannot be run without secondary data." @@ -303,7 +305,7 @@ protected trait EvcsAgentFundamentals */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -311,7 +313,7 @@ protected trait EvcsAgentFundamentals lastModelState: EvcsState, tick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = { + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = { /* extract EV data from secondary data, which should have been requested and received before */ baseStateData.receivedSecondaryDataStore .getOrElse(tick, Map.empty) @@ -344,7 +346,7 @@ protected trait EvcsAgentFundamentals protected def handleFreeLotsRequest( tick: Long, modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -378,13 +380,13 @@ protected trait EvcsAgentFundamentals tick: Long, requestedDepartingEvs: Seq[UUID], baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, ], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -475,12 +477,12 @@ protected trait EvcsAgentFundamentals tick: Long, scheduler: ActorRef, modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, ], - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = { + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = { val relevantData = createCalcRelevantData(modelBaseStateData, tick) @@ -541,12 +543,12 @@ protected trait EvcsAgentFundamentals */ override def determineReply( requestTick: Long, - baseStateData: BaseStateData[ApparentPower], - mostRecentRequest: Option[(Long, ApparentPower)], + baseStateData: BaseStateData[ComplexPower], + mostRecentRequest: Option[(Long, ComplexPower)], nodalVoltage: squants.Dimensionless, updatedVoltageValueStore: ValueStore[squants.Dimensionless], - alternativeResult: ApparentPower, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = { + alternativeResult: ComplexPower, + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = { /* No fast reply possible --> Some calculations have to be made */ mostRecentRequest match { case Some((lastRequestTick, _)) if lastRequestTick > requestTick => @@ -558,7 +560,7 @@ protected trait EvcsAgentFundamentals /* Repetitive request for the same tick, but with different voltage */ baseStateData match { case modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -602,7 +604,7 @@ protected trait EvcsAgentFundamentals val updatedBaseStateData = baseStateData match { case modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -669,15 +671,15 @@ protected trait EvcsAgentFundamentals */ override def handleCalculatedResult( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, ], - result: ApparentPower, + result: ComplexPower, currentTick: Long, ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -704,7 +706,7 @@ protected trait EvcsAgentFundamentals baseStateData.copy( resultValueStore = updatedResultValueStore ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -731,12 +733,12 @@ protected trait EvcsAgentFundamentals lastState: EvcsState, currentTick: Long, modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, ], - ): ValueStore[ApparentPower] = { + ): ValueStore[ComplexPower] = { val voltage = modelBaseStateData.voltageValueStore .last(currentTick) @@ -768,7 +770,7 @@ protected trait EvcsAgentFundamentals ValueStore.updateValueStore( resultValueStore, result.getTime.toTick(modelBaseStateData.startDate), - ApparentPower( + ComplexPower( Megawatts(result.getP.to(MEGAWATT).getValue.doubleValue), Megavars(result.getQ.to(MEGAVAR).getValue.doubleValue), ), @@ -790,7 +792,7 @@ protected trait EvcsAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new EvcsResult( dateTime, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala index 9b5b681f90..466ca9d070 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.fixedfeedin import edu.ie3.datamodel.models.input.system.FixedFeedInInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.statedata.ParticipantStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData import edu.ie3.simona.config.SimonaConfig.FixedFeedInRuntimeConfig @@ -23,7 +25,7 @@ object FixedFeedInAgent { initStateData: ParticipantInitializeStateData[ FixedFeedInInput, FixedFeedInRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -42,14 +44,14 @@ class FixedFeedInAgent( initStateData: ParticipantInitializeStateData[ FixedFeedInInput, FixedFeedInRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], FixedFeedInInput, FixedFeedInRuntimeConfig, FixedFeedInModel, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala index cbaabae42e..788cd8e7c8 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData @@ -63,18 +63,18 @@ import scala.reflect.{ClassTag, classTag} protected trait FixedFeedInAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], FixedFeedInInput, FixedFeedInRuntimeConfig, FixedFeedInModel, ] { this: FixedFeedInAgent => - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] - override val alternativeResult: ApparentPower = ZERO_POWER + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] + override val alternativeResult: ComplexPower = ZERO_POWER /** Determines the needed base state data in dependence of the foreseen * simulation mode of the agent. @@ -111,7 +111,7 @@ protected trait FixedFeedInAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -143,7 +143,7 @@ protected trait FixedFeedInAgentFundamentals ).filterNot(_ == lastTickInSimulation) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -188,7 +188,7 @@ protected trait FixedFeedInAgentFundamentals override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -197,7 +197,7 @@ protected trait FixedFeedInAgentFundamentals override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -223,7 +223,7 @@ protected trait FixedFeedInAgentFundamentals def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -231,7 +231,7 @@ protected trait FixedFeedInAgentFundamentals data: FixedRelevantData.type, lastState: ConstantState.type, setPower: squants.Power, - ): (ConstantState.type, ApparentPower, FlexChangeIndicator) = { + ): (ConstantState.type, ComplexPower, FlexChangeIndicator) = { /* Calculate result */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -239,7 +239,7 @@ protected trait FixedFeedInAgentFundamentals setPower, voltage, ) - val result = ApparentPower(setPower, reactivePower) + val result = ComplexPower(setPower, reactivePower) /* Handle the request within the model */ val (updatedState, flexChangeIndicator) = @@ -250,17 +250,17 @@ protected trait FixedFeedInAgentFundamentals override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = ( + ) => ComplexPower = ( currentTick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -305,7 +305,7 @@ protected trait FixedFeedInAgentFundamentals */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, FixedFeedInModel, @@ -313,7 +313,7 @@ protected trait FixedFeedInAgentFundamentals lastModelState: ConstantState.type, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = throw new InvalidRequestException( "Request to calculate power with secondary data cannot be processed in a fixed feed in agent." ) @@ -332,13 +332,13 @@ protected trait FixedFeedInAgentFundamentals * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, @@ -361,7 +361,7 @@ protected trait FixedFeedInAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new FixedFeedInResult( dateTime, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala index 0be0c2877b..6bec55f80a 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.hp import edu.ie3.datamodel.models.input.system.HpInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPowerAndHeat => ComplexPowerAndHeat +} import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData @@ -24,7 +26,7 @@ object HpAgent { initStateData: ParticipantInitializeStateData[ HpInput, HpRuntimeConfig, - ApparentPowerAndHeat, + ComplexPowerAndHeat, ], listener: Iterable[ActorRef], ): Props = @@ -46,15 +48,15 @@ class HpAgent( initStateData: ParticipantInitializeStateData[ HpInput, HpRuntimeConfig, - ApparentPowerAndHeat, + ComplexPowerAndHeat, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, ParticipantStateData[ - ApparentPowerAndHeat + ComplexPowerAndHeat ], HpInput, HpRuntimeConfig, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala index a428cd3cab..f61929c441 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala @@ -15,7 +15,9 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPowerAndHeat => ComplexPowerAndHeat +} import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.hp.HpAgent.neededServices import edu.ie3.simona.agent.participant.statedata.BaseStateData.{ @@ -64,18 +66,18 @@ import scala.reflect.{ClassTag, classTag} trait HpAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, - ParticipantStateData[ApparentPowerAndHeat], + ParticipantStateData[ComplexPowerAndHeat], HpInput, HpRuntimeConfig, HpModel, ] { this: HpAgent => - override protected val pdClassTag: ClassTag[ApparentPowerAndHeat] = - classTag[ApparentPowerAndHeat] - override val alternativeResult: ApparentPowerAndHeat = ApparentPowerAndHeat( + override protected val pdClassTag: ClassTag[ComplexPowerAndHeat] = + classTag[ComplexPowerAndHeat] + override val alternativeResult: ComplexPowerAndHeat = ComplexPowerAndHeat( zeroMW, zeroMVAr, zeroMW, @@ -88,14 +90,14 @@ trait HpAgentFundamentals override val calculateModelPowerFunc: ( Long, BaseStateData.ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, ], HpState, Dimensionless, - ) => ApparentPowerAndHeat = + ) => ComplexPowerAndHeat = (_, _, _, _) => throw new InvalidRequestException( "Heat pump model cannot be run without secondary data." @@ -103,7 +105,7 @@ trait HpAgentFundamentals override protected def createInitialState( baseStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -139,7 +141,7 @@ trait HpAgentFundamentals def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -147,7 +149,7 @@ trait HpAgentFundamentals data: HpRelevantData, lastState: HpState, setPower: squants.Power, - ): (HpState, ApparentPowerAndHeat, FlexChangeIndicator) = { + ): (HpState, ComplexPowerAndHeat, FlexChangeIndicator) = { /* Determine needed information */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -210,7 +212,7 @@ trait HpAgentFundamentals */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -218,7 +220,7 @@ trait HpAgentFundamentals lastModelState: HpState, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPowerAndHeat]] = { + ): FSM.State[AgentState, ParticipantStateData[ComplexPowerAndHeat]] = { /* Determine needed information */ val voltage = @@ -300,7 +302,7 @@ trait HpAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): BaseStateData.ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -329,7 +331,7 @@ trait HpAgentFundamentals ) ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -368,7 +370,7 @@ trait HpAgentFundamentals override protected def createCalcRelevantData( baseStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpRelevantData, HpState, HpModel, @@ -449,13 +451,13 @@ trait HpAgentFundamentals * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPowerAndHeat], + tickToResults: Map[Long, ComplexPowerAndHeat], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ], - ): ApparentPowerAndHeat = + ): ComplexPowerAndHeat = ParticipantAgentFundamentals.averageApparentPowerAndHeat( tickToResults, windowStart, @@ -478,7 +480,7 @@ trait HpAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPowerAndHeat, + result: ComplexPowerAndHeat, ): SystemParticipantResult = new HpResult( dateTime, uuid, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala index 338547efbc..05c97cbecf 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.load import edu.ie3.datamodel.models.input.system.LoadInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.load.LoadAgentFundamentals.{ FixedLoadAgentFundamentals, ProfileLoadAgentFundamentals, @@ -36,7 +38,7 @@ object LoadAgent { initStateData: ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -58,7 +60,7 @@ object LoadAgent { initStateData: ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends LoadAgent[ @@ -72,7 +74,7 @@ object LoadAgent { initStateData: ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends LoadAgent[ @@ -86,7 +88,7 @@ object LoadAgent { initStateData: ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends LoadAgent[ @@ -108,14 +110,14 @@ abstract class LoadAgent[LD <: LoadRelevantData, LM <: LoadModel[LD]]( initStateData: ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, LD, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], LoadInput, LoadRuntimeConfig, LM, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala index 79df65997c..05dad7dd4f 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData @@ -74,18 +74,18 @@ import scala.reflect.{ClassTag, classTag} protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ LD ]] extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, LD, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], LoadInput, LoadRuntimeConfig, LM, ] { this: LoadAgent[LD, LM] => - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] - override val alternativeResult: ApparentPower = ZERO_POWER + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] + override val alternativeResult: ComplexPower = ZERO_POWER /** Determines the needed base state data in dependence of the foreseen * simulation mode of the agent. @@ -122,7 +122,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, LD, ConstantState.type, LM, @@ -172,7 +172,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ SortedSet.empty[Long] } - ParticipantModelBaseStateData[ApparentPower, LD, ConstantState.type, LM]( + ParticipantModelBaseStateData[ComplexPower, LD, ConstantState.type, LM]( simulationStartDate, simulationEndDate, model, @@ -229,7 +229,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, LD, ConstantState.type, LM, @@ -253,7 +253,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, LD, ConstantState.type, LM, @@ -261,7 +261,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ data: LD, lastState: ConstantState.type, setPower: squants.Power, - ): (ConstantState.type, ApparentPower, FlexChangeIndicator) = { + ): (ConstantState.type, ComplexPower, FlexChangeIndicator) = { /* Calculate result */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -269,7 +269,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ setPower, voltage, ) - val result = ApparentPower(setPower, reactivePower) + val result = ComplexPower(setPower, reactivePower) /* Handle the request within the model */ val (updatedState, flexChangeIndicator) = @@ -300,7 +300,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, LD, ConstantState.type, LM, @@ -308,7 +308,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ lastModelState: ConstantState.type, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = throw new InconsistentStateException( s"Load model is not able to calculate power with secondary data." ) @@ -327,13 +327,13 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, @@ -356,7 +356,7 @@ protected trait LoadAgentFundamentals[LD <: LoadRelevantData, LM <: LoadModel[ override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new LoadResult( dateTime, @@ -397,7 +397,7 @@ object LoadAgentFundamentals { override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedLoadRelevantData.type, ConstantState.type, FixedLoadModel, @@ -413,17 +413,17 @@ object LoadAgentFundamentals { override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedLoadRelevantData.type, ConstantState.type, FixedLoadModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = ( + ) => ComplexPower = ( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedLoadRelevantData.type, ConstantState.type, FixedLoadModel, @@ -461,7 +461,7 @@ object LoadAgentFundamentals { override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, ProfileRelevantData, ConstantState.type, ProfileLoadModel, @@ -479,14 +479,14 @@ object LoadAgentFundamentals { override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, ProfileRelevantData, ConstantState.type, ProfileLoadModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = (tick, baseStateData, _, voltage) => { + ) => ComplexPower = (tick, baseStateData, _, voltage) => { val profileRelevantData = createCalcRelevantData(baseStateData, tick) @@ -521,7 +521,7 @@ object LoadAgentFundamentals { override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, RandomRelevantData, ConstantState.type, RandomLoadModel, @@ -539,14 +539,14 @@ object LoadAgentFundamentals { override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, RandomRelevantData, ConstantState.type, RandomLoadModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = (tick, baseStateData, _, voltage) => { + ) => ComplexPower = (tick, baseStateData, _, voltage) => { val profileRelevantData = createCalcRelevantData(baseStateData, tick) diff --git a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala index bf6f5db3b7..325159f08e 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.pv import edu.ie3.datamodel.models.input.system.PvInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData @@ -25,7 +27,7 @@ object PvAgent { initStateData: ParticipantInitializeStateData[ PvInput, PvRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -54,14 +56,14 @@ class PvAgent( initStateData: ParticipantInitializeStateData[ PvInput, PvRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], PvInput, PvRuntimeConfig, PvModel, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala index a60fa87b63..0e3fee0857 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData @@ -66,18 +66,18 @@ import scala.reflect.{ClassTag, classTag} protected trait PvAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], PvInput, PvRuntimeConfig, PvModel, ] { this: PvAgent => - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] - override val alternativeResult: ApparentPower = ZERO_POWER + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] + override val alternativeResult: ComplexPower = ZERO_POWER /** Determines the needed base state data in dependence of the foreseen * simulation mode of the agent. @@ -114,7 +114,7 @@ protected trait PvAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -135,7 +135,7 @@ protected trait PvAgentFundamentals ) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -180,7 +180,7 @@ protected trait PvAgentFundamentals override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -190,7 +190,7 @@ protected trait PvAgentFundamentals override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -262,7 +262,7 @@ protected trait PvAgentFundamentals override def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -270,7 +270,7 @@ protected trait PvAgentFundamentals data: PvRelevantData, lastState: ConstantState.type, setPower: squants.Power, - ): (ConstantState.type, ApparentPower, FlexChangeIndicator) = { + ): (ConstantState.type, ComplexPower, FlexChangeIndicator) = { /* Calculate result */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -278,7 +278,7 @@ protected trait PvAgentFundamentals setPower, voltage, ) - val result = ApparentPower(setPower, reactivePower) + val result = ComplexPower(setPower, reactivePower) /* Handle the request within the model */ val (updatedState, flexChangeIndicator) = @@ -293,14 +293,14 @@ protected trait PvAgentFundamentals override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = + ) => ComplexPower = (_, _, _, _) => throw new InvalidRequestException( "Pv model cannot be run without secondary data." @@ -329,7 +329,7 @@ protected trait PvAgentFundamentals */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, PvRelevantData, ConstantState.type, PvModel, @@ -337,7 +337,7 @@ protected trait PvAgentFundamentals lastModelState: ConstantState.type, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = { + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = { val voltage = getAndCheckNodalVoltage(baseStateData, currentTick) @@ -376,13 +376,13 @@ protected trait PvAgentFundamentals * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, @@ -405,7 +405,7 @@ protected trait PvAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new PvResult( dateTime, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala b/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala index 96758a2d16..e1a8285cf8 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala @@ -68,8 +68,9 @@ trait BaseStateData[+PD <: PrimaryDataWithApparentPower[PD]] val resultValueStore: ValueStore[PD] /** A store, holding information of the lastly requested and provided results. - * The request from the grid always targets at [[ApparentPower]], but for the - * sake of traceability, the whole averaged result ist stored + * The request from the grid always targets at + * [[edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower]], + * but for the sake of traceability, the whole averaged result ist stored */ val requestValueStore: ValueStore[PD] diff --git a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala index 957d48a28f..0466b7765d 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.wec import edu.ie3.datamodel.models.input.system.WecInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData @@ -25,7 +27,7 @@ object WecAgent { initStateData: ParticipantInitializeStateData[ WecInput, WecRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -54,14 +56,14 @@ class WecAgent( initStateData: ParticipantInitializeStateData[ WecInput, WecRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], WecInput, WecRuntimeConfig, WecModel, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala index 955131bafc..f48a01c92b 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent._ import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData @@ -61,18 +61,18 @@ import scala.reflect.{ClassTag, classTag} protected trait WecAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], WecInput, WecRuntimeConfig, WecModel, ] { this: WecAgent => - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] - override val alternativeResult: ApparentPower = ZERO_POWER + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] + override val alternativeResult: ComplexPower = ZERO_POWER /** Determines the needed base state data in dependence of the foreseen * simulation mode of the agent. @@ -109,7 +109,7 @@ protected trait WecAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -130,7 +130,7 @@ protected trait WecAgentFundamentals ) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -175,7 +175,7 @@ protected trait WecAgentFundamentals override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -185,7 +185,7 @@ protected trait WecAgentFundamentals override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -238,7 +238,7 @@ protected trait WecAgentFundamentals def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -246,7 +246,7 @@ protected trait WecAgentFundamentals data: WecRelevantData, lastState: ConstantState.type, setPower: squants.Power, - ): (ConstantState.type, ApparentPower, FlexChangeIndicator) = { + ): (ConstantState.type, ComplexPower, FlexChangeIndicator) = { /* Calculate result */ val voltage = getAndCheckNodalVoltage(baseStateData, tick) @@ -254,7 +254,7 @@ protected trait WecAgentFundamentals setPower, voltage, ) - val result = ApparentPower(setPower, reactivePower) + val result = ComplexPower(setPower, reactivePower) /* Handle the request within the model */ val (updatedState, flexChangeIndicator) = @@ -269,18 +269,18 @@ protected trait WecAgentFundamentals override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, ], ConstantState.type, Dimensionless, - ) => ApparentPower = + ) => ComplexPower = ( _: Long, _: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -315,7 +315,7 @@ protected trait WecAgentFundamentals */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -323,7 +323,7 @@ protected trait WecAgentFundamentals lastModelState: ConstantState.type, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = { + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = { val voltage = getAndCheckNodalVoltage(baseStateData, currentTick) @@ -362,13 +362,13 @@ protected trait WecAgentFundamentals * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ] = None, - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, @@ -391,7 +391,7 @@ protected trait WecAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new WecResult( dateTime, diff --git a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala index 418af563d5..ad61d74654 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala @@ -6,7 +6,9 @@ package edu.ie3.simona.model.participant -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.participant.BMModel.BMCalcRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl @@ -14,7 +16,7 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ -import edu.ie3.util.scala.quantities.EnergyPrice +import edu.ie3.util.scala.quantities.{ApparentPower, EnergyPrice} import squants.energy.Megawatts import squants.{Dimensionless, Money, Power, Temperature} @@ -29,7 +31,7 @@ final case class BMModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhi: Double, private val node: String, private val isCostControlled: Boolean, @@ -38,7 +40,7 @@ final case class BMModel( private val loadGradient: Double, ) extends SystemParticipant[ BMCalcRelevantData, - ApparentPower, + ComplexPower, ConstantState.type, ]( uuid, @@ -59,7 +61,7 @@ final case class BMModel( voltage: Dimensionless, modelState: ConstantState.type, data: BMCalcRelevantData, - ): ApparentPower = { + ): ComplexPower = { val result = super.calculatePower(tick, voltage, modelState, data) _lastPower = Some(result.p) @@ -198,7 +200,7 @@ final case class BMModel( sRated * cosPhi * (-1) else sRated * usage * eff * cosPhi * (-1) - } + }.toPower /** Applies the load gradient to the electrical output * @param pEl @@ -212,7 +214,7 @@ final case class BMModel( _lastPower match { case None => pEl case Some(lastPowerVal) => - val pElDeltaMaxAbs = sRated * cosPhi * loadGradient + val pElDeltaMaxAbs = sRated.toPower * cosPhi * loadGradient pEl - lastPowerVal match { case pElDelta if pElDelta > pElDeltaMaxAbs => diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 5af1b68236..8ce0245c4c 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -7,7 +7,9 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.ChpInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ChpModel._ import edu.ie3.simona.model.participant.ModelState.ConstantState @@ -17,8 +19,12 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.DefaultQuantities import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{ + ApparentPower, + DefaultQuantities, + Kilovoltamperes, +} import squants.energy.Kilowatts import squants.{Energy, Power, Seconds, Time} @@ -50,11 +56,11 @@ final case class ChpModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, pThermal: Power, storage: ThermalStorage with MutableStorage, -) extends SystemParticipant[ChpRelevantData, ApparentPower, ConstantState.type]( +) extends SystemParticipant[ChpRelevantData, ComplexPower, ConstantState.type]( uuid, id, operationInterval, @@ -64,7 +70,7 @@ final case class ChpModel( ) with ApparentPowerParticipant[ChpRelevantData, ConstantState.type] { - val pRated: Power = sRated * cosPhiRated + val pRated: Power = sRated.toPower * cosPhiRated /** As this is a state-full model (with respect to the current operation * condition and its thermal storage), the power calculation operates on the @@ -387,7 +393,7 @@ object ChpModel { scaledInput.getId, operationInterval, qControl, - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated .to(PowerSystemUnits.KILOWATT) .getValue diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index c50b2f6211..6b7b0834b8 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.model.participant import com.typesafe.scalalogging.LazyLogging import edu.ie3.datamodel.models.input.system.FixedFeedInInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.config.SimonaConfig import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData @@ -18,8 +20,8 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.Power -import squants.energy.Kilowatts import java.time.ZonedDateTime import java.util.UUID @@ -44,11 +46,11 @@ final case class FixedFeedInModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, ) extends SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ]( uuid, @@ -72,7 +74,7 @@ final case class FixedFeedInModel( modelState: ConstantState.type, data: FixedRelevantData.type = FixedRelevantData, ): Power = - sRated * (-1) * cosPhiRated + sRated.toPower * (-1) * cosPhiRated override def determineFlexOptions( data: FixedRelevantData.type, @@ -115,7 +117,7 @@ object FixedFeedInModel extends LazyLogging { scaledInput.getId, operationInterval, QControl.apply(scaledInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( scaledInput.getsRated .to(PowerSystemUnits.KILOWATT) .getValue diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index 7af9279611..47341eb919 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -7,7 +7,9 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.HpInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPowerAndHeat => ComplexPowerAndHeat +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.HpModel.{HpRelevantData, HpState} import edu.ie3.simona.model.participant.control.QControl @@ -17,8 +19,12 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.DefaultQuantities import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{ + ApparentPower, + DefaultQuantities, + Kilovoltamperes, +} import squants.energy.Kilowatts import squants.{Power, Temperature} @@ -53,13 +59,13 @@ final case class HpModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, pThermal: Power, thermalGrid: ThermalGrid, ) extends SystemParticipant[ HpRelevantData, - ApparentPowerAndHeat, + ComplexPowerAndHeat, HpState, ]( uuid, @@ -72,7 +78,7 @@ final case class HpModel( with ApparentPowerAndHeatParticipant[HpRelevantData, HpState] { private val pRated: Power = - sRated * cosPhiRated + sRated.toPower * cosPhiRated /** As this is a state-full model (with respect to the current operation * condition and inner temperature), the power calculation operates on the @@ -223,7 +229,7 @@ final case class HpModel( updatedState.activePower val upperBoundary = if (canOperate) - sRated * cosPhiRated + sRated.toPower * cosPhiRated else zeroKW @@ -258,7 +264,7 @@ final case class HpModel( setPower: Power, ): (HpState, FlexChangeIndicator) = { /* If the setpoint value is above 50 % of the electrical power, turn on the heat pump otherwise turn it off */ - val turnOn = setPower > (sRated * cosPhiRated * 0.5) + val turnOn = setPower > (sRated.toPower * cosPhiRated * 0.5) val updatedState = calcState(lastState, data, turnOn) ( @@ -299,7 +305,7 @@ object HpModel { scaledInput.getId, operationInterval, qControl, - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated .to(PowerSystemUnits.KILOWATT) .getValue @@ -402,7 +408,7 @@ object HpModel { scaledInput.getId, operationInterval, qControl, - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated .to(PowerSystemUnits.KILOWATT) .getValue diff --git a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala index 78508c91d5..bc226040c0 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala @@ -7,7 +7,9 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.PvInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.PvModel.PvRelevantData @@ -18,7 +20,6 @@ import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities._ import squants._ -import squants.energy.Kilowatts import squants.space.{Degrees, SquareMeters} import squants.time.Minutes import tech.units.indriya.unit.Units._ @@ -33,7 +34,7 @@ final case class PvModel private ( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, private val lat: Angle, private val lon: Angle, @@ -42,7 +43,7 @@ final case class PvModel private ( private val alphaE: Angle, private val gammaE: Angle, private val moduleSurface: Area = SquareMeters(1d), -) extends SystemParticipant[PvRelevantData, ApparentPower, ConstantState.type]( +) extends SystemParticipant[PvRelevantData, ComplexPower, ConstantState.type]( uuid, id, operationInterval, @@ -55,15 +56,15 @@ final case class PvModel private ( /** Override sMax as the power output of a pv unit could become easily up to * 10% higher than the sRated value found in the technical sheets */ - override val sMax: Power = sRated * 1.1 + override val sMax: ApparentPower = sRated * 1.1 /** Permissible maximum active power feed in (therefore negative) */ - protected val pMax: Power = sMax * cosPhiRated * -1d + protected val pMax: Power = sMax.toPower * cosPhiRated * -1d /** Reference yield at standard testing conditions (STC) */ private val yieldSTC = WattsPerSquareMeter(1000d) - private val activationThreshold = sRated * cosPhiRated * 0.001 * -1d + private val activationThreshold = sRated.toPower * cosPhiRated * 0.001 * -1d /** Calculate the active power behaviour of the model * @@ -691,7 +692,7 @@ final case class PvModel private ( eTotalInWhPerSM * moduleSurface.toSquareMeters * etaConv.toEach * (genCorr * tempCorr) /* Calculate the foreseen active power output without boundary condition adaptions */ - val proposal = sRated * (-1) * ( + val proposal = sRated.toPower * (-1) * ( actYield / irradiationSTC ) * cosPhiRated @@ -771,7 +772,7 @@ object PvModel { scaledInput.getId, operationInterval, QControl(scaledInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( scaledInput.getsRated .to(PowerSystemUnits.KILOWATT) .getValue diff --git a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala index 44c70539d7..84f09f5d0f 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala @@ -7,7 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ApparentPower => ComplexPower, PrimaryDataWithApparentPower, } import edu.ie3.simona.model.SystemComponent @@ -16,6 +16,7 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ import edu.ie3.util.scala.quantities.{ + ApparentPower, DefaultQuantities, Megavars, ReactivePower, @@ -55,7 +56,7 @@ abstract class SystemParticipant[ id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, ) extends SystemComponent(uuid, id, operationInterval) { @@ -64,7 +65,7 @@ abstract class SystemParticipant[ * overwritten if the system participant's apparent power can be higher than * sRated. */ - protected val sMax: Power = sRated + protected val sMax: ApparentPower = sRated /** Calculate the power behaviour based on the given data. * @@ -102,17 +103,17 @@ abstract class SystemParticipant[ voltage: Dimensionless, modelState: MS, data: CD, - ): ApparentPower = { + ): ComplexPower = { if (isInOperation(tick)) { val activePower = calculateActivePower(modelState, data) val reactivePower = calculateReactivePower(activePower, voltage) - ApparentPower( + ComplexPower( activePower, reactivePower, ) } else { - ApparentPower( + ComplexPower( DefaultQuantities.zeroMW, DefaultQuantities.zeroMVAr, ) @@ -173,7 +174,7 @@ abstract class SystemParticipant[ nodalVoltage: Dimensionless ): Power => ReactivePower = qControl.activeToReactivePowerFunc( - sRated, + sRated.toPower, cosPhiRated, nodalVoltage, ) @@ -221,7 +222,7 @@ abstract class SystemParticipant[ ) // tolerance for double inaccuracies - val sMaxWithTolerance = sMax * 1.00001d + val sMaxWithTolerance = sMax.toPower * 1.00001d if (apparentPower > sMaxWithTolerance) { logger.debug( @@ -232,7 +233,7 @@ abstract class SystemParticipant[ s"in correspondence to the existing active power $activePower." ) - val powerSquaredDifference = Math.pow(sMax.toMegawatts, 2) - + val powerSquaredDifference = Math.pow(sMax.toPower.toMegawatts, 2) - Math.pow(activePower.toMegawatts, 2) if (powerSquaredDifference < 0) { diff --git a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala index f2f34ac771..3d8de4a1cb 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.WecInput import edu.ie3.datamodel.models.input.system.characteristic.WecCharacteristicInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.WecModel.{ @@ -23,8 +25,9 @@ import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMin import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants._ -import squants.energy.{Kilowatts, Watts} +import squants.energy.Watts import squants.mass.{Kilograms, KilogramsPerCubicMeter} import squants.motion.{MetersPerSecond, Pressure} import squants.space.SquareMeters @@ -60,11 +63,11 @@ final case class WecModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, rotorArea: Area, betzCurve: WecCharacteristic, -) extends SystemParticipant[WecRelevantData, ApparentPower, ConstantState.type]( +) extends SystemParticipant[WecRelevantData, ComplexPower, ConstantState.type]( uuid, id, operationInterval, @@ -95,7 +98,7 @@ final case class WecModel( wecData: WecRelevantData, ): Power = { val activePower = determinePower(wecData) - val pMax = sMax * cosPhiRated + val pMax = sMax.toPower * cosPhiRated (if (activePower > pMax) { logger.warn( @@ -274,7 +277,7 @@ object WecModel { scaledInput.getId, operationInterval, QControl(scaledInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated.to(KILOWATT).getValue.doubleValue ), scaledInput.getType.getCosPhiRated, diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala index f928af2fcf..b5d0d7ec94 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala @@ -9,6 +9,7 @@ package edu.ie3.simona.model.participant.evcs import edu.ie3.simona.api.data.ev.model.EvModel import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.energy.{KilowattHours, Kilowatts} import java.util.UUID @@ -32,8 +33,10 @@ final case class EvModelWrapper( def uuid: UUID = original.getUuid def id: String = original.getId - lazy val sRatedAc: squants.Power = - Kilowatts(original.getSRatedAC.to(KILOWATT).getValue.doubleValue) + lazy val sRatedAc: ApparentPower = + Kilovoltamperes( + original.getSRatedAC.to(KILOVOLTAMPERE).getValue.doubleValue + ) lazy val sRatedDc: squants.Power = Kilowatts(original.getSRatedDC.to(KILOWATT).getValue.doubleValue) lazy val eStorage: squants.Energy = KilowattHours( diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index b00ec5e5e3..ad16931c9f 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -11,7 +11,9 @@ import edu.ie3.datamodel.models.ElectricCurrentType import edu.ie3.datamodel.models.input.system.EvcsInput import edu.ie3.datamodel.models.input.system.`type`.evcslocation.EvcsLocationType import edu.ie3.datamodel.models.result.system.{EvResult, EvcsResult} -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.model.participant.evcs.EvcsModel._ @@ -19,7 +21,6 @@ import edu.ie3.simona.model.participant.evcs.uncontrolled.{ ConstantPowerCharging, MaximumPowerCharging, } -import edu.ie3.util.scala.quantities.DefaultQuantities._ import edu.ie3.simona.model.participant.{ CalcRelevantData, FlexChangeIndicator, @@ -32,7 +33,9 @@ import edu.ie3.simona.util.TickUtil.TickLong import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble import edu.ie3.util.scala.OperationInterval -import squants.energy.{KilowattHours, Kilowatts} +import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} +import squants.energy.Kilowatts import squants.time.Seconds import squants.{Dimensionless, Energy, Power} import tech.units.indriya.unit.Units.PERCENT @@ -73,7 +76,7 @@ final case class EvcsModel( operationInterval: OperationInterval, simulationStartDate: ZonedDateTime, qControl: QControl, - sRated: Power, + sRated: ApparentPower, currentType: ElectricCurrentType, cosPhiRated: Double, chargingPoints: Int, @@ -81,7 +84,7 @@ final case class EvcsModel( vehicle2grid: Boolean, strategy: ChargingStrategy.Value, lowestEvSoc: Double, -) extends SystemParticipant[EvcsRelevantData, ApparentPower, EvcsState]( +) extends SystemParticipant[EvcsRelevantData, ComplexPower, EvcsState]( uuid, id, operationInterval, @@ -500,12 +503,12 @@ final case class EvcsModel( ): Power = { val evPower = currentType match { case ElectricCurrentType.AC => - ev.sRatedAc + ev.sRatedAc.toPower case ElectricCurrentType.DC => ev.sRatedDc } /* Limit the charging power to the minimum of ev's and evcs' permissible power */ - evPower.min(sRated) + evPower.min(sRated.toPower) } override def calculatePower( @@ -513,7 +516,7 @@ final case class EvcsModel( voltage: Dimensionless, modelState: EvcsState, data: EvcsRelevantData, - ): ApparentPower = + ): ComplexPower = throw new NotImplementedError("Use calculatePowerAndEvSoc() instead.") override protected def calculateActivePower( @@ -1062,7 +1065,7 @@ object EvcsModel { operationInterval, simulationStartDate, QControl(scaledInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated.to(KILOWATT).getValue.doubleValue ), scaledInput.getType.getElectricCurrentType, diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/FixedLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/FixedLoadModel.scala index 6b0b8a97ef..321c192849 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/FixedLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/FixedLoadModel.scala @@ -17,8 +17,8 @@ import edu.ie3.simona.model.participant.load.LoadReference.{ } import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.Power -import squants.energy.Kilowatts import squants.time.Days import java.util.UUID @@ -45,7 +45,7 @@ final case class FixedLoadModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, reference: LoadReference, ) extends LoadModel[FixedLoadRelevantData.type]( @@ -95,9 +95,9 @@ object FixedLoadModel { scaledInput.getId, operationInterval, QControl(scaledInput.getqCharacteristics()), - Kilowatts( + Kilovoltamperes( scaledInput.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala index 183f1dc5ae..1c94aa3020 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.model.participant.load import com.typesafe.scalalogging.LazyLogging import edu.ie3.datamodel.models.input.system.LoadInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.participant.CalcRelevantData.LoadRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl @@ -21,7 +23,7 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptio import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval -import squants.energy.Kilowatts +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.{Energy, Power} import java.util.UUID @@ -36,9 +38,9 @@ abstract class LoadModel[D <: LoadRelevantData]( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, -) extends SystemParticipant[D, ApparentPower, ConstantState.type]( +) extends SystemParticipant[D, ComplexPower, ConstantState.type]( uuid, id, operationInterval, @@ -89,14 +91,14 @@ object LoadModel extends LazyLogging { inputModel: LoadInput, activePower: Power, safetyFactor: Double = 1d, - ): Power = { - val sRated = Kilowatts( + ): ApparentPower = { + val sRated = Kilovoltamperes( inputModel.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ) - val pRated = sRated * inputModel.getCosPhiRated + val pRated = sRated.toPower * inputModel.getCosPhiRated val referenceScalingFactor = activePower / pRated sRated * referenceScalingFactor * safetyFactor } @@ -129,10 +131,10 @@ object LoadModel extends LazyLogging { def scaleSRatedEnergy( inputModel: LoadInput, energyConsumption: Energy, - profileMaxPower: Power, + profileMaxPower: ApparentPower, profileEnergyScaling: Energy, safetyFactor: Double = 1d, - ): Power = { + ): ApparentPower = { (profileMaxPower / inputModel.getCosPhiRated) * ( energyConsumption / profileEnergyScaling ) * safetyFactor diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala index f1e7d54f62..0104bd3875 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala @@ -17,6 +17,7 @@ import edu.ie3.simona.model.participant.load.profile.LoadProfileStore.{ initializeTypeDayValues, } import edu.ie3.simona.model.participant.load.{DayType, profile} +import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import org.apache.commons.csv.CSVFormat import squants.energy.{KilowattHours, Watts} @@ -88,10 +89,10 @@ class LoadProfileStore private (val reader: Reader) { */ def maxPower( loadProfile: StandardLoadProfile - ): squants.Power = { + ): ApparentPower = { maxParamMap.get(loadProfile) match { case Some(value) => - Watts(value) + Voltamperes(value) case None => throw new RuntimeException( "Max value for ConsumerType " + loadProfile.toString + " not found" diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala index 5e919a0064..5419436ebe 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala @@ -15,6 +15,7 @@ import edu.ie3.simona.model.participant.load.LoadReference._ import edu.ie3.simona.model.participant.load.profile.ProfileLoadModel.ProfileRelevantData import edu.ie3.simona.model.participant.load.{LoadModel, LoadReference} import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.ApparentPower import squants.Power import java.time.ZonedDateTime @@ -44,7 +45,7 @@ final case class ProfileLoadModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, loadProfile: StandardLoadProfile, reference: LoadReference, @@ -91,7 +92,7 @@ final case class ProfileLoadModel( reference match { case ActivePower(activePower) => /* scale the reference active power based on the profiles averagePower/maxPower ratio */ - val referenceScalingFactor = averagePower / profileMaxPower + val referenceScalingFactor = averagePower / profileMaxPower.toPower activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles average power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index a09e9bc8ff..e3ff1ee9e7 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -17,8 +17,9 @@ import edu.ie3.simona.model.participant.load.random.RandomLoadModel.RandomReleva import edu.ie3.simona.model.participant.load.{DayType, LoadModel, LoadReference} import edu.ie3.util.TimeUtil import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import squants.Power -import squants.energy.{KilowattHours, Kilowatts, Watts} +import squants.energy.{KilowattHours, Kilowatts} import java.time.ZonedDateTime import java.util.UUID @@ -50,7 +51,7 @@ final case class RandomLoadModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, reference: LoadReference, ) extends LoadModel[RandomRelevantData]( @@ -101,7 +102,7 @@ final case class RandomLoadModel( case ActivePower(activePower) => /* scale the reference active power based on the random profiles averagePower/maxPower ratio */ val referenceScalingFactor = - profilePower / RandomLoadModel.randomMaxPower + profilePower / RandomLoadModel.randomMaxPower.toPower activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles random power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ @@ -170,7 +171,7 @@ object RandomLoadModel { * @return * Reference power to use for later model calculations */ - private val randomMaxPower: Power = Watts(159d) + private val randomMaxPower: ApparentPower = Voltamperes(159d) def apply( input: LoadInput, diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala index 812eafbfff..6715abd69d 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.ontology.messages.flex import edu.ie3.datamodel.models.input.AssetInput import edu.ie3.simona.agent.em.EmAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.scheduler.ScheduleLock.ScheduleKey import org.apache.pekko.actor.typed.ActorRef import squants.Power @@ -136,7 +138,7 @@ object FlexibilityMessage { */ final case class FlexCtrlCompletion( override val modelUuid: UUID, - result: ApparentPower, + result: ComplexPower, requestAtNextActivation: Boolean = false, requestAtTick: Option[Long] = None, ) extends FlexResponse diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala index 73aa482b64..79f41a8811 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala @@ -6,7 +6,9 @@ package edu.ie3.simona.ontology.messages.services -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.ontology.messages.services.ServiceMessage.ProvisionMessage import edu.ie3.simona.scheduler.ScheduleLock.ScheduleKey import org.apache.pekko.actor.ActorRef @@ -15,7 +17,7 @@ sealed trait PrimaryDataMessage object PrimaryDataMessage { - /** Provides primary data in the form of [[ApparentPower]] + /** Provides primary data in the form of [[ComplexPower]] * * @param tick * Tick, the data belongs to @@ -28,9 +30,9 @@ object PrimaryDataMessage { final case class ApparentPowerProvisionMessage( override val tick: Long, override val serviceRef: ActorRef, - override val data: ApparentPower, + override val data: ComplexPower, override val nextDataTick: Option[Long], override val unlockKey: Option[ScheduleKey] = None, - ) extends ProvisionMessage[ApparentPower] + ) extends ProvisionMessage[ComplexPower] with PrimaryDataMessage } diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala new file mode 100644 index 0000000000..7c007d85b2 --- /dev/null +++ b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala @@ -0,0 +1,81 @@ +/* + * © 2022. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.util.scala.quantities + +import squants._ +import squants.energy._ +import squants.time.Time + +import scala.util.Try + +final class ApparentPower private ( + val value: Double, + val unit: ApparentPowerUnit, +) extends Quantity[ApparentPower] { + + def dimension: ApparentPower.type = ApparentPower + + def toMillivoltamperes: Double = to(Millivoltamperes) + def toVoltamperes: Double = to(Voltamperes) + def toKilovoltamperes: Double = to(Kilovoltamperes) + def toMegavoltamperes: Double = to(Megavoltamperes) + def toGigavoltamperes: Double = to(Gigavoltamperes) + + def toPower: Power = Watts(toVoltamperes) +} + +object ApparentPower extends Dimension[ApparentPower] { + private[quantities] def apply[A](n: A, unit: ApparentPowerUnit)(implicit + num: Numeric[A] + ) = new ApparentPower(num.toDouble(n), unit) + def apply(energy: Energy, time: Time): ApparentPower = + apply(energy.toWattHours / time.toHours, Voltamperes) + def apply(value: Any): Try[ApparentPower] = parse(value) + + def name = "Power" + def primaryUnit: Voltamperes.type = Voltamperes + def siUnit: Voltamperes.type = Voltamperes + def units: Set[UnitOfMeasure[ApparentPower]] = + Set( + Voltamperes, + Millivoltamperes, + Kilovoltamperes, + Megavoltamperes, + Gigavoltamperes, + ) +} + +trait ApparentPowerUnit + extends UnitOfMeasure[ApparentPower] + with UnitConverter { + def apply[A](n: A)(implicit num: Numeric[A]): ApparentPower = + ApparentPower(n, this) +} + +object Millivoltamperes extends ApparentPowerUnit with SiUnit { + val conversionFactor: Double = MetricSystem.Milli + val symbol = "mVA" +} + +object Voltamperes extends ApparentPowerUnit with PrimaryUnit with SiUnit { + val symbol = "VA" +} + +object Kilovoltamperes extends ApparentPowerUnit with SiUnit { + val conversionFactor: Double = MetricSystem.Kilo + val symbol = "kVA" +} + +object Megavoltamperes extends ApparentPowerUnit with SiUnit { + val conversionFactor: Double = MetricSystem.Mega + val symbol = "MVA" +} + +object Gigavoltamperes extends ApparentPowerUnit with SiUnit { + val conversionFactor: Double = MetricSystem.Giga + val symbol = "GVA" +} diff --git a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala index 08420edfbe..7bd48e2ac6 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala @@ -1300,9 +1300,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev900.sRatedAc - minPower shouldBe ev900.sRatedAc // battery is empty - maxPower shouldBe ev900.sRatedAc + referencePower shouldBe ev900.sRatedAc.toPower + minPower shouldBe ev900.sRatedAc.toPower // battery is empty + maxPower shouldBe ev900.sRatedAc.toPower } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1418,9 +1418,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc - minPower shouldBe ev900.sRatedAc // battery is empty - maxPower shouldBe ev4500.sRatedAc + referencePower shouldBe ev4500.sRatedAc.toPower + minPower shouldBe ev900.sRatedAc.toPower // battery is empty + maxPower shouldBe ev4500.sRatedAc.toPower } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1469,9 +1469,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc + referencePower shouldBe ev4500.sRatedAc.toPower minPower shouldBe Kilowatts(0.0) // battery is exactly at margin - maxPower shouldBe ev4500.sRatedAc + maxPower shouldBe ev4500.sRatedAc.toPower } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1558,7 +1558,7 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid refPower shouldBe combinedChargingPowerSq - minPower shouldBe ev4500.sRatedAc * -1 // battery of earlier ev is above lowest soc now + minPower shouldBe ev4500.sRatedAc.toPower * -1 // battery of earlier ev is above lowest soc now maxPower shouldBe combinedChargingPowerSq } @@ -1712,7 +1712,7 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid referencePower shouldBe combinedChargingPowerSq - minPower shouldBe ev4500.sRatedAc * -1 // battery of ev11700 is below lowest soc now + minPower shouldBe ev4500.sRatedAc.toPower * -1 // battery of ev11700 is below lowest soc now maxPower shouldBe combinedChargingPowerSq } @@ -1913,9 +1913,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc + referencePower shouldBe ev4500.sRatedAc.toPower minPower shouldBe Kilowatts(0d) - maxPower shouldBe ev4500.sRatedAc + maxPower shouldBe ev4500.sRatedAc.toPower } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala index 10a2652e9d..dde8ed4803 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala @@ -6,10 +6,6 @@ package edu.ie3.simona.agent.participant -import org.apache.pekko.actor.ActorRef.noSender -import org.apache.pekko.actor.{ActorRef, ActorSystem} -import org.apache.pekko.testkit.TestFSMRef -import org.apache.pekko.util.Timeout import breeze.numerics.pow import com.typesafe.config.ConfigFactory import edu.ie3.datamodel.models.input.system.SystemParticipantInput @@ -27,8 +23,8 @@ import edu.ie3.simona.exceptions.agent.{ InconsistentStateException, } import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData -import edu.ie3.simona.model.participant.SystemParticipant import edu.ie3.simona.model.participant.ModelState.ConstantState +import edu.ie3.simona.model.participant.SystemParticipant import edu.ie3.simona.model.participant.control.QControl.CosPhiFixed import edu.ie3.simona.model.participant.load.FixedLoadModel.FixedLoadRelevantData import edu.ie3.simona.model.participant.load.{FixedLoadModel, LoadReference} @@ -36,13 +32,22 @@ import edu.ie3.simona.test.common.AgentSpec import edu.ie3.simona.test.common.model.participant.LoadTestData import edu.ie3.util.TimeUtil import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.{Megavars, ReactivePower, Vars} +import edu.ie3.util.scala.quantities.{ + Kilovoltamperes, + Megavars, + ReactivePower, + Vars, +} +import org.apache.pekko.actor.ActorRef.noSender +import org.apache.pekko.actor.{ActorRef, ActorSystem} +import org.apache.pekko.testkit.TestFSMRef +import org.apache.pekko.util.Timeout import org.mockito.Mockito.when import org.scalatest.PrivateMethodTester import org.scalatest.prop.{TableDrivenPropertyChecks, TableFor3, TableFor5} import org.scalatestplus.mockito.MockitoSugar -import squants.{Each, Power} import squants.energy.{Kilowatts, Megawatts, Watts} +import squants.{Each, Power} import java.util.UUID import java.util.concurrent.TimeUnit @@ -538,7 +543,7 @@ class ParticipantAgentFundamentalsSpec "test_load", OperationInterval(0L, 1800L), CosPhiFixed(0.95), - Kilowatts(100.0), + Kilovoltamperes(100.0), 0.95, LoadReference.ActivePower(Kilowatts(95.0)), ), @@ -575,7 +580,7 @@ class ParticipantAgentFundamentalsSpec "test_load", OperationInterval(0L, 1800L), CosPhiFixed(0.95), - Kilowatts(100.0), + Kilovoltamperes(100.0), 0.95, LoadReference.ActivePower(Kilowatts(95.0)), ), diff --git a/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala index 6e8556d6ca..abcdb613a6 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala @@ -11,12 +11,17 @@ import edu.ie3.simona.model.participant.ApparentPowerAndHeatSpec.ApparentPowerAn import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl.CosPhiFixed -import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage +import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions import edu.ie3.simona.test.common.UnitSpec import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.{Megavars, ReactivePower, Vars} -import squants.energy.{Kilowatts, Megawatts, Watts} +import edu.ie3.util.scala.quantities.{ + Kilovoltamperes, + Megavars, + ReactivePower, + Vars, +} +import squants.energy.{Megawatts, Watts} import squants.{Each, Power} import java.util.UUID @@ -69,7 +74,7 @@ object ApparentPowerAndHeatSpec { "ParticipantMock", OperationInterval.apply(0L, 42L), CosPhiFixed(0.97), - Kilowatts(42d), + Kilovoltamperes(42d), 0.97, ) with ApparentPowerAndHeatParticipant[ diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala index bbd90653f1..d1308757e5 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala @@ -14,8 +14,13 @@ import edu.ie3.simona.test.common.input.FixedFeedInputTestData import edu.ie3.simona.test.common.{DefaultTestData, UnitSpec} import edu.ie3.simona.util.ConfigUtil import edu.ie3.util.quantities.PowerSystemUnits.MEGAVOLTAMPERE +import edu.ie3.util.scala.quantities.{ + ApparentPower, + Megavoltamperes, + Voltamperes, +} import org.scalatest.PrivateMethodTester -import squants.energy.{Kilowatts, Megawatts, Watts} +import squants.energy.Kilowatts class FixedFeedInModelSpec extends UnitSpec @@ -23,7 +28,7 @@ class FixedFeedInModelSpec with DefaultTestData with PrivateMethodTester { - private implicit val powerTolerance: squants.Power = Watts( + private implicit val powerTolerance: ApparentPower = Voltamperes( 1.0 ) // Equals to 1 W power @@ -62,7 +67,7 @@ class FixedFeedInModelSpec operationInterval shouldBe defaultOperationInterval qControl shouldBe QControl(fixedFeedInput.getqCharacteristics) sRated should approximate( - Megawatts( + Megavoltamperes( fixedFeedInput.getsRated().to(MEGAVOLTAMPERE).getValue.doubleValue ) ) diff --git a/src/test/scala/edu/ie3/simona/model/participant/HpModelTestData.scala b/src/test/scala/edu/ie3/simona/model/participant/HpModelTestData.scala index cbbe51ba9e..eb4119d270 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/HpModelTestData.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/HpModelTestData.scala @@ -28,6 +28,7 @@ import edu.ie3.simona.model.thermal.{ } import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.Kilovoltamperes import squants.energy.{KilowattHours, Kilowatts} import squants.thermal.Celsius import squants.{Power, Temperature} @@ -78,7 +79,7 @@ trait HpModelTestData { "HpModel", OperationInterval.apply(0L, 86400L), QControl.CosPhiFixed(0.95), - Kilowatts(100d), + Kilovoltamperes(100d), 0.95, Kilowatts(15d), thermalGrid, diff --git a/src/test/scala/edu/ie3/simona/model/participant/PvModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/PvModelSpec.scala index 660852e28b..157ff0a041 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/PvModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/PvModelSpec.scala @@ -14,7 +14,9 @@ import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils import edu.ie3.simona.test.common.{DefaultTestData, UnitSpec} import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.scala.quantities.{ + ApparentPower, Irradiation, + Kilovoltamperes, Megavars, ReactivePower, WattHoursPerSquareMeter, @@ -92,6 +94,9 @@ class PvModelSpec extends UnitSpec with GivenWhenThen with DefaultTestData { private implicit val angleTolerance: Angle = Radians(1e-10) private implicit val irradiationTolerance: Irradiation = WattHoursPerSquareMeter(1e-10) + private implicit val apparentPowerTolerance: ApparentPower = Kilovoltamperes( + 1e-10 + ) private implicit val powerTolerance: Power = Kilowatts(1e-10) private implicit val reactivePowerTolerance: ReactivePower = Megavars(1e-10) diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala index 358090b0a3..e53dffc943 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala @@ -812,7 +812,7 @@ class EvcsModelSpec modelUuid shouldBe evcsModel.getUuid refPower should approximate(Kilowatts(5.0)) // one hour left minPower should approximate(Kilowatts(0d)) // no v2g allowed! - maxPower should approximate(ev1.sRatedAc) + maxPower should approximate(ev1.sRatedAc.toPower) } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala index a53b82981e..c265a9f987 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala @@ -85,7 +85,7 @@ class MaximumPowerChargingSpec ScheduleEntry( offset, offset + expectedDuration, - ev.sRatedAc, + ev.sRatedAc.toPower, ) ) ) diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/LoadModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/LoadModelSpec.scala index 8d29d36b32..cca01b7904 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/LoadModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/LoadModelSpec.scala @@ -11,6 +11,7 @@ import edu.ie3.simona.model.participant.load.profile.ProfileLoadModel import edu.ie3.simona.model.participant.load.random.RandomLoadModel import edu.ie3.simona.test.common.UnitSpec import edu.ie3.simona.test.common.input.LoadInputTestData +import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import org.scalatest.PrivateMethodTester import org.scalatest.prop.TableDrivenPropertyChecks import squants.energy.{KilowattHours, Power, Watts} @@ -21,7 +22,7 @@ class LoadModelSpec with PrivateMethodTester with TableDrivenPropertyChecks { - private implicit val powerTolerance: Power = Watts(1e-3) + private implicit val powerTolerance: ApparentPower = Voltamperes(1e-3) "The load model object" should { @@ -32,27 +33,31 @@ class LoadModelSpec ( LoadReference.ActivePower(Watts(268.6)), 1d, - Watts(282.7368), + Voltamperes(282.7368), ), ( LoadReference.EnergyConsumption(KilowattHours(3000.0)), 1d, - Watts(848.2105), + Voltamperes(848.2105), ), ( LoadReference.ActivePower(Watts(268.6)), 1.5d, - Watts(424.1053), + Voltamperes(424.1053), ), ( LoadReference.EnergyConsumption(KilowattHours(3000.0)), 1.5d, - Watts(1272.3158), + Voltamperes(1272.3158), ), ) forAll(params) { - (reference: LoadReference, scaling: Double, expectedSRated: Power) => + ( + reference: LoadReference, + scaling: Double, + expectedSRated: ApparentPower, + ) => { val actual = ProfileLoadModel( loadInput, @@ -91,27 +96,31 @@ class LoadModelSpec ( LoadReference.ActivePower(Watts(268.6)), 1d, - Watts(311.0105), + Voltamperes(311.0105), ), ( LoadReference.EnergyConsumption(KilowattHours(3000.0)), 1d, - Watts(770.8076), + Voltamperes(770.8076), ), ( LoadReference.ActivePower(Watts(268.6)), 1.5d, - Watts(466.5158), + Voltamperes(466.5158), ), ( LoadReference.EnergyConsumption(KilowattHours(3000.0)), 1.5d, - Watts(1156.2114), + Voltamperes(1156.2114), ), ) forAll(params) { - (reference: LoadReference, scaling: Double, expectedSRated: Power) => + ( + reference: LoadReference, + scaling: Double, + expectedSRated: ApparentPower, + ) => { val actual = RandomLoadModel( loadInput, diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala index 64701fa993..f8c6fddc74 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala @@ -16,6 +16,7 @@ import edu.ie3.simona.model.participant.load.profile.{ } import edu.ie3.simona.test.common.UnitSpec import edu.ie3.util.TimeUtil +import edu.ie3.util.scala.quantities.Voltamperes import org.scalatest.PrivateMethodTester import org.scalatest.prop.TableDrivenPropertyChecks import squants.energy.{KilowattHours, Watts} @@ -91,7 +92,7 @@ class LoadProfileStoreSpec forAll(maxParams) { (loadProfile: StandardLoadProfile, maxParamValue: Double) => - val maxParam = Watts(maxParamValue) + val maxParam = Voltamperes(maxParamValue) customStore.maxPower(loadProfile) shouldBe maxParam } diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/ProfileLoadModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/ProfileLoadModelSpec.scala index 74077a250b..0cd81c66b5 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/ProfileLoadModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/ProfileLoadModelSpec.scala @@ -21,8 +21,8 @@ import edu.ie3.simona.model.participant.load.profile.ProfileLoadModel import edu.ie3.simona.test.common.UnitSpec import edu.ie3.util.TimeUtil import edu.ie3.util.quantities.PowerSystemUnits +import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import org.scalatest.prop.TableDrivenPropertyChecks -import squants.Power import squants.energy.{KilowattHours, Watts} import tech.units.indriya.quantity.Quantities @@ -30,7 +30,7 @@ import java.util.UUID class ProfileLoadModelSpec extends UnitSpec with TableDrivenPropertyChecks { - private implicit val tolerance: Power = Watts(1d) + private implicit val tolerance: ApparentPower = Voltamperes(1d) "Having a profile load model" when { val loadInput = @@ -78,38 +78,38 @@ class ProfileLoadModelSpec extends UnitSpec with TableDrivenPropertyChecks { ( BdewStandardLoadProfile.H0, ActivePower(Watts(268.6)), - Watts(282.74d), + Voltamperes(282.74d), ), ( BdewStandardLoadProfile.H0, EnergyConsumption( KilowattHours(3000d) ), - Watts(848.22d), + Voltamperes(848.22d), ), ( BdewStandardLoadProfile.L0, ActivePower(Watts(268.6)), - Watts(282.74d), + Voltamperes(282.74d), ), ( BdewStandardLoadProfile.L0, EnergyConsumption( KilowattHours(3000d) ), - Watts(759.158d), + Voltamperes(759.158d), ), ( BdewStandardLoadProfile.G0, ActivePower(Watts(268.6)), - Watts(282.74d), + Voltamperes(282.74d), ), ( BdewStandardLoadProfile.G0, EnergyConsumption( KilowattHours(3000d) ), - Watts(759.158d), + Voltamperes(759.158d), ), ) ) { (profile, reference, expectedSRated) => diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/RandomLoadModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/RandomLoadModelSpec.scala index 82fa1041e5..c0ee464734 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/RandomLoadModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/RandomLoadModelSpec.scala @@ -26,15 +26,19 @@ import edu.ie3.simona.model.participant.load.random.{ import edu.ie3.simona.test.common.UnitSpec import edu.ie3.util.TimeUtil import edu.ie3.util.quantities.PowerSystemUnits +import edu.ie3.util.scala.quantities.{ + ApparentPower, + Kilovoltamperes, + Voltamperes, +} import org.scalatest.prop.TableDrivenPropertyChecks -import squants.Power -import squants.energy.{KilowattHours, Kilowatts, Watts} +import squants.energy.{KilowattHours, Watts} import tech.units.indriya.quantity.Quantities import java.util.UUID class RandomLoadModelSpec extends UnitSpec with TableDrivenPropertyChecks { - implicit val tolerance: Power = Watts(1d) + implicit val tolerance: ApparentPower = Voltamperes(1d) "Having a random load model" when { val loadInput = new LoadInput( @@ -78,11 +82,11 @@ class RandomLoadModelSpec extends UnitSpec with TableDrivenPropertyChecks { val testData = Table( ("reference", "expectedSRated"), - (ActivePower(Watts(268.6)), Watts(311.0105263157895d)), - (EnergyConsumption(KilowattHours(2000d)), Watts(513.871737d)), + (ActivePower(Watts(268.6)), Voltamperes(311.0105263157895d)), + (EnergyConsumption(KilowattHours(2000d)), Voltamperes(513.871737d)), ) - forAll(testData) { (reference, expectedSRated: Power) => + forAll(testData) { (reference, expectedSRated: ApparentPower) => val actual = RandomLoadModel( loadInput, foreSeenOperationInterval, @@ -102,10 +106,10 @@ class RandomLoadModelSpec extends UnitSpec with TableDrivenPropertyChecks { loadInput.getId, foreSeenOperationInterval, QControl.apply(loadInput.getqCharacteristics()), - Kilowatts( + Kilovoltamperes( loadInput .getsRated() - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue() ), From aac2946293cf0a3a5d87650abb4b6d6d39ccff19 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 4 Jul 2024 13:59:19 +0200 Subject: [PATCH 02/22] Adapting groovy tests. --- .../model/participant/BMModelTest.groovy | 13 ++++++------ .../model/participant/ChpModelTest.groovy | 4 +++- .../participant/FixedFeedModelTest.groovy | 11 +++++----- .../participant/SystemParticipantTest.groovy | 21 +++++++++++-------- .../load/FixedLoadModelTest.groovy | 19 +++++++---------- .../test/common/model/MockParticipant.groovy | 3 ++- 6 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy index f6d83d770b..4c128dc207 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy @@ -6,9 +6,6 @@ package edu.ie3.simona.model.participant -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static tech.units.indriya.unit.Units.PERCENT - import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed import edu.ie3.datamodel.models.input.system.type.BmTypeInput @@ -16,6 +13,7 @@ import edu.ie3.simona.model.participant.ModelState.ConstantState$ import edu.ie3.simona.model.participant.control.QControl import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.EuroPerKilowatthour$ +import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq import scala.Some import spock.lang.Shared @@ -28,6 +26,9 @@ import tech.units.indriya.quantity.Quantities import java.time.ZonedDateTime +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static tech.units.indriya.unit.Units.PERCENT + /** * Test class that tries to cover all special cases of the current implementation of the {@link BMModel} * @@ -63,7 +64,7 @@ class BMModelTest extends Specification { "BM Model Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Sq.create(190, Kilowatts$.MODULE$), + Sq.create(190, Kilovoltamperes$.MODULE$), bmType.getCosPhiRated(), "MockNode", true, @@ -169,7 +170,7 @@ class BMModelTest extends Specification { "BM Model Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Sq.create(190, Kilowatts$.MODULE$), + Sq.create(190, Kilovoltamperes$.MODULE$), bmType.getCosPhiRated(), "MockNode", true, @@ -221,7 +222,7 @@ class BMModelTest extends Specification { "BM Model Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Sq.create(190, Kilowatts$.MODULE$), + Sq.create(190, Kilovoltamperes$.MODULE$), bmType.getCosPhiRated(), "MockNode", costControlled, diff --git a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy index a07273bb27..5c23821519 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy @@ -6,6 +6,8 @@ package edu.ie3.simona.model.participant +import edu.ie3.util.scala.quantities.Kilovoltamperes$ + import static edu.ie3.util.quantities.PowerSystemUnits.* import static tech.units.indriya.quantity.Quantities.getQuantity import static tech.units.indriya.unit.Units.PERCENT @@ -91,7 +93,7 @@ class ChpModelTest extends Specification { "ChpModel", null, null, - Sq.create(100, Kilowatts$.MODULE$), + Sq.create(100, Kilovoltamperes$.MODULE$), 0.95, Sq.create(50, Kilowatts$.MODULE$), thermalStorage) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy index 268323d95f..4e35daf57a 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy @@ -6,8 +6,6 @@ package edu.ie3.simona.model.participant -import static edu.ie3.util.quantities.PowerSystemUnits.* - import edu.ie3.datamodel.models.OperationTime import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.OperatorInput @@ -17,11 +15,14 @@ import edu.ie3.datamodel.models.voltagelevels.GermanVoltageLevelUtils import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl import edu.ie3.util.TimeUtil +import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq import spock.lang.Specification -import squants.energy.* +import squants.energy.Watts$ import tech.units.indriya.quantity.Quantities +import static edu.ie3.util.quantities.PowerSystemUnits.* + class FixedFeedModelTest extends Specification { def fixedFeedInput = new FixedFeedInInput( @@ -54,7 +55,7 @@ class FixedFeedModelTest extends Specification { fixedFeedInput.operationTime ) - def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1.0, Kilowatts$.MODULE$) + def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1000, Watts$.MODULE$) def "A fixed feed model should return approximately correct power calculations"() { when: @@ -68,7 +69,7 @@ class FixedFeedModelTest extends Specification { .to(KILOWATT) .value.doubleValue() .doubleValue(), - Kilowatts$.MODULE$ + Kilovoltamperes$.MODULE$ ), fixedFeedInput.cosPhiRated ) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/SystemParticipantTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/SystemParticipantTest.groovy index d13782be0c..8e484440ce 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/SystemParticipantTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/SystemParticipantTest.groovy @@ -12,10 +12,13 @@ import edu.ie3.datamodel.models.input.system.characteristic.QV import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.test.common.model.MockParticipant import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq import spock.lang.Specification -import squants.* -import squants.energy.* +import squants.Dimensionless +import squants.Each$ +import squants.energy.Kilowatts$ +import squants.energy.Power class SystemParticipantTest extends Specification { @@ -27,7 +30,7 @@ class SystemParticipantTest extends Specification { "System participant calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiFixed(varCharacteristicString)), - Sq.create(200, Kilowatts$.MODULE$), + Sq.create(200, Kilovoltamperes$.MODULE$), 1d) Dimensionless adjustedVoltage = Sq.create(1, Each$.MODULE$) // needed for method call but not applicable for cosphi_p @@ -58,7 +61,7 @@ class SystemParticipantTest extends Specification { "Load calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiP(varCharacteristicString)), - Sq.create(102, Kilowatts$.MODULE$), + Sq.create(102, Kilovoltamperes$.MODULE$), 1d) Dimensionless adjustedVoltage = Sq.create(1, Each$.MODULE$) // needed for method call but not applicable for cosphi_p @@ -87,7 +90,7 @@ class SystemParticipantTest extends Specification { "Generation calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new CosPhiP(varCharacteristicString)), - Sq.create(101, Kilowatts$.MODULE$), + Sq.create(101, Kilovoltamperes$.MODULE$), 1d) Dimensionless adjustedVoltage = Sq.create(1, Each$.MODULE$) // needed for method call but not applicable for cosphi_p @@ -118,7 +121,7 @@ class SystemParticipantTest extends Specification { "System participant calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Sq.create(200, Kilowatts$.MODULE$), + Sq.create(200, Kilovoltamperes$.MODULE$), 0.98) when: "the reactive power is calculated" @@ -151,7 +154,7 @@ class SystemParticipantTest extends Specification { "System participant calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Sq.create(200, Kilowatts$.MODULE$), + Sq.create(200, Kilovoltamperes$.MODULE$), 1d) when: "the reactive power is calculated" @@ -184,7 +187,7 @@ class SystemParticipantTest extends Specification { "System participant calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Sq.create(200, Kilowatts$.MODULE$), + Sq.create(200, Kilovoltamperes$.MODULE$), 0.95) when: "the reactive power is calculated" @@ -217,7 +220,7 @@ class SystemParticipantTest extends Specification { "System participant calculateQ Test", OperationInterval.apply(0L, 86400L), QControl.apply(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Sq.create(200, Kilowatts$.MODULE$), + Sq.create(200, Kilovoltamperes$.MODULE$), 0.95) when: "the reactive power is calculated" diff --git a/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy index a7ba4d9e87..73c2cffe09 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy @@ -6,11 +6,6 @@ package edu.ie3.simona.model.participant.load -import static edu.ie3.simona.model.participant.load.LoadReference.ActivePower -import static edu.ie3.simona.model.participant.load.LoadReference.EnergyConsumption -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static org.apache.commons.math3.util.FastMath.abs - import edu.ie3.datamodel.models.OperationTime import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.OperatorInput @@ -22,15 +17,17 @@ import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ModelState import edu.ie3.simona.model.participant.control.QControl import edu.ie3.util.TimeUtil -import spock.lang.Specification +import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq +import spock.lang.Specification import squants.energy.KilowattHours$ -import squants.energy.Kilowatts$ - import squants.energy.Watts$ import tech.units.indriya.quantity.Quantities - +import static edu.ie3.simona.model.participant.load.LoadReference.ActivePower +import static edu.ie3.simona.model.participant.load.LoadReference.EnergyConsumption +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static org.apache.commons.math3.util.FastMath.abs class FixedLoadModelTest extends Specification { def loadInput = @@ -75,7 +72,7 @@ class FixedLoadModelTest extends Specification { loadInput.id, operationInterval, QControl.apply(loadInput.qCharacteristics), - Sq.create(loadInput.sRated.to(KILOWATT).value.doubleValue(), Kilowatts$.MODULE$), + Sq.create(loadInput.sRated.to(KILOWATT).value.doubleValue(), Kilovoltamperes$.MODULE$), loadInput.cosPhiRated, reference ) @@ -96,7 +93,7 @@ class FixedLoadModelTest extends Specification { loadInput.id, operationInterval, QControl.apply(loadInput.qCharacteristics), - Sq.create(loadInput.sRated.to(KILOWATT).value.doubleValue(), Kilowatts$.MODULE$), + Sq.create(loadInput.sRated.to(KILOWATT).value.doubleValue(), Kilovoltamperes$.MODULE$), loadInput.cosPhiRated, reference ) diff --git a/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy b/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy index acfc06fa14..ccdc786b96 100644 --- a/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy +++ b/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy @@ -13,6 +13,7 @@ import edu.ie3.simona.model.participant.SystemParticipant import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.ApparentPower import edu.ie3.util.scala.quantities.Sq import scala.Tuple2 import squants.Dimensionless @@ -25,7 +26,7 @@ class MockParticipant extends SystemParticipant Date: Fri, 5 Jul 2024 15:45:30 +0200 Subject: [PATCH 03/22] Improving `ApparentPower`. --- .../simona/model/participant/BMModel.scala | 12 ++++---- .../simona/model/participant/ChpModel.scala | 2 +- .../model/participant/FixedFeedInModel.scala | 3 +- .../simona/model/participant/HpModel.scala | 7 ++--- .../simona/model/participant/PvModel.scala | 9 +++--- .../model/participant/SystemParticipant.scala | 21 ++++++-------- .../simona/model/participant/WecModel.scala | 4 +-- .../model/participant/control/QControl.scala | 22 +++++++++------ .../model/participant/evcs/EvcsModel.scala | 4 +-- .../model/participant/load/LoadModel.scala | 2 +- .../load/profile/LoadProfileStore.scala | 2 +- .../load/profile/ProfileLoadModel.scala | 5 +++- .../load/random/RandomLoadModel.scala | 8 +++--- .../util/scala/quantities/ApparentPower.scala | 6 +++- .../EvcsAgentModelCalculationSpec.scala | 28 +++++++++++-------- .../participant/ParticipantAgentMock.scala | 13 ++++++--- .../participant/evcs/EvcsModelSpec.scala | 2 +- .../MaximumPowerChargingSpec.scala | 2 +- 18 files changed, 82 insertions(+), 70 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala index ad61d74654..02bc1242e2 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala @@ -32,7 +32,7 @@ final case class BMModel( operationInterval: OperationInterval, qControl: QControl, sRated: ApparentPower, - cosPhi: Double, + cosPhiRated: Double, private val node: String, private val isCostControlled: Boolean, private val opex: Money, @@ -48,7 +48,7 @@ final case class BMModel( operationInterval, qControl, sRated, - cosPhi, + cosPhiRated, ) with ApparentPowerParticipant[BMCalcRelevantData, ConstantState.type] { @@ -197,10 +197,10 @@ final case class BMModel( isCostControlled && avgOpex.value.doubleValue() < feedInTariff.value .doubleValue() ) - sRated * cosPhi * (-1) + sRated.toPower(cosPhiRated) * (-1) else - sRated * usage * eff * cosPhi * (-1) - }.toPower + sRated.toPower(cosPhiRated) * usage * eff * (-1) + } /** Applies the load gradient to the electrical output * @param pEl @@ -214,7 +214,7 @@ final case class BMModel( _lastPower match { case None => pEl case Some(lastPowerVal) => - val pElDeltaMaxAbs = sRated.toPower * cosPhi * loadGradient + val pElDeltaMaxAbs = sRated.toPower(cosPhiRated) * loadGradient pEl - lastPowerVal match { case pElDelta if pElDelta > pElDeltaMaxAbs => diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 8ce0245c4c..9005760064 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -70,7 +70,7 @@ final case class ChpModel( ) with ApparentPowerParticipant[ChpRelevantData, ConstantState.type] { - val pRated: Power = sRated.toPower * cosPhiRated + val pRated: Power = sRated.toPower(cosPhiRated) /** As this is a state-full model (with respect to the current operation * condition and its thermal storage), the power calculation operates on the diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index 6b7b0834b8..0eb7bcf73e 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -73,8 +73,7 @@ final case class FixedFeedInModel( override protected def calculateActivePower( modelState: ConstantState.type, data: FixedRelevantData.type = FixedRelevantData, - ): Power = - sRated.toPower * (-1) * cosPhiRated + ): Power = sRated.toPower(cosPhiRated) * (-1) override def determineFlexOptions( data: FixedRelevantData.type, diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index 47341eb919..ed8af44311 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -77,8 +77,7 @@ final case class HpModel( ) with ApparentPowerAndHeatParticipant[HpRelevantData, HpState] { - private val pRated: Power = - sRated.toPower * cosPhiRated + private val pRated: Power = sRated.toPower(cosPhiRated) /** As this is a state-full model (with respect to the current operation * condition and inner temperature), the power calculation operates on the @@ -229,7 +228,7 @@ final case class HpModel( updatedState.activePower val upperBoundary = if (canOperate) - sRated.toPower * cosPhiRated + sRated.toPower(cosPhiRated) else zeroKW @@ -264,7 +263,7 @@ final case class HpModel( setPower: Power, ): (HpState, FlexChangeIndicator) = { /* If the setpoint value is above 50 % of the electrical power, turn on the heat pump otherwise turn it off */ - val turnOn = setPower > (sRated.toPower * cosPhiRated * 0.5) + val turnOn = setPower > (sRated.toPower(cosPhiRated) * 0.5) val updatedState = calcState(lastState, data, turnOn) ( diff --git a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala index bc226040c0..8262252bf0 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala @@ -59,12 +59,12 @@ final case class PvModel private ( override val sMax: ApparentPower = sRated * 1.1 /** Permissible maximum active power feed in (therefore negative) */ - protected val pMax: Power = sMax.toPower * cosPhiRated * -1d + protected val pMax: Power = sMax.toPower(cosPhiRated) * -1d /** Reference yield at standard testing conditions (STC) */ private val yieldSTC = WattsPerSquareMeter(1000d) - private val activationThreshold = sRated.toPower * cosPhiRated * 0.001 * -1d + private val activationThreshold = sRated.toPower(cosPhiRated) * 0.001 * -1d /** Calculate the active power behaviour of the model * @@ -692,9 +692,8 @@ final case class PvModel private ( eTotalInWhPerSM * moduleSurface.toSquareMeters * etaConv.toEach * (genCorr * tempCorr) /* Calculate the foreseen active power output without boundary condition adaptions */ - val proposal = sRated.toPower * (-1) * ( - actYield / irradiationSTC - ) * cosPhiRated + val proposal = + sRated.toPower(cosPhiRated) * (-1) * (actYield / irradiationSTC) /* Do sanity check, if the proposed feed in is above the estimated maximum to be apparent active power of the plant */ if (proposal < pMax) diff --git a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala index 84f09f5d0f..5a12280db2 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala @@ -7,22 +7,17 @@ package edu.ie3.simona.model.participant import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, PrimaryDataWithApparentPower, + ApparentPower => ComplexPower, } import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.ProvideFlexOptions import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ -import edu.ie3.util.scala.quantities.{ - ApparentPower, - DefaultQuantities, - Megavars, - ReactivePower, -} +import edu.ie3.util.scala.quantities._ import squants.Dimensionless -import squants.energy.{Kilowatts, Power} +import squants.energy.Power import java.util.UUID @@ -174,7 +169,7 @@ abstract class SystemParticipant[ nodalVoltage: Dimensionless ): Power => ReactivePower = qControl.activeToReactivePowerFunc( - sRated.toPower, + sRated, cosPhiRated, nodalVoltage, ) @@ -213,7 +208,7 @@ abstract class SystemParticipant[ reactivePower: ReactivePower, ): ReactivePower = { { - val apparentPower: Power = Kilowatts( + val apparentPower: ApparentPower = Kilovoltamperes( Math .sqrt( Math.pow(activePower.toKilowatts, 2) + Math @@ -222,7 +217,7 @@ abstract class SystemParticipant[ ) // tolerance for double inaccuracies - val sMaxWithTolerance = sMax.toPower * 1.00001d + val sMaxWithTolerance = sMax * 1.00001d if (apparentPower > sMaxWithTolerance) { logger.debug( @@ -233,8 +228,8 @@ abstract class SystemParticipant[ s"in correspondence to the existing active power $activePower." ) - val powerSquaredDifference = Math.pow(sMax.toPower.toMegawatts, 2) - - Math.pow(activePower.toMegawatts, 2) + val powerSquaredDifference = Math.pow(sMax.toMegavoltamperes, 2) - Math + .pow(activePower.toMegawatts, 2) if (powerSquaredDifference < 0) { logger.warn( diff --git a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala index 3d8de4a1cb..3489b8e31d 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala @@ -98,7 +98,7 @@ final case class WecModel( wecData: WecRelevantData, ): Power = { val activePower = determinePower(wecData) - val pMax = sMax.toPower * cosPhiRated + val pMax = sMax.toPower(cosPhiRated) (if (activePower > pMax) { logger.warn( @@ -278,7 +278,7 @@ object WecModel { operationInterval, QControl(scaledInput.getqCharacteristics), Kilovoltamperes( - scaledInput.getType.getsRated.to(KILOWATT).getValue.doubleValue + scaledInput.getType.getsRated.to(KILOVOLTAMPERE).getValue.doubleValue ), scaledInput.getType.getCosPhiRated, SquareMeters( diff --git a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala index 25504c2fff..4ffed344af 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala @@ -13,7 +13,7 @@ import edu.ie3.simona.model.system.Characteristic import edu.ie3.simona.model.system.Characteristic.XYPair import edu.ie3.util.quantities.PowerSystemUnits.PU import edu.ie3.util.scala.quantities.DefaultQuantities._ -import edu.ie3.util.scala.quantities.{Megavars, ReactivePower} +import edu.ie3.util.scala.quantities.{ApparentPower, Megavars, ReactivePower} import squants.{Dimensionless, Each, Power} import tech.units.indriya.AbstractUnit @@ -44,7 +44,7 @@ sealed trait QControl { * The function */ def activeToReactivePowerFunc( - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower @@ -117,7 +117,7 @@ object QControl { * The function */ override def activeToReactivePowerFunc( - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower = { activePower: Power => @@ -169,19 +169,23 @@ object QControl { * The function */ override def activeToReactivePowerFunc( - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower = { activePower: Power => + val pRated = sRated.toPower(1.0) + val qMaxFromP = Megavars( sqrt( - pow(sRated.toMegawatts, 2) - + pow(pRated.toMegawatts, 2) - pow(activePower.toMegawatts, 2) ) ) - val qFromCharacteristic = - q(nodalVoltage, Megavars((sRated * sin(acos(cosPhiRated))).toMegawatts)) + val qFromCharacteristic = q( + nodalVoltage, + Megavars(sRated.toReactivePower(cosPhiRated).toMegavars), + ) qMaxPossible(qMaxFromP, qFromCharacteristic) } @@ -244,13 +248,13 @@ object QControl { * The function */ override def activeToReactivePowerFunc( - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower = { activePower: Power => /* cosphi( P / P_N ) = cosphi( P / (S_N * cosphi_rated) ) */ val pInPu = - activePower / (sRated * cosPhiRated) + activePower / sRated.toPower(cosPhiRated) val instantCosPhi = cosPhi(Each(pInPu)) _cosPhiMultiplication(instantCosPhi.value.doubleValue, activePower) } diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index ad16931c9f..59582f95ff 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -503,12 +503,12 @@ final case class EvcsModel( ): Power = { val evPower = currentType match { case ElectricCurrentType.AC => - ev.sRatedAc.toPower + ev.sRatedAc.toPower(1.0) case ElectricCurrentType.DC => ev.sRatedDc } /* Limit the charging power to the minimum of ev's and evcs' permissible power */ - evPower.min(sRated.toPower) + evPower.min(sRated.toPower(1.0)) } override def calculatePower( diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala index 1c94aa3020..f30a179a25 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala @@ -98,7 +98,7 @@ object LoadModel extends LazyLogging { .getValue .doubleValue ) - val pRated = sRated.toPower * inputModel.getCosPhiRated + val pRated = sRated.toPower(inputModel.getCosPhiRated) val referenceScalingFactor = activePower / pRated sRated * referenceScalingFactor * safetyFactor } diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala index 0104bd3875..93b08ba62a 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala @@ -85,7 +85,7 @@ class LoadProfileStore private (val reader: Reader) { * @param loadProfile * the consumer type * @return - * the maximum load in W + * the maximum load in VA */ def maxPower( loadProfile: StandardLoadProfile diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala index 5419436ebe..9c030d2b10 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala @@ -92,7 +92,10 @@ final case class ProfileLoadModel( reference match { case ActivePower(activePower) => /* scale the reference active power based on the profiles averagePower/maxPower ratio */ - val referenceScalingFactor = averagePower / profileMaxPower.toPower + val referenceScalingFactor = + averagePower / profileMaxPower.toPower( + 1.0 + ) // only active power => cosPhi = 1.0 activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles average power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index e3ff1ee9e7..152a413ee6 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -19,7 +19,7 @@ import edu.ie3.util.TimeUtil import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import squants.Power -import squants.energy.{KilowattHours, Kilowatts} +import squants.energy.{KilowattHours, Kilowatts, Watts} import java.time.ZonedDateTime import java.util.UUID @@ -102,7 +102,7 @@ final case class RandomLoadModel( case ActivePower(activePower) => /* scale the reference active power based on the random profiles averagePower/maxPower ratio */ val referenceScalingFactor = - profilePower / RandomLoadModel.randomMaxPower.toPower + profilePower / RandomLoadModel.randomMaxPower activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles random power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ @@ -171,7 +171,7 @@ object RandomLoadModel { * @return * Reference power to use for later model calculations */ - private val randomMaxPower: ApparentPower = Voltamperes(159d) + private val randomMaxPower: Power = Watts(159d) def apply( input: LoadInput, @@ -191,7 +191,7 @@ object RandomLoadModel { LoadModel.scaleSRatedEnergy( scaledInput, energyConsumption, - randomMaxPower, + Voltamperes(randomMaxPower.toWatts), randomProfileEnergyScaling, 1.1, ) diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala index 7c007d85b2..c67b87879a 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala @@ -10,6 +10,7 @@ import squants._ import squants.energy._ import squants.time.Time +import scala.math.{acos, sin} import scala.util.Try final class ApparentPower private ( @@ -25,7 +26,10 @@ final class ApparentPower private ( def toMegavoltamperes: Double = to(Megavoltamperes) def toGigavoltamperes: Double = to(Gigavoltamperes) - def toPower: Power = Watts(toVoltamperes) + def toPower(cosPhi: Double): Power = Watts(toVoltamperes) * cosPhi + + def toReactivePower(cosPhi: Double): ReactivePower = + Vars(toVoltamperes) * sin(acos(cosPhi)) } object ApparentPower extends Dimension[ApparentPower] { diff --git a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala index 7bd48e2ac6..cc8619915e 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala @@ -1300,9 +1300,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev900.sRatedAc.toPower - minPower shouldBe ev900.sRatedAc.toPower // battery is empty - maxPower shouldBe ev900.sRatedAc.toPower + referencePower shouldBe ev900.sRatedAc.toPower(1.0) + minPower shouldBe ev900.sRatedAc.toPower(1.0) // battery is empty + maxPower shouldBe ev900.sRatedAc.toPower(1.0) } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1418,9 +1418,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower - minPower shouldBe ev900.sRatedAc.toPower // battery is empty - maxPower shouldBe ev4500.sRatedAc.toPower + referencePower shouldBe ev4500.sRatedAc.toPower(1.0) + minPower shouldBe ev900.sRatedAc.toPower(1.0) // battery is empty + maxPower shouldBe ev4500.sRatedAc.toPower(1.0) } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1469,9 +1469,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower + referencePower shouldBe ev4500.sRatedAc.toPower(1.0) minPower shouldBe Kilowatts(0.0) // battery is exactly at margin - maxPower shouldBe ev4500.sRatedAc.toPower + maxPower shouldBe ev4500.sRatedAc.toPower(1.0) } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1558,7 +1558,9 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid refPower shouldBe combinedChargingPowerSq - minPower shouldBe ev4500.sRatedAc.toPower * -1 // battery of earlier ev is above lowest soc now + minPower shouldBe ev4500.sRatedAc.toPower( + 1.0 + ) * -1 // battery of earlier ev is above lowest soc now maxPower shouldBe combinedChargingPowerSq } @@ -1712,7 +1714,9 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid referencePower shouldBe combinedChargingPowerSq - minPower shouldBe ev4500.sRatedAc.toPower * -1 // battery of ev11700 is below lowest soc now + minPower shouldBe ev4500.sRatedAc.toPower( + 1.0 + ) * -1 // battery of ev11700 is below lowest soc now maxPower shouldBe combinedChargingPowerSq } @@ -1913,9 +1917,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower + referencePower shouldBe ev4500.sRatedAc.toPower(1.0) minPower shouldBe Kilowatts(0d) - maxPower shouldBe ev4500.sRatedAc.toPower + maxPower shouldBe ev4500.sRatedAc.toPower(1.0) } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala index 2b7b5f399e..108bf91531 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala @@ -6,8 +6,6 @@ package edu.ie3.simona.agent.participant -import org.apache.pekko.actor.{ActorRef, FSM, Props} -import org.apache.pekko.actor.typed.{ActorRef => TypedActorRef} import edu.ie3.datamodel.models.input.system.SystemParticipantInput import edu.ie3.datamodel.models.result.system.SystemParticipantResult import edu.ie3.simona.agent.ValueStore @@ -43,7 +41,14 @@ import edu.ie3.simona.model.participant.{ } import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.FlexResponse import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble -import edu.ie3.util.scala.quantities.{Kilovars, Megavars, ReactivePower} +import edu.ie3.util.scala.quantities.{ + Kilovars, + Kilovoltamperes, + Megavars, + ReactivePower, +} +import org.apache.pekko.actor.typed.{ActorRef => TypedActorRef} +import org.apache.pekko.actor.{ActorRef, FSM, Props} import org.mockito.ArgumentMatchers.any import org.mockito.Mockito import org.mockito.Mockito.doReturn @@ -200,7 +205,7 @@ class ParticipantAgentMock( SystemParticipant[FixedRelevantData.type, ApparentPower, ConstantState.type], ] = { val func = CosPhiFixed(0.95).activeToReactivePowerFunc( - Kilowatts(0.0), + Kilovoltamperes(0.0), 0.95d, Each(1.0), ) diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala index e53dffc943..bb92b5b914 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala @@ -812,7 +812,7 @@ class EvcsModelSpec modelUuid shouldBe evcsModel.getUuid refPower should approximate(Kilowatts(5.0)) // one hour left minPower should approximate(Kilowatts(0d)) // no v2g allowed! - maxPower should approximate(ev1.sRatedAc.toPower) + maxPower should approximate(ev1.sRatedAc.toPower(1.0)) } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala index c265a9f987..0ad7182c2d 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala @@ -85,7 +85,7 @@ class MaximumPowerChargingSpec ScheduleEntry( offset, offset + expectedDuration, - ev.sRatedAc.toPower, + ev.sRatedAc.toPower(1.0), ) ) ) From 06c830694d78e6e057e7e28144adc2a06c4a8248 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Mon, 8 Jul 2024 11:13:06 +0200 Subject: [PATCH 04/22] Adapting `StorageModel`. --- .../simona/model/participant/StorageModel.scala | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala index 02f82d2670..2bd5a3b8e1 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala @@ -7,7 +7,9 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.StorageInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.StorageModel.{ RefTargetSocParams, @@ -20,6 +22,7 @@ import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMin import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.energy.{KilowattHours, Kilowatts} import squants.{Dimensionless, Each, Energy, Power, Seconds} @@ -31,14 +34,14 @@ final case class StorageModel( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, eStorage: Energy, pMax: Power, eta: Dimensionless, initialSoc: Double, targetSoc: Option[Double], -) extends SystemParticipant[StorageRelevantData, ApparentPower, StorageState]( +) extends SystemParticipant[StorageRelevantData, ComplexPower, StorageState]( uuid, id, operationInterval, @@ -103,7 +106,7 @@ final case class StorageModel( voltage: Dimensionless, modelState: StorageState, data: StorageRelevantData, - ): ApparentPower = + ): ComplexPower = throw new NotImplementedError( "Storage model cannot calculate power without flexibility control." ) @@ -354,9 +357,9 @@ object StorageModel { scaledInput.getId, operationInterval, QControl.apply(scaledInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( scaledInput.getType.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), From 43f1ab9a7c6c13f527632a13c61e128fe464e897 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 9 Jul 2024 12:51:30 +0200 Subject: [PATCH 05/22] Adapting `StorageAgent`. Improving `ApparentPower`. --- .../agent/participant/storage/StorageAgent.scala | 12 +++++++----- .../simona/model/participant/control/QControl.scala | 4 +--- .../participant/load/random/RandomLoadModel.scala | 8 +++++--- .../ie3/util/scala/quantities/ApparentPower.scala | 4 ++-- .../model/participant/FixedFeedModelTest.groovy | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala index f38328ea3b..5956f53822 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala @@ -8,7 +8,9 @@ package edu.ie3.simona.agent.participant.storage import edu.ie3.datamodel.models.input.system.StorageInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ApparentPower => ComplexPower +} import edu.ie3.simona.agent.participant.statedata.ParticipantStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData import edu.ie3.simona.config.SimonaConfig.StorageRuntimeConfig @@ -25,7 +27,7 @@ object StorageAgent { initStateData: ParticipantInitializeStateData[ StorageInput, StorageRuntimeConfig, - ApparentPower, + ComplexPower, ], listener: Iterable[ActorRef], ): Props = @@ -50,14 +52,14 @@ class StorageAgent( initStateData: ParticipantInitializeStateData[ StorageInput, StorageRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], StorageInput, StorageRuntimeConfig, StorageModel, diff --git a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala index 4ffed344af..f01c413fd5 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala @@ -173,11 +173,9 @@ object QControl { cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower = { activePower: Power => - val pRated = sRated.toPower(1.0) - val qMaxFromP = Megavars( sqrt( - pow(pRated.toMegawatts, 2) - + pow(sRated.toPower(1.0).toMegawatts, 2) - pow(activePower.toMegawatts, 2) ) ) diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index 152a413ee6..8596662ed9 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -102,7 +102,9 @@ final case class RandomLoadModel( case ActivePower(activePower) => /* scale the reference active power based on the random profiles averagePower/maxPower ratio */ val referenceScalingFactor = - profilePower / RandomLoadModel.randomMaxPower + profilePower / RandomLoadModel.randomMaxPower.toPower( + 1.0 + ) // only active power => cosPhi = 1.0 activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles random power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ @@ -171,7 +173,7 @@ object RandomLoadModel { * @return * Reference power to use for later model calculations */ - private val randomMaxPower: Power = Watts(159d) + private val randomMaxPower: ApparentPower = Voltamperes(159d) def apply( input: LoadInput, @@ -191,7 +193,7 @@ object RandomLoadModel { LoadModel.scaleSRatedEnergy( scaledInput, energyConsumption, - Voltamperes(randomMaxPower.toWatts), + randomMaxPower, randomProfileEnergyScaling, 1.1, ) diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala index c67b87879a..a436727075 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala @@ -26,10 +26,10 @@ final class ApparentPower private ( def toMegavoltamperes: Double = to(Megavoltamperes) def toGigavoltamperes: Double = to(Gigavoltamperes) - def toPower(cosPhi: Double): Power = Watts(toVoltamperes) * cosPhi + def toPower(cosPhi: Double): Power = Watts(toVoltamperes * cosPhi) def toReactivePower(cosPhi: Double): ReactivePower = - Vars(toVoltamperes) * sin(acos(cosPhi)) + Vars(toVoltamperes * sin(acos(cosPhi))) } object ApparentPower extends Dimension[ApparentPower] { diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy index 4e35daf57a..e7784b2eb4 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy @@ -18,7 +18,7 @@ import edu.ie3.util.TimeUtil import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq import spock.lang.Specification -import squants.energy.Watts$ +import squants.energy.Kilowatts$ import tech.units.indriya.quantity.Quantities import static edu.ie3.util.quantities.PowerSystemUnits.* @@ -55,7 +55,7 @@ class FixedFeedModelTest extends Specification { fixedFeedInput.operationTime ) - def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1000, Watts$.MODULE$) + def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1.0, Kilowatts$.MODULE$) def "A fixed feed model should return approximately correct power calculations"() { when: From e3f4e99de3eee2d59ddd228d73805cc5131b9934 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 9 Jul 2024 14:35:49 +0200 Subject: [PATCH 06/22] Fixing test. --- .../ie3/simona/model/participant/FixedFeedModelTest.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy index e7784b2eb4..4e35daf57a 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy @@ -18,7 +18,7 @@ import edu.ie3.util.TimeUtil import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.util.scala.quantities.Sq import spock.lang.Specification -import squants.energy.Kilowatts$ +import squants.energy.Watts$ import tech.units.indriya.quantity.Quantities import static edu.ie3.util.quantities.PowerSystemUnits.* @@ -55,7 +55,7 @@ class FixedFeedModelTest extends Specification { fixedFeedInput.operationTime ) - def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1.0, Kilowatts$.MODULE$) + def expectedPower = Sq.create(fixedFeedInput.sRated.value.doubleValue() * -1 * fixedFeedInput.cosPhiRated * 1000, Watts$.MODULE$) def "A fixed feed model should return approximately correct power calculations"() { when: From 4825f24ceae58216204c19b4f4eb875c8b41d921 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Mon, 29 Jul 2024 08:09:07 +0200 Subject: [PATCH 07/22] Fixing `codacy` issues. --- .../model/participant/ChpModelTest.groovy | 8 ++++---- .../model/participant/FixedFeedModelTest.groovy | 0 .../CylindricalThermalStorageTest.groovy | 6 +++--- .../model/thermal/ThermalHouseTest.groovy | 17 +++++++++-------- .../model/participant/FixedFeedModelSpec.scala | 3 ++- .../simona/model/participant/WecModelSpec.scala | 6 +++--- 6 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy diff --git a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy index 5c23821519..a4e0bbb0f0 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy @@ -8,10 +8,6 @@ package edu.ie3.simona.model.participant import edu.ie3.util.scala.quantities.Kilovoltamperes$ -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static tech.units.indriya.quantity.Quantities.getQuantity -import static tech.units.indriya.unit.Units.PERCENT - import edu.ie3.datamodel.models.OperationTime import edu.ie3.datamodel.models.StandardUnits import edu.ie3.datamodel.models.input.OperatorInput @@ -35,6 +31,10 @@ import squants.space.CubicMeters$ import squants.thermal.Celsius$ import testutils.TestObjectFactory +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static tech.units.indriya.quantity.Quantities.getQuantity +import static tech.units.indriya.unit.Units.PERCENT + class ChpModelTest extends Specification { @Shared diff --git a/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/FixedFeedModelTest.groovy deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy b/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy index af5ffef8e5..b3c17eb4e0 100644 --- a/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy @@ -6,9 +6,6 @@ package edu.ie3.simona.model.thermal -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR -import static tech.units.indriya.quantity.Quantities.getQuantity - import edu.ie3.datamodel.models.StandardUnits import edu.ie3.datamodel.models.input.thermal.CylindricalStorageInput import edu.ie3.util.scala.quantities.KilowattHoursPerKelvinCubicMeters$ @@ -20,6 +17,9 @@ import squants.energy.Kilowatts$ import squants.space.CubicMeters$ import squants.thermal.Celsius$ +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR +import static tech.units.indriya.quantity.Quantities.getQuantity + class CylindricalThermalStorageTest extends Specification { static final double TESTING_TOLERANCE = 1e-10 diff --git a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy b/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy index f23d532b03..4d8df7a96d 100644 --- a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy @@ -6,20 +6,21 @@ package edu.ie3.simona.model.thermal -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR_PER_KELVIN -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATT_PER_KELVIN -import static tech.units.indriya.quantity.Quantities.getQuantity -import static tech.units.indriya.unit.Units.CELSIUS - import edu.ie3.datamodel.models.StandardUnits import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput import edu.ie3.util.scala.quantities.Sq import spock.lang.Shared import spock.lang.Specification -import squants.energy.* -import squants.thermal.* -import squants.time.* +import squants.energy.Kilowatts$ +import squants.thermal.Celsius$ +import squants.thermal.Kelvin$ +import squants.thermal.Temperature +import squants.time.Seconds$ +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR_PER_KELVIN +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATT_PER_KELVIN +import static tech.units.indriya.quantity.Quantities.getQuantity +import static tech.units.indriya.unit.Units.CELSIUS class ThermalHouseTest extends Specification { diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala index 1cb083d9a0..e42f5d2655 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedModelSpec.scala @@ -10,6 +10,7 @@ import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.test.common.UnitSpec import edu.ie3.simona.test.common.input.FixedFeedInputTestData import edu.ie3.util.quantities.PowerSystemUnits +import edu.ie3.util.scala.quantities.Kilovoltamperes import org.scalatest.prop.TableDrivenPropertyChecks import squants.energy.{Kilowatts, Power, Watts} @@ -35,7 +36,7 @@ class FixedFeedModelSpec fixedFeedInput.getId, defaultOperationInterval, QControl.apply(fixedFeedInput.getqCharacteristics()), - Kilowatts( + Kilovoltamperes( fixedFeedInput .getsRated() .to(PowerSystemUnits.KILOWATT) diff --git a/src/test/scala/edu/ie3/simona/model/participant/WecModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/WecModelSpec.scala index 8933819773..ceac73c5e4 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/WecModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/WecModelSpec.scala @@ -95,7 +95,7 @@ class WecModelSpec extends UnitSpec with DefaultTestData { wecModel.rotorArea.toSquareMeters shouldBe (typeInput.getRotorArea.toSystemUnit.getValue .doubleValue() +- 1e-5) wecModel.cosPhiRated shouldBe typeInput.getCosPhiRated - wecModel.sRated.toWatts shouldBe (typeInput.getsRated.toSystemUnit.getValue + wecModel.sRated.toVoltamperes shouldBe (typeInput.getsRated.toSystemUnit.getValue .doubleValue() +- 1e-5) wecModel.betzCurve shouldBe WecModel.WecCharacteristic.apply( inputModel.getType.getCpCharacteristic @@ -126,7 +126,7 @@ class WecModelSpec extends UnitSpec with DefaultTestData { -24573.39638823692, 0) velocities.zip(expectedPowers).foreach { case (velocity, power) => - val wecData = new WecRelevantData( + val wecData = WecRelevantData( MetersPerSecond(velocity), Celsius(20), Some(Pascals(101325d)), @@ -175,7 +175,7 @@ class WecModelSpec extends UnitSpec with DefaultTestData { Seq(-23377.23862017266, -24573.41320418286, -29029.60338829823) temperatures.zip(expectedPowers).foreach { case (temperature, power) => - val wecData = new WecRelevantData( + val wecData = WecRelevantData( MetersPerSecond(3.0), Celsius(temperature), Some(Pascals(101325d)), From 6e49082e0599ab39dd94a5e18bbe54d973efc96b Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Mon, 29 Jul 2024 08:18:33 +0200 Subject: [PATCH 08/22] Fixing `codacy` issues. --- .../ie3/simona/model/participant/BMModelTest.groovy | 6 +++--- .../ie3/simona/model/participant/ChpModelTest.groovy | 8 ++++---- .../edu/ie3/simona/model/participant/PvModelIT.groovy | 6 +++--- .../simona/model/participant/StorageModelTest.groovy | 6 +++--- .../model/participant/load/FixedLoadModelTest.groovy | 10 +++++----- .../model/thermal/CylindricalThermalStorageTest.groovy | 6 +++--- .../ie3/simona/model/thermal/ThermalHouseTest.groovy | 10 +++++----- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy index 4c128dc207..0d23aaf479 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/BMModelTest.groovy @@ -6,6 +6,9 @@ package edu.ie3.simona.model.participant +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static tech.units.indriya.unit.Units.PERCENT + import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed import edu.ie3.datamodel.models.input.system.type.BmTypeInput @@ -26,9 +29,6 @@ import tech.units.indriya.quantity.Quantities import java.time.ZonedDateTime -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static tech.units.indriya.unit.Units.PERCENT - /** * Test class that tries to cover all special cases of the current implementation of the {@link BMModel} * diff --git a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy index a4e0bbb0f0..455b82f068 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/ChpModelTest.groovy @@ -6,6 +6,10 @@ package edu.ie3.simona.model.participant +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static tech.units.indriya.quantity.Quantities.getQuantity +import static tech.units.indriya.unit.Units.PERCENT + import edu.ie3.util.scala.quantities.Kilovoltamperes$ import edu.ie3.datamodel.models.OperationTime @@ -31,10 +35,6 @@ import squants.space.CubicMeters$ import squants.thermal.Celsius$ import testutils.TestObjectFactory -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static tech.units.indriya.quantity.Quantities.getQuantity -import static tech.units.indriya.unit.Units.PERCENT - class ChpModelTest extends Specification { @Shared diff --git a/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy b/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy index 00caef8dee..4219b301e2 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy @@ -6,6 +6,9 @@ package edu.ie3.simona.model.participant +import static java.util.Locale.US +import static java.util.Locale.setDefault + import edu.ie3.datamodel.io.source.csv.CsvJointGridContainerSource import edu.ie3.datamodel.models.input.system.PvInput import edu.ie3.simona.ontology.messages.services.WeatherMessage @@ -27,9 +30,6 @@ import java.nio.file.Path import java.time.ZonedDateTime import java.util.zip.GZIPInputStream -import static java.util.Locale.US -import static java.util.Locale.setDefault - /** * A simple integration test that uses pre-calculated data to check if the pv model works as expected. * It uses 8 pv models located in GER. diff --git a/src/test/groovy/edu/ie3/simona/model/participant/StorageModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/StorageModelTest.groovy index a28a405901..0bb982d6ff 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/StorageModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/StorageModelTest.groovy @@ -6,6 +6,9 @@ package edu.ie3.simona.model.participant +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static tech.units.indriya.quantity.Quantities.getQuantity + import edu.ie3.datamodel.models.OperationTime import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.OperatorInput @@ -21,9 +24,6 @@ import spock.lang.Shared import spock.lang.Specification import squants.energy.* -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static tech.units.indriya.quantity.Quantities.getQuantity - class StorageModelTest extends Specification { @Shared diff --git a/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy b/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy index 73c2cffe09..a7976a0491 100644 --- a/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/participant/load/FixedLoadModelTest.groovy @@ -6,6 +6,11 @@ package edu.ie3.simona.model.participant.load +import static edu.ie3.simona.model.participant.load.LoadReference.ActivePower +import static edu.ie3.simona.model.participant.load.LoadReference.EnergyConsumption +import static edu.ie3.util.quantities.PowerSystemUnits.* +import static org.apache.commons.math3.util.FastMath.abs + import edu.ie3.datamodel.models.OperationTime import edu.ie3.datamodel.models.input.NodeInput import edu.ie3.datamodel.models.input.OperatorInput @@ -24,11 +29,6 @@ import squants.energy.KilowattHours$ import squants.energy.Watts$ import tech.units.indriya.quantity.Quantities -import static edu.ie3.simona.model.participant.load.LoadReference.ActivePower -import static edu.ie3.simona.model.participant.load.LoadReference.EnergyConsumption -import static edu.ie3.util.quantities.PowerSystemUnits.* -import static org.apache.commons.math3.util.FastMath.abs - class FixedLoadModelTest extends Specification { def loadInput = new LoadInput( diff --git a/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy b/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy index b3c17eb4e0..af5ffef8e5 100644 --- a/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/thermal/CylindricalThermalStorageTest.groovy @@ -6,6 +6,9 @@ package edu.ie3.simona.model.thermal +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR +import static tech.units.indriya.quantity.Quantities.getQuantity + import edu.ie3.datamodel.models.StandardUnits import edu.ie3.datamodel.models.input.thermal.CylindricalStorageInput import edu.ie3.util.scala.quantities.KilowattHoursPerKelvinCubicMeters$ @@ -17,9 +20,6 @@ import squants.energy.Kilowatts$ import squants.space.CubicMeters$ import squants.thermal.Celsius$ -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR -import static tech.units.indriya.quantity.Quantities.getQuantity - class CylindricalThermalStorageTest extends Specification { static final double TESTING_TOLERANCE = 1e-10 diff --git a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy b/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy index 4d8df7a96d..459f57ef7c 100644 --- a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy +++ b/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy @@ -6,6 +6,11 @@ package edu.ie3.simona.model.thermal +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR_PER_KELVIN +import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATT_PER_KELVIN +import static tech.units.indriya.quantity.Quantities.getQuantity +import static tech.units.indriya.unit.Units.CELSIUS + import edu.ie3.datamodel.models.StandardUnits import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput import edu.ie3.util.scala.quantities.Sq @@ -17,11 +22,6 @@ import squants.thermal.Kelvin$ import squants.thermal.Temperature import squants.time.Seconds$ -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR_PER_KELVIN -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATT_PER_KELVIN -import static tech.units.indriya.quantity.Quantities.getQuantity -import static tech.units.indriya.unit.Units.CELSIUS - class ThermalHouseTest extends Specification { @Shared From a1c0c584ddbc719bdb267525dceb0a98ee4801bc Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 30 Jul 2024 13:09:17 +0200 Subject: [PATCH 09/22] Adapting some tests. --- .../model/participant/load/FixedLoadModelSpec.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala index 98fd066841..24b9150d0d 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala @@ -16,9 +16,10 @@ import edu.ie3.simona.model.participant.load.LoadReference.{ import edu.ie3.simona.test.common.input.LoadInputTestData import edu.ie3.simona.test.common.{DefaultTestData, UnitSpec} import edu.ie3.util.quantities.PowerSystemUnits +import edu.ie3.util.scala.quantities.Kilovoltamperes import org.scalatest.prop.TableDrivenPropertyChecks import squants.Power -import squants.energy.{KilowattHours, Kilowatts, Watts} +import squants.energy.{KilowattHours, Watts} class FixedLoadModelSpec extends UnitSpec @@ -50,7 +51,7 @@ class FixedLoadModelSpec loadInput.getId, defaultOperationInterval, QControl.apply(loadInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( loadInput.getsRated .to(PowerSystemUnits.KILOWATT) .getValue @@ -84,7 +85,7 @@ class FixedLoadModelSpec loadInput.getId, defaultOperationInterval, QControl.apply(loadInput.getqCharacteristics), - Kilowatts( + Kilovoltamperes( loadInput.getsRated .to(PowerSystemUnits.KILOWATT) .getValue @@ -118,7 +119,7 @@ class FixedLoadModelSpec var scale = 0.0 while (scale <= 2) { - val scaledSRated = Kilowatts( + val scaledSRated = Kilovoltamperes( loadInput.getsRated .to(PowerSystemUnits.KILOWATT) .getValue From be9df57ea39ebed969b890462210e773942c0831 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Wed, 21 Aug 2024 13:15:09 +0200 Subject: [PATCH 10/22] Adapting some parts. --- .../edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala | 8 ++++---- .../ontology/messages/services/PrimaryDataMessage.scala | 1 - .../simona/model/participant/FixedFeedInModelSpec.scala | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala index 095d722989..bbeb263592 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala @@ -116,11 +116,11 @@ class EvcsAgent( case Event( EvFreeLotsRequest(tick), - stateData: DataCollectionStateData[ApparentPower], + stateData: DataCollectionStateData[ComplexPower], ) => stateData.baseStateData match { case modelStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, @@ -135,11 +135,11 @@ class EvcsAgent( case Event( DepartingEvsRequest(tick, departingEvs), - stateData: DataCollectionStateData[ApparentPower], + stateData: DataCollectionStateData[ComplexPower], ) => stateData.baseStateData match { case modelStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, EvcsRelevantData, EvcsState, EvcsModel, diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala index 04fe527ee3..4f35770662 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala @@ -31,7 +31,6 @@ object PrimaryDataMessage { override val serviceRef: ActorRef, override val data: ComplexPower, override val nextDataTick: Option[Long], - override val unlockKey: Option[ScheduleKey] = None, ) extends ProvisionMessage[ComplexPower] with PrimaryDataMessage } diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala index f983943531..763fb4b677 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala @@ -17,6 +17,7 @@ import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.quantities.PowerSystemUnits.MEGAVOLTAMPERE import edu.ie3.util.scala.quantities.{ ApparentPower, + Kilovoltamperes, Megavoltamperes, Voltamperes, } @@ -90,7 +91,7 @@ class FixedFeedInModelSpec fixedFeedInput.getId, defaultOperationInterval, QControl.apply(fixedFeedInput.getqCharacteristics()), - Kilowatts( + Kilovoltamperes( fixedFeedInput .getsRated() .to(PowerSystemUnits.KILOWATT) From 707e0f30fdb303f5d370b54c909de049b620d47f Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Fri, 6 Sep 2024 14:00:50 +0200 Subject: [PATCH 11/22] Renaming some `ApparentPower` to `ComplexPower`. --- .../edu/ie3/simona/agent/em/EmAgent.scala | 4 +- .../edu/ie3/simona/agent/em/EmDataCore.scala | 8 +- .../agent/em/FlexCorrespondenceStore.scala | 4 +- .../ParticipantAgentFundamentals.scala | 12 +-- .../simona/agent/participant/data/Data.scala | 54 ++++++------ .../data/primary/PrimaryDataService.scala | 6 +- .../agent/participant/evcs/EvcsAgent.scala | 2 +- .../evcs/EvcsAgentFundamentals.scala | 4 +- .../fixedfeedin/FixedFeedInAgent.scala | 4 +- .../FixedFeedInAgentFundamentals.scala | 2 +- .../simona/agent/participant/hp/HpAgent.scala | 4 +- .../participant/hp/HpAgentFundamentals.scala | 4 +- .../agent/participant/load/LoadAgent.scala | 4 +- .../load/LoadAgentFundamentals.scala | 2 +- .../simona/agent/participant/pv/PvAgent.scala | 4 +- .../participant/pv/PvAgentFundamentals.scala | 2 +- .../participant/storage/StorageAgent.scala | 4 +- .../storage/StorageAgentFundamentals.scala | 46 +++++------ .../agent/participant/wec/WecAgent.scala | 4 +- .../wec/WecAgentFundamentals.scala | 2 +- .../ApparentPowerAndHeatParticipant.scala | 8 +- .../ApparentPowerParticipant.scala | 6 +- .../simona/model/participant/BMModel.scala | 4 +- .../simona/model/participant/ChpModel.scala | 4 +- .../model/participant/FixedFeedInModel.scala | 4 +- .../simona/model/participant/HpModel.scala | 4 +- .../simona/model/participant/PvModel.scala | 4 +- .../model/participant/StorageModel.scala | 4 +- .../model/participant/SystemParticipant.scala | 2 +- .../simona/model/participant/WecModel.scala | 4 +- .../model/participant/evcs/EvcsModel.scala | 4 +- .../model/participant/load/LoadModel.scala | 4 +- .../messages/flex/FlexibilityMessage.scala | 4 +- .../services/PrimaryDataMessage.scala | 4 +- .../test/common/model/MockParticipant.groovy | 4 +- .../edu/ie3/simona/agent/em/EmAgentSpec.scala | 30 +++---- .../EvcsAgentModelCalculationSpec.scala | 14 ++-- ...FixedFeedInAgentModelCalculationSpec.scala | 12 +-- .../HpAgentModelCalculationSpec.scala | 16 ++-- .../LoadAgentFixedModelCalculationSpec.scala | 12 +-- ...LoadAgentProfileModelCalculationSpec.scala | 12 +-- .../ParticipantAgent2ListenerSpec.scala | 6 +- .../ParticipantAgentExternalSourceSpec.scala | 76 ++++++++--------- .../ParticipantAgentFundamentalsSpec.scala | 80 +++++++++--------- .../participant/ParticipantAgentMock.scala | 82 +++++++++---------- .../PvAgentModelCalculationSpec.scala | 16 ++-- .../agent/participant/RichValueSpec.scala | 8 +- .../StorageAgentModelCalculationSpec.scala | 10 +-- .../WecAgentModelCalculationSpec.scala | 28 +++---- .../ApparentPowerAndHeatSpec.scala | 8 +- .../model/participant/BMModelSpec.scala | 12 +-- .../primary/PrimaryServiceWorkerSqlIT.scala | 4 +- 52 files changed, 311 insertions(+), 355 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala b/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala index 3bbbef2382..aea59cdae0 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.em import edu.ie3.datamodel.models.input.EmInput import edu.ie3.datamodel.models.result.system.{EmResult, FlexOptionsResult} -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.BaseStateData.FlexControlledData import edu.ie3.simona.config.SimonaConfig.EmRuntimeConfig import edu.ie3.simona.event.ResultEvent diff --git a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala index 8f6f3df941..400047a4bf 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala @@ -6,12 +6,10 @@ package edu.ie3.simona.agent.em +import edu.ie3.simona.agent.em.EmAgent.Actor +import edu.ie3.simona.agent.em.FlexCorrespondenceStore.WithTime +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.exceptions.CriticalFailureException -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} -import EmAgent.Actor -import FlexCorrespondenceStore.WithTime import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage._ import edu.ie3.util.scala.collection.mutable.PriorityMultiBiSet import squants.Power diff --git a/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala b/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala index aa4cca4b47..8d4a12445c 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala @@ -10,9 +10,7 @@ import edu.ie3.simona.agent.em.FlexCorrespondenceStore.{ FlexCorrespondence, WithTime, } -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{ IssueFlexControl, ProvideFlexOptions, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala index bdb53a3fc3..c8c10da18d 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala @@ -23,8 +23,8 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.StartCalculationTrigger import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals.RelevantResultValues import edu.ie3.simona.agent.participant.data.Data import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, - ApparentPowerAndHeat => ComplexPowerAndHeat, + ComplexPower, + ComplexPowerAndHeat, EnrichableData, PrimaryDataWithApparentPower, } @@ -799,7 +799,7 @@ protected trait ParticipantAgentFundamentals[ flexStateData.emAgent ! FlexCtrlCompletion( baseStateData.modelUuid, - result.primaryData.toApparentPower, + result.primaryData.toComplexPower, flexChangeIndicator.changesAtNextActivation, nextActivation, ) @@ -1734,7 +1734,7 @@ protected trait ParticipantAgentFundamentals[ baseStateData.foreseenDataTicks, ) - averageResult.toApparentPower match { + averageResult.toComplexPower match { case ComplexPower(p, q) => stay() using nextStateData replying AssetPowerChangedMessage(p, q) } @@ -2028,8 +2028,8 @@ object ParticipantAgentFundamentals { case Some(qFunc) => // NOTE: The type conversion to Megawatts is done to satisfy the methods type constraints // and is undone after unpacking the results - tick -> Megawatts(qFunc(pd.toApparentPower.p).toMegavars) - case None => tick -> Megawatts(pd.toApparentPower.q.toMegavars) + tick -> Megawatts(qFunc(pd.toComplexPower.p).toMegavars) + case None => tick -> Megawatts(pd.toComplexPower.q.toMegavars) } }, windowStart, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/data/Data.scala b/src/main/scala/edu/ie3/simona/agent/participant/data/Data.scala index cb56e1af92..7da7b04c5c 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/data/Data.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/data/Data.scala @@ -7,13 +7,13 @@ package edu.ie3.simona.agent.participant.data import edu.ie3.datamodel.models.value._ -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.util.quantities.PowerSystemUnits import edu.ie3.util.quantities.interfaces.EnergyPrice -import edu.ie3.util.scala.quantities.{Kilovars, Megavars, ReactivePower} -import squants.energy.{Power, Kilowatts, Megawatts} -import tech.units.indriya.ComparableQuantity import edu.ie3.util.scala.quantities.DefaultQuantities._ +import edu.ie3.util.scala.quantities.{Kilovars, ReactivePower} +import squants.energy.{Kilowatts, Power} +import tech.units.indriya.ComparableQuantity import java.time.ZonedDateTime import scala.jdk.OptionConverters.RichOptional @@ -36,7 +36,7 @@ object Data { */ sealed trait PrimaryData extends Data { val p: Power - def toApparentPower: ApparentPower + def toComplexPower: ComplexPower } object PrimaryData { @@ -61,7 +61,7 @@ object Data { val qDot: Power } - val ZERO_POWER: ApparentPower = ApparentPower(zeroMW, zeroMVAr) + val ZERO_POWER: ComplexPower = ComplexPower(zeroMW, zeroMVAr) /** Active power as participant simulation result * @@ -70,15 +70,15 @@ object Data { */ final case class ActivePower(override val p: Power) extends PrimaryData - with EnrichableData[ApparentPower] { - override def toApparentPower: ApparentPower = - ApparentPower( + with EnrichableData[ComplexPower] { + override def toComplexPower: ComplexPower = + ComplexPower( p, zeroMVAr, ) - override def add(q: ReactivePower): ApparentPower = - ApparentPower(p, q) + override def add(q: ReactivePower): ComplexPower = + ComplexPower(p, q) } /** Active and Reactive power as participant simulation result @@ -88,13 +88,13 @@ object Data { * @param q * Reactive power */ - final case class ApparentPower( + final case class ComplexPower( override val p: Power, override val q: ReactivePower, - ) extends PrimaryDataWithApparentPower[ApparentPower] { - override def toApparentPower: ApparentPower = this + ) extends PrimaryDataWithApparentPower[ComplexPower] { + override def toComplexPower: ComplexPower = this - override def withReactivePower(q: ReactivePower): ApparentPower = + override def withReactivePower(q: ReactivePower): ComplexPower = copy(q = q) } @@ -110,15 +110,15 @@ object Data { override val qDot: Power, ) extends PrimaryData with Heat - with EnrichableData[ApparentPowerAndHeat] { - override def toApparentPower: ApparentPower = - ApparentPower( + with EnrichableData[ComplexPowerAndHeat] { + override def toComplexPower: ComplexPower = + ComplexPower( p, zeroMVAr, ) - override def add(q: ReactivePower): ApparentPowerAndHeat = - ApparentPowerAndHeat(p, q, qDot) + override def add(q: ReactivePower): ComplexPowerAndHeat = + ComplexPowerAndHeat(p, q, qDot) } /** Apparent power and heat demand as participant simulation result @@ -130,16 +130,16 @@ object Data { * @param qDot * Heat demand */ - final case class ApparentPowerAndHeat( + final case class ComplexPowerAndHeat( override val p: Power, override val q: ReactivePower, override val qDot: Power, - ) extends PrimaryDataWithApparentPower[ApparentPowerAndHeat] + ) extends PrimaryDataWithApparentPower[ComplexPowerAndHeat] with Heat { - override def toApparentPower: ApparentPower = - ApparentPower(p, q) + override def toComplexPower: ComplexPower = + ComplexPower(p, q) - override def withReactivePower(q: ReactivePower): ApparentPowerAndHeat = + override def withReactivePower(q: ReactivePower): ComplexPowerAndHeat = copy(q = q) } @@ -150,7 +150,7 @@ object Data { (hs.getP.toScala, hs.getQ.toScala, hs.getHeatDemand.toScala) match { case (Some(p), Some(q), Some(qDot)) => Success( - ApparentPowerAndHeat( + ComplexPowerAndHeat( Kilowatts( p.to(PowerSystemUnits.KILOWATT).getValue.doubleValue ), @@ -173,7 +173,7 @@ object Data { (s.getP.toScala, s.getQ.toScala) match { case (Some(p), Some(q)) => Success( - ApparentPower( + ComplexPower( Kilowatts( p.to(PowerSystemUnits.KILOWATT).getValue.doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/agent/participant/data/primary/PrimaryDataService.scala b/src/main/scala/edu/ie3/simona/agent/participant/data/primary/PrimaryDataService.scala index 33cb4b7519..92c4e510d3 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/data/primary/PrimaryDataService.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/data/primary/PrimaryDataService.scala @@ -6,10 +6,10 @@ package edu.ie3.simona.agent.participant.data.primary -import org.apache.pekko.actor.ActorRef import edu.ie3.simona.agent.participant.data.Data.PrimaryData -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.DataService +import org.apache.pekko.actor.ActorRef /** Enum-like trait to denote possible external data sources for systems */ @@ -23,5 +23,5 @@ object PrimaryDataService { * actor reference of the actual source */ final case class DummyPrimaryService(override val actorRef: ActorRef) - extends PrimaryDataService[ApparentPower] + extends PrimaryDataService[ComplexPower] } diff --git a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala index bbeb263592..5b37ae70e3 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgent.scala @@ -8,7 +8,7 @@ package edu.ie3.simona.agent.participant.evcs import edu.ie3.datamodel.models.input.system.EvcsInput import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService diff --git a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala index 4d5fd31994..0b3798a6ab 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/evcs/EvcsAgentFundamentals.scala @@ -16,9 +16,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.grid.GridAgentMessages.AssetPowerChangedMessage import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.Data.SecondaryData import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorExtEvDataService diff --git a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala index 466ca9d070..38826657e2 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.fixedfeedin import edu.ie3.datamodel.models.input.system.FixedFeedInInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.ParticipantStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData import edu.ie3.simona.config.SimonaConfig.FixedFeedInRuntimeConfig diff --git a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala index a4a6019e26..0960618890 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/fixedfeedin/FixedFeedInAgentFundamentals.scala @@ -16,7 +16,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala index 6bec55f80a..7861575ef5 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.hp import edu.ie3.datamodel.models.input.system.HpInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPowerAndHeat => ComplexPowerAndHeat -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala index 71b584cc49..27ef1cefd0 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/hp/HpAgentFundamentals.scala @@ -15,9 +15,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPowerAndHeat => ComplexPowerAndHeat -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.hp.HpAgent.neededServices import edu.ie3.simona.agent.participant.statedata.BaseStateData.{ diff --git a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala index 05c97cbecf..67607acbf1 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.load import edu.ie3.datamodel.models.input.system.LoadInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.load.LoadAgentFundamentals.{ FixedLoadAgentFundamentals, ProfileLoadAgentFundamentals, diff --git a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala index 943069c16b..88d69b10c8 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/load/LoadAgentFundamentals.scala @@ -16,7 +16,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala index 325159f08e..a46f7478a8 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.pv import edu.ie3.datamodel.models.input.system.PvInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala index 11891f76ca..f84d69306b 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/pv/PvAgentFundamentals.scala @@ -16,7 +16,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala index 5956f53822..84eda8c92b 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.storage import edu.ie3.datamodel.models.input.system.StorageInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.ParticipantStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData import edu.ie3.simona.config.SimonaConfig.StorageRuntimeConfig diff --git a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgentFundamentals.scala index 574cbbfbf7..bfa312e68a 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/storage/StorageAgentFundamentals.scala @@ -17,7 +17,7 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.getAndCheckNodalVoltage import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService @@ -65,19 +65,19 @@ import scala.reflect.{ClassTag, classTag} trait StorageAgentFundamentals extends ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], StorageInput, StorageRuntimeConfig, StorageModel, ] { this: StorageAgent => - override val alternativeResult: ApparentPower = ZERO_POWER + override val alternativeResult: ComplexPower = ZERO_POWER - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] /** Abstract definition, individual implementations found in individual agent * fundamental classes @@ -93,7 +93,7 @@ trait StorageAgentFundamentals outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -113,7 +113,7 @@ trait StorageAgentFundamentals ) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -162,7 +162,7 @@ trait StorageAgentFundamentals override protected def createInitialState( baseStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -175,7 +175,7 @@ trait StorageAgentFundamentals override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -187,14 +187,14 @@ trait StorageAgentFundamentals override val calculateModelPowerFunc: ( Long, BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, ], StorageState, Dimensionless, - ) => ApparentPower = + ) => ComplexPower = (_, _, _, _) => throw new InvalidRequestException( "Storage model cannot be run without secondary data." @@ -202,7 +202,7 @@ trait StorageAgentFundamentals override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -216,13 +216,13 @@ trait StorageAgentFundamentals ) override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ Power => ReactivePower ], - ): ApparentPower = ParticipantAgentFundamentals.averageApparentPower( + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, windowEnd, @@ -233,7 +233,7 @@ trait StorageAgentFundamentals override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new StorageResult( dateTime, uuid, @@ -256,15 +256,15 @@ trait StorageAgentFundamentals */ override protected def handleCalculatedResult( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, ], - result: AccompaniedSimulationResult[ApparentPower], + result: AccompaniedSimulationResult[ComplexPower], currentTick: Long, ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -325,7 +325,7 @@ trait StorageAgentFundamentals override def handleControlledPowerChange( tick: Long, baseStateData: BaseStateData.ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, StorageRelevantData, StorageState, StorageModel, @@ -335,7 +335,7 @@ trait StorageAgentFundamentals setPower: Power, ): ( StorageState, - AccompaniedSimulationResult[ApparentPower], + AccompaniedSimulationResult[ComplexPower], FlexChangeIndicator, ) = { val (updatedState, flexChangeIndicator) = @@ -350,9 +350,9 @@ trait StorageAgentFundamentals voltage, ) - val apparentPower = ApparentPower(updatedSetPower, reactivePower) + val apparentPower = ComplexPower(updatedSetPower, reactivePower) - val result: AccompaniedSimulationResult[ApparentPower] = + val result: AccompaniedSimulationResult[ComplexPower] = AccompaniedSimulationResult(apparentPower, Seq.empty[ResultEntity]) (updatedState, result, flexChangeIndicator) diff --git a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala index 0466b7765d..f8858ded76 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgent.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.agent.participant.wec import edu.ie3.datamodel.models.input.system.WecInput import edu.ie3.simona.agent.participant.ParticipantAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.ParticipantStateData diff --git a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala index da05d47468..01c903dba1 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/wec/WecAgentFundamentals.scala @@ -16,7 +16,7 @@ import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgent._ import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData diff --git a/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatParticipant.scala b/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatParticipant.scala index eb51174cb5..b9476aae14 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatParticipant.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatParticipant.scala @@ -6,7 +6,7 @@ package edu.ie3.simona.model.participant -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.util.scala.quantities.DefaultQuantities._ import squants.{Dimensionless, Power} @@ -14,13 +14,13 @@ trait ApparentPowerAndHeatParticipant[ CD <: CalcRelevantData, MS <: ModelState, ] { - this: SystemParticipant[CD, ApparentPowerAndHeat, MS] => + this: SystemParticipant[CD, ComplexPowerAndHeat, MS] => override def calculatePower( tick: Long, voltage: Dimensionless, modelState: MS, data: CD, - ): ApparentPowerAndHeat = { + ): ComplexPowerAndHeat = { val apparentPower = calculateApparentPower(tick, voltage, modelState, data) val heat = @@ -29,7 +29,7 @@ trait ApparentPowerAndHeatParticipant[ else zeroMW - ApparentPowerAndHeat(apparentPower.p, apparentPower.q, heat) + ComplexPowerAndHeat(apparentPower.p, apparentPower.q, heat) } /** Calculate the heat of the asset. As for electrical assets, positive values diff --git a/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerParticipant.scala b/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerParticipant.scala index d1d71a58ac..e630c7fb5c 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerParticipant.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ApparentPowerParticipant.scala @@ -6,16 +6,16 @@ package edu.ie3.simona.model.participant -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import squants.Dimensionless trait ApparentPowerParticipant[CD <: CalcRelevantData, MS <: ModelState] { - this: SystemParticipant[CD, ApparentPower, MS] => + this: SystemParticipant[CD, ComplexPower, MS] => override def calculatePower( tick: Long, voltage: Dimensionless, modelState: MS, data: CD, - ): ApparentPower = + ): ComplexPower = calculateApparentPower(tick, voltage, modelState, data) } diff --git a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala index ad447896cd..7961758da9 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala @@ -6,9 +6,7 @@ package edu.ie3.simona.model.participant -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.participant.BMModel.BMCalcRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 9005760064..36a420806f 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -7,9 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.ChpInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ChpModel._ import edu.ie3.simona.model.participant.ModelState.ConstantState diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index d5159df267..ad76fbbddb 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.model.participant import com.typesafe.scalalogging.LazyLogging import edu.ie3.datamodel.models.input.system.FixedFeedInInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.config.SimonaConfig import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index c622d77b5d..48e3e1b11a 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -7,9 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.HpInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPowerAndHeat => ComplexPowerAndHeat -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.HpModel.{HpRelevantData, HpState} import edu.ie3.simona.model.participant.control.QControl diff --git a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala index 8262252bf0..581afdeb65 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala @@ -7,9 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.PvInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.PvModel.PvRelevantData diff --git a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala index 2bd5a3b8e1..6d53c05466 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/StorageModel.scala @@ -7,9 +7,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.StorageInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.StorageModel.{ RefTargetSocParams, diff --git a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala index 5a12280db2..f70d9f2e05 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/SystemParticipant.scala @@ -7,8 +7,8 @@ package edu.ie3.simona.model.participant import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ + ComplexPower, PrimaryDataWithApparentPower, - ApparentPower => ComplexPower, } import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl diff --git a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala index c035527d94..e7345fbc8e 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.model.participant import edu.ie3.datamodel.models.input.system.WecInput import edu.ie3.datamodel.models.input.system.characteristic.WecCharacteristicInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.WecModel.{ diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index 59582f95ff..d8f904fbce 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -11,9 +11,7 @@ import edu.ie3.datamodel.models.ElectricCurrentType import edu.ie3.datamodel.models.input.system.EvcsInput import edu.ie3.datamodel.models.input.system.`type`.evcslocation.EvcsLocationType import edu.ie3.datamodel.models.result.system.{EvResult, EvcsResult} -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.SystemComponent import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.model.participant.evcs.EvcsModel._ diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala index f30a179a25..78378893a5 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.model.participant.load import com.typesafe.scalalogging.LazyLogging import edu.ie3.datamodel.models.input.system.LoadInput -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.model.participant.CalcRelevantData.LoadRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala index 6715abd69d..e34201290d 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala @@ -8,9 +8,7 @@ package edu.ie3.simona.ontology.messages.flex import edu.ie3.datamodel.models.input.AssetInput import edu.ie3.simona.agent.em.EmAgent -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.scheduler.ScheduleLock.ScheduleKey import org.apache.pekko.actor.typed.ActorRef import squants.Power diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala index 4f35770662..f78e1f5fe4 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/services/PrimaryDataMessage.scala @@ -6,9 +6,7 @@ package edu.ie3.simona.ontology.messages.services -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower => ComplexPower -} +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.ontology.messages.services.ServiceMessage.ProvisionMessage import org.apache.pekko.actor.ActorRef diff --git a/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy b/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy index ccdc786b96..3af256e814 100644 --- a/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy +++ b/src/test/groovy/edu/ie3/simona/test/common/model/MockParticipant.groovy @@ -19,7 +19,7 @@ import scala.Tuple2 import squants.Dimensionless import squants.energy.* -class MockParticipant extends SystemParticipant { +class MockParticipant extends SystemParticipant { MockParticipant( UUID uuid, @@ -40,7 +40,7 @@ class MockParticipant extends SystemParticipant Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower](resolution) + requestValueStore shouldBe ValueStore[ComplexPower](resolution) /* Additional information */ awaitRegistrationResponsesFrom shouldBe Iterable(evService.ref) @@ -389,11 +389,11 @@ class EvcsAgentModelCalculationSpec inside(evcsAgent.stateData) { case baseStateData: ParticipantModelBaseStateData[_, _, _, _] => baseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -1167,7 +1167,7 @@ class EvcsAgentModelCalculationSpec resultValueStore shouldBe ValueStore( resolution ) - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution ) case unrecognized => diff --git a/src/test/scala/edu/ie3/simona/agent/participant/FixedFeedInAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/FixedFeedInAgentModelCalculationSpec.scala index 35277823c6..dc041f0efa 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/FixedFeedInAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/FixedFeedInAgentModelCalculationSpec.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.fixedfeedin.FixedFeedInAgent import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.{ @@ -105,7 +105,7 @@ class FixedFeedInAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ FixedFeedInInput, FixedFeedInRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -221,7 +221,7 @@ class FixedFeedInAgentModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution ) case _ => @@ -270,11 +270,11 @@ class FixedFeedInAgentModelCalculationSpec inside(fixedFeedAgent.stateData) { case baseStateData: ParticipantModelBaseStateData[_, _, _, _] => baseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) @@ -324,7 +324,7 @@ class FixedFeedInAgentModelCalculationSpec baseStateData.resultValueStore.last(0L) match { case Some((tick, entry)) => tick shouldBe 0L - inside(entry) { case ApparentPower(p, q) => + inside(entry) { case ComplexPower(p, q) => p should approximate(Megawatts(-268.603e-6)) q should approximate(Megavars(0.0)) } diff --git a/src/test/scala/edu/ie3/simona/agent/participant/HpAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/HpAgentModelCalculationSpec.scala index 79e64e7a12..3d882c51a2 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/HpAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/HpAgentModelCalculationSpec.scala @@ -14,7 +14,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.hp.HpAgent import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData @@ -121,7 +121,7 @@ class HpAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ HpInput, HpRuntimeConfig, - ApparentPowerAndHeat, + ComplexPowerAndHeat, ]( inputModel = hpInput, modelConfig = modelConfig, @@ -186,7 +186,7 @@ class HpAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ HpInput, HpRuntimeConfig, - ApparentPowerAndHeat, + ComplexPowerAndHeat, ]( inputModel = hpInput, thermalGrid = defaultThermalGrid, @@ -318,7 +318,7 @@ class HpAgentModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPowerAndHeat]( + requestValueStore shouldBe ValueStore[ComplexPowerAndHeat]( resolution ) @@ -403,11 +403,11 @@ class HpAgentModelCalculationSpec inside(hpAgent.stateData) { case modelBaseStateData: ParticipantModelBaseStateData[_, _, _, _] => modelBaseStateData.requestValueStore shouldBe ValueStore[ - ApparentPowerAndHeat + ComplexPowerAndHeat ]( resolution, SortedMap( - 0L -> ApparentPowerAndHeat( + 0L -> ComplexPowerAndHeat( Megawatts(0.0), Megavars(0.0), Megawatts(0.0), @@ -539,7 +539,7 @@ class HpAgentModelCalculationSpec 0L, fail("Expected a simulation result for tick 900."), ) match { - case ApparentPowerAndHeat(p, q, qDot) => + case ComplexPowerAndHeat(p, q, qDot) => p should approximate(Megawatts(0d)) q should approximate(Megavars(0d)) qDot should approximate(Megawatts(0d)) @@ -667,7 +667,7 @@ class HpAgentModelCalculationSpec 0L, fail("Expected a simulation result for tick 0."), ) match { - case ApparentPowerAndHeat(p, q, qDot) => + case ComplexPowerAndHeat(p, q, qDot) => p should approximate(Megawatts(0d)) q should approximate(Megavars(0d)) qDot should approximate(Megawatts(0d)) diff --git a/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentFixedModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentFixedModelCalculationSpec.scala index ca26c49cb7..5860fa04bb 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentFixedModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentFixedModelCalculationSpec.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.load.LoadAgent.FixedLoadAgent import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.{ @@ -99,7 +99,7 @@ class LoadAgentFixedModelCalculationSpec val initStateData = ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -215,7 +215,7 @@ class LoadAgentFixedModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution ) case _ => @@ -264,11 +264,11 @@ class LoadAgentFixedModelCalculationSpec inside(loadAgent.stateData) { case baseStateData: ParticipantModelBaseStateData[_, _, _, _] => baseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) @@ -318,7 +318,7 @@ class LoadAgentFixedModelCalculationSpec baseStateData.resultValueStore.last(0L) match { case Some((tick, entry)) => tick shouldBe 0L - inside(entry) { case ApparentPower(p, q) => + inside(entry) { case ComplexPower(p, q) => p should approximate(Megawatts(268.603e-6)) q should approximate(Megavars(0.0)) } diff --git a/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentProfileModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentProfileModelCalculationSpec.scala index 5790868a44..7101b96671 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentProfileModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/LoadAgentProfileModelCalculationSpec.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.load.LoadAgent.ProfileLoadAgent import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.{ @@ -99,7 +99,7 @@ class LoadAgentProfileModelCalculationSpec val initStateData = ParticipantInitializeStateData[ LoadInput, LoadRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -215,7 +215,7 @@ class LoadAgentProfileModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution ) case _ => @@ -264,11 +264,11 @@ class LoadAgentProfileModelCalculationSpec inside(loadAgent.stateData) { case baseStateData: ParticipantModelBaseStateData[_, _, _, _] => baseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) @@ -318,7 +318,7 @@ class LoadAgentProfileModelCalculationSpec baseStateData.resultValueStore.last(0L) match { case Some((tick, entry)) => tick shouldBe 0L - inside(entry) { case ApparentPower(p, q) => + inside(entry) { case ComplexPower(p, q) => p should approximate(Megawatts(84.000938e-6)) q should approximate(Megavars(0.0)) } diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgent2ListenerSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgent2ListenerSpec.scala index a768fdb73f..d233b102ed 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgent2ListenerSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgent2ListenerSpec.scala @@ -17,7 +17,7 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.{ FinishParticipantSimulation, RequestAssetPowerMessage, } -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData import edu.ie3.simona.config.SimonaConfig import edu.ie3.simona.config.SimonaConfig.BaseRuntimeConfig @@ -87,12 +87,12 @@ class ParticipantAgent2ListenerSpec val initStateData: NotifierConfig => ParticipantInitializeStateData[ SystemParticipantInput, BaseRuntimeConfig, - ApparentPower, + ComplexPower, ] = outputConfig => ParticipantInitializeStateData[ SystemParticipantInput, BaseRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = mockInputModel, modelConfig = mock[BaseRuntimeConfig], diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentExternalSourceSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentExternalSourceSpec.scala index 79158df7e7..7e152fedb3 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentExternalSourceSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentExternalSourceSpec.scala @@ -23,8 +23,8 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessag import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ ActivePower, ActivePowerAndHeat, - ApparentPower, - ApparentPowerAndHeat, + ComplexPower, + ComplexPowerAndHeat, } import edu.ie3.simona.agent.participant.statedata.BaseStateData.FromOutsideBaseStateData import edu.ie3.simona.agent.participant.statedata.DataCollectionStateData @@ -97,7 +97,7 @@ class ParticipantAgentExternalSourceSpec private val mockModel = mock[SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ]] when(mockModel.getUuid).thenReturn(testUUID) @@ -128,7 +128,7 @@ class ParticipantAgentExternalSourceSpec val initStateData = ParticipantInitializeStateData[ SystemParticipantInput, BaseRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = mockInputModel, modelConfig = mock[BaseRuntimeConfig], @@ -216,9 +216,9 @@ class ParticipantAgentExternalSourceSpec mockAgent.stateData match { case baseStateData: FromOutsideBaseStateData[SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower] => + ], ComplexPower] => /* Only check the awaited next data ticks, as the rest has yet been checked */ baseStateData.foreseenDataTicks shouldBe Map( primaryServiceProxy.ref -> Some(4711L) @@ -279,10 +279,10 @@ class ParticipantAgentExternalSourceSpec _, requestValueStore, ) => - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -322,7 +322,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 900L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(0.0), Kilovars(900.0), ), @@ -336,9 +336,9 @@ class ParticipantAgentExternalSourceSpec case DataCollectionStateData( baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower], + ], ComplexPower], expectedSenders, isYetTriggered, ) => @@ -350,7 +350,7 @@ class ParticipantAgentExternalSourceSpec /* The yet sent data is also registered */ expectedSenders shouldBe Map( primaryServiceProxy.ref -> Some( - ApparentPower( + ComplexPower( Kilowatts(0.0), Kilovars(900.0), ) @@ -376,14 +376,14 @@ class ParticipantAgentExternalSourceSpec mockAgent.stateData match { case baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower] => + ], ComplexPower] => /* The new data is apparent in the result value store */ baseStateData.resultValueStore match { case ValueStore(_, store) => store shouldBe Map( - 900L -> ApparentPower( + 900L -> ComplexPower( Kilowatts(0.0), Kilovars(900.0), ) @@ -426,9 +426,9 @@ class ParticipantAgentExternalSourceSpec case DataCollectionStateData( baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower], + ], ComplexPower], expectedSenders, isYetTriggered, ) => @@ -454,7 +454,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 900L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(0.0), Kilovars(900.0), ), @@ -470,14 +470,14 @@ class ParticipantAgentExternalSourceSpec mockAgent.stateData match { case baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower] => + ], ComplexPower] => /* The new data is apparent in the result value store */ baseStateData.resultValueStore match { case ValueStore(_, store) => store shouldBe Map( - 900L -> ApparentPower( + 900L -> ComplexPower( Kilowatts(0.0), Kilovars(900.0), ) @@ -527,7 +527,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 900L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(0.0), Kilovars(900.0), ), @@ -554,13 +554,13 @@ class ParticipantAgentExternalSourceSpec "correctly determine the reactive power function when trivial reactive power is requested" in { val baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower] = FromOutsideBaseStateData[SystemParticipant[ + ], ComplexPower] = FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower]( + ], ComplexPower]( mockModel, defaultSimulationStart, defaultSimulationEnd, @@ -585,13 +585,13 @@ class ParticipantAgentExternalSourceSpec "correctly determine the reactive power function from model when requested" in { val baseStateData: FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower] = FromOutsideBaseStateData[SystemParticipant[ + ], ComplexPower] = FromOutsideBaseStateData[SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, - ], ApparentPower]( + ], ComplexPower]( mockModel, defaultSimulationStart, defaultSimulationEnd, @@ -635,7 +635,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 900L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(100.0), Kilovars(33.0), ), @@ -651,7 +651,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 1800L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(150.0), Kilovars(49.0), ), @@ -667,7 +667,7 @@ class ParticipantAgentExternalSourceSpec ProvidePrimaryDataMessage( 2700L, primaryServiceProxy.ref, - ApparentPower( + ComplexPower( Kilowatts(200.0), Kilovars(66.0), ), @@ -738,7 +738,7 @@ class ParticipantAgentExternalSourceSpec "fail" in { val data = Map( primaryServiceProxy.ref -> Some( - ApparentPowerAndHeat( + ComplexPowerAndHeat( Kilowatts(0.0), Kilovars(0.0), Kilowatts(0.0), @@ -748,7 +748,7 @@ class ParticipantAgentExternalSourceSpec participantAgent.prepareData(data, reactivePowerFunction) match { case Failure(exception: IllegalStateException) => - exception.getMessage shouldBe "Got the wrong primary data. Expected: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ApparentPower, got: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ApparentPowerAndHeat" + exception.getMessage shouldBe "Got the wrong primary data. Expected: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ComplexPower, got: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ComplexPowerAndHeat" case Failure(exception) => fail(s"Failed with wrong exception:\n\t$exception") case Success(_) => fail("Was meant to fail, but succeeded") @@ -769,7 +769,7 @@ class ParticipantAgentExternalSourceSpec participantAgent.prepareData(data, reactivePowerFunction) match { case Failure(exception: IllegalStateException) => - exception.getMessage shouldBe "Received primary data cannot be enriched to expected data. Expected: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ApparentPower, got: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ActivePowerAndHeat, enriched to: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ApparentPowerAndHeat" + exception.getMessage shouldBe "Received primary data cannot be enriched to expected data. Expected: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ComplexPower, got: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ActivePowerAndHeat, enriched to: edu.ie3.simona.agent.participant.data.Data$PrimaryData$ComplexPowerAndHeat" case Failure(exception) => fail(s"Failed with wrong exception:\n\t$exception") case Success(_) => fail("Was meant to fail, but succeeded") @@ -784,7 +784,7 @@ class ParticipantAgentExternalSourceSpec ) participantAgent.prepareData(data, reactivePowerFunction) match { - case Success(ApparentPower(p, q)) => + case Success(ComplexPower(p, q)) => p should approximate(Megawatts(0.0)) q should approximate(Megavars(0.0)) case Success(value) => @@ -808,7 +808,7 @@ class ParticipantAgentExternalSourceSpec data, (p: squants.Power) => Kilovars(p.toKilowatts * tan(acos(0.9))), ) match { - case Success(ApparentPower(p, q)) => + case Success(ComplexPower(p, q)) => p should approximate(Kilowatts(100.0)) q should approximate(Kilovars(48.43221)) case Success(value) => diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala index dde8ed4803..26058683b3 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentalsSpec.scala @@ -11,7 +11,7 @@ import com.typesafe.config.ConfigFactory import edu.ie3.datamodel.models.input.system.SystemParticipantInput import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.ParticipantAgentFundamentals.RelevantResultValues -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.ParticipantInitializeStateData @@ -82,7 +82,7 @@ class ParticipantAgentFundamentalsSpec /* Get one instance of the mock for participant agent */ private val mockAgentTestRef: TestFSMRef[AgentState, ParticipantStateData[ - ApparentPower + ComplexPower ], ParticipantAgentMock] = TestFSMRef( new ParticipantAgentMock( @@ -90,7 +90,7 @@ class ParticipantAgentFundamentalsSpec initStateData = mock[ParticipantInitializeStateData[ SystemParticipantInput, BaseRuntimeConfig, - ApparentPower, + ComplexPower, ]], ) ) @@ -98,35 +98,35 @@ class ParticipantAgentFundamentalsSpec private val powerValues = Map( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(1.0), Megavars(0.0), ), - 1L -> ApparentPower( + 1L -> ComplexPower( Megawatts(2.0), Megavars(1.0), ), - 3L -> ApparentPower( + 3L -> ComplexPower( Megawatts(3.0), Megavars(2.0), ), - 4L -> ApparentPower( + 4L -> ComplexPower( Megawatts(5.0), Megavars(4.0), ), - 7L -> ApparentPower( + 7L -> ComplexPower( Megawatts(3.0), Megavars(2.0), ), - 8L -> ApparentPower( + 8L -> ComplexPower( Megawatts(6.0), Megavars(5.0), ), - 9L -> ApparentPower( + 9L -> ComplexPower( Megawatts(6.0), Megavars(5.0), ), - 10L -> ApparentPower( + 10L -> ComplexPower( Megawatts(4.0), Megavars(3.0), ), @@ -326,7 +326,7 @@ class ParticipantAgentFundamentalsSpec None, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.8666666666666667)) q should approximate(Megavars(0.5333333333333334)) } @@ -341,7 +341,7 @@ class ParticipantAgentFundamentalsSpec None, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(4.571428571428573)) q should approximate(Megavars(3.571428571428571)) } @@ -356,7 +356,7 @@ class ParticipantAgentFundamentalsSpec None, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(4.571428571428573)) q should approximate(Megavars(3.571428571428571)) } @@ -371,7 +371,7 @@ class ParticipantAgentFundamentalsSpec activeToReactivePowerFuncOpt, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.8666666666666667)) q should approximate(Megavars(2.8666666666666667)) } @@ -386,7 +386,7 @@ class ParticipantAgentFundamentalsSpec activeToReactivePowerFuncOpt, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(4.571428571428573)) q should approximate(Megavars(21.71428571428571)) } @@ -401,7 +401,7 @@ class ParticipantAgentFundamentalsSpec activeToReactivePowerFuncOpt, ) apparentPower match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(4.571428571428573)) q should approximate(Megavars(21.71428571428571)) } @@ -414,27 +414,27 @@ class ParticipantAgentFundamentalsSpec val resultValueStore = ValueStore( 900, SortedMap( - 800L -> ApparentPower( + 800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1000L -> ApparentPower( + 1000L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1200L -> ApparentPower( + 1200L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1400L -> ApparentPower( + 1400L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1600L -> ApparentPower( + 1600L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1800L -> ApparentPower( + 1800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), @@ -443,7 +443,7 @@ class ParticipantAgentFundamentalsSpec val requestValueStore = ValueStore( 900, SortedMap( - 900L -> ApparentPower( + 900L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -459,27 +459,27 @@ class ParticipantAgentFundamentalsSpec 900L, 1800L, Map( - 800L -> ApparentPower( + 800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1000L -> ApparentPower( + 1000L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1200L -> ApparentPower( + 1200L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1400L -> ApparentPower( + 1400L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1600L -> ApparentPower( + 1600L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), - 1800L -> ApparentPower( + 1800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ), @@ -493,7 +493,7 @@ class ParticipantAgentFundamentalsSpec val resultValueStore = ValueStore( 900, SortedMap( - 800L -> ApparentPower( + 800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -502,7 +502,7 @@ class ParticipantAgentFundamentalsSpec val requestValueStore = ValueStore( 900, SortedMap( - 900L -> ApparentPower( + 900L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -518,7 +518,7 @@ class ParticipantAgentFundamentalsSpec 900L, 1800L, Map( - 800L -> ApparentPower( + 800L -> ComplexPower( Megawatts(0.0), Megavars(0.0), ) @@ -531,7 +531,7 @@ class ParticipantAgentFundamentalsSpec "Determining the applicable nodal voltage" should { "deliver the correct voltage" in { val baseStateData = ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedLoadRelevantData.type, ConstantState.type, FixedLoadModel, @@ -568,7 +568,7 @@ class ParticipantAgentFundamentalsSpec "throw an error, if no nodal voltage is available" in { val baseStateData = ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedLoadRelevantData.type, ConstantState.type, FixedLoadModel, @@ -620,25 +620,25 @@ case object ParticipantAgentFundamentalsSpec extends MockitoSugar { additionalActivationTicks: SortedSet[Long], foreseenDataTicks: Map[ActorRef, Option[Long]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - SystemParticipant[FixedRelevantData.type, ApparentPower, ConstantState.type], + SystemParticipant[FixedRelevantData.type, ComplexPower, ConstantState.type], ] = { val modelMock = mock[SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ]] when(modelMock.getUuid).thenReturn(UUID.randomUUID()) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ]( diff --git a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala index fb965d72d3..1e70a3f443 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/ParticipantAgentMock.scala @@ -11,7 +11,7 @@ import edu.ie3.datamodel.models.result.ResultEntity import edu.ie3.datamodel.models.result.system.SystemParticipantResult import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ - ApparentPower, + ComplexPower, ZERO_POWER, } import edu.ie3.simona.agent.participant.data.Data.SecondaryData @@ -73,38 +73,38 @@ class ParticipantAgentMock( initStateData: ParticipantInitializeStateData[ SystemParticipantInput, SimonaConfig.BaseRuntimeConfig, - ApparentPower, + ComplexPower, ], override val listener: Iterable[ActorRef] = Iterable.empty[ActorRef], ) extends ParticipantAgent[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], SystemParticipantInput, SimonaConfig.BaseRuntimeConfig, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ](scheduler, initStateData) with ParticipantAgentFundamentals[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - ParticipantStateData[ApparentPower], + ParticipantStateData[ComplexPower], SystemParticipantInput, SimonaConfig.BaseRuntimeConfig, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ] { - override protected val pdClassTag: ClassTag[ApparentPower] = - classTag[ApparentPower] - override val alternativeResult: ApparentPower = ZERO_POWER + override protected val pdClassTag: ClassTag[ComplexPower] = + classTag[ComplexPower] + override val alternativeResult: ComplexPower = ZERO_POWER /** Partial function, that is able to transfer * [[ParticipantModelBaseStateData]] (holding the actual calculation model) @@ -113,20 +113,20 @@ class ParticipantAgentMock( override val calculateModelPowerFunc: ( Long, ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ], ConstantState.type, squants.Dimensionless, - ) => ApparentPower = (_, _, _, _) => + ) => ComplexPower = (_, _, _, _) => // output different from default (0, 0) - ApparentPower( + ComplexPower( Megawatts(2.0), Megavars(1.0), ) @@ -149,19 +149,19 @@ class ParticipantAgentMock( */ override def calculatePowerWithSecondaryDataAndGoToIdle( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ], modelState: ConstantState.type, currentTick: Long, scheduler: ActorRef, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = throw new InvalidRequestException( "Request to calculate power with secondary data cannot be processed for this mock agent." ) @@ -201,10 +201,10 @@ class ParticipantAgentMock( outputConfig: NotifierConfig, maybeEmAgent: Option[TypedActorRef[FlexResponse]], ): ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, - SystemParticipant[FixedRelevantData.type, ApparentPower, ConstantState.type], + SystemParticipant[FixedRelevantData.type, ComplexPower, ConstantState.type], ] = { val func = CosPhiFixed(0.95).activeToReactivePowerFunc( Kilovoltamperes(0.0), @@ -213,23 +213,23 @@ class ParticipantAgentMock( ) val participant: SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ] = mock[SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ]] doReturn(func).when(participant).activeToReactivePowerFunc(any()) ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ]( @@ -272,13 +272,13 @@ class ParticipantAgentMock( simulationEndDate: ZonedDateTime, ): SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ] = { val mockModel = mock[SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ]] val uuid = inputModel.electricalInputModel.getUuid @@ -288,12 +288,12 @@ class ParticipantAgentMock( override protected def createInitialState( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ] @@ -302,12 +302,12 @@ class ParticipantAgentMock( override protected def createCalcRelevantData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, FixedRelevantData.type, ConstantState.type, SystemParticipant[ FixedRelevantData.type, - ApparentPower, + ComplexPower, ConstantState.type, ], ], @@ -325,9 +325,9 @@ class ParticipantAgentMock( * [[Idle]] with updated result values */ override def finalizeTickAfterPF( - baseStateData: BaseStateData[ApparentPower], + baseStateData: BaseStateData[ComplexPower], currentTick: Long, - ): FSM.State[AgentState, ParticipantStateData[ApparentPower]] = + ): FSM.State[AgentState, ParticipantStateData[ComplexPower]] = goto(Idle) using baseStateData /** Determine the average result within the given tick window @@ -344,13 +344,13 @@ class ParticipantAgentMock( * The averaged result */ override def averageResults( - tickToResults: Map[Long, ApparentPower], + tickToResults: Map[Long, ComplexPower], windowStart: Long, windowEnd: Long, activeToReactivePowerFuncOpt: Option[ squants.Power => ReactivePower ] = None, - ): ApparentPower = + ): ComplexPower = ParticipantAgentFundamentals.averageApparentPower( tickToResults, windowStart, @@ -373,7 +373,7 @@ class ParticipantAgentMock( override protected def buildResult( uuid: UUID, dateTime: ZonedDateTime, - result: ApparentPower, + result: ComplexPower, ): SystemParticipantResult = new SystemParticipantResult( dateTime, @@ -400,12 +400,12 @@ class ParticipantAgentMock( override def handleControlledPowerChange( tick: Long, baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, CalcRelevantData.FixedRelevantData.type, ModelState.ConstantState.type, SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ModelState.ConstantState.type, ], ], @@ -414,12 +414,12 @@ class ParticipantAgentMock( setPower: squants.Power, ): ( ModelState.ConstantState.type, - AccompaniedSimulationResult[ApparentPower], + AccompaniedSimulationResult[ComplexPower], FlexChangeIndicator, ) = ( ConstantState, AccompaniedSimulationResult( - ApparentPower( + ComplexPower( Kilowatts(0.0), Kilovars(0.0), ), @@ -451,7 +451,7 @@ class ParticipantAgentMock( nodalVoltage: squants.Dimensionless, model: SystemParticipant[ CalcRelevantData.FixedRelevantData.type, - ApparentPower, + ComplexPower, ModelState.ConstantState.type, ], ): ModelState.ConstantState.type = modelState @@ -463,7 +463,7 @@ object ParticipantAgentMock { initStateData: ParticipantInitializeStateData[ SystemParticipantInput, SimonaConfig.BaseRuntimeConfig, - ApparentPower, + ComplexPower, ], ): Props = Props( diff --git a/src/test/scala/edu/ie3/simona/agent/participant/PvAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/PvAgentModelCalculationSpec.scala index 9bda1b8b99..f2985dd693 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/PvAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/PvAgentModelCalculationSpec.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.pv.PvAgent import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData @@ -122,7 +122,7 @@ class PvAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ PvInput, PvRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -186,7 +186,7 @@ class PvAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ PvInput, PvRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -314,7 +314,7 @@ class PvAgentModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower](resolution) + requestValueStore shouldBe ValueStore[ComplexPower](resolution) /* Additional information */ awaitRegistrationResponsesFrom shouldBe Iterable(weatherService.ref) @@ -397,11 +397,11 @@ class PvAgentModelCalculationSpec inside(pvAgent.stateData) { case baseStateData: ParticipantModelBaseStateData[_, _, _, _] => baseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) @@ -509,7 +509,7 @@ class PvAgentModelCalculationSpec 0L, fail("Expected a simulation result for tick 900."), ) match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.0)) q should approximate(Megavars(0.0)) } @@ -613,7 +613,7 @@ class PvAgentModelCalculationSpec 0L, fail("Expected a simulation result for tick 0."), ) match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.0)) q should approximate(Megavars(0.0)) } diff --git a/src/test/scala/edu/ie3/simona/agent/participant/RichValueSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/RichValueSpec.scala index 5710c15417..0c8b16b35b 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/RichValueSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/RichValueSpec.scala @@ -18,8 +18,8 @@ import edu.ie3.simona.agent.participant.data.Data.PrimaryData import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ ActivePower, ActivePowerAndHeat, - ApparentPower, - ApparentPowerAndHeat, + ComplexPower, + ComplexPowerAndHeat, RichValue, } import edu.ie3.simona.test.common.UnitSpec @@ -116,7 +116,7 @@ class RichValueSpec extends UnitSpec with TableDrivenPropertyChecks { Quantities.getQuantity(50d, PowerSystemUnits.KILOWATT), Quantities.getQuantity(25d, PowerSystemUnits.KILOVAR), ), - ApparentPower( + ComplexPower( Kilowatts(50d), Kilovars(25d), ), @@ -127,7 +127,7 @@ class RichValueSpec extends UnitSpec with TableDrivenPropertyChecks { Quantities.getQuantity(25d, PowerSystemUnits.KILOVAR), Quantities.getQuantity(12.5, PowerSystemUnits.KILOWATT), ), - ApparentPowerAndHeat( + ComplexPowerAndHeat( Kilowatts(50d), Kilovars(25d), Kilowatts(12.5), diff --git a/src/test/scala/edu/ie3/simona/agent/participant/StorageAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/StorageAgentModelCalculationSpec.scala index d7c8378ce5..dc2b1b96ff 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/StorageAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/StorageAgentModelCalculationSpec.scala @@ -13,7 +13,7 @@ import edu.ie3.datamodel.models.result.system.StorageResult import edu.ie3.simona.agent.ValueStore import edu.ie3.simona.agent.grid.GridAgentMessages.AssetPowerChangedMessage import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.ParticipantStateData.{ ParticipantInitializeStateData, @@ -110,7 +110,7 @@ class StorageAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ StorageInput, StorageRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = storageInputQv, modelConfig = modelConfig, @@ -219,7 +219,7 @@ class StorageAgentModelCalculationSpec resultValueStore shouldBe ValueStore( resolution ) - requestValueStore shouldBe ValueStore[ApparentPower]( + requestValueStore shouldBe ValueStore[ComplexPower]( resolution ) case unrecognized => @@ -271,11 +271,11 @@ class StorageAgentModelCalculationSpec inside(storageAgent.stateData) { case modelBaseStateData: ParticipantModelBaseStateData[_, _, _, _] => modelBaseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) diff --git a/src/test/scala/edu/ie3/simona/agent/participant/WecAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/WecAgentModelCalculationSpec.scala index 08193e798c..704877ee79 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/WecAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/WecAgentModelCalculationSpec.scala @@ -15,7 +15,7 @@ import edu.ie3.simona.agent.grid.GridAgentMessages.{ AssetPowerUnchangedMessage, } import edu.ie3.simona.agent.participant.ParticipantAgent.RequestAssetPowerMessage -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.ActorWeatherService import edu.ie3.simona.agent.participant.statedata.BaseStateData.ParticipantModelBaseStateData import edu.ie3.simona.agent.participant.statedata.DataCollectionStateData @@ -125,7 +125,7 @@ class WecAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ WecInput, WecRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, simulationStartDate = simulationStartDate, @@ -193,7 +193,7 @@ class WecAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ WecInput, WecRuntimeConfig, - ApparentPower, + ComplexPower, ]( inputModel = voltageSensitiveInput, modelConfig = modelConfig, @@ -291,7 +291,7 @@ class WecAgentModelCalculationSpec SortedMap(0L -> Each(1.0)), ) resultValueStore shouldBe ValueStore(resolution) - requestValueStore shouldBe ValueStore[ApparentPower](resolution) + requestValueStore shouldBe ValueStore[ComplexPower](resolution) /* Additional information */ awaitRegistrationResponsesFrom shouldBe Iterable(weatherService.ref) @@ -315,7 +315,7 @@ class WecAgentModelCalculationSpec wecAgent.stateName shouldBe Idle wecAgent.stateData match { case baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -376,17 +376,17 @@ class WecAgentModelCalculationSpec inside(wecAgent.stateData) { case modelBaseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, ] => modelBaseStateData.requestValueStore shouldBe ValueStore[ - ApparentPower + ComplexPower ]( resolution, SortedMap( - 0L -> ApparentPower( + 0L -> ComplexPower( Megawatts(0d), Megavars(0d), ) @@ -452,7 +452,7 @@ class WecAgentModelCalculationSpec wecAgent.stateData match { case DataCollectionStateData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -488,7 +488,7 @@ class WecAgentModelCalculationSpec wecAgent.stateName shouldBe Idle wecAgent.stateData match { case baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -509,7 +509,7 @@ class WecAgentModelCalculationSpec 900L, fail("Expected a simulation result for tick 900."), ) match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.0)) q should approximate(Megavars(0.0)) } @@ -558,7 +558,7 @@ class WecAgentModelCalculationSpec wecAgent.stateData match { case DataCollectionStateData( baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -607,7 +607,7 @@ class WecAgentModelCalculationSpec wecAgent.stateName shouldBe Idle wecAgent.stateData match { case baseStateData: ParticipantModelBaseStateData[ - ApparentPower, + ComplexPower, WecRelevantData, ConstantState.type, WecModel, @@ -628,7 +628,7 @@ class WecAgentModelCalculationSpec 900L, fail("Expected a simulation result for tick 900."), ) match { - case ApparentPower(p, q) => + case ComplexPower(p, q) => p should approximate(Megawatts(0.0)) q should approximate(Megavars(0.0)) } diff --git a/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala index abcdb613a6..e47c309c37 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/ApparentPowerAndHeatSpec.scala @@ -6,7 +6,7 @@ package edu.ie3.simona.model.participant -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPowerAndHeat +import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPowerAndHeat import edu.ie3.simona.model.participant.ApparentPowerAndHeatSpec.ApparentPowerAndHeatMock import edu.ie3.simona.model.participant.CalcRelevantData.FixedRelevantData import edu.ie3.simona.model.participant.ModelState.ConstantState @@ -38,7 +38,7 @@ class ApparentPowerAndHeatSpec extends UnitSpec { ConstantState, FixedRelevantData, ) match { - case ApparentPowerAndHeat(p, q, qDot) => + case ComplexPowerAndHeat(p, q, qDot) => p should approximate(Megawatts(0d)) q should approximate(Megavars(0d)) qDot should approximate(Megawatts(0d)) @@ -53,7 +53,7 @@ class ApparentPowerAndHeatSpec extends UnitSpec { ConstantState, FixedRelevantData, ) match { - case ApparentPowerAndHeat(p, q, qDot) => + case ComplexPowerAndHeat(p, q, qDot) => p should approximate(Megawatts(43d)) q should approximate(Megavars(0d)) qDot should approximate(Megawatts(42d)) @@ -67,7 +67,7 @@ object ApparentPowerAndHeatSpec { object ApparentPowerAndHeatMock extends SystemParticipant[ FixedRelevantData.type, - ApparentPowerAndHeat, + ComplexPowerAndHeat, ConstantState.type, ]( UUID.randomUUID(), diff --git a/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala index 011dbb9567..6320271e9a 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala @@ -11,7 +11,7 @@ import edu.ie3.simona.model.participant.ModelState.ConstantState import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.test.common.UnitSpec import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.EuroPerKilowatthour +import edu.ie3.util.scala.quantities.{EuroPerKilowatthour, Kilovoltamperes} import squants.energy.{Kilowatts, Megawatts} import squants.market.EUR import squants.thermal.Celsius @@ -21,7 +21,7 @@ import java.time.ZonedDateTime import java.util.UUID /** Test class that tries to cover all special cases of the current - * implementation of the {@link BMModel} + * implementation of the [[BMModel]] * * Test results have been calculated on paper using equations from wiki: * https://wiki.ie3.e-technik.tu-dortmund.de/!simona/model:bm_model @@ -38,7 +38,7 @@ class BMModelSpec extends UnitSpec { "BM Model Test", OperationInterval(0L, 86400L), QControl(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Kilowatts(190), + Kilovoltamperes(190), 1d, "MockNode", isCostControlled = true, @@ -164,7 +164,7 @@ class BMModelSpec extends UnitSpec { "BM Model Test", OperationInterval(0L, 86400L), QControl(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Kilowatts(190), + Kilovoltamperes(190), 1d, "MockNode", isCostControlled = true, @@ -174,7 +174,7 @@ class BMModelSpec extends UnitSpec { ) val pElCalc = bmModel.calculateElOutput(usage, eff) - pElCalc.value should be(Kilowatts(pElSol).value +- 1e-4) + pElCalc.value should be(Kilovoltamperes(pElSol).toVoltamperes +- 1e-4) } } @@ -306,7 +306,7 @@ class BMModelSpec extends UnitSpec { "BM Model Test", OperationInterval(0L, 86400L), QControl(new CosPhiFixed("cosPhiFixed:{(0.0,1.0)}")), - Kilowatts(190), + Kilovoltamperes(190), 1d, "MockNode", costControlled, diff --git a/src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceWorkerSqlIT.scala b/src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceWorkerSqlIT.scala index 2b7023daa3..9a50b4fce9 100644 --- a/src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceWorkerSqlIT.scala +++ b/src/test/scala/edu/ie3/simona/service/primary/PrimaryServiceWorkerSqlIT.scala @@ -15,7 +15,7 @@ import edu.ie3.datamodel.io.naming.DatabaseNamingStrategy import edu.ie3.datamodel.models.value.{HeatAndSValue, PValue} import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{ ActivePower, - ApparentPowerAndHeat, + ComplexPowerAndHeat, } import edu.ie3.simona.config.SimonaConfig.Simona.Input.Primary.SqlParams import edu.ie3.simona.ontology.messages.Activation @@ -107,7 +107,7 @@ class PrimaryServiceWorkerSqlIT ), uuidPqh, 0L, - ApparentPowerAndHeat( + ComplexPowerAndHeat( Kilowatts(1000.0), Kilovars(329.0), Kilowatts(8000.0), From 907c9944d7bd3d8b1ac923483876bf7b286c0aae Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 5 Nov 2024 15:53:39 +0100 Subject: [PATCH 12/22] Resolving merge conflicts. --- .../edu/ie3/simona/agent/em/EmDataCore.scala | 4 ---- .../messages/flex/FlexibilityMessage.scala | 2 +- .../edu/ie3/simona/agent/em/EmAgentSpec.scala | 22 +++++++++---------- .../EvcsAgentModelCalculationSpec.scala | 2 +- .../model/participant/ChpModelSpec.scala | 4 ++-- .../participant/SystemParticipantSpec.scala | 21 +++++++++++------- .../test/common/model/MockParticipant.scala | 7 +++--- 7 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala index b4fc5e06f2..aaf3943cc2 100644 --- a/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala +++ b/src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala @@ -6,10 +6,6 @@ package edu.ie3.simona.agent.em -import edu.ie3.simona.agent.em.EmAgent.Actor -import edu.ie3.simona.agent.em.FlexCorrespondenceStore.WithTime -import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower -import edu.ie3.simona.exceptions.CriticalFailureException import edu.ie3.simona.agent.em.EmAgent.Actor import edu.ie3.simona.agent.em.FlexCorrespondenceStore.WithTime import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower diff --git a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala index 21a7f32cd6..662c11e2d2 100644 --- a/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala +++ b/src/main/scala/edu/ie3/simona/ontology/messages/flex/FlexibilityMessage.scala @@ -128,7 +128,7 @@ object FlexibilityMessage { */ final case class FlexResult( override val modelUuid: UUID, - result: ApparentPower, + result: ComplexPower, ) extends FlexResponse /** Message sent by flex options providers indicating that the diff --git a/src/test/scala/edu/ie3/simona/agent/em/EmAgentSpec.scala b/src/test/scala/edu/ie3/simona/agent/em/EmAgentSpec.scala index 07da29ed41..c0b8f93489 100644 --- a/src/test/scala/edu/ie3/simona/agent/em/EmAgentSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/em/EmAgentSpec.scala @@ -307,7 +307,7 @@ class EmAgentSpec // send completions emAgent ! FlexResult( modelUuid = pvInput.getUuid, - result = ApparentPower(Kilowatts(-5d), Kilovars(-0.5d)), + result = ComplexPower(Kilowatts(-5d), Kilovars(-0.5d)), ) emAgent ! FlexCompletion( modelUuid = pvInput.getUuid, @@ -316,7 +316,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(5d), Kilovars(0.1d)), + result = ComplexPower(Kilowatts(5d), Kilovars(0.1d)), ) scheduler.expectNoMessage() @@ -361,7 +361,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = pvInput.getUuid, - result = ApparentPower(Kilowatts(-3d), Kilovars(-0.06d)), + result = ComplexPower(Kilowatts(-3d), Kilovars(-0.06d)), ) emAgent ! FlexCompletion( @@ -378,7 +378,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(3d), Kilovars(0.06d)), + result = ComplexPower(Kilowatts(3d), Kilovars(0.06d)), ) emAgent ! FlexCompletion( modelUuid = evcsInput.getUuid, @@ -470,7 +470,7 @@ class EmAgentSpec // send completions emAgent ! FlexResult( modelUuid = pvInput.getUuid, - result = ApparentPower(Kilowatts(-5d), Kilovars(-0.5d)), + result = ComplexPower(Kilowatts(-5d), Kilovars(-0.5d)), ) emAgent ! FlexCompletion( modelUuid = pvInput.getUuid, @@ -479,7 +479,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(5d), Kilovars(0.1d)), + result = ComplexPower(Kilowatts(5d), Kilovars(0.1d)), ) scheduler.expectNoMessage() @@ -534,7 +534,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = pvInput.getUuid, - result = ApparentPower(Kilowatts(-3d), Kilovars(-0.06d)), + result = ComplexPower(Kilowatts(-3d), Kilovars(-0.06d)), ) emAgent ! FlexCompletion( modelUuid = pvInput.getUuid @@ -549,7 +549,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(3d), Kilovars(0.06d)), + result = ComplexPower(Kilowatts(3d), Kilovars(0.06d)), ) emAgent ! FlexCompletion( modelUuid = evcsInput.getUuid // revoking tick 600 @@ -696,7 +696,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = pvInput.getUuid, - result = ApparentPower(Kilowatts(-5), Kilovars(-0.5)), + result = ComplexPower(Kilowatts(-5), Kilovars(-0.5)), ) emAgent ! FlexCompletion( modelUuid = pvInput.getUuid, @@ -712,7 +712,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(11), Kilovars(1.1)), + result = ComplexPower(Kilowatts(11), Kilovars(1.1)), ) emAgent ! FlexCompletion( modelUuid = evcsInput.getUuid, @@ -762,7 +762,7 @@ class EmAgentSpec emAgent ! FlexResult( modelUuid = evcsInput.getUuid, - result = ApparentPower(Kilowatts(5.0), Kilovars(0.5)), + result = ComplexPower(Kilowatts(5.0), Kilovars(0.5)), ) emAgent ! FlexCompletion( modelUuid = evcsInput.getUuid, diff --git a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala index 77bf5a1505..74d3c83d90 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala @@ -2020,7 +2020,7 @@ class EvcsAgentModelCalculationSpec val initStateData = ParticipantInitializeStateData[ EvcsInput, EvcsRuntimeConfig, - ApparentPower, + ComplexPower, ]( evcsInputModel, modelConfig = modelConfig, diff --git a/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala index 2d4a66da85..91a72ddd63 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala @@ -6,9 +6,9 @@ package edu.ie3.simona.model.participant +import edu.ie3.datamodel.models.input.OperatorInput import edu.ie3.datamodel.models.input.system.ChpInput import edu.ie3.datamodel.models.input.system.`type`.ChpTypeInput -import edu.ie3.datamodel.models.input.OperatorInput import edu.ie3.datamodel.models.input.system.characteristic.CosPhiFixed import edu.ie3.datamodel.models.input.thermal.{ CylindricalStorageInput, @@ -105,7 +105,7 @@ class ChpModelSpec "ChpModel", null, null, - Kilowatts(100), + Kilovoltamperes(100), 0.95, Kilowatts(50), thermalStorage, diff --git a/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala index 0c36be3e9c..ecb8afe884 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala @@ -15,7 +15,12 @@ import edu.ie3.simona.model.participant.control.QControl import edu.ie3.simona.test.common.UnitSpec import edu.ie3.simona.test.common.model.MockParticipant import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.{Kilovars, Megavars, ReactivePower} +import edu.ie3.util.scala.quantities.{ + Kilovars, + Kilovoltamperes, + Megavars, + ReactivePower, +} import org.scalatest.matchers.should.Matchers import squants._ import squants.energy._ @@ -52,7 +57,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { "System participant calculateQ Test", OperationInterval(0L, 86400L), QControl(new CosPhiFixed(varCharacteristicString)), - Kilowatts(200), + Kilovoltamperes(200), 1d, ) val power = Kilowatts(pVal) @@ -92,7 +97,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { QControl( new CosPhiP(varCharacteristicString) ), - Kilowatts(102), + Kilovoltamperes(102), 1d, ) val power = Kilowatts(pVal) @@ -130,7 +135,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { QControl( new CosPhiP(varCharacteristicString) ), - Kilowatts(101), + Kilovoltamperes(101), 1d, ) val power = Kilowatts(pVal) @@ -146,7 +151,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { "System participant calculateQ Test", OperationInterval(0L, 86400L), QControl(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Kilowatts(200), + Kilovoltamperes(200), 0.98, ) @@ -177,7 +182,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { "System participant calculateQ Test", OperationInterval(0L, 86400L), QControl(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Kilowatts(200), + Kilovoltamperes(200), 1d, ) @@ -208,7 +213,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { "System participant calculateQ Test", OperationInterval(0L, 86400L), QControl(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Kilowatts(200), + Kilovoltamperes(200), 0.95, ) @@ -240,7 +245,7 @@ class SystemParticipantSpec extends UnitSpec with Matchers { "System participant calculateQ Test", OperationInterval(0L, 86400L), QControl(new QV("qV:{(0.93,-1),(0.97,0),(1,0),(1.03,0),(1.07,1)}")), - Kilowatts(200), + Kilovoltamperes(200), 0.95, ) diff --git a/src/test/scala/edu/ie3/simona/test/common/model/MockParticipant.scala b/src/test/scala/edu/ie3/simona/test/common/model/MockParticipant.scala index ad407dbfb4..fdd518cb4b 100644 --- a/src/test/scala/edu/ie3/simona/test/common/model/MockParticipant.scala +++ b/src/test/scala/edu/ie3/simona/test/common/model/MockParticipant.scala @@ -16,6 +16,7 @@ import edu.ie3.simona.model.participant.{ } import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage import edu.ie3.util.scala.OperationInterval +import edu.ie3.util.scala.quantities.ApparentPower import squants.Dimensionless import squants.energy._ @@ -26,11 +27,11 @@ class MockParticipant( id: String, operationInterval: OperationInterval, qControl: QControl, - sRated: Power, + sRated: ApparentPower, cosPhiRated: Double, ) extends SystemParticipant[ CalcRelevantData, - Data.PrimaryData.ApparentPower, + Data.PrimaryData.ComplexPower, ModelState, ]( uuid, @@ -46,7 +47,7 @@ class MockParticipant( voltage: Dimensionless, state: ModelState, data: CalcRelevantData, - ): Data.PrimaryData.ApparentPower = { + ): Data.PrimaryData.ComplexPower = { super.calculateApparentPower(tick, voltage, state, data) } From 5851215c9dd27d68497271a1bc475646bf6d4367 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 7 Nov 2024 15:14:53 +0100 Subject: [PATCH 13/22] Improving code. --- .../simona/model/participant/BMModel.scala | 6 +- .../simona/model/participant/ChpModel.scala | 2 +- .../model/participant/FixedFeedInModel.scala | 4 +- .../simona/model/participant/HpModel.scala | 4 +- .../simona/model/participant/PvModel.scala | 6 +- .../model/participant/evcs/EvcsModel.scala | 6 +- .../load/random/RandomLoadModel.scala | 8 +- .../util/scala/quantities/ApparentPower.scala | 25 +- .../simona/model/participant/PvModelIT.groovy | 223 ------------------ .../model/participant/BMModelSpec.scala | 2 +- .../participant/FixedFeedInModelSpec.scala | 2 +- .../participant/SystemParticipantSpec.scala | 1 - .../participant/load/FixedLoadModelSpec.scala | 4 +- 13 files changed, 46 insertions(+), 247 deletions(-) delete mode 100644 src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy diff --git a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala index 7961758da9..1d849d9783 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala @@ -195,9 +195,9 @@ final case class BMModel( isCostControlled && avgOpex.value.doubleValue() < feedInTariff.value .doubleValue() ) - sRated.toPower(cosPhiRated) * (-1) + sRated.toPower(cosPhiRated) * -1 else - sRated.toPower(cosPhiRated) * usage * eff * (-1) + sRated.toPower(cosPhiRated) * usage * eff * -1 } /** Applies the load gradient to the electrical output @@ -217,7 +217,7 @@ final case class BMModel( pEl - lastPowerVal match { case pElDelta if pElDelta > pElDeltaMaxAbs => lastPowerVal + pElDeltaMaxAbs - case pElDelta if pElDelta < (pElDeltaMaxAbs * (-1)) => + case pElDelta if pElDelta < (pElDeltaMaxAbs * -1) => lastPowerVal - pElDeltaMaxAbs case _ => pEl diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 36a420806f..2a704adc43 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -393,7 +393,7 @@ object ChpModel { qControl, Kilovoltamperes( scaledInput.getType.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index ad76fbbddb..84a6531a02 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -71,7 +71,7 @@ final case class FixedFeedInModel( override def calculateActivePower( modelState: ConstantState.type, data: FixedRelevantData.type = FixedRelevantData, - ): Power = sRated.toPower(cosPhiRated) * (-1) + ): Power = sRated.toPower(cosPhiRated) * -1 override def determineFlexOptions( data: FixedRelevantData.type, @@ -116,7 +116,7 @@ object FixedFeedInModel extends LazyLogging { QControl.apply(scaledInput.getqCharacteristics), Kilovoltamperes( scaledInput.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index 94d2ae4bf9..8767e1f640 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -305,7 +305,7 @@ object HpModel { qControl, Kilovoltamperes( scaledInput.getType.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), @@ -408,7 +408,7 @@ object HpModel { qControl, Kilovoltamperes( scaledInput.getType.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala index 581afdeb65..f6103aa1c3 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala @@ -240,7 +240,7 @@ final case class PvModel private ( /** Calculates the sunrise hour angle omegaSR given omegaSS. */ private val calcSunriseAngleOmegaSR = - (omegaSS: Angle) => omegaSS * (-1) + (omegaSS: Angle) => omegaSS * -1 /** Calculates the solar altitude angle alphaS which represents the angle * between the horizontal and the line to the sun, that is, the complement of @@ -691,7 +691,7 @@ final case class PvModel private ( /* Calculate the foreseen active power output without boundary condition adaptions */ val proposal = - sRated.toPower(cosPhiRated) * (-1) * (actYield / irradiationSTC) + sRated.toPower(cosPhiRated) * -1 * (actYield / irradiationSTC) /* Do sanity check, if the proposed feed in is above the estimated maximum to be apparent active power of the plant */ if (proposal < pMax) @@ -771,7 +771,7 @@ object PvModel { QControl(scaledInput.getqCharacteristics), Kilovoltamperes( scaledInput.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue ), diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index eed22dbabe..e39e6b0345 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -753,7 +753,7 @@ final case class EvcsModel( if (setPower > zeroKW) maxPower else - maxPower * (-1) + maxPower * -1 val chargingTicks = calcFlexOptionsChange(ev, power) val endTick = Math.min(currentTick + chargingTicks, ev.departureTick) @@ -822,7 +822,7 @@ final case class EvcsModel( (targetEnergy - ev.storedEnergy) / power } else - (ev.storedEnergy - (ev.eStorage * lowestEvSoc)) / (power * (-1)) + (ev.storedEnergy - (ev.eStorage * lowestEvSoc)) / (power * -1) Math.round(timeUntilFullOrEmpty.toSeconds) } @@ -1070,7 +1070,7 @@ object EvcsModel { simulationStartDate, QControl(scaledInput.getqCharacteristics), Kilovoltamperes( - scaledInput.getType.getsRated.to(KILOWATT).getValue.doubleValue + scaledInput.getType.getsRated.to(KILOVOLTAMPERE).getValue.doubleValue ), scaledInput.getType.getElectricCurrentType, scaledInput.getCosPhiRated, diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index 8596662ed9..c10c8ace44 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -102,7 +102,7 @@ final case class RandomLoadModel( case ActivePower(activePower) => /* scale the reference active power based on the random profiles averagePower/maxPower ratio */ val referenceScalingFactor = - profilePower / RandomLoadModel.randomMaxPower.toPower( + profilePower / RandomLoadModel.randomMaxApparentPower.toPower( 1.0 ) // only active power => cosPhi = 1.0 activePower * referenceScalingFactor @@ -171,9 +171,9 @@ object RandomLoadModel { * active power. * * @return - * Reference power to use for later model calculations + * Reference apparent power to use for later model calculations */ - private val randomMaxPower: ApparentPower = Voltamperes(159d) + private val randomMaxApparentPower: ApparentPower = Voltamperes(159d) def apply( input: LoadInput, @@ -193,7 +193,7 @@ object RandomLoadModel { LoadModel.scaleSRatedEnergy( scaledInput, energyConsumption, - randomMaxPower, + randomMaxApparentPower, randomProfileEnergyScaling, 1.1, ) diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala index a436727075..eeec8fd219 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala @@ -13,6 +13,13 @@ import squants.time.Time import scala.math.{acos, sin} import scala.util.Try +/** Class that represents an apparent power. An apparent power is the absolute + * value of the complex power (|S|). + * @param value + * power value + * @param unit + * of the power + */ final class ApparentPower private ( val value: Double, val unit: ApparentPowerUnit, @@ -26,10 +33,26 @@ final class ApparentPower private ( def toMegavoltamperes: Double = to(Megavoltamperes) def toGigavoltamperes: Double = to(Gigavoltamperes) + /** Method to convert this apparent power into a [[Power]] using a given + * cosPhi. + * @param cosPhi + * cosine of the corresponding angle + * @return + * the resulting active power + */ def toPower(cosPhi: Double): Power = Watts(toVoltamperes * cosPhi) - def toReactivePower(cosPhi: Double): ReactivePower = + /** Method to convert this apparent power into a [[ReactivePower]] using a + * given cosPhi. + * @param cosPhi + * cosine of the corresponding angle + * @return + * the resulting reactive power + */ + def toReactivePower(cosPhi: Double): ReactivePower = { + // Q = |S| * sin(φ), φ = acos(cosPhi) Vars(toVoltamperes * sin(acos(cosPhi))) + } } object ApparentPower extends Dimension[ApparentPower] { diff --git a/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy b/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy deleted file mode 100644 index 4219b301e2..0000000000 --- a/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy +++ /dev/null @@ -1,223 +0,0 @@ -/* - * © 2020. TU Dortmund University, - * Institute of Energy Systems, Energy Efficiency and Energy Economics, - * Research group Distribution grid planning and operation - */ - -package edu.ie3.simona.model.participant - -import static java.util.Locale.US -import static java.util.Locale.setDefault - -import edu.ie3.datamodel.io.source.csv.CsvJointGridContainerSource -import edu.ie3.datamodel.models.input.system.PvInput -import edu.ie3.simona.ontology.messages.services.WeatherMessage -import edu.ie3.util.TimeUtil -import edu.ie3.util.scala.quantities.Sq -import edu.ie3.util.scala.quantities.WattsPerSquareMeter$ -import org.apache.commons.csv.CSVFormat -import org.apache.commons.csv.CSVRecord -import spock.lang.Shared -import spock.lang.Specification -import squants.Dimensionless -import squants.Each$ -import squants.energy.Megawatts$ -import squants.energy.Power -import squants.motion.MetersPerSecond$ -import squants.thermal.Kelvin$ - -import java.nio.file.Path -import java.time.ZonedDateTime -import java.util.zip.GZIPInputStream - -/** - * A simple integration test that uses pre-calculated data to check if the pv model works as expected. - * It uses 8 pv models located in GER. - * - */ -class PvModelIT extends Specification implements PvModelITHelper { - - @Shared - Map pvModels - - @Shared - Map> weatherMap - - @Shared - Map> resultsMap - - - def setupSpec() { - // input weather data values are in us format - // if locale is not set hard coded to US, quantity parsing will return invalid values - setDefault(US) - - pvModels = createPvModels() - weatherMap = weatherData - resultsMap = resultsData - } - - def "8 pv panels full year test"() { - - given: "an empty array to collect the results" - ArrayList testRes = new ArrayList<>() - - when: "we calculate the photovoltaic in-feed for each unit for the whole year" - List modelIds = new ArrayList<>(pvModels.keySet()) - // sort models: east, south, west - Collections.sort(modelIds) - final int modelCount = modelIds.size() - - // sort, in case dates & times have not been sorted before - List keyList = new ArrayList<>(weatherMap.keySet()) - Collections.sort(keyList) - - for (ZonedDateTime dateTime : keyList) { - - Map modelToWeatherMap = weatherMap.get(dateTime) - - String[] row = new String[2*modelCount+1] - row[0] = dateTime.toString() - - int modelI = 0 - for (String modelId : modelIds) { - PvModel model = pvModels.get(modelId) - - "build the needed data" - WeatherMessage.WeatherData weather = modelToWeatherMap.get(modelId) - PvModel.PvRelevantData neededData = new PvModel.PvRelevantData( - dateTime, - 3600L, - weather.diffIrr(), - weather.dirIrr() - ) - Dimensionless voltage = Sq.create(1.414213562d, Each$.MODULE$) - - "collect the results and calculate the difference between the provided results and the calculated ones" - double calc = model.calculatePower(0L, voltage, ModelState.ConstantState$.MODULE$, neededData).p().toMegawatts() - double sol = resultsMap.get(dateTime).get(modelId).toMegawatts() - - testRes.add(Math.abs(calc - sol)) - - row[1 + modelI] = calc.toString() - row[1 + modelCount + modelI] = sol.toString() - - modelI++ - } - } - - then: "we expect the calculated result to be quasi equal the provided results data" - testRes.every { - (it < 0.00000000000001) // floating point operation - } - } -} - -trait PvModelITHelper { - private static final CSV_FORMAT = CSVFormat.DEFAULT.builder().setHeader().build() - - Iterable getCsvRecords(String fileName) { - def resultsInputData = new File(this.getClass().getResource(fileName).file) - def fileStream = new FileInputStream(resultsInputData) - def gzipStream = new GZIPInputStream(fileStream) - def decoder = new InputStreamReader(gzipStream, "UTF-8") - def br = new BufferedReader(decoder) - return CSV_FORMAT.parse(br) - } - - Map createPvModels() { - "load the grid input data from the corresponding resources folder" - - def csvGridSource = CsvJointGridContainerSource.read("it_grid", ";", - Path.of(this.getClass().getResource("_pv/it/grid_data").toURI()), false) - - def simulationStartDate = TimeUtil.withDefaults.toZonedDateTime("2011-01-01T00:00:00Z") - def simulationEndDate = TimeUtil.withDefaults.toZonedDateTime("2012-01-01T00:00:00Z") - - Map pvModels = new HashMap<>() - for (PvInput inputModel : csvGridSource.systemParticipants.pvPlants) { - PvModel model = PvModel.apply( - inputModel, - 1d, - simulationStartDate, - simulationEndDate - ) - - pvModels.put(inputModel.getId(), model) - } - - return pvModels - } - - Map> getWeatherData() { - "read the weather data from the provided weather data file" - final String fileName = "_pv/it/weather.tar.gz" - final def csvRecords = getCsvRecords(fileName) - - Map> weatherMap = new HashMap<>() - for (row in csvRecords) { - ZonedDateTime time = TimeUtil.withDefaults.toZonedDateTime(row.get(0)) - Map modelToWeatherMap - if (weatherMap.containsKey(time)) { - modelToWeatherMap = weatherMap.get(time) - } - - if (modelToWeatherMap == null) { - modelToWeatherMap = new HashMap() - weatherMap.put(time, modelToWeatherMap) - } - - String modelId = row.get(1) - - double temp = 0 - double windVel = 0 - - WeatherMessage.WeatherData weather = new WeatherMessage.WeatherData( - Sq.create(row.get(22).replace("Wh/m²", "").toDouble(), WattsPerSquareMeter$.MODULE$), - Sq.create(row.get(21).replace("Wh/m²", "").toDouble(), WattsPerSquareMeter$.MODULE$), - Sq.create(temp, Kelvin$.MODULE$), - Sq.create(windVel, MetersPerSecond$.MODULE$)) - - modelToWeatherMap.put(modelId, weather) - } - - return weatherMap - } - - Map> getResultsData() { - "read the results data from the provided file" - final String fileName = "_pv/it/results2.tar.gz" - def csvRecords = getCsvRecords(fileName) - - // we skip the first line and use hardcoded headers, because the first line is garbled - String[] headers = [ - "Datetime", - "pv_east_1", - "pv_east_2", - "pv_south_1", - "pv_south_2", - "pv_south_3", - "pv_south_4", - "pv_west_1", - "pv_west_2" - ] - - Map> resultsMap = new HashMap<>() - for(row in csvRecords) { - // last line is trash - if (row.get(0).startsWith('\u0000')) - break - - ZonedDateTime time = TimeUtil.withDefaults.toZonedDateTime(row.get(0)) - Map modelToPowerMap = new HashMap<>() - for (int i = 1; i < headers.length; i++) { - String modelId = headers[i] - String rawValue = row[i] - Power power = Sq.create(Double.parseDouble(rawValue), Megawatts$.MODULE$) - modelToPowerMap.put(modelId, power) - } - resultsMap.put(time, modelToPowerMap) - } - return resultsMap - } -} \ No newline at end of file diff --git a/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala index 6320271e9a..9aa118c0b3 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/BMModelSpec.scala @@ -174,7 +174,7 @@ class BMModelSpec extends UnitSpec { ) val pElCalc = bmModel.calculateElOutput(usage, eff) - pElCalc.value should be(Kilovoltamperes(pElSol).toVoltamperes +- 1e-4) + pElCalc should approximate(Kilowatts(pElSol)) } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala index 763fb4b677..c787f6ce0d 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala @@ -94,7 +94,7 @@ class FixedFeedInModelSpec Kilovoltamperes( fixedFeedInput .getsRated() - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue() ), diff --git a/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala index ecb8afe884..02036d6a62 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/SystemParticipantSpec.scala @@ -141,7 +141,6 @@ class SystemParticipantSpec extends UnitSpec with Matchers { val power = Kilowatts(pVal) val qCalc = loadMock.calculateReactivePower(power, adjustedVoltage) qCalc should approximate(qSol) - } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala index eb86f9a4aa..6a75bd93e5 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/FixedLoadModelSpec.scala @@ -53,7 +53,7 @@ class FixedLoadModelSpec QControl.apply(loadInput.getqCharacteristics), Kilovoltamperes( loadInput.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue() ), @@ -87,7 +87,7 @@ class FixedLoadModelSpec QControl.apply(loadInput.getqCharacteristics), Kilovoltamperes( loadInput.getsRated - .to(PowerSystemUnits.KILOWATT) + .to(PowerSystemUnits.KILOVOLTAMPERE) .getValue .doubleValue() ), From 52af7a91e9833e8472f9ae557f87090fd3efa511 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Thu, 7 Nov 2024 15:18:24 +0100 Subject: [PATCH 14/22] Updating `CHANGELOG`. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac4517ba8c..2b8f062475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added option to directly zip the output files [#793](https://github.com/ie3-institute/simona/issues/793) - Added weatherData HowTo for Copernicus ERA5 data [#967](https://github.com/ie3-institute/simona/issues/967) - Add some quote to 'printGoodbye' [#997](https://github.com/ie3-institute/simona/issues/997) +- Added `ApparentPower` to differentiate between different power types [#794](https://github.com/ie3-institute/simona/issues/794) ### Changed - Adapted to changed data source in PSDM [#435](https://github.com/ie3-institute/simona/issues/435) @@ -94,7 +95,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Replace mutable var in ChpModelSpec [#1002](https://github.com/ie3-institute/simona/issues/1002) - Move compression of output files into `ResultEventListener`[#965](https://github.com/ie3-institute/simona/issues/965) - Rewrote StorageModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - + ### Fixed - Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658) - Removed version number "2.0" from the logo printed to console [#642](https://github.com/ie3-institute/simona/issues/642) From 423a7d3f66a5ffb833b4b93e241aa618d53c62cc Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Fri, 8 Nov 2024 09:54:20 +0100 Subject: [PATCH 15/22] Addressing some change requests. --- .../participant/statedata/BaseStateData.scala | 2 +- .../participant/evcs/EvModelWrapper.scala | 2 +- .../model/participant/evcs/EvcsModel.scala | 2 +- .../model/participant/load/LoadModel.scala | 6 +- .../load/profile/LoadProfileStore.scala | 7 +- .../load/profile/ProfileLoadModel.scala | 5 +- .../load/random/RandomLoadModel.scala | 8 +- .../simona/model/participant/PvModelIT.groovy | 223 ++++++++++++++++++ .../EvcsAgentModelCalculationSpec.scala | 4 +- .../participant/FixedFeedInModelSpec.scala | 3 +- .../participant/evcs/EvcsModelSpec.scala | 2 +- .../load/LoadProfileStoreSpec.scala | 2 +- 12 files changed, 245 insertions(+), 21 deletions(-) create mode 100644 src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy diff --git a/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala b/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala index e1a8285cf8..192d30b3cd 100644 --- a/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala +++ b/src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala @@ -69,7 +69,7 @@ trait BaseStateData[+PD <: PrimaryDataWithApparentPower[PD]] /** A store, holding information of the lastly requested and provided results. * The request from the grid always targets at - * [[edu.ie3.simona.agent.participant.data.Data.PrimaryData.ApparentPower]], + * [[edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower]], * but for the sake of traceability, the whole averaged result ist stored */ val requestValueStore: ValueStore[PD] diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala index b5d0d7ec94..457b0fe348 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala @@ -37,7 +37,7 @@ final case class EvModelWrapper( Kilovoltamperes( original.getSRatedAC.to(KILOVOLTAMPERE).getValue.doubleValue ) - lazy val sRatedDc: squants.Power = + lazy val pRatedDc: squants.Power = Kilowatts(original.getSRatedDC.to(KILOWATT).getValue.doubleValue) lazy val eStorage: squants.Energy = KilowattHours( original.getEStorage.to(KILOWATTHOUR).getValue.doubleValue diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index e39e6b0345..38d0d3e1b4 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -505,7 +505,7 @@ final case class EvcsModel( case ElectricCurrentType.AC => ev.sRatedAc.toPower(1.0) case ElectricCurrentType.DC => - ev.sRatedDc + ev.pRatedDc } /* Limit the charging power to the minimum of ev's and evcs' permissible power */ evPower.min(sRated.toPower(1.0)) diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala index 78378893a5..bbb7f19063 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala @@ -129,13 +129,15 @@ object LoadModel extends LazyLogging { def scaleSRatedEnergy( inputModel: LoadInput, energyConsumption: Energy, - profileMaxPower: ApparentPower, + profileMaxPower: Power, profileEnergyScaling: Energy, safetyFactor: Double = 1d, ): ApparentPower = { - (profileMaxPower / inputModel.getCosPhiRated) * ( + val power = (profileMaxPower / inputModel.getCosPhiRated) * ( energyConsumption / profileEnergyScaling ) * safetyFactor + + Kilovoltamperes(power.toKilowatts) } } diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala index 93b08ba62a..659efb5749 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala @@ -19,6 +19,7 @@ import edu.ie3.simona.model.participant.load.profile.LoadProfileStore.{ import edu.ie3.simona.model.participant.load.{DayType, profile} import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import org.apache.commons.csv.CSVFormat +import squants.Power import squants.energy.{KilowattHours, Watts} import java.io.{InputStreamReader, Reader} @@ -85,14 +86,14 @@ class LoadProfileStore private (val reader: Reader) { * @param loadProfile * the consumer type * @return - * the maximum load in VA + * the maximum load in W */ def maxPower( loadProfile: StandardLoadProfile - ): ApparentPower = { + ): Power = { maxParamMap.get(loadProfile) match { case Some(value) => - Voltamperes(value) + Watts(value) case None => throw new RuntimeException( "Max value for ConsumerType " + loadProfile.toString + " not found" diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala index 9c030d2b10..b2594a6b02 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/ProfileLoadModel.scala @@ -92,10 +92,7 @@ final case class ProfileLoadModel( reference match { case ActivePower(activePower) => /* scale the reference active power based on the profiles averagePower/maxPower ratio */ - val referenceScalingFactor = - averagePower / profileMaxPower.toPower( - 1.0 - ) // only active power => cosPhi = 1.0 + val referenceScalingFactor = averagePower / profileMaxPower activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles average power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index c10c8ace44..3ad619d7bb 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -102,9 +102,7 @@ final case class RandomLoadModel( case ActivePower(activePower) => /* scale the reference active power based on the random profiles averagePower/maxPower ratio */ val referenceScalingFactor = - profilePower / RandomLoadModel.randomMaxApparentPower.toPower( - 1.0 - ) // only active power => cosPhi = 1.0 + profilePower / RandomLoadModel.randomMaxPower activePower * referenceScalingFactor case _: EnergyConsumption => /* scale the profiles random power based on the energyConsumption/profileEnergyScaling(=1000kWh/year) ratio */ @@ -173,7 +171,7 @@ object RandomLoadModel { * @return * Reference apparent power to use for later model calculations */ - private val randomMaxApparentPower: ApparentPower = Voltamperes(159d) + private val randomMaxPower: Power = Watts(159d) def apply( input: LoadInput, @@ -193,7 +191,7 @@ object RandomLoadModel { LoadModel.scaleSRatedEnergy( scaledInput, energyConsumption, - randomMaxApparentPower, + randomMaxPower, randomProfileEnergyScaling, 1.1, ) diff --git a/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy b/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy new file mode 100644 index 0000000000..00caef8dee --- /dev/null +++ b/src/test/groovy/edu/ie3/simona/model/participant/PvModelIT.groovy @@ -0,0 +1,223 @@ +/* + * © 2020. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.simona.model.participant + +import edu.ie3.datamodel.io.source.csv.CsvJointGridContainerSource +import edu.ie3.datamodel.models.input.system.PvInput +import edu.ie3.simona.ontology.messages.services.WeatherMessage +import edu.ie3.util.TimeUtil +import edu.ie3.util.scala.quantities.Sq +import edu.ie3.util.scala.quantities.WattsPerSquareMeter$ +import org.apache.commons.csv.CSVFormat +import org.apache.commons.csv.CSVRecord +import spock.lang.Shared +import spock.lang.Specification +import squants.Dimensionless +import squants.Each$ +import squants.energy.Megawatts$ +import squants.energy.Power +import squants.motion.MetersPerSecond$ +import squants.thermal.Kelvin$ + +import java.nio.file.Path +import java.time.ZonedDateTime +import java.util.zip.GZIPInputStream + +import static java.util.Locale.US +import static java.util.Locale.setDefault + +/** + * A simple integration test that uses pre-calculated data to check if the pv model works as expected. + * It uses 8 pv models located in GER. + * + */ +class PvModelIT extends Specification implements PvModelITHelper { + + @Shared + Map pvModels + + @Shared + Map> weatherMap + + @Shared + Map> resultsMap + + + def setupSpec() { + // input weather data values are in us format + // if locale is not set hard coded to US, quantity parsing will return invalid values + setDefault(US) + + pvModels = createPvModels() + weatherMap = weatherData + resultsMap = resultsData + } + + def "8 pv panels full year test"() { + + given: "an empty array to collect the results" + ArrayList testRes = new ArrayList<>() + + when: "we calculate the photovoltaic in-feed for each unit for the whole year" + List modelIds = new ArrayList<>(pvModels.keySet()) + // sort models: east, south, west + Collections.sort(modelIds) + final int modelCount = modelIds.size() + + // sort, in case dates & times have not been sorted before + List keyList = new ArrayList<>(weatherMap.keySet()) + Collections.sort(keyList) + + for (ZonedDateTime dateTime : keyList) { + + Map modelToWeatherMap = weatherMap.get(dateTime) + + String[] row = new String[2*modelCount+1] + row[0] = dateTime.toString() + + int modelI = 0 + for (String modelId : modelIds) { + PvModel model = pvModels.get(modelId) + + "build the needed data" + WeatherMessage.WeatherData weather = modelToWeatherMap.get(modelId) + PvModel.PvRelevantData neededData = new PvModel.PvRelevantData( + dateTime, + 3600L, + weather.diffIrr(), + weather.dirIrr() + ) + Dimensionless voltage = Sq.create(1.414213562d, Each$.MODULE$) + + "collect the results and calculate the difference between the provided results and the calculated ones" + double calc = model.calculatePower(0L, voltage, ModelState.ConstantState$.MODULE$, neededData).p().toMegawatts() + double sol = resultsMap.get(dateTime).get(modelId).toMegawatts() + + testRes.add(Math.abs(calc - sol)) + + row[1 + modelI] = calc.toString() + row[1 + modelCount + modelI] = sol.toString() + + modelI++ + } + } + + then: "we expect the calculated result to be quasi equal the provided results data" + testRes.every { + (it < 0.00000000000001) // floating point operation + } + } +} + +trait PvModelITHelper { + private static final CSV_FORMAT = CSVFormat.DEFAULT.builder().setHeader().build() + + Iterable getCsvRecords(String fileName) { + def resultsInputData = new File(this.getClass().getResource(fileName).file) + def fileStream = new FileInputStream(resultsInputData) + def gzipStream = new GZIPInputStream(fileStream) + def decoder = new InputStreamReader(gzipStream, "UTF-8") + def br = new BufferedReader(decoder) + return CSV_FORMAT.parse(br) + } + + Map createPvModels() { + "load the grid input data from the corresponding resources folder" + + def csvGridSource = CsvJointGridContainerSource.read("it_grid", ";", + Path.of(this.getClass().getResource("_pv/it/grid_data").toURI()), false) + + def simulationStartDate = TimeUtil.withDefaults.toZonedDateTime("2011-01-01T00:00:00Z") + def simulationEndDate = TimeUtil.withDefaults.toZonedDateTime("2012-01-01T00:00:00Z") + + Map pvModels = new HashMap<>() + for (PvInput inputModel : csvGridSource.systemParticipants.pvPlants) { + PvModel model = PvModel.apply( + inputModel, + 1d, + simulationStartDate, + simulationEndDate + ) + + pvModels.put(inputModel.getId(), model) + } + + return pvModels + } + + Map> getWeatherData() { + "read the weather data from the provided weather data file" + final String fileName = "_pv/it/weather.tar.gz" + final def csvRecords = getCsvRecords(fileName) + + Map> weatherMap = new HashMap<>() + for (row in csvRecords) { + ZonedDateTime time = TimeUtil.withDefaults.toZonedDateTime(row.get(0)) + Map modelToWeatherMap + if (weatherMap.containsKey(time)) { + modelToWeatherMap = weatherMap.get(time) + } + + if (modelToWeatherMap == null) { + modelToWeatherMap = new HashMap() + weatherMap.put(time, modelToWeatherMap) + } + + String modelId = row.get(1) + + double temp = 0 + double windVel = 0 + + WeatherMessage.WeatherData weather = new WeatherMessage.WeatherData( + Sq.create(row.get(22).replace("Wh/m²", "").toDouble(), WattsPerSquareMeter$.MODULE$), + Sq.create(row.get(21).replace("Wh/m²", "").toDouble(), WattsPerSquareMeter$.MODULE$), + Sq.create(temp, Kelvin$.MODULE$), + Sq.create(windVel, MetersPerSecond$.MODULE$)) + + modelToWeatherMap.put(modelId, weather) + } + + return weatherMap + } + + Map> getResultsData() { + "read the results data from the provided file" + final String fileName = "_pv/it/results2.tar.gz" + def csvRecords = getCsvRecords(fileName) + + // we skip the first line and use hardcoded headers, because the first line is garbled + String[] headers = [ + "Datetime", + "pv_east_1", + "pv_east_2", + "pv_south_1", + "pv_south_2", + "pv_south_3", + "pv_south_4", + "pv_west_1", + "pv_west_2" + ] + + Map> resultsMap = new HashMap<>() + for(row in csvRecords) { + // last line is trash + if (row.get(0).startsWith('\u0000')) + break + + ZonedDateTime time = TimeUtil.withDefaults.toZonedDateTime(row.get(0)) + Map modelToPowerMap = new HashMap<>() + for (int i = 1; i < headers.length; i++) { + String modelId = headers[i] + String rawValue = row[i] + Power power = Sq.create(Double.parseDouble(rawValue), Megawatts$.MODULE$) + modelToPowerMap.put(modelId, power) + } + resultsMap.put(time, modelToPowerMap) + } + return resultsMap + } +} \ No newline at end of file diff --git a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala index 74d3c83d90..aa61fd4dd1 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala @@ -1609,9 +1609,11 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid refPower shouldBe combinedChargingPowerSq + + // battery of earlier ev is above lowest soc now minPower shouldBe ev4500.sRatedAc.toPower( 1.0 - ) * -1 // battery of earlier ev is above lowest soc now + ) * -1 maxPower shouldBe combinedChargingPowerSq } diff --git a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala index c787f6ce0d..be5dc6ac69 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/FixedFeedInModelSpec.scala @@ -30,9 +30,10 @@ class FixedFeedInModelSpec with DefaultTestData with PrivateMethodTester { + // Equals to 1 VA power private implicit val powerTolerance: ApparentPower = Voltamperes( 1.0 - ) // Equals to 1 W power + ) "The fixed feed in model object" should { diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala index bb92b5b914..ede77ceda1 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala @@ -189,7 +189,7 @@ class EvcsModelSpec actualEv.uuid shouldBe ev.uuid actualEv.id shouldBe ev.id actualEv.sRatedAc shouldBe ev.sRatedAc - actualEv.sRatedDc shouldBe ev.sRatedDc + actualEv.pRatedDc shouldBe ev.pRatedDc actualEv.eStorage shouldBe ev.eStorage actualEv.storedEnergy should approximate( KilowattHours(expectedStored) diff --git a/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala index f8c6fddc74..2a6ed9a6bb 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/load/LoadProfileStoreSpec.scala @@ -92,7 +92,7 @@ class LoadProfileStoreSpec forAll(maxParams) { (loadProfile: StandardLoadProfile, maxParamValue: Double) => - val maxParam = Voltamperes(maxParamValue) + val maxParam = Watts(maxParamValue) customStore.maxPower(loadProfile) shouldBe maxParam } From 43c2786298bcfcf04523143d5bd7fca8d11b6e14 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Fri, 8 Nov 2024 14:10:42 +0100 Subject: [PATCH 16/22] Renaming `sRatedAc` in `EvModelWrapper` into `pRatedAc`. --- .../participant/evcs/EvModelWrapper.scala | 8 +++--- .../model/participant/evcs/EvcsModel.scala | 4 +-- .../EvcsAgentModelCalculationSpec.scala | 28 ++++++++----------- .../participant/evcs/EvcsModelSpec.scala | 4 +-- .../MaximumPowerChargingSpec.scala | 2 +- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala index 457b0fe348..3c9f1077c6 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala @@ -9,7 +9,7 @@ package edu.ie3.simona.model.participant.evcs import edu.ie3.simona.api.data.ev.model.EvModel import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble -import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} +import squants.Power import squants.energy.{KilowattHours, Kilowatts} import java.util.UUID @@ -33,9 +33,9 @@ final case class EvModelWrapper( def uuid: UUID = original.getUuid def id: String = original.getId - lazy val sRatedAc: ApparentPower = - Kilovoltamperes( - original.getSRatedAC.to(KILOVOLTAMPERE).getValue.doubleValue + lazy val pRatedAc: Power = + Kilowatts( + original.getSRatedAC.to(KILOWATT).getValue.doubleValue ) lazy val pRatedDc: squants.Power = Kilowatts(original.getSRatedDC.to(KILOWATT).getValue.doubleValue) diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index 38d0d3e1b4..b27749046d 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -32,8 +32,6 @@ import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble import edu.ie3.util.scala.OperationInterval import edu.ie3.util.scala.quantities.DefaultQuantities._ -import squants.energy.Kilowatts -import edu.ie3.util.scala.quantities.DefaultQuantities._ import edu.ie3.util.scala.quantities.{ApparentPower, Kilovoltamperes} import squants.energy.Kilowatts import squants.time.Seconds @@ -503,7 +501,7 @@ final case class EvcsModel( ): Power = { val evPower = currentType match { case ElectricCurrentType.AC => - ev.sRatedAc.toPower(1.0) + ev.pRatedAc case ElectricCurrentType.DC => ev.pRatedDc } diff --git a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala index aa61fd4dd1..4d3c444156 100644 --- a/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala +++ b/src/test/scala/edu/ie3/simona/agent/participant/EvcsAgentModelCalculationSpec.scala @@ -1355,9 +1355,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev900.sRatedAc.toPower(1.0) - minPower shouldBe ev900.sRatedAc.toPower(1.0) // battery is empty - maxPower shouldBe ev900.sRatedAc.toPower(1.0) + referencePower shouldBe ev900.pRatedAc + minPower shouldBe ev900.pRatedAc // battery is empty + maxPower shouldBe ev900.pRatedAc } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1472,9 +1472,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower(1.0) - minPower shouldBe ev900.sRatedAc.toPower(1.0) // battery is empty - maxPower shouldBe ev4500.sRatedAc.toPower(1.0) + referencePower shouldBe ev4500.pRatedAc + minPower shouldBe ev900.pRatedAc // battery is empty + maxPower shouldBe ev4500.pRatedAc } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1522,9 +1522,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower(1.0) + referencePower shouldBe ev4500.pRatedAc minPower shouldBe Kilowatts(0.0) // battery is exactly at margin - maxPower shouldBe ev4500.sRatedAc.toPower(1.0) + maxPower shouldBe ev4500.pRatedAc } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => @@ -1611,9 +1611,7 @@ class EvcsAgentModelCalculationSpec refPower shouldBe combinedChargingPowerSq // battery of earlier ev is above lowest soc now - minPower shouldBe ev4500.sRatedAc.toPower( - 1.0 - ) * -1 + minPower shouldBe ev4500.pRatedAc * -1 maxPower shouldBe combinedChargingPowerSq } @@ -1763,9 +1761,7 @@ class EvcsAgentModelCalculationSpec ) => modelUuid shouldBe evcsInputModelQv.getUuid referencePower shouldBe combinedChargingPowerSq - minPower shouldBe ev4500.sRatedAc.toPower( - 1.0 - ) * -1 // battery of ev11700 is below lowest soc now + minPower shouldBe ev4500.pRatedAc * -1 // battery of ev11700 is below lowest soc now maxPower shouldBe combinedChargingPowerSq } @@ -1961,9 +1957,9 @@ class EvcsAgentModelCalculationSpec maxPower, ) => modelUuid shouldBe evcsInputModelQv.getUuid - referencePower shouldBe ev4500.sRatedAc.toPower(1.0) + referencePower shouldBe ev4500.pRatedAc minPower shouldBe Kilowatts(0d) - maxPower shouldBe ev4500.sRatedAc.toPower(1.0) + maxPower shouldBe ev4500.pRatedAc } resultListener.expectMsgPF() { case FlexOptionsResultEvent(flexResult) => diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala index ede77ceda1..67d757c55e 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/EvcsModelSpec.scala @@ -188,7 +188,7 @@ class EvcsModelSpec actualEv.uuid shouldBe ev.uuid actualEv.id shouldBe ev.id - actualEv.sRatedAc shouldBe ev.sRatedAc + actualEv.pRatedAc shouldBe ev.pRatedAc actualEv.pRatedDc shouldBe ev.pRatedDc actualEv.eStorage shouldBe ev.eStorage actualEv.storedEnergy should approximate( @@ -812,7 +812,7 @@ class EvcsModelSpec modelUuid shouldBe evcsModel.getUuid refPower should approximate(Kilowatts(5.0)) // one hour left minPower should approximate(Kilowatts(0d)) // no v2g allowed! - maxPower should approximate(ev1.sRatedAc.toPower(1.0)) + maxPower should approximate(ev1.pRatedAc) } } diff --git a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala index 0ad7182c2d..39f9a52564 100644 --- a/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/participant/evcs/uncontrolled/MaximumPowerChargingSpec.scala @@ -85,7 +85,7 @@ class MaximumPowerChargingSpec ScheduleEntry( offset, offset + expectedDuration, - ev.sRatedAc.toPower(1.0), + ev.pRatedAc, ) ) ) From 835582369b958a5db96f1fad3acebc69777a1f52 Mon Sep 17 00:00:00 2001 From: Sebastian Peter Date: Mon, 18 Nov 2024 21:14:11 +0100 Subject: [PATCH 17/22] Refactoring ResultFileHierarchy Signed-off-by: Sebastian Peter --- .../event/listener/ResultEventListener.scala | 2 +- .../logback/LogbackConfiguration.scala | 10 +- .../scala/edu/ie3/simona/main/RunSimona.scala | 4 +- .../ie3/simona/sim/setup/SetupHelper.scala | 9 +- .../ie3/simona/sim/setup/SimonaSetup.scala | 4 +- .../sim/setup/SimonaStandaloneSetup.scala | 3 +- .../ie3/simona/util/ResultFileHierarchy.scala | 283 +++++++++--------- .../listener/ResultEventListenerSpec.scala | 85 +++--- .../integration/RunSimonaStandaloneIT.scala | 12 +- .../io/file/ResultFileHierarchySpec.scala | 64 +--- .../edu/ie3/simona/sim/SimonaSimSpec.scala | 3 +- .../simona/sim/setup/SimonaSetupSpec.scala | 3 +- 12 files changed, 230 insertions(+), 252 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/event/listener/ResultEventListener.scala b/src/main/scala/edu/ie3/simona/event/listener/ResultEventListener.scala index 8e7dd12abd..d9c910ef1a 100644 --- a/src/main/scala/edu/ie3/simona/event/listener/ResultEventListener.scala +++ b/src/main/scala/edu/ie3/simona/event/listener/ResultEventListener.scala @@ -88,7 +88,7 @@ object ResultEventListener extends Transformer3wResultSupport { filePathFuture.map { fileName => val finalFileName = - fileName match { + fileName.toString match { case name if name.endsWith(".csv.gz") && enableCompression => name.replace(".gz", "") case name if name.endsWith(".csv") => name diff --git a/src/main/scala/edu/ie3/simona/logging/logback/LogbackConfiguration.scala b/src/main/scala/edu/ie3/simona/logging/logback/LogbackConfiguration.scala index 3d236a1f41..9f95df1c2c 100644 --- a/src/main/scala/edu/ie3/simona/logging/logback/LogbackConfiguration.scala +++ b/src/main/scala/edu/ie3/simona/logging/logback/LogbackConfiguration.scala @@ -16,16 +16,16 @@ import ch.qos.logback.core.filter.Filter import com.typesafe.scalalogging.LazyLogging import org.slf4j.LoggerFactory -import java.io.File +import java.nio.file.Path import scala.jdk.CollectionConverters._ object LogbackConfiguration extends LazyLogging { - def default(logPath: String): Unit = { + def default(logPath: Path): Unit = { LoggerFactory.getILoggerFactory match { case loggerContext: LoggerContext => val rootLogger = loggerContext.getLogger("root") - val log = logPath.concat(File.separator).concat("simona.log") + val log = logPath.resolve("simona.log") // stop all appenders rootLogger.iteratorForAppenders().asScala.foreach(_.stop()) /* Identify the filters of existing rolling file appender */ @@ -58,7 +58,7 @@ object LogbackConfiguration extends LazyLogging { } private def fileAppender( - logPath: String, + logPath: Path, appenderName: String, maybeFilterList: Option[Seq[Filter[ILoggingEvent]]], loggerContext: LoggerContext, @@ -70,7 +70,7 @@ object LogbackConfiguration extends LazyLogging { layoutEncoder.start() val fileAppender = new FileAppender[ILoggingEvent] - fileAppender.setFile(logPath) + fileAppender.setFile(logPath.toString) fileAppender.setEncoder(layoutEncoder) fileAppender.setContext(loggerContext) fileAppender.setName(appenderName) diff --git a/src/main/scala/edu/ie3/simona/main/RunSimona.scala b/src/main/scala/edu/ie3/simona/main/RunSimona.scala index b08db66361..3ba0c8f9aa 100644 --- a/src/main/scala/edu/ie3/simona/main/RunSimona.scala +++ b/src/main/scala/edu/ie3/simona/main/RunSimona.scala @@ -57,7 +57,7 @@ trait RunSimona[T <: SimonaSetup] extends LazyLogging { private def printGoodbye( successful: Boolean, - outputPath: String = "", + logOutputDir: Path, ): Unit = { val myWords = Array( "\"Vielleicht ist heute ein besonders guter Tag zum Sterben.\" - Worf (in Star Trek: Der erste Kontakt)", @@ -78,7 +78,7 @@ trait RunSimona[T <: SimonaSetup] extends LazyLogging { // to ensure that the link to the log is printed last Thread.sleep(1000) - val path = Path.of(outputPath).resolve("simona.log").toUri + val path = logOutputDir.resolve("simona.log").toUri logger.error( s"Simulation stopped due to the occurrence of an error! The full log can be found here: $path" diff --git a/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala b/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala index d5b21a99a7..23fe9e1997 100644 --- a/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala +++ b/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala @@ -220,7 +220,7 @@ trait SetupHelper extends LazyLogging { val modelsToWrite = SetupHelper.allResultEntitiesToWrite(simonaConfig.simona.output) - val resultFileHierarchy = ResultFileHierarchy( + ResultFileHierarchy( simonaConfig.simona.output.base.dir, simonaConfig.simona.simulationName, ResultEntityPathConfig( @@ -230,15 +230,10 @@ trait SetupHelper extends LazyLogging { simonaConfig.simona.simulationName, ), ), + config = Some(config), addTimeStampToOutputDir = simonaConfig.simona.output.base.addTimestampToOutputDir, - createDirs = createDirs, ) - - // copy config data to output directory - ResultFileHierarchy.prepareDirectories(config, resultFileHierarchy) - - resultFileHierarchy } } diff --git a/src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala b/src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala index 4a2d8abd42..4c452a4c3c 100644 --- a/src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala +++ b/src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala @@ -21,6 +21,8 @@ import org.apache.pekko.actor.typed.ActorRef import org.apache.pekko.actor.typed.scaladsl.ActorContext import org.apache.pekko.actor.{ActorRef => ClassicRef} +import java.nio.file.Path + /** Trait that can be used to set up a customized simona simulation by providing * implementations for all setup information required by a * [[edu.ie3.simona.sim.SimonaSim]]. Most of the time, using or extending @@ -40,7 +42,7 @@ trait SimonaSetup { /** Directory of the log output. */ - def logOutputDir: String + def logOutputDir: Path /** Creates the runtime event listener * diff --git a/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala b/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala index 65d47863cf..55848d2ced 100644 --- a/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala +++ b/src/main/scala/edu/ie3/simona/sim/setup/SimonaStandaloneSetup.scala @@ -50,6 +50,7 @@ import org.apache.pekko.actor.typed.scaladsl.adapter.{ } import org.apache.pekko.actor.{ActorRef => ClassicRef} +import java.nio.file.Path import java.util.UUID import java.util.concurrent.LinkedBlockingQueue import scala.jdk.CollectionConverters._ @@ -68,7 +69,7 @@ class SimonaStandaloneSetup( override val args: Array[String], ) extends SimonaSetup { - override def logOutputDir: String = resultFileHierarchy.logOutputDir + override def logOutputDir: Path = resultFileHierarchy.logOutputDir override def gridAgents( context: ActorContext[_], diff --git a/src/main/scala/edu/ie3/simona/util/ResultFileHierarchy.scala b/src/main/scala/edu/ie3/simona/util/ResultFileHierarchy.scala index 3c1028be2b..3dc207d350 100644 --- a/src/main/scala/edu/ie3/simona/util/ResultFileHierarchy.scala +++ b/src/main/scala/edu/ie3/simona/util/ResultFileHierarchy.scala @@ -7,7 +7,7 @@ package edu.ie3.simona.util import java.io.{BufferedWriter, File, FileWriter} -import java.nio.file.{Files, Paths} +import java.nio.file.{Files, Path, Paths} import java.text.SimpleDateFormat import com.typesafe.config.{ConfigRenderOptions, Config => TypesafeConfig} import com.typesafe.scalalogging.LazyLogging @@ -20,130 +20,135 @@ import edu.ie3.simona.exceptions.FileHierarchyException import edu.ie3.simona.io.result.ResultSinkType import edu.ie3.simona.io.result.ResultSinkType.Csv import edu.ie3.simona.logging.logback.LogbackConfiguration -import edu.ie3.simona.util.ResultFileHierarchy.ResultEntityPathConfig import edu.ie3.util.io.FileIOUtils import org.apache.commons.io.FilenameUtils._ import scala.jdk.OptionConverters.RichOptional -/** Represents the output directory where the results will be materialized. If - * new directories are added please remember to add them to the dirsToBeCreated - * Vector if they should be created. Otherwise, they will not be created! - * - * @version 0.1 - * @since 12.01.20 +/** Represents the output directory where the results will be materialized. */ -final case class ResultFileHierarchy( - private val outputDir: String, - private val simulationName: String, - private val resultEntityPathConfig: ResultEntityPathConfig, - private val configureLogger: String => Unit = LogbackConfiguration.default, - private val addTimeStampToOutputDir: Boolean = true, - private val createDirs: Boolean = false, -) extends LazyLogging { +final case class ResultFileHierarchy private ( + runOutputDir: Path, + rawOutputDataFilePaths: Map[Class[_ <: ResultEntity], Path], + configOutputDir: Path, + logOutputDir: Path, + tmpDir: Path, + resultSinkType: ResultSinkType, + resultEntitiesToConsider: Set[Class[_ <: ResultEntity]], +) - private val fileSeparator: String = File.separator - - val runStartTimeUTC: String = - new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new java.util.Date()) - - val baseOutputDir: String = buildBaseOutputDir - - val runOutputDir: String = buildRunOutputDir +object ResultFileHierarchy extends LazyLogging { - val configOutputDir: String = - runOutputDir.concat(fileSeparator).concat("configs") + /** Creates the [[ResultFileHierarchy]] and relevant directories + */ + def apply( + outputDir: String, + simulationName: String, + resultEntityPathConfig: ResultEntityPathConfig, + configureLogger: Path => Unit = LogbackConfiguration.default, + config: Option[TypesafeConfig] = None, + addTimeStampToOutputDir: Boolean = true, + ): ResultFileHierarchy = { + + val runStartTimeUTC = Option.when(addTimeStampToOutputDir)( + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new java.util.Date()) + ) - val rawOutputDataDir: String = - runOutputDir.concat(fileSeparator).concat("rawOutputData") + val baseOutputDir = buildBaseOutputDir(outputDir) - val logOutputDir: String = - runOutputDir.concat(fileSeparator).concat("log") + val runOutputDir = buildRunOutputDir( + baseOutputDir, + simulationName, + runStartTimeUTC, + ) - val resultSinkType: ResultSinkType = resultEntityPathConfig.resultSinkType + val configOutputDir = runOutputDir.resolve("configs") + val rawOutputDataDir = runOutputDir.resolve("rawOutputData") + val logOutputDir = runOutputDir.resolve("log") + val tmpDir = runOutputDir.resolve("tmp") - val resultEntitiesToConsider: Set[Class[_ <: ResultEntity]] = - resultEntityPathConfig.resultEntitiesToConsider + val resultSinkType: ResultSinkType = resultEntityPathConfig.resultSinkType - val rawOutputDataFilePaths: Map[Class[_ <: ResultEntity], String] = { - resultSinkType match { - case csv: Csv => - resultEntityPathConfig.resultEntitiesToConsider - .map(resultEntityClass => - ( - resultEntityClass, - ResultFileHierarchy.buildRawOutputFilePath( + val rawOutputDataFilePaths: Map[Class[_ <: ResultEntity], Path] = { + resultSinkType match { + case csv: Csv => + resultEntityPathConfig.resultEntitiesToConsider + .map(resultEntityClass => + ( resultEntityClass, - csv, - rawOutputDataDir, - fileSeparator, - ), + ResultFileHierarchy.buildRawOutputFilePath( + resultEntityClass, + csv, + rawOutputDataDir, + ), + ) ) - ) - .toMap - case _ => - Map.empty + .toMap + case _ => + Map.empty + } } - } - - val graphOutputDir: String = - runOutputDir.concat(fileSeparator).concat("graphs") - val kpiOutputDir: String = runOutputDir.concat(fileSeparator).concat("kpi") - - val tmpDir: String = runOutputDir.concat(fileSeparator).concat("tmp") + val dirsToBeCreated = Seq( + baseOutputDir, + runOutputDir, + configOutputDir, + rawOutputDataDir, + logOutputDir, + tmpDir, + ) - private val dirsToBeCreated: Vector[String] = Vector( - baseOutputDir, - runOutputDir, - configOutputDir, - rawOutputDataDir, - graphOutputDir, - kpiOutputDir, - tmpDir, - logOutputDir, - ) + val resultFileHierarchy = ResultFileHierarchy( + runOutputDir, + rawOutputDataFilePaths, + configOutputDir, + logOutputDir, + tmpDir, + resultSinkType, + resultEntityPathConfig.resultEntitiesToConsider, + ) + prepareDirectories( + baseOutputDir, + dirsToBeCreated, + resultFileHierarchy, + config, + ) - // needs to be the latest call because otherwise the values are null as they are not initialized yet - if (createDirs) - ResultFileHierarchy.createOutputDirectories(this) + // needs to be done after dir creation + configureLogger(logOutputDir) - // needs to be done after dir creation - configureLogger(logOutputDir) + resultFileHierarchy + } - /** Builds the base output directory string + /** Builds the base output directory * * @return - * the filepath string to the directory + * the filepath of the directory */ - private def buildBaseOutputDir: String = { - + private def buildBaseOutputDir( + outputDir: String + ): Path = { // clean file string if necessary val cleanedBaseOutputDir = { val normalizedOutputDir = normalize(outputDir) - (fileSeparator + "$").r.replaceAllIn(normalizedOutputDir, "") + (File.separator + "$").r.replaceAllIn(normalizedOutputDir, "") } - // create base output dir if non-existent - Paths.get(cleanedBaseOutputDir).toFile.getAbsolutePath + Paths.get(cleanedBaseOutputDir) } - /** Builds the output directory string for this specific run - * - * @return + /** Builds the output directory for this specific run */ - private def buildRunOutputDir: String = { + private def buildRunOutputDir( + baseOutputDir: Path, + simulationName: String, + runStartTimeUTC: Option[String], + ): Path = { val optionalSuffix = - if (addTimeStampToOutputDir) s"_$runStartTimeUTC" else "" - baseOutputDir - .concat(fileSeparator) - .concat(simulationName) - .concat(optionalSuffix) - } + runStartTimeUTC.map(pattern => s"_$pattern").getOrElse("") -} - -object ResultFileHierarchy extends LazyLogging { + baseOutputDir.resolve(s"$simulationName$optionalSuffix") + } /** @param resultEntitiesToConsider * [[ResultEntity]] s to consider to be written out @@ -161,8 +166,6 @@ object ResultFileHierarchy extends LazyLogging { * the csv sink type parameters * @param rawOutputDataDir * the directory of the raw output data - * @param fileSeparator - * the file separator to be used * @return * an absolute file path as string for the provided model class incl. file * name + extension @@ -170,9 +173,8 @@ object ResultFileHierarchy extends LazyLogging { private def buildRawOutputFilePath( modelClass: Class[_ <: ResultEntity], csvSink: Csv, - rawOutputDataDir: String, - fileSeparator: String, - ): String = { + rawOutputDataDir: Path, + ): Path = { val fileEnding = if (csvSink.fileFormat.startsWith(".")) csvSink.fileFormat @@ -192,64 +194,72 @@ object ResultFileHierarchy extends LazyLogging { ) } - rawOutputDataDir - .concat(fileSeparator) - .concat(filename.toString) - .concat(fileEnding) + rawOutputDataDir.resolve(s"${filename.toString}$fileEnding") } /** Prepares the output directories to be ready to hold the output data. This * includes creating the run directory with all subsequent directories as * well as copying the simulation configuration to the output dir * - * @param config + * @param baseOutputDir + * The base output directory + * @param dirsToBeCreated + * The directories that need to be created + * @param maybeConfig * the config of the current simulation * @param resultFileHierarchy * the output file hierarchy of the current simulation */ - def prepareDirectories( - config: TypesafeConfig, + private def prepareDirectories( + baseOutputDir: Path, + dirsToBeCreated: Seq[Path], resultFileHierarchy: ResultFileHierarchy, + maybeConfig: Option[TypesafeConfig], ): Unit = { // create output directories if they are not present yet if (!runOutputDirExists(resultFileHierarchy)) - ResultFileHierarchy.createOutputDirectories(resultFileHierarchy) + createOutputDirectories( + baseOutputDir, + dirsToBeCreated, + resultFileHierarchy, + ) - logger.info( - "Processing configs for simulation: {}.", - config.getString("simona.simulationName"), - ) + maybeConfig.foreach { config => + logger.info( + "Processing configs for simulation: {}.", + config.getString("simona.simulationName"), + ) - val outFile = - Paths.get(resultFileHierarchy.configOutputDir, "vn_simona.conf").toFile - val bw = new BufferedWriter(new FileWriter(outFile)) - bw.write( - config - .root() - .render( - ConfigRenderOptions - .defaults() - .setOriginComments(false) - .setComments(false) - ) - ) - bw.close() - logger.info("Config '{}' written to '{}'.", outFile.getPath, outFile) + val outFile = + resultFileHierarchy.configOutputDir.resolve("vn_simona.conf").toFile + val bw = new BufferedWriter(new FileWriter(outFile)) + bw.write( + config + .root() + .render( + ConfigRenderOptions + .defaults() + .setOriginComments(false) + .setComments(false) + ) + ) + bw.close() + logger.info("Config '{}' written to '{}'.", outFile.getPath, outFile) + } } /** Checks if the directory of the current run already exists * - * @param outputFileHierarchy + * @param fileHierarchy * the [[ResultFileHierarchy]] that holds information on the run directory * path * @return * true if it exists, false if not */ - def runOutputDirExists(outputFileHierarchy: ResultFileHierarchy): Boolean = { - new File(outputFileHierarchy.runOutputDir).exists() && new File( - outputFileHierarchy.runOutputDir - ).listFiles().length > 0 + def runOutputDirExists(fileHierarchy: ResultFileHierarchy): Boolean = { + val outputDir = fileHierarchy.runOutputDir.toFile + outputDir.exists() && outputDir.listFiles().length > 0 } /** Creates all output directories of the provided [[ResultFileHierarchy]] @@ -257,11 +267,12 @@ object ResultFileHierarchy extends LazyLogging { * @param outputFileHierarchy * the [[ResultFileHierarchy]] the directories should be created for */ - def createOutputDirectories( - outputFileHierarchy: ResultFileHierarchy + private def createOutputDirectories( + baseOutputDir: Path, + dirsToBeCreated: Seq[Path], + outputFileHierarchy: ResultFileHierarchy, ): Unit = { // try to create base output dir - val baseOutputDir = Paths.get(outputFileHierarchy.baseOutputDir) // / check for existence of the provided baseOutputDir, if not create it if (Files.exists(baseOutputDir) && baseOutputDir.toFile.isFile) { throw new FileHierarchyException( @@ -270,17 +281,17 @@ object ResultFileHierarchy extends LazyLogging { } // check if there is data inside the runOutputDir taking into account the provided FileHandling - val runOutputDir = new File(outputFileHierarchy.runOutputDir) + val runOutputDir = outputFileHierarchy.runOutputDir.toFile if (runOutputDir.exists() && runOutputDir.listFiles().length > 0) { // files inside the runOutputDir -> fail throw new FileHierarchyException( - s"The runOutputDir ${outputFileHierarchy.runOutputDir} already exists and is NOT empty! " + + s"The runOutputDir ${outputFileHierarchy.runOutputDir.toString} already exists and is NOT empty! " + s"Please either delete or empty the directory." ) } // create the output directories for the specific run - outputFileHierarchy.dirsToBeCreated.foreach(createDir) + dirsToBeCreated.foreach(createDir) } @@ -289,8 +300,8 @@ object ResultFileHierarchy extends LazyLogging { * @param dir * the full path where the directory should be created (incl. it's name) */ - private def createDir(dir: String): Unit = { - val dirFile = new File(dir) + private def createDir(dir: Path): Unit = { + val dirFile = dir.toFile if (!dirFile.mkdirs() && !dirFile.exists()) throw new FileHierarchyException( "The output directory path " + dir diff --git a/src/test/scala/edu/ie3/simona/event/listener/ResultEventListenerSpec.scala b/src/test/scala/edu/ie3/simona/event/listener/ResultEventListenerSpec.scala index 26c3145945..68caa1706b 100644 --- a/src/test/scala/edu/ie3/simona/event/listener/ResultEventListenerSpec.scala +++ b/src/test/scala/edu/ie3/simona/event/listener/ResultEventListenerSpec.scala @@ -84,7 +84,6 @@ class ResultEventListenerSpec classes, resultSinkType, ), - createDirs = true, ) } @@ -122,14 +121,14 @@ class ResultEventListenerSpec ) // after the creation of the listener, it is expected that a corresponding raw result data file is present - val outputFile = new File( - fileHierarchy.rawOutputDataFilePaths.getOrElse( + val outputFile = fileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[PvResult], fail( s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" ), ) - ) + .toFile assert(outputFile.exists) assert(outputFile.isFile) @@ -162,14 +161,14 @@ class ResultEventListenerSpec listenerRef ! ParticipantResultEvent(dummyPvResult) - val outputFile = new File( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( + val outputFile = specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[PvResult], fail( s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" ), ) - ) + .toFile // wait until output file exists (headers are flushed out immediately): awaitCond( @@ -219,39 +218,37 @@ class ResultEventListenerSpec ) val outputFiles = Map( - dummyNodeResultString -> new File( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( + dummyNodeResultString -> specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[NodeResult], fail( s"Cannot get filepath for raw result file of class '${classOf[NodeResult].getSimpleName}' from outputFileHierarchy!'" ), - ) - ), - dummySwitchResultString -> new File( + ), + dummySwitchResultString -> specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( classOf[SwitchResult], fail( s"Cannot get filepath for raw result file of class '${classOf[SwitchResult].getSimpleName}' from outputFileHierarchy!'" ), - ) - ), - dummyLineResultDataString -> new File( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( + ), + dummyLineResultDataString -> specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[LineResult], fail( s"Cannot get filepath for raw result file of class '${classOf[LineResult].getSimpleName}' from outputFileHierarchy!'" ), - ) - ), - dummyTrafo2wResultDataString -> new File( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( + ), + dummyTrafo2wResultDataString -> specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[Transformer2WResult], fail( s"Cannot get filepath for raw result file of class '${classOf[Transformer2WResult].getSimpleName}' from outputFileHierarchy!'" ), - ) - ), - ) + ), + ).map { case (dummyString, path) => + (dummyString, path.toFile) + } // wait until all output files exist (headers are flushed out immediately): awaitCond( @@ -308,14 +305,15 @@ class ResultEventListenerSpec ) ) - val outputFile = new File( - fileHierarchy.rawOutputDataFilePaths.getOrElse( + val outputFile = fileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[Transformer3WResult], fail( s"Cannot get filepath for raw result file of class '${classOf[Transformer3WResult].getSimpleName}' from outputFileHierarchy!'" ), ) - ) + .toFile + /* The result file is created at start up and only contains a headline. */ awaitCond( outputFile.exists(), @@ -386,12 +384,14 @@ class ResultEventListenerSpec val outputFile = new File( ".gz$".r.replaceAllIn( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( - classOf[PvResult], - fail( - s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" - ), - ), + specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( + classOf[PvResult], + fail( + s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" + ), + ) + .toString, "", ) ) @@ -413,26 +413,29 @@ class ResultEventListenerSpec // wait until file exists awaitCond( - new File( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( + specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( classOf[PvResult], fail( s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" ), ) - ).exists, + .toFile + .exists, timeoutDuration, ) val resultFileSource = Source.fromInputStream( new GZIPInputStream( new FileInputStream( - specificOutputFileHierarchy.rawOutputDataFilePaths.getOrElse( - classOf[PvResult], - fail( - s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" - ), - ) + specificOutputFileHierarchy.rawOutputDataFilePaths + .getOrElse( + classOf[PvResult], + fail( + s"Cannot get filepath for raw result file of class '${classOf[PvResult].getSimpleName}' from outputFileHierarchy!'" + ), + ) + .toFile ) ) ) diff --git a/src/test/scala/edu/ie3/simona/integration/RunSimonaStandaloneIT.scala b/src/test/scala/edu/ie3/simona/integration/RunSimonaStandaloneIT.scala index 4e53f0e078..083b9681e3 100644 --- a/src/test/scala/edu/ie3/simona/integration/RunSimonaStandaloneIT.scala +++ b/src/test/scala/edu/ie3/simona/integration/RunSimonaStandaloneIT.scala @@ -90,7 +90,7 @@ class RunSimonaStandaloneIT /* check the results */ // check configs - val configOutputDir = new File(resultFileHierarchy.configOutputDir) + val configOutputDir = resultFileHierarchy.configOutputDir.toFile configOutputDir.isDirectory shouldBe true configOutputDir.listFiles.toVector.size shouldBe 1 @@ -118,10 +118,12 @@ class RunSimonaStandaloneIT entityClass: Class[_ <: ResultEntity], ): BufferedSource = { Source.fromFile( - resultFileHierarchy.rawOutputDataFilePaths.getOrElse( - entityClass, - fail(s"Unable to get output path for result entity: $entityClass"), - ) + resultFileHierarchy.rawOutputDataFilePaths + .getOrElse( + entityClass, + fail(s"Unable to get output path for result entity: $entityClass"), + ) + .toFile ) } diff --git a/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala b/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala index 3b89d418f2..c273634fbe 100644 --- a/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala +++ b/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala @@ -51,37 +51,15 @@ class ResultFileHierarchySpec ), ) - val runOutputDirWithDate = - "vn_simona_".concat(validOutputFileHierarchy.runStartTimeUTC) - - relativizePath( - validOutputFileHierarchy.baseOutputDir - ).toString shouldBe baseOutputDir - relativizePath( - validOutputFileHierarchy.runOutputDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate - relativizePath( - validOutputFileHierarchy.tmpDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "tmp" - relativizePath( - validOutputFileHierarchy.configOutputDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "configs" - relativizePath( - validOutputFileHierarchy.rawOutputDataDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "rawOutputData" - relativizePath( - validOutputFileHierarchy.graphOutputDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "graphs" - relativizePath( - validOutputFileHierarchy.kpiOutputDir - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "kpi" - - relativizePath( - validOutputFileHierarchy.rawOutputDataFilePaths(classOf[PvResult]) - ).toString shouldBe baseOutputDir + fileSeparator + runOutputDirWithDate + fileSeparator + "rawOutputData" + fileSeparator + "pref_pv_res_suff.csv" + validOutputFileHierarchy.tmpDir.toString shouldBe validOutputFileHierarchy.runOutputDir.toString + fileSeparator + "tmp" + validOutputFileHierarchy.configOutputDir.toString shouldBe validOutputFileHierarchy.runOutputDir.toString + fileSeparator + "configs" + validOutputFileHierarchy.logOutputDir.toString shouldBe validOutputFileHierarchy.runOutputDir.toString + fileSeparator + "log" + + validOutputFileHierarchy + .rawOutputDataFilePaths(classOf[PvResult]) + .toString shouldBe validOutputFileHierarchy.runOutputDir.toString + fileSeparator + "rawOutputData" + fileSeparator + "pref_pv_res_suff.csv" } - "not write directories automatically on instantiation" in {} // todo "write directories automatically on instantiation when requested so" in { // delete file if they exist @@ -97,7 +75,6 @@ class ResultFileHierarchySpec Set(classOf[PvResult]), ResultSinkType.Csv("csv", "pref", "suff"), ), - createDirs = true, ) // check for existence of run output dir @@ -106,26 +83,13 @@ class ResultFileHierarchySpec ) shouldBe true // check for existence of other folders - assert( - Files.exists(new File(validOutputFileHierarchy.baseOutputDir).toPath) - ) - assert(Files.exists(new File(validOutputFileHierarchy.tmpDir).toPath)) - assert( - Files.exists(new File(validOutputFileHierarchy.configOutputDir).toPath) - ) - assert( - Files.exists(new File(validOutputFileHierarchy.rawOutputDataDir).toPath) - ) - assert( - Files.exists(new File(validOutputFileHierarchy.graphOutputDir).toPath) - ) - assert( - Files.exists(new File(validOutputFileHierarchy.kpiOutputDir).toPath) - ) + assert(Files.exists(validOutputFileHierarchy.configOutputDir)) + assert(Files.exists(validOutputFileHierarchy.logOutputDir)) + assert(Files.exists(validOutputFileHierarchy.tmpDir)) // check if tmp directory can be deleted by output file hierarchy ResultFileHierarchy.deleteTmpDir(validOutputFileHierarchy) - assert(!Files.exists(new File(validOutputFileHierarchy.tmpDir).toPath)) + assert(!Files.exists(validOutputFileHierarchy.tmpDir)) } @@ -133,10 +97,8 @@ class ResultFileHierarchySpec } - private def relativizePath(fullPath: String): Path = { - new File(new File("").getAbsolutePath).toPath - .relativize(new File(fullPath).toPath) - } + private def relativizePath(fullPath: Path): Path = + new File(new File("").getAbsolutePath).toPath.relativize(fullPath) // todo output model path config compression should always be disabled -> test for this diff --git a/src/test/scala/edu/ie3/simona/sim/SimonaSimSpec.scala b/src/test/scala/edu/ie3/simona/sim/SimonaSimSpec.scala index 63be126c0f..9d1140be17 100644 --- a/src/test/scala/edu/ie3/simona/sim/SimonaSimSpec.scala +++ b/src/test/scala/edu/ie3/simona/sim/SimonaSimSpec.scala @@ -34,6 +34,7 @@ import org.apache.pekko.actor.typed.scaladsl.{ActorContext, Behaviors} import org.apache.pekko.actor.typed.{ActorRef, Behavior} import org.apache.pekko.actor.{ActorRef => ClassicRef} +import java.nio.file.Path import java.util.UUID class SimonaSimSpec extends ScalaTestWithActorTestKit with UnitSpec { @@ -398,7 +399,7 @@ object SimonaSimSpec { override val args: Array[String] = Array.empty[String] - override def logOutputDir: String = throw new NotImplementedError() + override def logOutputDir: Path = throw new NotImplementedError() override def runtimeEventListener( context: ActorContext[_] diff --git a/src/test/scala/edu/ie3/simona/sim/setup/SimonaSetupSpec.scala b/src/test/scala/edu/ie3/simona/sim/setup/SimonaSetupSpec.scala index 7fa3ab3469..0428ed765b 100644 --- a/src/test/scala/edu/ie3/simona/sim/setup/SimonaSetupSpec.scala +++ b/src/test/scala/edu/ie3/simona/sim/setup/SimonaSetupSpec.scala @@ -26,13 +26,14 @@ import org.apache.pekko.actor.typed.ActorRef import org.apache.pekko.actor.typed.scaladsl.ActorContext import org.apache.pekko.actor.{ActorRef => ClassicRef} +import java.nio.file.Path import java.util.UUID class SimonaSetupSpec extends UnitSpec with SimonaSetup with SubGridGateMokka { override val args: Array[String] = Array.empty[String] - override def logOutputDir: String = throw new NotImplementedError() + override def logOutputDir: Path = throw new NotImplementedError() override def runtimeEventListener( context: ActorContext[_] From 6e821bf84454aafc298b7059a7e15254f852892e Mon Sep 17 00:00:00 2001 From: Sebastian Peter Date: Mon, 18 Nov 2024 21:15:44 +0100 Subject: [PATCH 18/22] Adding to changelog Signed-off-by: Sebastian Peter --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cef76459a..4ea36f463e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -99,6 +99,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated `ExtEvSimulationClasses` [#898](https://github.com/ie3-institute/simona/issues/898) - Refactoring of `ThermalGrid.energyGrid` to distinguish between demand of house and storage [#928](https://github.com/ie3-institute/simona/issues/928) - Refactoring to use zeroKW and zeroKWH in thermal grid unit tests [#1023](https://github.com/ie3-institute/simona/issues/1023) +- Refactor `ResultFileHierarchy` [#1031](https://github.com/ie3-institute/simona/issues/1031) ### Fixed - Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505) From c0d45979ffb8b7ad2e4f8adad516435e63adefb1 Mon Sep 17 00:00:00 2001 From: Sebastian Peter Date: Tue, 19 Nov 2024 10:52:46 +0100 Subject: [PATCH 19/22] Addressing reviewer's comments Signed-off-by: Sebastian Peter --- src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala | 8 ++------ .../edu/ie3/simona/io/file/ResultFileHierarchySpec.scala | 3 --- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala b/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala index 05a6f0ffd5..1b2d2df7e7 100644 --- a/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala +++ b/src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala @@ -202,17 +202,13 @@ trait SetupHelper extends LazyLogging { /** Build the result file hierarchy based on the provided configuration file. * The provided type safe config must be able to be parsed as * [[SimonaConfig]], otherwise an exception is thrown + * * @param config * the configuration file - * @param createDirs - * if directories of the result file hierarchy should be created or not * @return * the resulting result file hierarchy */ - def buildResultFileHierarchy( - config: TypesafeConfig, - createDirs: Boolean = true, - ): ResultFileHierarchy = { + def buildResultFileHierarchy(config: TypesafeConfig): ResultFileHierarchy = { val simonaConfig = SimonaConfig(config) diff --git a/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala b/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala index c273634fbe..6ddc02a059 100644 --- a/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala +++ b/src/test/scala/edu/ie3/simona/io/file/ResultFileHierarchySpec.scala @@ -97,9 +97,6 @@ class ResultFileHierarchySpec } - private def relativizePath(fullPath: Path): Path = - new File(new File("").getAbsolutePath).toPath.relativize(fullPath) - // todo output model path config compression should always be disabled -> test for this } From 9bdec0da846e7907c068a1f0471533fcf975f57c Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 19 Nov 2024 11:09:49 +0100 Subject: [PATCH 20/22] Addressing reviewer's comments. --- .../simona/model/participant/BMModel.scala | 6 +++--- .../simona/model/participant/ChpModel.scala | 2 +- .../model/participant/FixedFeedInModel.scala | 2 +- .../simona/model/participant/HpModel.scala | 6 +++--- .../simona/model/participant/PvModel.scala | 7 ++++--- .../simona/model/participant/WecModel.scala | 2 +- .../model/participant/control/QControl.scala | 4 ++-- .../participant/evcs/EvModelWrapper.scala | 20 ++++++++++--------- .../model/participant/evcs/EvcsModel.scala | 2 +- .../model/participant/load/LoadModel.scala | 2 +- .../load/profile/LoadProfileStore.scala | 1 - .../load/random/RandomLoadModel.scala | 2 +- .../util/scala/quantities/ApparentPower.scala | 2 +- 13 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala index ac25324c1f..6f93742eeb 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/BMModel.scala @@ -195,9 +195,9 @@ final case class BMModel( isCostControlled && avgOpex.value.doubleValue() < feedInTariff.value .doubleValue() ) - sRated.toPower(cosPhiRated) * -1 + sRated.toActivePower(cosPhiRated) * -1 else - sRated.toPower(cosPhiRated) * usage * eff * -1 + sRated.toActivePower(cosPhiRated) * usage * eff * -1 } /** Applies the load gradient to the electrical output @@ -212,7 +212,7 @@ final case class BMModel( _lastPower match { case None => pEl case Some(lastPowerVal) => - val pElDeltaMaxAbs = sRated.toPower(cosPhiRated) * loadGradient + val pElDeltaMaxAbs = sRated.toActivePower(cosPhiRated) * loadGradient pEl - lastPowerVal match { case pElDelta if pElDelta > pElDeltaMaxAbs => diff --git a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala index 7bba620f63..e48909bd91 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/ChpModel.scala @@ -68,7 +68,7 @@ final case class ChpModel( ) with ApparentPowerParticipant[ChpRelevantData, ConstantState.type] { - val pRated: Power = sRated.toPower(cosPhiRated) + val pRated: Power = sRated.toActivePower(cosPhiRated) /** As this is a state-full model (with respect to the current operation * condition and its thermal storage), the power calculation operates on the diff --git a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala index 396bfec08d..0501fcb025 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/FixedFeedInModel.scala @@ -71,7 +71,7 @@ final case class FixedFeedInModel( override def calculateActivePower( modelState: ConstantState.type, data: FixedRelevantData.type = FixedRelevantData, - ): Power = sRated.toPower(cosPhiRated) * -1 + ): Power = sRated.toActivePower(cosPhiRated) * -1 override def determineFlexOptions( data: FixedRelevantData.type, diff --git a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala index f5c6c7e66e..98d18d9ce3 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/HpModel.scala @@ -74,7 +74,7 @@ final case class HpModel( ) with ApparentPowerAndHeatParticipant[HpRelevantData, HpState] { - private val pRated: Power = sRated.toPower(cosPhiRated) + private val pRated: Power = sRated.toActivePower(cosPhiRated) /** As this is a state-full model (with respect to the current operation * condition and inner temperature), the power calculation operates on the @@ -312,7 +312,7 @@ final case class HpModel( updatedHpState.activePower val upperBoundary = if (canOperate) - sRated.toPower(cosPhiRated) + sRated.toActivePower(cosPhiRated) else zeroKW @@ -347,7 +347,7 @@ final case class HpModel( setPower: Power, ): (HpState, FlexChangeIndicator) = { /* If the setpoint value is above 50 % of the electrical power, turn on the heat pump otherwise turn it off */ - val turnOn = setPower > (sRated.toPower(cosPhiRated) * 0.5) + val turnOn = setPower > (sRated.toActivePower(cosPhiRated) * 0.5) val updatedHpState = calcState( lastState, diff --git a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala index f6103aa1c3..5d83478da0 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/PvModel.scala @@ -57,12 +57,13 @@ final case class PvModel private ( override val sMax: ApparentPower = sRated * 1.1 /** Permissible maximum active power feed in (therefore negative) */ - protected val pMax: Power = sMax.toPower(cosPhiRated) * -1d + protected val pMax: Power = sMax.toActivePower(cosPhiRated) * -1d /** Reference yield at standard testing conditions (STC) */ private val yieldSTC = WattsPerSquareMeter(1000d) - private val activationThreshold = sRated.toPower(cosPhiRated) * 0.001 * -1d + private val activationThreshold = + sRated.toActivePower(cosPhiRated) * 0.001 * -1d /** Calculate the active power behaviour of the model * @@ -691,7 +692,7 @@ final case class PvModel private ( /* Calculate the foreseen active power output without boundary condition adaptions */ val proposal = - sRated.toPower(cosPhiRated) * -1 * (actYield / irradiationSTC) + sRated.toActivePower(cosPhiRated) * -1 * (actYield / irradiationSTC) /* Do sanity check, if the proposed feed in is above the estimated maximum to be apparent active power of the plant */ if (proposal < pMax) diff --git a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala index f1ca6258a0..50f26708e7 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/WecModel.scala @@ -96,7 +96,7 @@ final case class WecModel( wecData: WecRelevantData, ): Power = { val activePower = determinePower(wecData) - val pMax = sMax.toPower(cosPhiRated) + val pMax = sMax.toActivePower(cosPhiRated) (if (activePower > pMax) { logger.warn( diff --git a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala index aa6f7e77eb..aced18487d 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala @@ -175,7 +175,7 @@ object QControl { ): Power => ReactivePower = { activePower: Power => val qMaxFromP = Megavars( sqrt( - pow(sRated.toPower(1.0).toMegawatts, 2) - + pow(sRated.toActivePower(1.0).toMegawatts, 2) - pow(activePower.toMegawatts, 2) ) ) @@ -252,7 +252,7 @@ object QControl { ): Power => ReactivePower = { activePower: Power => /* cosphi( P / P_N ) = cosphi( P / (S_N * cosphi_rated) ) */ val pInPu = - activePower / sRated.toPower(cosPhiRated) + activePower / sRated.toActivePower(cosPhiRated) val instantCosPhi = cosPhi(Each(pInPu)) _cosPhiMultiplication(instantCosPhi.value.doubleValue, activePower) } diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala index 3c9f1077c6..7883557dbe 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvModelWrapper.scala @@ -10,7 +10,7 @@ import edu.ie3.simona.api.data.ev.model.EvModel import edu.ie3.util.quantities.PowerSystemUnits._ import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble import squants.Power -import squants.energy.{KilowattHours, Kilowatts} +import squants.energy.{Energy, KilowattHours, Kilowatts} import java.util.UUID @@ -27,21 +27,23 @@ import java.util.UUID * The wrapped [[EvModel]] */ final case class EvModelWrapper( - storedEnergy: squants.Energy, + storedEnergy: Energy, private val original: EvModel, ) { def uuid: UUID = original.getUuid def id: String = original.getId - lazy val pRatedAc: Power = - Kilowatts( - original.getSRatedAC.to(KILOWATT).getValue.doubleValue - ) - lazy val pRatedDc: squants.Power = - Kilowatts(original.getSRatedDC.to(KILOWATT).getValue.doubleValue) - lazy val eStorage: squants.Energy = KilowattHours( + + lazy val pRatedAc: Power = Kilowatts( + original.getSRatedAC.to(KILOWATT).getValue.doubleValue + ) + lazy val pRatedDc: Power = Kilowatts( + original.getSRatedDC.to(KILOWATT).getValue.doubleValue + ) + lazy val eStorage: Energy = KilowattHours( original.getEStorage.to(KILOWATTHOUR).getValue.doubleValue ) + def departureTick: Long = original.getDepartureTick /** Unwrapping the original [[EvModel]] while also updating the diff --git a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala index d85d9c584c..30b3f0a249 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/evcs/EvcsModel.scala @@ -506,7 +506,7 @@ final case class EvcsModel( ev.pRatedDc } /* Limit the charging power to the minimum of ev's and evcs' permissible power */ - evPower.min(sRated.toPower(1.0)) + evPower.min(sRated.toActivePower(1.0)) } override def calculatePower( diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala index bbb7f19063..6eb5a6fd0d 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/LoadModel.scala @@ -96,7 +96,7 @@ object LoadModel extends LazyLogging { .getValue .doubleValue ) - val pRated = sRated.toPower(inputModel.getCosPhiRated) + val pRated = sRated.toActivePower(inputModel.getCosPhiRated) val referenceScalingFactor = activePower / pRated sRated * referenceScalingFactor * safetyFactor } diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala index 270b044037..209d9349c8 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/profile/LoadProfileStore.scala @@ -17,7 +17,6 @@ import edu.ie3.simona.model.participant.load.profile.LoadProfileStore.{ initializeTypeDayValues, } import edu.ie3.simona.model.participant.load.{DayType, profile} -import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} import org.apache.commons.csv.CSVFormat import squants.Power import squants.energy.{KilowattHours, Watts} diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index 9488102135..200e94465c 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -169,7 +169,7 @@ object RandomLoadModel { * active power. * * @return - * Reference apparent power to use for later model calculations + * Reference active power to use for later model calculations */ private val randomMaxPower: Power = Watts(159d) diff --git a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala index eeec8fd219..2fe765ce9b 100644 --- a/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala +++ b/src/main/scala/edu/ie3/util/scala/quantities/ApparentPower.scala @@ -40,7 +40,7 @@ final class ApparentPower private ( * @return * the resulting active power */ - def toPower(cosPhi: Double): Power = Watts(toVoltamperes * cosPhi) + def toActivePower(cosPhi: Double): Power = Watts(toVoltamperes * cosPhi) /** Method to convert this apparent power into a [[ReactivePower]] using a * given cosPhi. From 840cf76abdcf64fa358b775cd2eaa3ea3e20cec2 Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 19 Nov 2024 12:08:40 +0100 Subject: [PATCH 21/22] Improving code. --- .../edu/ie3/simona/model/participant/control/QControl.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala index aced18487d..06ea4b98d7 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala @@ -173,11 +173,9 @@ object QControl { cosPhiRated: Double, nodalVoltage: Dimensionless, ): Power => ReactivePower = { activePower: Power => + // Q = sqrt(S^2 - P^2) val qMaxFromP = Megavars( - sqrt( - pow(sRated.toActivePower(1.0).toMegawatts, 2) - - pow(activePower.toMegawatts, 2) - ) + sqrt(pow(sRated.toMegavoltamperes, 2) - pow(activePower.toMegawatts, 2)) ) val qFromCharacteristic = q( From 0a90ee1e52f89e4d8ac3fe05d8841adc9edf312d Mon Sep 17 00:00:00 2001 From: staudtMarius Date: Tue, 19 Nov 2024 15:16:58 +0100 Subject: [PATCH 22/22] Implementing reviewer's comments. --- .../edu/ie3/simona/model/participant/control/QControl.scala | 2 +- .../simona/model/participant/load/random/RandomLoadModel.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala index 06ea4b98d7..7c998cbc4e 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/control/QControl.scala @@ -180,7 +180,7 @@ object QControl { val qFromCharacteristic = q( nodalVoltage, - Megavars(sRated.toReactivePower(cosPhiRated).toMegavars), + sRated.toReactivePower(cosPhiRated), ) qMaxPossible(qMaxFromP, qFromCharacteristic) } diff --git a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala index 200e94465c..bb0d95a9c8 100644 --- a/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala +++ b/src/main/scala/edu/ie3/simona/model/participant/load/random/RandomLoadModel.scala @@ -17,7 +17,7 @@ import edu.ie3.simona.model.participant.load.random.RandomLoadModel.RandomReleva import edu.ie3.simona.model.participant.load.{DayType, LoadModel, LoadReference} import edu.ie3.util.TimeUtil import edu.ie3.util.scala.OperationInterval -import edu.ie3.util.scala.quantities.{ApparentPower, Voltamperes} +import edu.ie3.util.scala.quantities.ApparentPower import squants.Power import squants.energy.{KilowattHours, Kilowatts, Watts}