Skip to content

Commit fd1758c

Browse files
Merge pull request #1358 from ie3-institute/df/#1357-validation-load
Enhance ValidationUtils for load profile
2 parents 7777b24 + 835e05f commit fd1758c

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
### Changed
1717
- Fixed CFF-Version [#1392](https://github.com/ie3-institute/PowerSystemDataModel/issues/1392)
18+
- Enhanced `ValidationUtils` for `LoadModel` to check for correct profile naming [#1357](https://github.com/ie3-institute/PowerSystemDataModel/issues/1357)
1819

1920
## [8.0.0] - 2025-07-22
2021

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
*/
66
package edu.ie3.datamodel.utils.validation;
77

8-
import static edu.ie3.datamodel.models.StandardUnits.*;
8+
import static edu.ie3.datamodel.models.StandardUnits.AZIMUTH;
9+
import static edu.ie3.datamodel.models.StandardUnits.SOLAR_ELEVATION_ANGLE;
910

1011
import edu.ie3.datamodel.exceptions.InvalidEntityException;
1112
import edu.ie3.datamodel.exceptions.TryException;
1213
import edu.ie3.datamodel.models.input.UniqueInputEntity;
1314
import edu.ie3.datamodel.models.input.system.*;
1415
import edu.ie3.datamodel.models.input.system.type.*;
16+
import edu.ie3.datamodel.models.profile.LoadProfile;
1517
import edu.ie3.datamodel.utils.Try;
1618
import edu.ie3.datamodel.utils.Try.Failure;
1719
import java.util.ArrayList;
20+
import java.util.Arrays;
1821
import java.util.List;
1922
import javax.measure.Quantity;
2023
import javax.measure.quantity.Dimensionless;
@@ -359,7 +362,8 @@ private static Try<Void, InvalidEntityException> checkHpType(HpTypeInput hpTypeI
359362
* Validates a LoadInput if:
360363
*
361364
* <ul>
362-
* <li>its standard load profile is not null
365+
* <li>its load profile is not null
366+
* <li>its load profile matches the supported types / profile names
363367
* <li>its rated apparent power is not negative
364368
* <li>its annual energy consumption is not negative
365369
* <li>its rated power factor is between 0 and 1
@@ -375,10 +379,23 @@ private static List<Try<Void, InvalidEntityException>> checkLoad(LoadInput loadI
375379
exceptions.add(
376380
Try.ofVoid(
377381
loadInput.getLoadProfile() == null,
378-
() ->
379-
new InvalidEntityException(
380-
"No standard load profile defined for load", loadInput)));
382+
() -> new InvalidEntityException("No load profile defined for load", loadInput)));
383+
384+
if (loadInput.getLoadProfile() != null) {
385+
LoadProfile profile = loadInput.getLoadProfile();
386+
387+
// Validate if the profile is one of the allowed profiles
388+
exceptions.add(
389+
Try.ofVoid(
390+
!(profile.equals(LoadProfile.DefaultLoadProfiles.NO_LOAD_PROFILE)
391+
|| Arrays.asList(LoadProfile.getAllProfiles()).contains(profile)),
392+
() ->
393+
new InvalidEntityException(
394+
"Load profile must contain at least one valid entry: h0, g[0-6], l[0-2], ep1, ez2, random, or LoadProfile#NO_LOAD_PROFILE.",
395+
loadInput)));
396+
}
381397

398+
// Check negative quantities and power factor
382399
exceptions.addAll(
383400
Try.ofVoid(
384401
InvalidEntityException.class,

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import edu.ie3.datamodel.exceptions.InvalidEntityException
1414
import edu.ie3.datamodel.models.input.system.characteristic.WecCharacteristicInput
1515
import edu.ie3.datamodel.models.input.system.type.*
1616
import edu.ie3.datamodel.models.input.system.type.chargingpoint.ChargingPointType
17+
import edu.ie3.datamodel.models.profile.StandardLoadProfile
1718
import edu.ie3.datamodel.utils.Try
1819
import edu.ie3.test.common.SystemParticipantTestData
1920
import edu.ie3.util.quantities.interfaces.Currency
@@ -324,9 +325,41 @@ class SystemParticipantValidationUtilsTest extends Specification {
324325

325326
where:
326327
invalidLoad || expectedSize || expectedException
327-
SystemParticipantTestData.loadInput.copy().loadprofile(null).build() || 1 || new InvalidEntityException("No standard load profile defined for load", invalidLoad)
328+
SystemParticipantTestData.loadInput.copy().loadprofile(null).build() || 1 || new InvalidEntityException("No load profile defined for load", invalidLoad)
328329
SystemParticipantTestData.loadInput.copy().sRated(Quantities.getQuantity(-25d, ACTIVE_POWER_IN)).eConsAnnual(Quantities.getQuantity(-4000, ENERGY_IN)).build() || 1 || new InvalidEntityException("The following quantities have to be zero or positive: -25 kVA, -4000 kWh", invalidLoad)
329330
SystemParticipantTestData.loadInput.copy().cosPhiRated(2).build() || 1 || new InvalidEntityException("Rated power factor of LoadInput must be between 0 and 1", invalidLoad)
331+
SystemParticipantTestData.loadInput.copy().loadprofile(createInvalidStandardLoadProfile("h1")).build() || 1 || new InvalidEntityException("Load profile must contain at least one valid entry: h0, g[0-6], l[0-2], ep1, ez2, random, or LoadProfile#NO_LOAD_PROFILE.", invalidLoad)
332+
SystemParticipantTestData.loadInput.copy().loadprofile(createInvalidStandardLoadProfile("g7")).build() || 1 || new InvalidEntityException("Load profile must contain at least one valid entry: h0, g[0-6], l[0-2], ep1, ez2, random, or LoadProfile#NO_LOAD_PROFILE.", invalidLoad)
333+
SystemParticipantTestData.loadInput.copy().loadprofile(createInvalidStandardLoadProfile("l3")).build() || 1 || new InvalidEntityException("Load profile must contain at least one valid entry: h0, g[0-6], l[0-2], ep1, ez2, random, or LoadProfile#NO_LOAD_PROFILE.", invalidLoad)
334+
SystemParticipantTestData.loadInput.copy().loadprofile(createInvalidStandardLoadProfile("invalid")).build() || 1 || new InvalidEntityException("Load profile must contain at least one valid entry: h0, g[0-6], l[0-2], ep1, ez2, random, or LoadProfile#NO_LOAD_PROFILE.", invalidLoad)
335+
}
336+
337+
// Helper method to create invalid standard load profiles for testing
338+
private static StandardLoadProfile createInvalidStandardLoadProfile(String profileName) {
339+
return new StandardLoadProfile() {
340+
@Override
341+
String getKey() {
342+
return profileName
343+
}
344+
345+
@Override
346+
String toString() {
347+
return profileName
348+
}
349+
350+
@Override
351+
boolean equals(Object obj) {
352+
if (obj instanceof String) {
353+
return obj == "Simona"
354+
}
355+
return false
356+
}
357+
358+
@Override
359+
int hashCode() {
360+
return profileName.hashCode()
361+
}
362+
}
330363
}
331364

332365
// PV

0 commit comments

Comments
 (0)