@@ -18,9 +18,9 @@ import edu.ie3.simona.exceptions.CriticalFailureException
18
18
import edu .ie3 .simona .model .SystemComponent
19
19
import edu .ie3 .simona .model .em .EmTools
20
20
import edu .ie3 .simona .model .participant2 .ParticipantModel .{
21
- OperationChangeIndicator ,
22
21
ModelState ,
23
22
OperatingPoint ,
23
+ OperationChangeIndicator ,
24
24
OperationRelevantData ,
25
25
}
26
26
import edu .ie3 .simona .model .participant2 .ParticipantModelShell .ResultsContainer
@@ -29,6 +29,7 @@ import edu.ie3.simona.ontology.messages.flex.FlexibilityMessage.{
29
29
ProvideFlexOptions ,
30
30
}
31
31
import edu .ie3 .simona .ontology .messages .flex .MinMaxFlexibilityMessage .ProvideMinMaxFlexOptions
32
+ import edu .ie3 .simona .service .ServiceType
32
33
import edu .ie3 .simona .util .TickUtil .TickLong
33
34
import edu .ie3 .util .scala .OperationInterval
34
35
import edu .ie3 .util .scala .quantities .DefaultQuantities ._
@@ -38,6 +39,7 @@ import squants.Dimensionless
38
39
import squants .energy .Power
39
40
40
41
import java .time .ZonedDateTime
42
+ import java .util .UUID
41
43
import scala .reflect .ClassTag
42
44
43
45
/** Takes care of:
@@ -53,18 +55,75 @@ final case class ParticipantModelShell[
53
55
S <: ModelState ,
54
56
OR <: OperationRelevantData ,
55
57
](
56
- model : ParticipantModel [OP , S , OR ] with ParticipantFlexibility [OP , S , OR ],
57
- operationInterval : OperationInterval ,
58
- simulationStartDate : ZonedDateTime ,
59
- state : Option [S ] = None ,
60
- relevantData : Option [OR ] = None ,
61
- flexOptions : Option [ProvideFlexOptions ] = None ,
62
- lastOperatingPoint : Option [OP ] = None ,
63
- operatingPoint : Option [OP ] = None ,
64
- private val modelChange : OperationChangeIndicator =
58
+ private val model : ParticipantModel [OP , S , OR ]
59
+ with ParticipantFlexibility [OP , S , OR ],
60
+ private val operationInterval : OperationInterval ,
61
+ private val simulationStartDate : ZonedDateTime ,
62
+ private val _state : Option [S ] = None ,
63
+ private val _relevantData : Option [OR ] = None ,
64
+ private val _flexOptions : Option [ProvideFlexOptions ] = None ,
65
+ private val _lastOperatingPoint : Option [OP ] = None ,
66
+ private val _operatingPoint : Option [OP ] = None ,
67
+ private val _modelChange : OperationChangeIndicator =
65
68
OperationChangeIndicator (),
66
69
) {
67
70
71
+ /** Returns the model UUID.
72
+ *
73
+ * @return
74
+ * the UUID of the model
75
+ */
76
+ def uuid : UUID = model.uuid
77
+
78
+ /** Returns the types of required secondary services for the model to
79
+ * function.
80
+ *
81
+ * @return
82
+ * the types of secondary services required
83
+ */
84
+ def requiredServices : Iterable [ServiceType ] =
85
+ model.getRequiredSecondaryServices
86
+
87
+ /** Returns the current relevant data, if present, or throws a
88
+ * [[CriticalFailureException ]]. Only call this if you are certain the
89
+ * operation relevant data has been set.
90
+ *
91
+ * @return
92
+ * the operation relevant data
93
+ */
94
+ private def getRelevantData : OR =
95
+ _relevantData.getOrElse(
96
+ throw new CriticalFailureException (" No relevant data available!" )
97
+ )
98
+
99
+ /** Returns the current operating point, if present, or throws a
100
+ * [[CriticalFailureException ]]. Only call this if you are certain the
101
+ * operating point has been set.
102
+ *
103
+ * @return
104
+ * the operating point
105
+ */
106
+ private def operatingPoint : OP = {
107
+ _operatingPoint
108
+ .getOrElse(
109
+ throw new CriticalFailureException (" No operating point available!" )
110
+ )
111
+ }
112
+
113
+ /** Returns the current flex options, if present, or throws a
114
+ * [[CriticalFailureException ]]. Only call this if you are certain the flex
115
+ * options have been set.
116
+ *
117
+ * @return
118
+ * the flex options
119
+ */
120
+ def flexOptions : ProvideFlexOptions =
121
+ _flexOptions.getOrElse(
122
+ throw new CriticalFailureException (
123
+ " Flex options have not been calculated!"
124
+ )
125
+ )
126
+
68
127
def updateRelevantData (
69
128
receivedData : Seq [Data ],
70
129
nodalVoltage : Dimensionless ,
@@ -79,7 +138,7 @@ final case class ParticipantModelShell[
79
138
currentSimulationTime,
80
139
)
81
140
82
- copy(relevantData = Some (updatedRelevantData))
141
+ copy(_relevantData = Some (updatedRelevantData))
83
142
}
84
143
85
144
/** Update operating point when the model is '''not''' em-controlled.
@@ -92,12 +151,10 @@ final case class ParticipantModelShell[
92
151
): ParticipantModelShell [OP , S , OR ] = {
93
152
val currentState = determineCurrentState(currentTick)
94
153
95
- def modelOperatingPoint () = {
154
+ def modelOperatingPoint (): ( OP , OperationChangeIndicator ) = {
96
155
val (modelOp, modelNextTick) = model.determineOperatingPoint(
97
156
currentState,
98
- relevantData.getOrElse(
99
- throw new CriticalFailureException (" No relevant data available!" )
100
- ),
157
+ getRelevantData,
101
158
)
102
159
val modelIndicator =
103
160
OperationChangeIndicator (changesAtTick = modelNextTick)
@@ -108,10 +165,10 @@ final case class ParticipantModelShell[
108
165
determineOperatingPoint(modelOperatingPoint, currentTick)
109
166
110
167
copy(
111
- state = Some (currentState),
112
- lastOperatingPoint = operatingPoint ,
113
- operatingPoint = Some (newOperatingPoint),
114
- modelChange = newChangeIndicator,
168
+ _state = Some (currentState),
169
+ _lastOperatingPoint = _operatingPoint ,
170
+ _operatingPoint = Some (newOperatingPoint),
171
+ _modelChange = newChangeIndicator,
115
172
)
116
173
}
117
174
@@ -122,23 +179,16 @@ final case class ParticipantModelShell[
122
179
currentTick : Long ,
123
180
nodalVoltage : Dimensionless ,
124
181
): ResultsContainer = {
125
- val op = operatingPoint
126
- .getOrElse(
127
- throw new CriticalFailureException (" No operating point available!" )
128
- )
129
-
130
- val activePower = op.activePower
131
- val reactivePower = op.reactivePower.getOrElse(
182
+ val activePower = operatingPoint.activePower
183
+ val reactivePower = operatingPoint.reactivePower.getOrElse(
132
184
activeToReactivePowerFunc(nodalVoltage)(activePower)
133
185
)
134
186
val complexPower = ComplexPower (activePower, reactivePower)
135
187
136
188
val participantResults = model.createResults(
137
- state.getOrElse(
138
- throw new CriticalFailureException (" No model state available!" )
139
- ),
140
- lastOperatingPoint,
141
- op,
189
+ determineCurrentState(currentTick),
190
+ _lastOperatingPoint,
191
+ operatingPoint,
142
192
complexPower,
143
193
currentTick.toDateTime(simulationStartDate),
144
194
)
@@ -156,16 +206,14 @@ final case class ParticipantModelShell[
156
206
if (operationInterval.includes(currentTick)) {
157
207
model.calcFlexOptions(
158
208
currentState,
159
- relevantData.getOrElse(
160
- throw new CriticalFailureException (" No relevant data available!" )
161
- ),
209
+ getRelevantData,
162
210
)
163
211
} else {
164
212
// Out of operation, there's no way to operate besides 0 kW
165
213
ProvideMinMaxFlexOptions .noFlexOption(model.uuid, zeroKW)
166
214
}
167
215
168
- copy(state = Some (currentState), flexOptions = Some (flexOptions))
216
+ copy(_state = Some (currentState), _flexOptions = Some (flexOptions))
169
217
}
170
218
171
219
/** Update operating point on receiving [[IssueFlexControl ]], i.e. when the
@@ -181,8 +229,8 @@ final case class ParticipantModelShell[
181
229
182
230
val currentTick = flexControl.tick
183
231
184
- def modelOperatingPoint () = {
185
- val fo = flexOptions .getOrElse(
232
+ def modelOperatingPoint (): ( OP , OperationChangeIndicator ) = {
233
+ val fo = _flexOptions .getOrElse(
186
234
throw new CriticalFailureException (" No flex options available!" )
187
235
)
188
236
@@ -193,9 +241,7 @@ final case class ParticipantModelShell[
193
241
194
242
model.handlePowerControl(
195
243
currentState,
196
- relevantData.getOrElse(
197
- throw new CriticalFailureException (" No relevant data available!" )
198
- ),
244
+ getRelevantData,
199
245
fo,
200
246
setPointActivePower,
201
247
)
@@ -205,10 +251,10 @@ final case class ParticipantModelShell[
205
251
determineOperatingPoint(modelOperatingPoint, currentTick)
206
252
207
253
copy(
208
- state = Some (currentState),
209
- lastOperatingPoint = operatingPoint ,
210
- operatingPoint = Some (newOperatingPoint),
211
- modelChange = newChangeIndicator,
254
+ _state = Some (currentState),
255
+ _lastOperatingPoint = _operatingPoint ,
256
+ _operatingPoint = Some (newOperatingPoint),
257
+ _modelChange = newChangeIndicator,
212
258
)
213
259
}
214
260
@@ -238,12 +284,12 @@ final case class ParticipantModelShell[
238
284
// the end of the operation interval
239
285
val adaptedNextTick =
240
286
Seq (
241
- modelChange .changesAtTick,
287
+ _modelChange .changesAtTick,
242
288
nextDataTick,
243
289
Option (operationInterval.end),
244
290
).flatten.minOption
245
291
246
- modelChange .copy(changesAtTick = adaptedNextTick)
292
+ _modelChange .copy(changesAtTick = adaptedNextTick)
247
293
} else {
248
294
// If the model is not active, all activation ticks are ignored besides
249
295
// potentially the operation start
@@ -262,26 +308,26 @@ final case class ParticipantModelShell[
262
308
val currentState = determineCurrentState(request.tick)
263
309
val updatedState = model.handleRequest(currentState, ctx, request)
264
310
265
- copy(state = Some (updatedState))
311
+ copy(_state = Some (updatedState))
266
312
}
267
313
268
314
private def determineCurrentState (currentTick : Long ): S = {
269
315
// new state is only calculated if there's an old state and an operating point
270
- val currentState = state
271
- .zip(operatingPoint )
316
+ val state = _state
317
+ .zip(_operatingPoint )
272
318
.flatMap { case (st, op) =>
273
319
Option .when(st.tick < currentTick) {
274
320
model.determineState(st, op, currentTick)
275
321
}
276
322
}
277
323
.getOrElse(model.initialState(currentTick))
278
324
279
- if (currentState .tick != currentTick)
325
+ if (state .tick != currentTick)
280
326
throw new CriticalFailureException (
281
- s " New state $currentState is not set to current tick $currentTick"
327
+ s " New state $state is not set to current tick $currentTick"
282
328
)
283
329
284
- currentState
330
+ state
285
331
}
286
332
287
333
}
0 commit comments