-
Notifications
You must be signed in to change notification settings - Fork 5
/
SystemParticipantValidationUtils.java
682 lines (624 loc) · 26.3 KB
/
SystemParticipantValidationUtils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
/*
* © 2021. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/
package edu.ie3.datamodel.utils.validation;
import static edu.ie3.datamodel.models.StandardUnits.*;
import edu.ie3.datamodel.exceptions.InvalidEntityException;
import edu.ie3.datamodel.exceptions.NotImplementedException;
import edu.ie3.datamodel.exceptions.ValidationException;
import edu.ie3.datamodel.models.input.InputEntity;
import edu.ie3.datamodel.models.input.system.*;
import edu.ie3.datamodel.models.input.system.type.*;
import edu.ie3.datamodel.utils.ExceptionUtils;
import edu.ie3.datamodel.utils.options.Failure;
import edu.ie3.datamodel.utils.options.Success;
import edu.ie3.datamodel.utils.options.Try;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import javax.measure.Quantity;
import javax.measure.quantity.Dimensionless;
import tech.units.indriya.ComparableQuantity;
import tech.units.indriya.quantity.Quantities;
import tech.units.indriya.unit.Units;
public class SystemParticipantValidationUtils extends ValidationUtils {
/** Private Constructor as this class is not meant to be instantiated */
private SystemParticipantValidationUtils() {
throw new IllegalStateException("Don't try and instantiate a Utility class.");
}
/**
* Validates a system participant if: <br>
* - it is not null <br>
* - its qCharacteristics are not null
*
* <p>A "distribution" method, that forwards the check request to specific implementations to
* fulfill the checking task, based on the class of the given object.
*
* @param systemParticipant systemParticipant to validate
* @return a try object either containing an {@link ValidationException} or an empty Success
*/
protected static Try<Void, ValidationException> check(SystemParticipantInput systemParticipant) {
try {
checkNonNull(systemParticipant, "a system participant");
} catch (InvalidEntityException e) {
return new Failure<>(
new InvalidEntityException(
"Validation not possible because received object {"
+ systemParticipant
+ "} was null",
e));
}
Try<Void, InvalidEntityException> qCharacteristic;
if (systemParticipant.getqCharacteristics() == null) {
qCharacteristic =
new Failure<>(
new InvalidEntityException(
"Reactive power characteristics of system participant is not defined",
systemParticipant));
} else {
qCharacteristic = Success.empty();
}
Try<Void, InvalidEntityException> participant;
// Further checks for subclasses
if (BmInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkBm((BmInput) systemParticipant));
} else if (ChpInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkChp((ChpInput) systemParticipant));
} else if (EvInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkEv((EvInput) systemParticipant));
} else if (FixedFeedInInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = checkFixedFeedIn((FixedFeedInInput) systemParticipant);
} else if (HpInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkHp((HpInput) systemParticipant));
} else if (LoadInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = checkLoad((LoadInput) systemParticipant);
} else if (PvInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = checkPv((PvInput) systemParticipant);
} else if (StorageInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkStorage((StorageInput) systemParticipant));
} else if (WecInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(() -> checkWec((WecInput) systemParticipant));
} else if (EvcsInput.class.isAssignableFrom(systemParticipant.getClass())) {
participant = Try.apply(SystemParticipantValidationUtils::checkEvcs);
} else {
participant =
new Failure<>(
new InvalidEntityException(
"Validation failed due to: ", checkNotImplementedException(systemParticipant)));
}
List<InvalidEntityException> exceptions =
Stream.of(qCharacteristic, participant)
.filter(Try::isFailure)
.map(Try::getException)
.toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a system participant type if: <br>
* - it is not null <br>
* - capex is not null and not negative <br>
* - opex is not null and not negative <br>
* - sRated is not null and not negative <br>
* - cosphiRated is between zero and one
*
* <p>A "distribution" method, that forwards the check request to specific implementations to
* fulfill the checking task, based on the class of the given object.
*
* @param systemParticipantTypeInput systemParticipant Type to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
protected static Try<Void, InvalidEntityException> checkType(
SystemParticipantTypeInput systemParticipantTypeInput) {
try {
checkNonNull(systemParticipantTypeInput, "a system participant type");
} catch (InvalidEntityException e) {
return new Failure<>(
new InvalidEntityException(
"Validation not possible because received object {"
+ systemParticipantTypeInput
+ "} was null",
e));
}
List<InvalidEntityException> exceptions = new ArrayList<>();
if ((systemParticipantTypeInput.getCapex() == null)
|| (systemParticipantTypeInput.getOpex() == null)
|| (systemParticipantTypeInput.getsRated() == null)) {
exceptions.add(
new InvalidEntityException(
"At least one of capex, opex, or sRated is null", systemParticipantTypeInput));
}
Try<Void, InvalidEntityException> negative =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {
systemParticipantTypeInput.getCapex(),
systemParticipantTypeInput.getOpex(),
systemParticipantTypeInput.getsRated()
},
systemParticipantTypeInput));
Try<Void, InvalidEntityException> ratedPF =
Try.apply(
() ->
checkRatedPowerFactor(
systemParticipantTypeInput, systemParticipantTypeInput.getCosPhiRated()));
Try<Void, InvalidEntityException> type;
if (BmTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkBmType((BmTypeInput) systemParticipantTypeInput);
} else if (ChpTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkChpType((ChpTypeInput) systemParticipantTypeInput);
} else if (EvTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkEvType((EvTypeInput) systemParticipantTypeInput);
} else if (HpTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkHpType((HpTypeInput) systemParticipantTypeInput);
} else if (StorageTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkStorageType((StorageTypeInput) systemParticipantTypeInput);
} else if (WecTypeInput.class.isAssignableFrom(systemParticipantTypeInput.getClass())) {
type = checkWecType((WecTypeInput) systemParticipantTypeInput);
} else {
type =
new Failure<>(
new InvalidEntityException(
"Validation failed due to: ",
checkNotImplementedException(systemParticipantTypeInput)));
}
exceptions.addAll(
Stream.of(negative, ratedPF, type).filter(Try::isFailure).map(Try::getException).toList());
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a bmInput if: <br>
* - {@link SystemParticipantValidationUtils#checkBmType(BmTypeInput)} confirms a valid type
* properties <br>
*
* @param bmInput BmInput to validate
*/
private static void checkBm(BmInput bmInput) {
checkType(bmInput.getType());
}
/**
* Validates a bmTypeInput if: <br>
* - its active power gradient is not negative <br>
* - its efficiency of assets inverter is between 0% and 100%
*
* @param bmTypeInput BmTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkBmType(BmTypeInput bmTypeInput) {
Try<Void, InvalidEntityException> negative =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {bmTypeInput.getActivePowerGradient()}, bmTypeInput));
Try<Void, InvalidEntityException> betweenZero =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
bmTypeInput, bmTypeInput.getEtaConv(), "Efficiency of inverter"));
List<InvalidEntityException> exceptions =
Stream.of(negative, betweenZero).filter(Try::isFailure).map(Try::getException).toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a chpInput if: <br>
* - {@link SystemParticipantValidationUtils#checkChpType(ChpTypeInput)} confirms a valid type
* properties
*
* @param chpInput ChpInput to validate
*/
private static void checkChp(ChpInput chpInput) {
checkType(chpInput.getType());
}
/**
* Validates a chpTypeInput if: <br>
* - its efficiency of the electrical inverter is between 0% and 100% <br>
* - its thermal efficiency of the system is between 0% and 100% <br>
* - its rated thermal power is positive <br>
* - its needed self-consumption is not negative
*
* @param chpTypeInput ChpTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkChpType(ChpTypeInput chpTypeInput) {
Try<Void, InvalidEntityException> negative =
Try.apply(
() ->
detectNegativeQuantities(new Quantity<?>[] {chpTypeInput.getpOwn()}, chpTypeInput));
Try<Void, InvalidEntityException> zeroOrNegative =
Try.apply(
() ->
detectZeroOrNegativeQuantities(
new Quantity<?>[] {chpTypeInput.getpThermal()}, chpTypeInput));
Try<Void, InvalidEntityException> betweenZero =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
chpTypeInput, chpTypeInput.getEtaEl(), "Electrical efficiency"));
Try<Void, InvalidEntityException> betweenZero2 =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
chpTypeInput, chpTypeInput.getEtaThermal(), "Thermal efficiency"));
List<InvalidEntityException> exceptions =
Stream.of(negative, zeroOrNegative, betweenZero, betweenZero2)
.filter(Try::isFailure)
.map(Try::getException)
.toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a EvInput if: <br>
* - {@link SystemParticipantValidationUtils#checkEvType(EvTypeInput)} confirms a valid type
* properties
*
* @param evInput EvInput to validate
*/
private static void checkEv(EvInput evInput) {
checkType(evInput.getType());
}
/**
* Validates a EvTypeInput if: <br>
* - its available battery capacity is positive <br>
* - its energy consumption per driven kilometre is positive
*
* @param evTypeInput EvTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkEvType(EvTypeInput evTypeInput) {
return Try.apply(
() ->
detectZeroOrNegativeQuantities(
new Quantity<?>[] {evTypeInput.geteStorage(), evTypeInput.geteCons()},
evTypeInput));
}
/**
* Validates a FixedFeedInInput if: <br>
* - its rated apparent power is not negative <br>
* - its rated power factor is between 0 and 1
*
* @param fixedFeedInInput FixedFeedInInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkFixedFeedIn(
FixedFeedInInput fixedFeedInInput) {
Try<Void, InvalidEntityException> negative =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {fixedFeedInInput.getsRated()}, fixedFeedInInput));
Try<Void, InvalidEntityException> ratedPF =
Try.apply(() -> checkRatedPowerFactor(fixedFeedInInput, fixedFeedInInput.getCosPhiRated()));
List<InvalidEntityException> exceptions =
Stream.of(negative, ratedPF).filter(Try::isFailure).map(Try::getException).toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a HpInput if: <br>
* - {@link SystemParticipantValidationUtils#checkHpType(HpTypeInput)} confirms a valid type
* properties
*
* @param hpInput HpInput to validate
*/
private static void checkHp(HpInput hpInput) {
checkType(hpInput.getType());
}
/**
* Validates a HpTypeInput if: <br>
* - its rated thermal power is positive
*
* @param hpTypeInput HpTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkHpType(HpTypeInput hpTypeInput) {
return Try.apply(
() ->
detectZeroOrNegativeQuantities(
new Quantity<?>[] {hpTypeInput.getpThermal()}, hpTypeInput));
}
/**
* Validates a LoadInput if: <br>
* - its standard load profile is not null <br>
* - its rated apparent power is not negative <br>
* - its annual energy consumption is not negative <br>
* - its rated power factor is between 0 and 1
*
* @param loadInput LoadInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkLoad(LoadInput loadInput) {
List<InvalidEntityException> exceptions = new ArrayList<>();
if (loadInput.getLoadProfile() == null) {
exceptions.add(
new InvalidEntityException("No standard load profile defined for load", loadInput));
}
Try<Void, InvalidEntityException> negative =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {loadInput.getsRated(), loadInput.geteConsAnnual()},
loadInput));
Try<Void, InvalidEntityException> ratedPF =
Try.apply(() -> checkRatedPowerFactor(loadInput, loadInput.getCosPhiRated()));
exceptions.addAll(
Stream.of(negative, ratedPF).filter(Try::isFailure).map(Try::getException).toList());
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a PvInput if: <br>
* - its rated apparent power is not negative <br>
* - its albedo value of the plant's surrounding is between 0 and 1 <br>
* - its inclination in a compass direction (azimuth) is between -90° and 90° <br>
* - its efficiency of the asset's inverter (etaConv) is between 0% and 100% <br>
* - its tilted inclination from horizontal (elevation angle) is between 0° and 90° <br>
* - its rated power factor is between 0 and 1
*
* @param pvInput PvInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkPv(PvInput pvInput) {
Try<Void, InvalidEntityException> negative =
Try.apply(() -> detectNegativeQuantities(new Quantity<?>[] {pvInput.getsRated()}, pvInput));
Try<Void, InvalidEntityException> albedo = Try.apply(() -> checkAlbedo(pvInput));
Try<Void, InvalidEntityException> azimuth = Try.apply(() -> checkAzimuth(pvInput));
Try<Void, InvalidEntityException> betweenZero =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
pvInput, pvInput.getEtaConv(), "Efficiency of the converter"));
Try<Void, InvalidEntityException> elevationAngle =
Try.apply(() -> checkElevationAngle(pvInput));
Try<Void, InvalidEntityException> ratedPF =
Try.apply(() -> checkRatedPowerFactor(pvInput, pvInput.getCosPhiRated()));
List<InvalidEntityException> exceptions =
Stream.of(negative, albedo, azimuth, betweenZero, elevationAngle, ratedPF)
.filter(Try::isFailure)
.map(Try::getException)
.toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Check if albedo of pvInput is between 0 and 1
*
* @param pvInput PvInput to validate
*/
private static void checkAlbedo(PvInput pvInput) {
if (pvInput.getAlbedo() < 0d || pvInput.getAlbedo() > 1d)
throw new InvalidEntityException(
"Albedo of the plant's surrounding of "
+ pvInput.getClass().getSimpleName()
+ " must be between 0 and 1",
pvInput);
}
/**
* Check if azimuth angle of pvInput is between -90° and 90°
*
* @param pvInput PvInput to validate
*/
private static void checkAzimuth(PvInput pvInput) {
if (pvInput.getAzimuth().isLessThan(Quantities.getQuantity(-90d, AZIMUTH))
|| pvInput.getAzimuth().isGreaterThan(Quantities.getQuantity(90d, AZIMUTH)))
throw new InvalidEntityException(
"Azimuth angle of "
+ pvInput.getClass().getSimpleName()
+ " must be between -90° (east) and 90° (west)",
pvInput);
}
/**
* Check if tilted inclination from horizontal of pvInput is between 0° and 90°
*
* @param pvInput PvInput to validate
*/
private static void checkElevationAngle(PvInput pvInput) {
if (pvInput.getElevationAngle().isLessThan(Quantities.getQuantity(0d, SOLAR_ELEVATION_ANGLE))
|| pvInput
.getElevationAngle()
.isGreaterThan(Quantities.getQuantity(90d, SOLAR_ELEVATION_ANGLE)))
throw new InvalidEntityException(
"Tilted inclination from horizontal of "
+ pvInput.getClass().getSimpleName()
+ " must be between 0° and 90°",
pvInput);
}
/**
* Validates a StorageInput if: <br>
* - {@link SystemParticipantValidationUtils#checkStorageType(StorageTypeInput)} confirms a valid
* type properties
*
* @param storageInput StorageInput to validate
*/
private static void checkStorage(StorageInput storageInput) {
checkType(storageInput.getType());
}
/**
* Validates a StorageTypeInput if: <br>
* - its permissible amount of full cycles is not negative <br>
* - its efficiency of the electrical converter is between 0% and 100% <br>
* - its maximum permissible depth of discharge is between 0% and 100% <br>
* - its active power gradient is not negative <br>
* - its battery capacity is positive <br>
* - its maximum permissible active power (in-feed or consumption) is not negative <br>
* - its permissible hours of full use is not negative
*
* @param storageTypeInput StorageTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkStorageType(
StorageTypeInput storageTypeInput) {
List<InvalidEntityException> exceptions = new ArrayList<>();
if (storageTypeInput.getLifeCycle() < 0) {
exceptions.add(
new InvalidEntityException(
"Permissible amount of life cycles of the storage type must be zero or positive",
storageTypeInput));
}
Try<Void, InvalidEntityException> betweenZero =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
storageTypeInput,
storageTypeInput.getEta(),
"Efficiency of the electrical converter"));
Try<Void, InvalidEntityException> betweenZero2 =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
storageTypeInput,
storageTypeInput.getDod(),
"Maximum permissible depth of discharge"));
Try<Void, InvalidEntityException> betweenZero3 =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {
storageTypeInput.getpMax(),
storageTypeInput.getActivePowerGradient(),
storageTypeInput.getLifeTime()
},
storageTypeInput));
Try<Void, InvalidEntityException> betweenZero4 =
Try.apply(
() ->
detectZeroOrNegativeQuantities(
new Quantity<?>[] {storageTypeInput.geteStorage()}, storageTypeInput));
exceptions.addAll(
Stream.of(betweenZero, betweenZero2, betweenZero3, betweenZero4)
.filter(Try::isFailure)
.map(Try::getException)
.toList());
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/**
* Validates a WecInput if: <br>
* - {@link SystemParticipantValidationUtils#checkWecType(WecTypeInput)} confirms a valid type
* properties
*
* @param wecInput WecInput to validate
*/
private static void checkWec(WecInput wecInput) {
checkType(wecInput.getType());
}
/**
* Validates a WecTypeInput if: <br>
* - its efficiency of the assets converter is between 0% and 100% <br>
* - its rotor area is not negative <br>
* - its height of the rotor hub is not negative
*
* @param wecTypeInput WecTypeInput to validate
* @return a try object either containing an {@link InvalidEntityException} or an empty Success
*/
private static Try<Void, InvalidEntityException> checkWecType(WecTypeInput wecTypeInput) {
Try<Void, InvalidEntityException> betweenZero =
Try.apply(
() ->
isBetweenZeroAndHundredPercent(
wecTypeInput, wecTypeInput.getEtaConv(), "Efficiency of the converter"));
Try<Void, InvalidEntityException> betweenZero2 =
Try.apply(
() ->
detectNegativeQuantities(
new Quantity<?>[] {wecTypeInput.getRotorArea(), wecTypeInput.getHubHeight()},
wecTypeInput));
List<InvalidEntityException> exceptions =
Stream.of(betweenZero, betweenZero2).filter(Try::isFailure).map(Try::getException).toList();
if (exceptions.size() > 0) {
return new Failure<>(
new InvalidEntityException(
"Validation failed due to the following exception(s): ",
new Throwable(ExceptionUtils.getMessages(exceptions))));
} else {
return Success.empty();
}
}
/** Validates a EvcsInput */
private static void checkEvcs() {
throw new NotImplementedException(
String.format(
"Validation of '%s' is currently not supported.", EvcsInput.class.getSimpleName()));
}
/**
* Validates if the rated power factor is between 0 and 1, otherwise throws an {@link
* InvalidEntityException}
*
* @param input entity to validate
* @param cosPhiRated rated power factor to check
*/
private static void checkRatedPowerFactor(InputEntity input, double cosPhiRated) {
if (cosPhiRated < 0d || cosPhiRated > 1d)
throw new InvalidEntityException(
"Rated power factor of " + input.getClass().getSimpleName() + " must be between 0 and 1",
input);
}
/**
* Validates if a value (e.g. an efficiency) is between 0% and 100%, otherwise throws an {@link
* InvalidEntityException}
*
* @param input entity to validate
* @param value value of entity to check
*/
private static void isBetweenZeroAndHundredPercent(
InputEntity input, ComparableQuantity<Dimensionless> value, String string) {
if (value.isLessThan(Quantities.getQuantity(0d, Units.PERCENT))
|| value.isGreaterThan(Quantities.getQuantity(100d, Units.PERCENT)))
throw new InvalidEntityException(
string + " of " + input.getClass().getSimpleName() + " must be between 0% and 100%",
input);
}
}