|
37 | 37 | import static org.gridsuite.modification.dto.OperationalLimitsGroupInfos.Applicability.SIDE1; |
38 | 38 | import static org.gridsuite.modification.dto.OperationalLimitsGroupInfos.Applicability.SIDE2; |
39 | 39 | import static org.gridsuite.modification.modifications.AbstractBranchModification.*; |
| 40 | +import static org.gridsuite.modification.modifications.byfilter.AbstractModificationByAssignment.*; |
40 | 41 |
|
41 | 42 | /** |
42 | 43 | * @author Slimane Amar <slimane.amar at rte-france.com> |
@@ -71,6 +72,10 @@ public final class ModificationUtils { |
71 | 72 | private static final String COULD_NOT_ACTION_EQUIPMENT_ON_SIDE = COULD_NOT_ACTION_EQUIPMENT + " on side %s"; |
72 | 73 | public static final String CONNECT = "connect"; |
73 | 74 | public static final String DISCONNECT = "disconnect"; |
| 75 | + public static final String FIELD_MAX_ACTIVE_POWER = "Maximum active power"; |
| 76 | + public static final String FIELD_MIN_ACTIVE_POWER = "Minimum active power"; |
| 77 | + public static final String FIELD_PLANNED_ACTIVE_POWER_SET_POINT = "Planned active power set point"; |
| 78 | + public static final String FIELD_ACTIVE_POWER_TARGET = "Active power target"; |
74 | 79 |
|
75 | 80 | public static String applicabilityToString(OperationalLimitsGroupInfos.Applicability applicability) { |
76 | 81 | return switch (applicability) { |
@@ -1921,6 +1926,110 @@ public static void checkLimitsGroupExist(String errorMessage, String limitsGroup |
1921 | 1926 | } |
1922 | 1927 | } |
1923 | 1928 |
|
| 1929 | + public static void checkActivePowerValue(String errorMessage, String fieldName, double newValue, double minP, double maxP, NetworkModificationException.Type exceptionType) throws NetworkModificationException { |
| 1930 | + if (newValue > maxP || newValue < minP) { |
| 1931 | + String message = String.format("Invalid value %.2f field %s should be within interval [%.2f; %.2f]", newValue, fieldName, minP, maxP); |
| 1932 | + throw new NetworkModificationException(exceptionType, errorMessage + message); |
| 1933 | + } |
| 1934 | + } |
| 1935 | + |
| 1936 | + public static void checkPowerValues(String errorMessage, double minP, double maxP, double targetP, Double plannedActivePowerSetPoint, NetworkModificationException.Type exceptionType) throws NetworkModificationException { |
| 1937 | + if (targetP != 0) { // exception for the rule minP <= targetP <= maxP |
| 1938 | + checkActivePowerValue(errorMessage, FIELD_ACTIVE_POWER_TARGET, targetP, minP, maxP, exceptionType); |
| 1939 | + } |
| 1940 | + if (plannedActivePowerSetPoint != null) { |
| 1941 | + checkActivePowerValue(errorMessage, FIELD_PLANNED_ACTIVE_POWER_SET_POINT, plannedActivePowerSetPoint, minP, maxP, exceptionType); |
| 1942 | + } |
| 1943 | + checkMinimumActivePower(errorMessage, maxP, targetP, plannedActivePowerSetPoint, minP, exceptionType); |
| 1944 | + checkMaximumActivePower(errorMessage, minP, targetP, plannedActivePowerSetPoint, maxP, exceptionType); |
| 1945 | + } |
| 1946 | + |
| 1947 | + public static void checkMinimumActivePower(String errorMessage, double maxP, double targetP, Double pImp, double newValue, NetworkModificationException.Type exceptionType) throws NetworkModificationException { |
| 1948 | + // targetP = 0 is an exception to the rule |
| 1949 | + double pMin = targetP != 0 ? Math.min(targetP, maxP) : maxP; |
| 1950 | + if (pImp != null) { |
| 1951 | + pMin = Math.min(pMin, pImp); |
| 1952 | + } |
| 1953 | + if (pMin < newValue) { |
| 1954 | + throw new NetworkModificationException(exceptionType, errorMessage + String.format("Invalid value %.2f of field %s should be be smaller or equal to %.2f", newValue, FIELD_MIN_ACTIVE_POWER, pMin)); |
| 1955 | + } |
| 1956 | + } |
| 1957 | + |
| 1958 | + public static void checkMaximumActivePower(String errorMessage, double minP, double targetP, Double plannedActivePowerSetPoint, double newValue, NetworkModificationException.Type exceptionType) throws NetworkModificationException { |
| 1959 | + // targetP = 0 is an exception to the rule |
| 1960 | + double pMax = targetP != 0 ? Math.max(targetP, minP) : minP; |
| 1961 | + if (plannedActivePowerSetPoint != null) { |
| 1962 | + pMax = Math.max(pMax, plannedActivePowerSetPoint); |
| 1963 | + } |
| 1964 | + if (pMax > newValue) { |
| 1965 | + throw new NetworkModificationException(exceptionType, errorMessage + String.format("Invalid value %.2f of field %s should be be greater or equal to %.2f", newValue, FIELD_MAX_ACTIVE_POWER, pMax)); |
| 1966 | + } |
| 1967 | + } |
| 1968 | + |
| 1969 | + public static boolean validateMinimumActivePower(Generator generator, List<ReportNode> reports, double newValue) { |
| 1970 | + GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class); |
| 1971 | + Double plannedActivePowerSetPoint = generatorStartup != null && !Double.isNaN(generatorStartup.getPlannedActivePowerSetpoint()) ? generatorStartup.getPlannedActivePowerSetpoint() : null; |
| 1972 | + |
| 1973 | + // targetP = 0 is an exception to the rule |
| 1974 | + double minP = generator.getTargetP() != 0 ? Math.min(generator.getTargetP(), generator.getMaxP()) : generator.getMaxP(); |
| 1975 | + if (plannedActivePowerSetPoint != null) { |
| 1976 | + minP = Math.min(minP, plannedActivePowerSetPoint); |
| 1977 | + } |
| 1978 | + |
| 1979 | + if (minP < newValue) { |
| 1980 | + reports.add(ReportNode.newRootReportNode() |
| 1981 | + .withMessageTemplate("network.modification.generator.ValueShouldBeSmallerThan") |
| 1982 | + .withUntypedValue(VALUE_KEY_EQUIPMENT_NAME, generator.getId()) |
| 1983 | + .withUntypedValue(VALUE_KEY_FIELD_NAME, FIELD_MIN_ACTIVE_POWER) |
| 1984 | + .withUntypedValue(VALUE_KEY_FIELD_VALUE, newValue) |
| 1985 | + .withUntypedValue(VALUE_KEY_TARGET_VALUE, minP) |
| 1986 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 1987 | + .build()); |
| 1988 | + return false; |
| 1989 | + } |
| 1990 | + return true; |
| 1991 | + } |
| 1992 | + |
| 1993 | + public static boolean validateMaximumActivePower(Generator generator, List<ReportNode> reports, double newValue) { |
| 1994 | + GeneratorStartup generatorStartup = generator.getExtension(GeneratorStartup.class); |
| 1995 | + Double pImp = generatorStartup != null && !Double.isNaN(generatorStartup.getPlannedActivePowerSetpoint()) ? generatorStartup.getPlannedActivePowerSetpoint() : null; |
| 1996 | + |
| 1997 | + // targetP = 0 is an exception to the rule |
| 1998 | + double maxP = generator.getTargetP() != 0 ? Math.max(generator.getTargetP(), generator.getMinP()) : generator.getMinP(); |
| 1999 | + if (pImp != null) { |
| 2000 | + maxP = Math.min(maxP, pImp); |
| 2001 | + } |
| 2002 | + |
| 2003 | + if (newValue < maxP) { |
| 2004 | + reports.add(ReportNode.newRootReportNode() |
| 2005 | + .withMessageTemplate("network.modification.generator.ValueShouldBeGreaterThan") |
| 2006 | + .withUntypedValue(VALUE_KEY_EQUIPMENT_NAME, generator.getId()) |
| 2007 | + .withUntypedValue(VALUE_KEY_FIELD_NAME, FIELD_MAX_ACTIVE_POWER) |
| 2008 | + .withUntypedValue(VALUE_KEY_FIELD_VALUE, newValue) |
| 2009 | + .withUntypedValue(VALUE_KEY_TARGET_VALUE, maxP) |
| 2010 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 2011 | + .build()); |
| 2012 | + return false; |
| 2013 | + } |
| 2014 | + return true; |
| 2015 | + } |
| 2016 | + |
| 2017 | + public static boolean validateActivePowerValue(Generator generator, String fieldName, List<ReportNode> reports, double newValue) { |
| 2018 | + if (newValue > generator.getMaxP() || newValue < generator.getMinP()) { |
| 2019 | + reports.add(ReportNode.newRootReportNode() |
| 2020 | + .withMessageTemplate("network.modification.generator.ValueShouldBeWithinInterval") |
| 2021 | + .withUntypedValue(VALUE_KEY_EQUIPMENT_NAME, generator.getId()) |
| 2022 | + .withUntypedValue(VALUE_KEY_FIELD_NAME, fieldName) |
| 2023 | + .withUntypedValue(VALUE_KEY_FIELD_VALUE, newValue) |
| 2024 | + .withUntypedValue(VALUE_KEY_MIN_VALUE, generator.getMinP()) |
| 2025 | + .withUntypedValue(VALUE_KEY_MAX_VALUE, generator.getMaxP()) |
| 2026 | + .withSeverity(TypedValue.WARN_SEVERITY) |
| 2027 | + .build()); |
| 2028 | + return false; |
| 2029 | + } |
| 2030 | + return true; |
| 2031 | + } |
| 2032 | + |
1924 | 2033 | public static List<OperationalLimitsGroupInfos> getOperationalLimitsGroupsOnSide(List<OperationalLimitsGroupInfos> operationalLimitsGroupInfos, |
1925 | 2034 | OperationalLimitsGroupInfos.Applicability applicability) { |
1926 | 2035 | if (operationalLimitsGroupInfos == null || operationalLimitsGroupInfos.isEmpty()) { |
|
0 commit comments