|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, RTE (http://www.rte-france.com) |
| 3 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | + */ |
| 7 | + |
| 8 | +package com.powsybl.openrao.data.generatorconstraints; |
| 9 | + |
| 10 | +import com.powsybl.openrao.commons.OpenRaoException; |
| 11 | + |
| 12 | +import java.util.Optional; |
| 13 | + |
| 14 | +/** |
| 15 | + * Set of physical and operational constraints that apply on a generator. |
| 16 | + * |
| 17 | + * @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} |
| 18 | + */ |
| 19 | +public final class GeneratorConstraints { |
| 20 | + private final String generatorId; |
| 21 | + private final double pMin; |
| 22 | + private final double pMax; |
| 23 | + private final double leadTime; |
| 24 | + private final double lagTime; |
| 25 | + private final Double minUpTime; |
| 26 | + private final Double maxUpTime; |
| 27 | + private final Double minOffTime; |
| 28 | + private final Double upwardPowerGradient; |
| 29 | + private final Double downwardPowerGradient; |
| 30 | + |
| 31 | + private GeneratorConstraints(String generatorId, double pMin, double pMax, double leadTime, double lagTime, Double minUpTime, Double maxUpTime, Double minOffTime, Double upwardPowerGradient, Double downwardPowerGradient) { |
| 32 | + this.generatorId = generatorId; |
| 33 | + this.pMin = pMin; |
| 34 | + this.pMax = pMax; |
| 35 | + this.leadTime = leadTime; |
| 36 | + this.lagTime = lagTime; |
| 37 | + this.minUpTime = minUpTime; |
| 38 | + this.maxUpTime = maxUpTime; |
| 39 | + this.minOffTime = minOffTime; |
| 40 | + this.upwardPowerGradient = upwardPowerGradient; |
| 41 | + this.downwardPowerGradient = downwardPowerGradient; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Get the id of the generator on which the constraints apply. |
| 46 | + * @return if of the generator |
| 47 | + */ |
| 48 | + public String getGeneratorId() { |
| 49 | + return generatorId; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Get the minimal operational power of the generator in MW. |
| 54 | + * @return minimal operational power of the generator |
| 55 | + */ |
| 56 | + public double getPMin() { |
| 57 | + return pMin; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Get the maximal operational power of the generator in MW. |
| 62 | + * @return maximal operational power of the generator |
| 63 | + */ |
| 64 | + public double getPMax() { |
| 65 | + return pMax; |
| 66 | + } |
| 67 | + |
| 68 | + /** |
| 69 | + * Get the lead time of the generator, i.e. the time required by the power to go from 0 to pMin, in hours. |
| 70 | + * @return lead time of the generator |
| 71 | + */ |
| 72 | + public double getLeadTime() { |
| 73 | + return leadTime; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Get the lag time of the generator, i.e. the time required by the power to go from pMin to 0, in hours. |
| 78 | + * @return lag time of the generator |
| 79 | + */ |
| 80 | + public double getLagTime() { |
| 81 | + return lagTime; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Get the minUp time the generator, i.e. the minimum time during which the generator must be operated with a power greater than pMin, in hours. |
| 86 | + * @return minUp time of the generator |
| 87 | + */ |
| 88 | + public Optional<Double> getMinUpTime() { |
| 89 | + return Optional.ofNullable(minUpTime); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * Get the maxUp time the generator, i.e. the maximum time during which the generator can be operated with a power greater than pMin, in hours. |
| 94 | + * @return maxUp time of the generator |
| 95 | + */ |
| 96 | + public Optional<Double> getMaxUpTime() { |
| 97 | + return Optional.ofNullable(maxUpTime); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * Get the minOff time the generator, i.e. the minimum time during which the generator must be kept shutdown, in hours. |
| 102 | + * @return minOff time of the generator |
| 103 | + */ |
| 104 | + public Optional<Double> getMinOffTime() { |
| 105 | + return Optional.ofNullable(minOffTime); |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Get the upward power gradient of the generator in MW/hours. |
| 110 | + * It only applies when the generator is on, i.e. when its power is greater than pMin. |
| 111 | + * Its value is always positive. |
| 112 | + * @return upward power gradient of the generator |
| 113 | + */ |
| 114 | + public Optional<Double> getUpwardPowerGradient() { |
| 115 | + return Optional.ofNullable(upwardPowerGradient); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Get the downward power gradient of the generator in MW/hours. |
| 120 | + * It only applies when the generator is on, i.e. when its power is greater than pMin. |
| 121 | + * Its value is always negative. |
| 122 | + * @return downward power gradient of the generator |
| 123 | + */ |
| 124 | + public Optional<Double> getDownwardPowerGradient() { |
| 125 | + return Optional.ofNullable(downwardPowerGradient); |
| 126 | + } |
| 127 | + |
| 128 | + public static GeneratorConstraintsBuilder create() { |
| 129 | + return new GeneratorConstraintsBuilder(); |
| 130 | + } |
| 131 | + |
| 132 | + public static final class GeneratorConstraintsBuilder { |
| 133 | + private String generatorId; |
| 134 | + private Double pMin; |
| 135 | + private Double pMax; |
| 136 | + private Double leadTime; |
| 137 | + private Double lagTime; |
| 138 | + private Double minUpTime; |
| 139 | + private Double maxUpTime; |
| 140 | + private Double minOffTime; |
| 141 | + private Double upwardPowerGradient; |
| 142 | + private Double downwardPowerGradient; |
| 143 | + |
| 144 | + private GeneratorConstraintsBuilder() { |
| 145 | + } |
| 146 | + |
| 147 | + public GeneratorConstraintsBuilder withGeneratorId(String generatorId) { |
| 148 | + this.generatorId = generatorId; |
| 149 | + return this; |
| 150 | + } |
| 151 | + |
| 152 | + public GeneratorConstraintsBuilder withPMin(Double pMin) { |
| 153 | + this.pMin = pMin; |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + public GeneratorConstraintsBuilder withPMax(Double pMax) { |
| 158 | + this.pMax = pMax; |
| 159 | + return this; |
| 160 | + } |
| 161 | + |
| 162 | + public GeneratorConstraintsBuilder withLeadTime(Double leadTime) { |
| 163 | + this.leadTime = leadTime; |
| 164 | + return this; |
| 165 | + } |
| 166 | + |
| 167 | + public GeneratorConstraintsBuilder withLagTime(Double lagTime) { |
| 168 | + this.lagTime = lagTime; |
| 169 | + return this; |
| 170 | + } |
| 171 | + |
| 172 | + public GeneratorConstraintsBuilder withMinUpTime(Double minUpTime) { |
| 173 | + this.minUpTime = minUpTime; |
| 174 | + return this; |
| 175 | + } |
| 176 | + |
| 177 | + public GeneratorConstraintsBuilder withMaxUpTime(Double maxUpTime) { |
| 178 | + this.maxUpTime = maxUpTime; |
| 179 | + return this; |
| 180 | + } |
| 181 | + |
| 182 | + public GeneratorConstraintsBuilder withMinOffTime(Double minOffTime) { |
| 183 | + this.minOffTime = minOffTime; |
| 184 | + return this; |
| 185 | + } |
| 186 | + |
| 187 | + public GeneratorConstraintsBuilder withUpwardPowerGradient(Double upwardPowerGradient) { |
| 188 | + this.upwardPowerGradient = upwardPowerGradient; |
| 189 | + return this; |
| 190 | + } |
| 191 | + |
| 192 | + public GeneratorConstraintsBuilder withDownwardPowerGradient(Double downwardPowerGradient) { |
| 193 | + this.downwardPowerGradient = downwardPowerGradient; |
| 194 | + return this; |
| 195 | + } |
| 196 | + |
| 197 | + public GeneratorConstraints build() { |
| 198 | + if (generatorId == null) { |
| 199 | + throw new OpenRaoException("The id of the generator is mandatory."); |
| 200 | + } |
| 201 | + if (pMin == null) { |
| 202 | + throw new OpenRaoException("The pMin of the generator is mandatory."); |
| 203 | + } |
| 204 | + if (pMax == null) { |
| 205 | + throw new OpenRaoException("The pMax of the generator is mandatory."); |
| 206 | + } |
| 207 | + if (leadTime == null) { |
| 208 | + throw new OpenRaoException("The lead time of the generator is mandatory."); |
| 209 | + } |
| 210 | + if (lagTime == null) { |
| 211 | + throw new OpenRaoException("The lag time of the generator is mandatory."); |
| 212 | + } |
| 213 | + if (pMin < 0) { |
| 214 | + throw new OpenRaoException("The minimal power of the generator must be positive."); |
| 215 | + } |
| 216 | + if (pMax < pMin) { |
| 217 | + throw new OpenRaoException("The maximal power of the generator must greater than its minimal power."); |
| 218 | + } |
| 219 | + if (leadTime < 0) { |
| 220 | + throw new OpenRaoException("The lead time of the generator must be positive."); |
| 221 | + } |
| 222 | + if (lagTime < 0) { |
| 223 | + throw new OpenRaoException("The lag time of the generator must be positive."); |
| 224 | + } |
| 225 | + if (minUpTime != null && minUpTime < 0) { |
| 226 | + throw new OpenRaoException("The minUp time of the generator must be positive."); |
| 227 | + } |
| 228 | + if (maxUpTime != null) { |
| 229 | + if (minUpTime != null && maxUpTime < minUpTime) { |
| 230 | + throw new OpenRaoException("The maxUp time of the generator must be greater than its minUp time."); |
| 231 | + } |
| 232 | + if (maxUpTime < 0) { |
| 233 | + throw new OpenRaoException("The maxUp time of the generator must be positive."); |
| 234 | + } |
| 235 | + } |
| 236 | + if (minOffTime != null && minOffTime < 0) { |
| 237 | + throw new OpenRaoException("The minOff time of the generator must be positive."); |
| 238 | + } |
| 239 | + if (upwardPowerGradient != null && upwardPowerGradient < 0) { |
| 240 | + throw new OpenRaoException("The upward power gradient of the generator must be positive."); |
| 241 | + } |
| 242 | + if (downwardPowerGradient != null && downwardPowerGradient > 0) { |
| 243 | + throw new OpenRaoException("The downward power gradient of the generator must be negative."); |
| 244 | + } |
| 245 | + return new GeneratorConstraints(generatorId, pMin, pMax, leadTime, lagTime, minUpTime, maxUpTime, minOffTime, upwardPowerGradient, downwardPowerGradient); |
| 246 | + } |
| 247 | + } |
| 248 | +} |
0 commit comments