Skip to content

Commit 957bf49

Browse files
Extend ValidationUtils for validating ThermalGrids
1 parent 24c8f3c commit 957bf49

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
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

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
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;
16+
import java.util.Set;
17+
import java.util.stream.Stream;
1518
import javax.measure.Quantity;
1619

1720
public class ThermalUnitValidationUtils extends ValidationUtils {
@@ -57,6 +60,46 @@ private ThermalUnitValidationUtils() {
5760
return exceptions;
5861
}
5962

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

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

Lines changed: 5 additions & 0 deletions
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(ThermalUnitValidationUtils.check((ThermalGrid) obj));
7174
} else {
7275
logNotImplemented(obj);
7376
}
@@ -152,6 +155,8 @@ else if (SystemParticipantInput.class.isAssignableFrom(assetInput.getClass()))
152155
SystemParticipantValidationUtils.check((SystemParticipantInput) assetInput));
153156
else if (ThermalUnitInput.class.isAssignableFrom(assetInput.getClass()))
154157
exceptions.addAll(ThermalUnitValidationUtils.check((ThermalUnitInput) assetInput));
158+
else if (ThermalGrid.class.isAssignableFrom(assetInput.getClass()))
159+
exceptions.addAll(ThermalUnitValidationUtils.check((ThermalUnitInput) assetInput));
155160
else {
156161
logNotImplemented(assetInput);
157162
}

src/test/groovy/edu/ie3/datamodel/utils/validation/ThermalUnitValidationUtilsTest.groovy

Lines changed: 28 additions & 0 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
@@ -112,4 +113,31 @@ class ThermalUnitValidationUtilsTest extends Specification {
112113
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 domesticHotWaterStorageInput = [
121+
ThermalUnitInputTestData.domesticHotWaterStorageInput
122+
]
123+
def cylindricalStorageInput = [
124+
ThermalUnitInputTestData.cylindricalStorageInput
125+
]
126+
127+
ThermalGrid thermalGrid = new ThermalGrid(thermalBus, [thermalHouse], cylindricalStorageInput, domesticHotWaterStorageInput)
128+
129+
130+
List<Try<Void, ? extends ValidationException>> exceptions = ThermalUnitValidationUtils.check(thermalGrid).stream().filter { it -> it.failure }.toList()
131+
132+
then:
133+
exceptions.size() == expectedSize
134+
Exception ex = exceptions.get(0).exception.get()
135+
ex.class == expectedException.class
136+
ex.message == expectedException.message
137+
138+
139+
where:
140+
thermalHouse || expectedSize || expectedException
141+
new ThermalHouseInput(thermalUnitUuid, id, operator, operationTime, SystemParticipantTestData.thermalBus, thermalConductance, ethCapa, Quantities.getQuantity(0, StandardUnits.TEMPERATURE), UPPER_TEMPERATURE_LIMIT, LOWER_TEMPERATURE_LIMIT, HOUSING_TYPE, NUMBER_INHABITANTS) || 1 || new InvalidEntityException("Target temperature must be higher than lower temperature limit and lower than upper temperature limit", thermalHouse)
142+
}
115143
}

0 commit comments

Comments
 (0)