@@ -178,41 +178,55 @@ private static boolean checkGeneratorsNaNValues(String id, double p, double q, d
178178 return true ;
179179 }
180180
181+ /**
182+ * Rule1: Active power (p) must match setpoint (expectedP) (within threshold)
183+ * Rule2: if voltageRegulatorOn="false" then reactive power (Q) should match to setpoint (targetQ) (within threshold)
184+ * Rule3: if voltageRegulatorOn="true"
185+ * Rule3.1: (minQ/maxQ/targetV) are not NaN
186+ * Rule3.2: If V > targetV + threshold, generator (Qgen) must be at min reactive limit
187+ * Rule3.3: If V < targetV - threshold, generator (Qgen) must be at max reactive limit
188+ * Rule3.4: If |V-targetV| <= threshold, generator (Qgen) must be within [minQ, maxQ]
189+ */
181190 private static boolean checkGeneratorsValues (String id , double p , double q , double v , double expectedP , double targetQ , double targetV ,
182191 boolean voltageRegulatorOn , double minQ , double maxQ , ValidationConfig config ) {
183192 boolean validated = true ;
184- // active power should be equal to setpoint
185- if (ValidationUtils .areNaN (config , expectedP ) || Math .abs (p + expectedP ) > config .getThreshold ()) {
193+ double threshold = config .getThreshold ();
194+ // Rule1: Active power (p) must match setpoint (expectedP) (within threshold)
195+ if (ValidationUtils .areNaN (config , expectedP ) || Math .abs (p + expectedP ) > threshold ) {
186196 LOGGER .warn ("{} {}: {}: P={} expectedP={}" , ValidationType .GENERATORS , ValidationUtils .VALIDATION_ERROR , id , p , expectedP );
187197 validated = false ;
188198 }
189- // if voltageRegulatorOn="false" then reactive power should be equal to setpoint
190- if (!voltageRegulatorOn && (ValidationUtils .areNaN (config , targetQ ) || Math .abs (q + targetQ ) > config . getThreshold () )) {
199+ //Rule2: if voltageRegulatorOn="false" then reactive power (Q) should match to setpoint (targetQ) (within threshold)
200+ if (!voltageRegulatorOn && (ValidationUtils .areNaN (config , targetQ ) || Math .abs (q + targetQ ) > threshold )) {
191201 LOGGER .warn ("{} {}: {}: voltage regulator off - Q={} targetQ={}" , ValidationType .GENERATORS , ValidationUtils .VALIDATION_ERROR , id , q , targetQ );
192202 validated = false ;
193203 }
204+ // Rule3, then
205+ // either Rule3.1, Rule3.2, Rule3.3 or Rule3.4
206+ //
194207 // if voltageRegulatorOn="true" then
195- // either q is equal to g.getReactiveLimits().getMinQ(p) and V is higher than g.getTargetV()
208+ // either if minQ/maxQ/targetV are not NaN,
209+ // or q is equal to g.getReactiveLimits().getMinQ(p) and V is higher than g.getTargetV()
196210 // or q is equal to g.getReactiveLimits().getMaxQ(p) and V is lower than g.getTargetV()
197211 // or V at the connected bus is equal to g.getTargetV() and the reactive bounds are satisfied
198212 double qGen = -q ;
199213 if (voltageRegulatorOn
200214 && (ValidationUtils .areNaN (config , minQ , maxQ , targetV )
201- || v > targetV + config . getThreshold () && Math .abs (qGen - getMinQ (minQ , maxQ )) > config . getThreshold ()
202- || v < targetV - config . getThreshold () && Math .abs (qGen - getMaxQ (minQ , maxQ )) > config . getThreshold ()
203- || Math .abs (v - targetV ) <= config . getThreshold () && !ValidationUtils .boundedWithin (minQ , maxQ , qGen , config . getThreshold () ))) {
215+ || v > targetV + threshold && Math .abs (qGen - getMinQ (minQ , maxQ )) > threshold
216+ || v < targetV - threshold && Math .abs (qGen - getMaxQ (minQ , maxQ )) > threshold
217+ || Math .abs (v - targetV ) <= threshold && !ValidationUtils .boundedWithin (minQ , maxQ , qGen , threshold ))) {
204218 LOGGER .warn ("{} {}: {}: voltage regulator on - Q={} minQ={} maxQ={} - V={} targetV={}" , ValidationType .GENERATORS , ValidationUtils .VALIDATION_ERROR , id , qGen , minQ , maxQ , v , targetV );
205219 validated = false ;
206220 }
207221 return validated ;
208222 }
209223
210224 private static double getMaxQ (double minQ , double maxQ ) {
211- return maxQ < minQ ? minQ : maxQ ;
225+ return Math . max ( maxQ , minQ ) ;
212226 }
213227
214228 private static double getMinQ (double minQ , double maxQ ) {
215- return maxQ < minQ ? maxQ : minQ ;
229+ return Math . min ( maxQ , minQ ) ;
216230 }
217231
218232 private static boolean checkReactiveBoundInversion (double minQ , double maxQ , ValidationConfig config ) {
0 commit comments