Skip to content

Commit d0fe103

Browse files
committed
Merge branch 'dev' into ms/#1182-add-getPreviousValue-to-TimeSeriesSource
# Conflicts: # CHANGELOG.md
2 parents 72270a5 + a1ab6f5 commit d0fe103

File tree

9 files changed

+112
-21
lines changed

9 files changed

+112
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ 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
- Enhance `TimeSeriesSource` with method to retrieve the previous value before a given key [#1182](https://github.com/ie3-institute/PowerSystemDataModel/issues/1182)
1516

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

1820
### Changed
1921
- Storage minimum level parameter removed from cylindrical thermal storage [#1123](https://github.com/ie3-institute/PowerSystemDataModel/issues/1123)
@@ -24,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2426
- Converted `MappingEntry` into a normal class [#1087](https://github.com/ie3-institute/PowerSystemDataModel/issues/1087)
2527
- Renamed timeseries mapping `participant` column to `asset` [#1191](https://github.com/ie3-institute/PowerSystemDataModel/issues/1191)
2628
- Removed attribute `dsm` from `LoadInput` [#1195](https://github.com/ie3-institute/PowerSystemDataModel/issues/1195)
29+
- Fix spotless deprecations [#1123](https://github.com/ie3-institute/PowerSystemDataModel/issues/1223)
2730

2831
## [5.1.0] - 2024-06-24
2932

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
id 'signing'
66
id 'pmd' // code check, working on source code
77
id 'com.diffplug.spotless' version '7.0.2' //code format
8-
id 'com.github.spotbugs' version '6.1.0' // code check, working on byte code
8+
id 'com.github.spotbugs' version '6.1.3' // code check, working on byte code
99
id 'de.undercouch.download' version '5.6.0'
1010
id 'kr.motd.sphinx' version '2.10.1' // documentation generation
1111
id 'jacoco' // java code coverage plugin
@@ -17,7 +17,7 @@ ext {
1717
//version (changing these should be considered thoroughly!)
1818
javaVersion = JavaVersion.VERSION_17
1919
groovyVersion = "4.0"
20-
groovyBinaryVersion = "4.0.24"
20+
groovyBinaryVersion = "4.0.25"
2121
testcontainersVersion = '1.20.4'
2222

2323
scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator //location of script plugins
@@ -73,7 +73,7 @@ dependencies {
7373
testImplementation 'org.junit.jupiter:junit-jupiter:5.11.4'
7474
testImplementation "org.spockframework:spock-core:2.3-groovy-$groovyVersion"
7575
testImplementation 'org.objenesis:objenesis:3.4' // Mock creation with constructor parameters
76-
testImplementation 'net.bytebuddy:byte-buddy:1.15.11' // Mocks of classes
76+
testImplementation 'net.bytebuddy:byte-buddy:1.17.0' // Mocks of classes
7777

7878
// testcontainers (docker framework for testing)
7979
testImplementation "org.testcontainers:testcontainers:$testcontainersVersion"
@@ -94,7 +94,7 @@ dependencies {
9494
runtimeOnly 'org.postgresql:postgresql:42.7.5' // postgresql jdbc driver required during runtime
9595

9696
implementation 'commons-io:commons-io:2.18.0' // I/O functionalities
97-
implementation 'commons-codec:commons-codec:1.17.2' // needed by commons-compress
97+
implementation 'commons-codec:commons-codec:1.18.0' // needed by commons-compress
9898
implementation 'org.apache.commons:commons-compress:1.27.1' // I/O functionalities
9999
}
100100

docs/readthedocs/io/ValidationUtils.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The methods in ValidationUtils and subclasses can be used to check that objects
1111
The general validation checks:
1212
- if assigned values are valid, e.g. lines are not allowed to have negative lengths or the rated power factor of any unit must be between 0 and 1
1313
- furthermore, several connections are checked, e.g. that lines only connect nodes of the same voltage level or that the voltage levels indicated for the transformer sides match the voltage levels of the nodes they are connected to.
14-
- the connectivity of the given grid for all defined operation intervals
14+
- the connectivity of the given grid for all defined operation intervals, if a switch is opened, it is filtered out for the connectivity check
1515

1616
The uniqueness validation checks if a collection of given objects are unique in either:
1717
- a specific field

gradle/scripts/spotless.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ spotless {
2222
// the Groovy Eclipse formatter extends the Java Eclipse formatter,
2323
// so it formats Java files by default (unless `excludeJava` is used).
2424
greclipse().configFile('greclipse.properties')
25-
indentWithSpaces 2
25+
leadingTabsToSpaces 2
2626
}
2727

2828
groovyGradle {
2929
// same as groovy, but for .gradle (defaults to '*.gradle')
3030
target '*.gradle', 'gradle/scripts/*.gradle'
3131
greclipse()
32-
indentWithSpaces 2
32+
leadingTabsToSpaces 2
3333
}
3434

3535
// removes unnecessary whitespace, indents with tabs and ends on new line for gradle, md and gitignore files and config-XMLs
3636
format 'misc', {
3737
target '**/.gitignore', 'configs/**'
3838
trimTrailingWhitespace()
39-
indentWithTabs()
39+
leadingSpacesToTabs()
4040
endWithNewline()
4141
}
4242
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
import edu.ie3.datamodel.models.input.AssetInput;
1717
import edu.ie3.datamodel.models.input.MeasurementUnitInput;
1818
import edu.ie3.datamodel.models.input.NodeInput;
19-
import edu.ie3.datamodel.models.input.connector.ConnectorInput;
20-
import edu.ie3.datamodel.models.input.connector.LineInput;
21-
import edu.ie3.datamodel.models.input.connector.Transformer3WInput;
19+
import edu.ie3.datamodel.models.input.connector.*;
2220
import edu.ie3.datamodel.models.input.container.*;
2321
import edu.ie3.datamodel.models.input.graphics.GraphicInput;
2422
import edu.ie3.datamodel.models.input.system.SystemParticipantInput;
@@ -241,6 +239,7 @@ protected static Try<Void, InvalidGridException> checkConnectivity(
241239
graph.addEdge(connector.getNodeA().getUuid(), connector.getNodeB().getUuid()));
242240
rawGridElements.getSwitches().stream()
243241
.filter(isInOperation)
242+
.filter(SwitchInput::isClosed)
244243
.forEach(
245244
connector ->
246245
graph.addEdge(connector.getNodeA().getUuid(), connector.getNodeB().getUuid()));

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
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,25 @@ class GridContainerValidationUtilsTest extends Specification {
103103
GTD.nodeG.uuid
104104
])
105105
}
106+
107+
def "The GridContainerValidationUtils should return an exception if the grid is not properly connected, because a switch is open"() {
108+
given:
109+
def nodeA = GTD.nodeA.copy().operationTime(OperationTime.notLimited()).build()
110+
def nodeB = GTD.nodeB.copy().operationTime(OperationTime.notLimited()).build()
111+
112+
def switchAtoB = GTD.switchAtoB.copy()
113+
.nodeA(nodeA)
114+
.nodeB(nodeB)
115+
.operationTime(OperationTime.notLimited())
116+
.closed(false)
117+
.build()
118+
119+
def rawGrid = new RawGridElements([nodeA, nodeB] as Set, [] as Set, [] as Set, [] as Set, [switchAtoB] as Set, [] as Set)
120+
121+
when:
122+
def actual = GridContainerValidationUtils.checkConnectivity(rawGrid, Optional.of(start) as Optional<ZonedDateTime>)
123+
124+
then:
125+
actual.exception.get().message == "The grid contains unconnected elements for time "+start+": [47d29df0-ba2d-4d23-8e75-c82229c5c758]"
126+
}
106127
}
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)