Skip to content

Commit 772eb65

Browse files
committed
Merge branch 'dev' into ms/#53-upgrate-to-scala3
# Conflicts: # .scalafmt.conf # CHANGELOG.md # src/main/scala/edu/ie3/simona/config/SimonaConfig.scala # src/main/scala/edu/ie3/simona/main/RunSimonaStandalone.scala # src/main/scala/edu/ie3/simona/model/em/PrioritizedFlexStrat.scala # src/main/scala/edu/ie3/simona/model/participant2/ParticipantModelInit.scala # src/main/scala/edu/ie3/simona/model/participant2/ParticipantModelShell.scala # src/main/scala/edu/ie3/simona/ontology/messages/flex/MinMaxFlexibilityMessage.scala # src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala # src/main/scala/edu/ie3/simona/util/ResultFileHierarchy.scala # src/test/scala/edu/ie3/simona/agent/grid/ThermalGridIT.scala # src/test/scala/edu/ie3/simona/integration/RunSimonaStandaloneIT.scala
2 parents 0feae5e + 853c1a0 commit 772eb65

File tree

83 files changed

+4699
-2886
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+4699
-2886
lines changed

.scalafmt.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = 3.7.3
1+
version = 3.8.1
22
runner.dialect = scala3
33

44
rewrite.scala3.convertToNewSyntax = false

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6464
- Integration test for thermal grids without Em [#1145](https://github.com/ie3-institute/simona/issues/1145)
6565
- Change thermal house behaviour to heat till targetTemperature [#1176](https://github.com/ie3-institute/simona/issues/1176)
6666
- Add test case to EmAgentIT to check for correct reactive power [#1185](https://github.com/ie3-institute/simona/issues/1185)
67+
- Integration test for thermal grids with Em [#1146](https://github.com/ie3-institute/simona/issues/1146)
68+
- Added check for equal start and end date of simulation to ConfigFailFast [#1317](https://github.com/ie3-institute/simona/issues/1317)
69+
- Introduce ParticipantModel factory pattern [#1324](https://github.com/ie3-institute/simona/issues/1324)
6770

6871
### Changed
6972
- Adapted to changed data source in PSDM [#435](https://github.com/ie3-institute/simona/issues/435)
@@ -165,6 +168,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
165168
- Converting `WeatherService` to pekko typed [#1216](https://github.com/ie3-institute/simona/issues/1216)
166169
- Converting `PrimaryServiceWorker` to pekko typed [#1229](https://github.com/ie3-institute/simona/issues/1229)
167170
- Converting `PrimaryServiceProxy` to pekko typed [#1230](https://github.com/ie3-institute/simona/issues/1230)
171+
- Made some methods of `PvModel` static [#1217](https://github.com/ie3-institute/simona/issues/1217)
172+
- FlexOptions types in `FlexibilityMessage` [#1306](https://github.com/ie3-institute/simona/issues/1306)
173+
- Isolate solar radiation calculations of PvModel to its own object [#1327](https://github.com/ie3-institute/simona/issues/1327)
168174
- Upgraded `scala2` to `scala3` [#53](https://github.com/ie3-institute/simona/issues/53)
169175

170176
### Fixed
@@ -228,6 +234,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
228234
- Fix vn_simona time series mapping [#1288](https://github.com/ie3-institute/simona/issues/1288)
229235
- Fix hierarchical em structures leading to exception while initializing [#1293](https://github.com/ie3-institute/simona/issues/1293)
230236
- Fix failing `ExtEvDataServiceSpec` [#1297](https://github.com/ie3-institute/simona/issues/1297)
237+
- Fixed pekko config not written as output [#1302](https://github.com/ie3-institute/simona/issues/1302)
238+
- Cleanups and log capturing in `ExtEvDataServiceSpec` [#1320](https://github.com/ie3-institute/simona/issues/1320)
231239

232240
### Removed
233241
- Removed `SimonaListerner` and related code [#1205](https://github.com/ie3-institute/simona/issues/1205)

build.gradle

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ plugins {
55
id 'scala' // scala support
66
id 'signing'
77
id 'maven-publish' // publish to a maven repo (local or mvn central, has to be defined)
8-
id 'com.diffplug.spotless' version '6.25.0' // code format
8+
id 'com.diffplug.spotless' version '7.0.2' // code format
99
id "com.github.ben-manes.versions" version '0.52.0'
1010
id "de.undercouch.download" version "5.6.0" // downloads plugin
1111
id "kr.motd.sphinx" version "2.10.1" // documentation generation
1212
id 'com.gradleup.shadow' version '8.3.6' // fat jar
13-
id "org.sonarqube" version "6.0.1.5171" // sonarqube
13+
id "org.sonarqube" version "6.1.0.5360" // sonarqube
1414
id "org.scoverage" version "8.1" // scala code coverage scoverage
1515
id 'org.hidetake.ssh' version '2.11.2'
1616
id 'net.thauvin.erik.gradle.semver' version '1.0.4' // semantic versioning
@@ -210,8 +210,7 @@ tasks.withType(ScalaCompile).configureEach {
210210
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
211211
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
212212
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/src/",
213-
"-P:scapegoat:disabledInspections:VariableShadowing",
214-
"-P:scapegoat:ignoredFiles:.*/SimonaConfig.scala" // see scapegoat-sbt page for this param
213+
"-P:scapegoat:disabledInspections:TryGet"
215214
]
216215
scalaCompileOptions.forkOptions.jvmArgs = [
217216
'-Xss2m',
@@ -224,7 +223,7 @@ compileTestScala {
224223
scalaCompileOptions.additionalParameters = scala3compilerOptions + [
225224
"-Xplugin:" + configurations.scalaCompilerPlugin.asPath,
226225
"-P:scapegoat:dataDir:" + project.layout.buildDirectory.get().asFile.absolutePath + "/reports/scapegoat/testsrc/",
227-
"-P:scapegoat:disabledInspections:VariableShadowing"
226+
"-P:scapegoat:disabledInspections:TryGet"
228227
]
229228
}
230229

docs/readthedocs/models/thermal_house_model.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
This page documents the functionality of the thermal house available in SIMONA.
66

7+
78
## Behaviour
89

910
This house model represents the thermal behaviour of a building. It represents a simple shoebox with thermal capacity and transmission losses.
@@ -21,7 +22,9 @@ As the storage is initialised as empty, the heat source will start charging the
2122

2223
### Behaviour under EM control
2324

24-
Currently, not fully supported. Will be fixed by [PR #1159](https://github.com/ie3-institute/simona/pull/1159)
25+
When {ref}`em` is applied to the heat source of this building, the thermal behaviour should be basically the same as without EM control, so internal temperature of the house should remain between the target temperature and the lower temperature limit.
26+
27+
However, for flexibility usage, the energy management system can turn on the heat source whenever the thermal house has additional demand. Same for the thermal storage. When the heat source is EM controlled, the thermal storage will only be recharged when the flexibility strategy allows. E.g. when there is surplus energy from PV plant.
2528

2629
## Attributes, Units and Remarks
2730

gradle/scripts/spotless.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ spotless {
1919
// same as groovy, but for .gradle (defaults to '*.gradle')
2020
target('*.gradle', 'gradle/scripts/*.gradle')
2121
greclipse()
22-
indentWithSpaces(2)
22+
leadingTabsToSpaces(2)
2323
}
2424

2525
//sets a license header, removes unused imports and formats conforming to the scala fmt formatter
@@ -32,15 +32,15 @@ spotless {
3232
format ('misc') {
3333
target('**/.gitignore', 'configs/**')
3434
trimTrailingWhitespace()
35-
indentWithTabs()
35+
leadingSpacesToTabs()
3636
endWithNewline()
3737
}
3838

3939
/* Formats markdown files, just like the other misc files, but without trimming trailing white spaces (nested
4040
* enumerations) */
4141
format('md') {
4242
target('**/*.md')
43-
indentWithSpaces(2)
43+
leadingTabsToSpaces(2)
4444
endWithNewline()
4545
}
4646
}

src/main/scala/edu/ie3/simona/agent/em/EmAgent.scala

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import edu.ie3.simona.ontology.messages.SchedulerMessage.{
2424
ScheduleActivation,
2525
}
2626
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage._
27-
import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions
27+
import edu.ie3.simona.ontology.messages.flex.MinMaxFlexOptions
2828
import edu.ie3.simona.ontology.messages.{Activation, SchedulerMessage}
2929
import edu.ie3.simona.util.TickUtil.TickLong
3030
import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble
@@ -33,6 +33,7 @@ import org.apache.pekko.actor.typed.scaladsl.Behaviors
3333
import org.apache.pekko.actor.typed.{ActorRef, Behavior}
3434

3535
import java.time.ZonedDateTime
36+
import scala.util.{Failure, Try}
3637

3738
/** Energy management agent that receives flex options from and issues control
3839
* messages to connected agents
@@ -223,14 +224,17 @@ object EmAgent {
223224
modelShell: EmModelShell,
224225
flexOptionsCore: EmDataCore.AwaitingFlexOptions,
225226
): Behavior[Request] = Behaviors.receiveMessagePartial {
226-
case flexOptions: ProvideFlexOptions =>
227-
val updatedCore = flexOptionsCore.handleFlexOptions(flexOptions)
227+
case provideFlex: ProvideFlexOptions =>
228+
val updatedCore = flexOptionsCore.handleFlexOptions(
229+
provideFlex.modelUuid,
230+
provideFlex.flexOptions,
231+
)
228232

229233
if (updatedCore.isComplete) {
230234

231235
val allFlexOptions = updatedCore.getFlexOptions
232236

233-
val (emRef, emMin, emMax) =
237+
val emFlexOptions =
234238
modelShell.aggregateFlexOptions(allFlexOptions)
235239

236240
if (emData.outputConfig.flexResult) {
@@ -239,9 +243,9 @@ object EmAgent {
239243
emData.simulationStartDate
240244
),
241245
modelShell.uuid,
242-
emRef.toMegawatts.asMegaWatt,
243-
emMin.toMegawatts.asMegaWatt,
244-
emMax.toMegawatts.asMegaWatt,
246+
emFlexOptions.ref.toMegawatts.asMegaWatt,
247+
emFlexOptions.min.toMegawatts.asMegaWatt,
248+
emFlexOptions.max.toMegawatts.asMegaWatt,
245249
)
246250

247251
emData.listener.foreach {
@@ -252,19 +256,15 @@ object EmAgent {
252256
emData.parentData match {
253257
case Right(flexStateData) =>
254258
// provide aggregate flex options to parent
255-
val flexMessage = ProvideMinMaxFlexOptions(
259+
flexStateData.emAgent ! ProvideFlexOptions(
256260
modelShell.uuid,
257-
emRef,
258-
emMin,
259-
emMax,
261+
emFlexOptions,
260262
)
261263

262-
flexStateData.emAgent ! flexMessage
263-
264264
val updatedEmData = emData.copy(
265265
parentData = Right(
266266
flexStateData.copy(
267-
lastFlexOptions = Some(flexMessage)
267+
lastFlexOptions = Some(emFlexOptions)
268268
)
269269
)
270270
)
@@ -327,10 +327,17 @@ object EmAgent {
327327
)
328328
)
329329

330-
val setPointActivePower = EmTools.determineFlexPower(
331-
ownFlexOptions,
332-
flexCtrl,
333-
)
330+
val setPointActivePower =
331+
Try(EmTools.determineFlexPower(ownFlexOptions, flexCtrl))
332+
.recoverWith(exception =>
333+
Failure(
334+
new CriticalFailureException(
335+
s"Determining flex power failed for EmAgent ${modelShell.uuid}",
336+
exception,
337+
)
338+
)
339+
)
340+
.get
334341

335342
// flex options calculated by connected agents
336343
val receivedFlexOptions = flexOptionsCore.getFlexOptions

src/main/scala/edu/ie3/simona/agent/em/EmDataCore.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import edu.ie3.simona.agent.em.EmAgent.Actor
1010
import edu.ie3.simona.agent.em.FlexCorrespondenceStore.WithTime
1111
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower
1212
import edu.ie3.simona.exceptions.CriticalFailureException
13+
import edu.ie3.simona.ontology.messages.flex.FlexOptions
1314
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage._
1415
import edu.ie3.simona.util.SimonaConstants.INIT_SIM_TICK
1516
import edu.ie3.util.scala.collection.mutable.PriorityMultiBiSet
@@ -251,13 +252,13 @@ object EmDataCore {
251252
* The updated [[AwaitingFlexOptions]] core
252253
*/
253254
def handleFlexOptions(
254-
flexOptions: ProvideFlexOptions
255+
modelUuid: UUID,
256+
flexOptions: FlexOptions,
255257
): AwaitingFlexOptions =
256258
copy(
257259
correspondences =
258-
correspondences.updateFlexOptions(flexOptions, activeTick),
259-
awaitedConnectedAgents =
260-
awaitedConnectedAgents.excl(flexOptions.modelUuid),
260+
correspondences.updateFlexOptions(modelUuid, flexOptions, activeTick),
261+
awaitedConnectedAgents = awaitedConnectedAgents.excl(modelUuid),
261262
)
262263

263264
/** Checks whether all awaited flex options have been received, and we can
@@ -273,7 +274,7 @@ object EmDataCore {
273274
* @return
274275
* all relevant flex options
275276
*/
276-
def getFlexOptions: Iterable[(UUID, ProvideFlexOptions)] =
277+
def getFlexOptions: Iterable[(UUID, FlexOptions)] =
277278
correspondences.store.flatMap { case (model, correspondence) =>
278279
correspondence.receivedFlexOptions.map(model -> _.get)
279280
}

src/main/scala/edu/ie3/simona/agent/em/FlexCorrespondenceStore.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@ import edu.ie3.simona.agent.em.FlexCorrespondenceStore.{
1111
WithTime,
1212
}
1313
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.ComplexPower
14-
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{
15-
IssueFlexControl,
16-
ProvideFlexOptions,
17-
}
14+
import edu.ie3.simona.ontology.messages.flex.FlexOptions
15+
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.IssueFlexControl
1816

1917
import java.time.ZonedDateTime
2018
import java.util.UUID
@@ -36,6 +34,8 @@ final case class FlexCorrespondenceStore(
3634
/** Updates the latest flex options for the flex provider, overwriting the
3735
* former flex options, if applicable
3836
*
37+
* @param modelUuid
38+
* The UUID of the flex provider model
3939
* @param flexOptions
4040
* The new flex options
4141
* @param tick
@@ -44,11 +44,12 @@ final case class FlexCorrespondenceStore(
4444
* The updated flex options store
4545
*/
4646
def updateFlexOptions(
47-
flexOptions: ProvideFlexOptions,
47+
modelUuid: UUID,
48+
flexOptions: FlexOptions,
4849
tick: Long,
4950
): FlexCorrespondenceStore =
5051
updateCorrespondence(
51-
flexOptions.modelUuid,
52+
modelUuid,
5253
_.copy(receivedFlexOptions = Some(WithTime(flexOptions, tick))),
5354
)
5455

@@ -122,7 +123,7 @@ object FlexCorrespondenceStore {
122123
* The latest result that has been received by the EmAgent
123124
*/
124125
final case class FlexCorrespondence(
125-
receivedFlexOptions: Option[WithTime[ProvideFlexOptions]] = None,
126+
receivedFlexOptions: Option[WithTime[FlexOptions]] = None,
126127
issuedCtrlMsg: Option[WithTime[IssueFlexControl]] = None,
127128
receivedResult: Option[WithTime[ComplexPower]] = None,
128129
)

src/main/scala/edu/ie3/simona/agent/participant/ParticipantAgentFundamentals.scala

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ import edu.ie3.simona.model.participant.{
8181
import edu.ie3.simona.ontology.messages.Activation
8282
import edu.ie3.simona.ontology.messages.SchedulerMessage.Completion
8383
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage._
84-
import edu.ie3.simona.ontology.messages.flex.MinMaxFlexibilityMessage.ProvideMinMaxFlexOptions
84+
import edu.ie3.simona.ontology.messages.flex.MinMaxFlexOptions
8585
import edu.ie3.simona.util.TickUtil._
8686
import edu.ie3.util.quantities.PowerSystemUnits._
8787
import edu.ie3.util.quantities.QuantityUtils.RichQuantityDouble
@@ -676,7 +676,10 @@ protected trait ParticipantAgentFundamentals[
676676
)
677677
)
678678

679-
updatedFlexData.emAgent ! newestFlexOptions
679+
updatedFlexData.emAgent ! ProvideFlexOptions(
680+
participantStateData.modelUuid,
681+
newestFlexOptions,
682+
)
680683

681684
updatedBaseStateData
682685
}
@@ -703,15 +706,14 @@ protected trait ParticipantAgentFundamentals[
703706
// does not include reactive power which could change later)
704707
if (baseStateData.outputConfig.flexResult) {
705708
val flexResult = flexOptions match {
706-
case ProvideMinMaxFlexOptions(
707-
modelUuid,
709+
case MinMaxFlexOptions(
708710
referencePower,
709711
minPower,
710712
maxPower,
711713
) =>
712714
new FlexOptionsResult(
713715
tick.toDateTime,
714-
modelUuid,
716+
baseStateData.modelUuid,
715717
referencePower.toMegawatts.asMegaWatt,
716718
minPower.toMegawatts.asMegaWatt,
717719
maxPower.toMegawatts.asMegaWatt,
@@ -753,7 +755,16 @@ protected trait ParticipantAgentFundamentals[
753755
)
754756

755757
val setPointActivePower =
756-
EmTools.determineFlexPower(flexOptions, flexCtrl)
758+
Try(EmTools.determineFlexPower(flexOptions, flexCtrl))
759+
.recoverWith(exception =>
760+
Failure(
761+
new CriticalFailureException(
762+
s"Determining flex power failed for model ${baseStateData.modelUuid}",
763+
exception,
764+
)
765+
)
766+
)
767+
.get
757768

758769
/* Handle the flex signal */
759770
val (updatedState, result, flexChangeIndicator) =

src/main/scala/edu/ie3/simona/agent/participant/statedata/BaseStateData.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import edu.ie3.simona.model.participant.{
1616
ModelState,
1717
SystemParticipant,
1818
}
19+
import edu.ie3.simona.ontology.messages.flex.FlexOptions
1920
import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{
2021
FlexRequest,
2122
FlexResponse,
22-
ProvideFlexOptions,
2323
}
2424
import org.apache.pekko.actor.typed.ActorRef
2525
import org.apache.pekko.actor.{ActorRef => ClassicActorRef}
@@ -250,7 +250,7 @@ object BaseStateData {
250250
final case class FlexControlledData(
251251
emAgent: ActorRef[FlexResponse],
252252
flexAdapter: ActorRef[FlexRequest],
253-
lastFlexOptions: Option[ProvideFlexOptions] = None,
253+
lastFlexOptions: Option[FlexOptions] = None,
254254
)
255255

256256
/** Updates the base state data with the given value stores

src/main/scala/edu/ie3/simona/agent/participant2/ParticipantAgent.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ object ParticipantAgent {
455455
throw new CriticalFailureException(
456456
"Received flex activation while not controlled by EM"
457457
),
458-
_.emAgent ! shellWithFlex.flexOptions,
458+
_.emAgent ! ProvideFlexOptions(
459+
shellWithFlex.uuid,
460+
shellWithFlex.getFlexOptions,
461+
),
459462
)
460463

461464
(shellWithFlex, gridAdapter)

0 commit comments

Comments
 (0)