Skip to content

Commit a1ab6f5

Browse files
authored
Merge pull request #1217 from ie3-institute/df/#1216-ValidationUtils-for-validating-ThermalGrids
Extend ValidationUtils for validating ThermalGrids
2 parents 171e7cc + 6a64ff1 commit a1ab6f5

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Enhance `WeatherSource` with method to retrieve all time keys after a given key [#572](https://github.com/ie3-institute/PowerSystemDataModel/issues/572)
1212
- Adding timeseries for voltage values [#1128](https://github.com/ie3-institute/PowerSystemDataModel/issues/1128)
1313
- Added Staudt to list of reviewers [#1190](https://github.com/ie3-institute/PowerSystemDataModel/issues/1190)
14+
- Extend ValidationUtils for validating ThermalGrids [#1216](https://github.com/ie3-institute/PowerSystemDataModel/issues/1216)
1415

1516
### Fixed
1617
- Removing opened `SwitchInput` during connectivity check [#1221](https://github.com/ie3-institute/PowerSystemDataModel/issues/1221)

src/main/java/edu/ie3/datamodel/utils/validation/ThermalUnitValidationUtils.java renamed to src/main/java/edu/ie3/datamodel/utils/validation/ThermalValidationUtils.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77

88
import edu.ie3.datamodel.exceptions.InvalidEntityException;
99
import edu.ie3.datamodel.exceptions.ValidationException;
10+
import edu.ie3.datamodel.models.input.container.ThermalGrid;
1011
import edu.ie3.datamodel.models.input.thermal.*;
1112
import edu.ie3.datamodel.utils.Try;
1213
import edu.ie3.datamodel.utils.Try.Failure;
1314
import java.util.ArrayList;
1415
import java.util.List;
1516
import javax.measure.Quantity;
1617

17-
public class ThermalUnitValidationUtils extends ValidationUtils {
18+
public class ThermalValidationUtils extends ValidationUtils {
1819

1920
/** Private Constructor as this class is not meant to be instantiated */
20-
private ThermalUnitValidationUtils() {
21+
private ThermalValidationUtils() {
2122
throw new IllegalStateException("Don't try and instantiate a Utility class.");
2223
}
2324

@@ -57,6 +58,42 @@ private ThermalUnitValidationUtils() {
5758
return exceptions;
5859
}
5960

61+
/**
62+
* Validates a thermal grid if:
63+
*
64+
* <ul>
65+
* <li>it is not null
66+
* </ul>
67+
*
68+
* A "distribution" method, that forwards the check request to specific implementations to fulfill
69+
* the checking task, based on the class of the given object.
70+
*
71+
* @param thermalGrid ThermalGrid to validate
72+
* @return a list of try objects either containing an {@link ValidationException} or an empty
73+
* Success
74+
*/
75+
protected static List<Try<Void, ? extends ValidationException>> check(ThermalGrid thermalGrid) {
76+
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalGrid, "a thermal grid");
77+
78+
if (isNull.isFailure()) {
79+
return List.of(isNull);
80+
}
81+
82+
List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();
83+
84+
// Validate houses
85+
for (ThermalHouseInput house : thermalGrid.houses()) {
86+
exceptions.addAll(checkThermalHouse(house));
87+
}
88+
89+
// Validate storages
90+
for (ThermalStorageInput storage : thermalGrid.storages()) {
91+
exceptions.addAll(check(storage));
92+
}
93+
94+
return exceptions;
95+
}
96+
6097
/**
6198
* Validates a thermalSinkInput if:
6299
*

src/main/java/edu/ie3/datamodel/utils/validation/ValidationUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import edu.ie3.datamodel.models.input.connector.type.Transformer2WTypeInput;
1717
import edu.ie3.datamodel.models.input.connector.type.Transformer3WTypeInput;
1818
import edu.ie3.datamodel.models.input.container.GridContainer;
19+
import edu.ie3.datamodel.models.input.container.ThermalGrid;
1920
import edu.ie3.datamodel.models.input.graphics.GraphicInput;
2021
import edu.ie3.datamodel.models.input.system.SystemParticipantInput;
2122
import edu.ie3.datamodel.models.input.system.type.SystemParticipantTypeInput;
@@ -68,6 +69,8 @@ public static void check(Object obj) throws ValidationException {
6869
exceptions.addAll(GraphicValidationUtils.check((GraphicInput) obj));
6970
} else if (AssetTypeInput.class.isAssignableFrom(obj.getClass())) {
7071
exceptions.addAll(checkAssetType((AssetTypeInput) obj));
72+
} else if (ThermalGrid.class.isAssignableFrom(obj.getClass())) {
73+
exceptions.addAll(ThermalValidationUtils.check((ThermalGrid) obj));
7174
} else {
7275
logNotImplemented(obj);
7376
}
@@ -151,7 +154,9 @@ else if (SystemParticipantInput.class.isAssignableFrom(assetInput.getClass()))
151154
exceptions.addAll(
152155
SystemParticipantValidationUtils.check((SystemParticipantInput) assetInput));
153156
else if (ThermalUnitInput.class.isAssignableFrom(assetInput.getClass()))
154-
exceptions.addAll(ThermalUnitValidationUtils.check((ThermalUnitInput) assetInput));
157+
exceptions.addAll(ThermalValidationUtils.check((ThermalUnitInput) assetInput));
158+
else if (ThermalGrid.class.isAssignableFrom(assetInput.getClass()))
159+
exceptions.addAll(ThermalValidationUtils.check((ThermalUnitInput) assetInput));
155160
else {
156161
logNotImplemented(assetInput);
157162
}
Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import edu.ie3.datamodel.exceptions.ValidationException
1010
import edu.ie3.datamodel.models.OperationTime
1111
import edu.ie3.datamodel.models.StandardUnits
1212
import edu.ie3.datamodel.models.input.OperatorInput
13+
import edu.ie3.datamodel.models.input.container.ThermalGrid
1314
import edu.ie3.datamodel.models.input.thermal.CylindricalStorageInput
1415
import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput
1516
import edu.ie3.datamodel.utils.Try
@@ -26,7 +27,7 @@ import tech.units.indriya.quantity.Quantities
2627
import javax.measure.quantity.Temperature
2728
import javax.measure.quantity.Volume
2829

29-
class ThermalUnitValidationUtilsTest extends Specification {
30+
class ThermalValidationUtilsTest extends Specification {
3031

3132
// General data
3233
private static final UUID thermalUnitUuid = UUID.fromString("717af017-cc69-406f-b452-e022d7fb516a")
@@ -44,7 +45,7 @@ class ThermalUnitValidationUtilsTest extends Specification {
4445
private static final ComparableQuantity<Temperature> UPPER_TEMPERATURE_LIMIT = Quantities.getQuantity(25, StandardUnits.TEMPERATURE)
4546
private static final ComparableQuantity<Temperature> LOWER_TEMPERATURE_LIMIT = Quantities.getQuantity(15, StandardUnits.TEMPERATURE)
4647

47-
// Specific data for thermal cylindric storage input
48+
// Specific data for thermal cylindrical storage input
4849
private static final ComparableQuantity<Volume> storageVolumeLvl = Quantities.getQuantity(100, StandardUnits.VOLUME)
4950
private static final ComparableQuantity<Temperature> inletTemp = Quantities.getQuantity(100, StandardUnits.TEMPERATURE)
5051
private static final ComparableQuantity<Temperature> returnTemp = Quantities.getQuantity(80, StandardUnits.TEMPERATURE)
@@ -65,7 +66,7 @@ class ThermalUnitValidationUtilsTest extends Specification {
6566

6667
def "ThermalUnitValidationUtils.checkThermalHouse() recognizes all potential errors for a thermal house"() {
6768
when:
68-
List<Try<Void, ? extends ValidationException>> exceptions = ThermalUnitValidationUtils.check(invalidThermalHouse).stream().filter { it -> it.failure }.toList()
69+
List<Try<Void, ? extends ValidationException>> exceptions = ThermalValidationUtils.check(invalidThermalHouse).stream().filter { it -> it.failure }.toList()
6970

7071
then:
7172
exceptions.size() == expectedSize
@@ -98,7 +99,7 @@ class ThermalUnitValidationUtilsTest extends Specification {
9899

99100
def "ThermalUnitValidationUtils.checkCylindricalStorage() recognizes all potential errors for a thermal cylindrical storage"() {
100101
when:
101-
List<Try<Void, ? extends ValidationException>> exceptions = ThermalUnitValidationUtils.check(invalidCylindricalStorage).stream().filter { it -> it.failure }.toList()
102+
List<Try<Void, ? extends ValidationException>> exceptions = ThermalValidationUtils.check(invalidCylindricalStorage).stream().filter { it -> it.failure }.toList()
102103

103104
then:
104105
exceptions.size() == expectedSize
@@ -107,9 +108,34 @@ class ThermalUnitValidationUtilsTest extends Specification {
107108
ex.message == expectedException.message
108109

109110
where:
110-
invalidCylindricalStorage || expectedSize || expectedException
111-
new CylindricalStorageInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, storageVolumeLvl, Quantities.getQuantity(100, StandardUnits.TEMPERATURE), Quantities.getQuantity(200, StandardUnits.TEMPERATURE), c) || 1 || new InvalidEntityException("Inlet temperature of the cylindrical storage cannot be lower or equal than outlet temperature", invalidCylindricalStorage)
112-
new CylindricalStorageInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, storageVolumeLvl, Quantities.getQuantity(100, StandardUnits.TEMPERATURE), Quantities.getQuantity(100, StandardUnits.TEMPERATURE), c) || 1 || new InvalidEntityException("Inlet temperature of the cylindrical storage cannot be lower or equal than outlet temperature", invalidCylindricalStorage)
111+
invalidCylindricalStorage || expectedSize || expectedException
112+
new CylindricalStorageInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, storageVolumeLvl, Quantities.getQuantity(100, StandardUnits.TEMPERATURE), Quantities.getQuantity(200, StandardUnits.TEMPERATURE), c) || 1 || new InvalidEntityException("Inlet temperature of the cylindrical storage cannot be lower or equal than outlet temperature", invalidCylindricalStorage)
113+
new CylindricalStorageInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, storageVolumeLvl, Quantities.getQuantity(100, StandardUnits.TEMPERATURE), Quantities.getQuantity(100, StandardUnits.TEMPERATURE), c) || 1 || new InvalidEntityException("Inlet temperature of the cylindrical storage cannot be lower or equal than outlet temperature", invalidCylindricalStorage)
113114
new CylindricalStorageInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, Quantities.getQuantity(-100, StandardUnits.VOLUME), inletTemp, returnTemp, Quantities.getQuantity(-1.05, StandardUnits.SPECIFIC_HEAT_CAPACITY)) || 1 || new InvalidEntityException("The following quantities have to be positive: -100 ㎥, -1.05 kWh/K*m³", invalidCylindricalStorage)
114115
}
116+
117+
def "ThermalUnitValidationUtils.check() works for complete ThermalGrid as well"() {
118+
when:
119+
def thermalBus = ThermalUnitInputTestData.thermalBus
120+
def cylindricalStorageInput = [
121+
ThermalUnitInputTestData.cylindricStorageInput
122+
]
123+
124+
125+
ThermalGrid thermalGrid = new ThermalGrid(thermalBus, [thermalHouse], cylindricalStorageInput)
126+
127+
128+
List<Try<Void, ? extends ValidationException>> exceptions = ThermalValidationUtils.check(thermalGrid).stream().filter { it -> it.failure }.toList()
129+
130+
then:
131+
exceptions.size() == expectedSize
132+
Exception ex = exceptions.get(0).exception.get()
133+
ex.class == expectedException.class
134+
ex.message == expectedException.message
135+
136+
137+
where:
138+
thermalHouse || expectedSize || expectedException
139+
new ThermalHouseInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, thermalConductance, ethCapa, Quantities.getQuantity(0, StandardUnits.TEMPERATURE), UPPER_TEMPERATURE_LIMIT, LOWER_TEMPERATURE_LIMIT) || 1 || new InvalidEntityException("Target temperature must be higher than lower temperature limit and lower than upper temperature limit", thermalHouse)
140+
}
115141
}

0 commit comments

Comments
 (0)