Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Replaced `LoadProfileInput` with `LoadProfileTimeSeries` [#1228](https://github.com/ie3-institute/PowerSystemDataModel/issues/1228)
- Enhance `CsvDataSource` [#1246](https://github.com/ie3-institute/PowerSystemDataModel/issues/1246)
- Updated `_joint_grid` csv files from simona [#750](https://github.com/ie3-institute/PowerSystemDataModel/issues/750)
- Small harmonisation in `ThermalGrid` validation [#1549](https://github.com/ie3-institute/PowerSystemDataModel/issues/1549)

### Updates
- Updated gradle to v8.13 [#1264](https://github.com/ie3-institute/PowerSystemDataModel/issues/1264)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Stream;
import javax.measure.Quantity;

public class ThermalValidationUtils extends ValidationUtils {
Expand All @@ -24,7 +26,7 @@ private ThermalValidationUtils() {
}

/**
* Validates a thermal unit if:
* Validates a thermal grid if:
*
* <ul>
* <li>it is not null
Expand All @@ -33,34 +35,28 @@ private ThermalValidationUtils() {
* 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 thermalUnitInput ThermalUnitInput to validate
* @param thermalGrid ThermalGrid to validate
* @return a list of try objects either containing an {@link ValidationException} or an empty
* Success
*/
protected static List<Try<Void, ? extends ValidationException>> check(
ThermalUnitInput thermalUnitInput) {
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalUnitInput, "a thermal unit");
protected static List<Try<Void, ? extends ValidationException>> check(ThermalGrid thermalGrid) {
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalGrid, "a thermal grid");

if (isNull.isFailure()) {
return List.of(isNull);
}

List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();

// Further checks for subclasses
if (ThermalSinkInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
exceptions.addAll(checkThermalSink((ThermalSinkInput) thermalUnitInput));
} else if (ThermalStorageInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
exceptions.addAll(checkThermalStorage((ThermalStorageInput) thermalUnitInput));
} else {
logNotImplemented(thermalUnitInput);
}

return exceptions;
return Stream.of(
thermalGrid.houses().stream().map(ThermalValidationUtils::check),
thermalGrid.heatStorages().stream().map(ThermalValidationUtils::check),
thermalGrid.domesticHotWaterStorages().stream().map(ThermalValidationUtils::check))
.flatMap(Function.identity())
.flatMap(List::stream)
.toList();
}

/**
* Validates a thermal grid if:
* Validates a thermal unit if:
*
* <ul>
* <li>it is not null
Expand All @@ -69,32 +65,27 @@ private ThermalValidationUtils() {
* 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 thermalGrid ThermalGrid to validate
* @param thermalUnitInput ThermalUnitInput to validate
* @return a list of try objects either containing an {@link ValidationException} or an empty
* Success
*/
protected static List<Try<Void, ? extends ValidationException>> check(ThermalGrid thermalGrid) {
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalGrid, "a thermal grid");
protected static List<Try<Void, ? extends ValidationException>> check(
ThermalUnitInput thermalUnitInput) {
Try<Void, InvalidEntityException> isNull = checkNonNull(thermalUnitInput, "a thermal unit");

if (isNull.isFailure()) {
return List.of(isNull);
}

List<Try<Void, ? extends ValidationException>> exceptions = new ArrayList<>();

// Validate houses
for (ThermalHouseInput house : thermalGrid.houses()) {
exceptions.addAll(checkThermalHouse(house));
}

// Validate heat storages
for (ThermalStorageInput storage : thermalGrid.heatStorages()) {
exceptions.addAll(check(storage));
}

// Validate domestic hot water storages
for (ThermalStorageInput storage : thermalGrid.domesticHotWaterStorages()) {
exceptions.addAll(check(storage));
// Further checks for subclasses
if (ThermalSinkInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
exceptions.addAll(checkThermalSink((ThermalSinkInput) thermalUnitInput));
} else if (ThermalStorageInput.class.isAssignableFrom(thermalUnitInput.getClass())) {
exceptions.addAll(checkThermalStorage((ThermalStorageInput) thermalUnitInput));
} else {
logNotImplemented(thermalUnitInput);
}

return exceptions;
Expand Down