Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive slacks on all buses by default #69

Merged
merged 12 commits into from
Jul 11, 2024
4 changes: 2 additions & 2 deletions open-reac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ These are specified in the file `param_algo.txt`:
| `min_plausible_low_voltage_limit` | Consistency bound for low voltage limit of voltage levels (see [4.1](#41-voltage-level-limits-computation)) | $0.5$ (p.u.) | $\mathbb{R}^{+}$ |
| `max_plausible_high_voltage_limit` | Consistency bound for high voltage limit of voltage levels (see [4.1](#41-voltage-level-limits-computation)) | $1.5$ (p.u.) | [`min_plausible_low_voltage_limit`; $\infty$] |
| `ignore_voltage_bounds` | Threshold to replace voltage limits of voltage levels with nominal voltage lower than it, by [min_plausible_low_voltage_limit; max_plausible_high_voltage_limit] | $0$ (p.u.) | $\mathbb{R}^{+}$ |
| `buses_with_reactive_slacks` | Choice of which buses will have reactive slacks attached in ACOPF solving (see [7](#7-alternative-current-optimal-power-flow)) | NO_GENERATION | {CONFIGURED, NO_GENERATION, ALL} |
| `buses_with_reactive_slacks` | Choice of which buses will have reactive slacks attached in ACOPF solving (see [7](#7-alternative-current-optimal-power-flow)) | ALL | {CONFIGURED, NO_GENERATION, ALL} |
| `PQmax` | Threshold for maximum active and reactive power considered in correction of generator limits (see [4.4](#44-pq-units-domain)) | $9000$ (MW, MVAr) | $\mathbb{R}$ |
| `defaultPmax` | Threshold for correction of high active power limit produced by generators (see [4.4](#44-pq-units-domain)) | $1000$ (MW) | $\mathbb{R}$ |
| `defaultPmin` | Threshold for correction of low active power limit produced by generators (see [4.4](#44-pq-units-domain)) | $0$ (MW) | $\mathbb{R}$ |
Expand All @@ -104,7 +104,7 @@ These are specified in the file `param_algo.txt`:
| `default_constraint_scaling_factor` | Default scaling factor applied to all the constraints before ACOPF solving | $1$ | $\mathbb{R}^{+}$ |
| `reactive_slack_variable_scaling_factor` | Scaling factor applied to all reactive slacks variables before ACOPF solving (see [7](#7-alternative-current-optimal-power-flow)) | $0.1$ | $\mathbb{R}^{*,+}$ |
| `transformer_ratio_variable_scaling_factor` | Scaling factor applied to all transformer ratio variables before ACOPF solving (see [7](#7-alternative-current-optimal-power-flow)) | $0.001$ | $\mathbb{R}^{*,+}$ |

| `shunt_variable_scaling_factor` | Scaling factor applied to all shunt variables before ACOPF solving (see [7](#7-alternative-current-optimal-power-flow)) | $0.1$ | $\mathbb{R}^{*,+}$ |

Please note that for these parameters, the AMPL code defines default values which may be different from those in Java (for example, for the
scaling values). This allows a user to use the AMPL code without going through the Java interface, and without providing the file `param_algo.txt`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class OpenReacParameters {

private double maxPlausibleHighVoltageLimit = 1.5; // in pu

private ReactiveSlackBusesMode reactiveSlackBusesMode = ReactiveSlackBusesMode.NO_GENERATION;
private ReactiveSlackBusesMode reactiveSlackBusesMode = ReactiveSlackBusesMode.ALL;

private static final String ACTIVE_POWER_VARIATION_RATE_KEY = "coeff_alpha";

Expand Down Expand Up @@ -118,6 +118,10 @@ public class OpenReacParameters {

private double twoWindingTransformerRatioVariableScalingFactor = 1e-3;

private static final String SHUNT_VARIABLE_SCALING_FACTOR_KEY = "shunt_variable_scaling_factor";

private double shuntVariableScalingFactor = 1e-1;

// Shunt compensator alert threshold
// (to help reporting the shunt compensators with a delta between optimized and discretized reactive value over this threshold in MVar)

Expand Down Expand Up @@ -514,6 +518,21 @@ public OpenReacParameters setTwoWindingTransformerRatioVariableScalingFactor(dou
return this;
}

/**
* @return the scaling value of shunt variables in ACOPF.
*/
public double getShuntVariableScalingFactor() {
return shuntVariableScalingFactor;
}

public OpenReacParameters setShuntVariableScalingFactor(double shuntVariableScalingFactor) {
if (shuntVariableScalingFactor <= 0 || Double.isNaN(shuntVariableScalingFactor)) {
throw new IllegalArgumentException("Scaling factor for shunt variables must be > 0 and defined to be consistent.");
}
this.shuntVariableScalingFactor = shuntVariableScalingFactor;
return this;
}

/**
* @return the shunt compensator activation alert threshold
*/
Expand Down Expand Up @@ -554,6 +573,7 @@ public List<OpenReacAlgoParam> getAllAlgorithmParams() {
allAlgoParams.add(new OpenReacAlgoParamImpl(DEFAULT_CONSTRAINT_SCALING_FACTOR, Double.toString(defaultConstraintScalingFactor)));
allAlgoParams.add(new OpenReacAlgoParamImpl(REACTIVE_SLACK_VARIABLE_SCALING_FACTOR, Double.toString(reactiveSlackVariableScalingFactor)));
allAlgoParams.add(new OpenReacAlgoParamImpl(TWO_WINDING_TRANSFORMER_RATIO_VARIABLE_SCALING_FACTOR, Double.toString(twoWindingTransformerRatioVariableScalingFactor)));
allAlgoParams.add(new OpenReacAlgoParamImpl(SHUNT_VARIABLE_SCALING_FACTOR_KEY, Double.toString(shuntVariableScalingFactor)));
return allAlgoParams;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext
parser.nextToken();
parameters.setTwoWindingTransformerRatioVariableScalingFactor(parser.readValueAs(Double.class));
}
case "shuntVariableScalingFactor" -> {
parser.nextToken();
parameters.setShuntVariableScalingFactor(parser.readValueAs(Double.class));
}
default -> throw new IllegalStateException("Unexpected field: " + parser.getCurrentName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG
serializerProvider.defaultSerializeField("defaultConstraintScalingFactor", openReacParameters.getDefaultConstraintScalingFactor(), jsonGenerator);
serializerProvider.defaultSerializeField("reactiveSlackVariableScalingFactor", openReacParameters.getReactiveSlackVariableScalingFactor(), jsonGenerator);
serializerProvider.defaultSerializeField("twoWindingTransformerRatioVariableScalingFactor", openReacParameters.getTwoWindingTransformerRatioVariableScalingFactor(), jsonGenerator);
serializerProvider.defaultSerializeField("shuntVariableScalingFactor", openReacParameters.getShuntVariableScalingFactor(), jsonGenerator);
jsonGenerator.writeEndObject();
}
}
12 changes: 6 additions & 6 deletions open-reac/src/main/resources/openreac/reactiveopf.mod
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ subject to ctr_balance_P{PROBLEM_ACOPF,k in BUSCC}:
set BUSCC_SLACK := if buses_with_reactive_slacks == "ALL" then BUSCC
else if buses_with_reactive_slacks == "NO_GENERATION" then {n in BUSCC: (card{(g,n) in UNITON: (g,n) not in UNIT_FIXQ}==0 and card{(svc,n) in SVCON}==0 and card{(vscconv,n) in VSCCONVON}==0)}
else BUSCC inter PARAM_BUSES_WITH_REACTIVE_SLACK; # if = "CONFIGURED", buses given as parameter but in connex component
var slack1_balance_Q{BUSCC_SLACK} >=0;
var slack2_balance_Q{BUSCC_SLACK} >=0;
var slack1_shunt_B{BUSCC_SLACK} >= 0;
var slack2_shunt_B{BUSCC_SLACK} >= 0;
#subject to ctr_compl_slack_Q{PROBLEM_ACOPF,k in BUSCC_SLACK}: slack1_balance_Q[k] >= 0 complements slack2_balance_Q[k] >= 0;

subject to ctr_balance_Q{PROBLEM_ACOPF,k in BUSCC}:
Expand All @@ -980,8 +980,8 @@ subject to ctr_balance_Q{PROBLEM_ACOPF,k in BUSCC}:
+ sum{(l,k) in LCCCONVON} lccconv_Q0[1,l,k] # Fixed value
# Slack variables
+ if k in BUSCC_SLACK then
(- slack1_balance_Q[k] # Homogeneous to a generation of reactive power (condensator)
+ slack2_balance_Q[k]) # homogeneous to a reactive load (self)
(- base100MVA * V[k]^2 * slack1_shunt_B[k] # Homogeneous to a generation of reactive power (condensator)
+ base100MVA * V[k]^2 * slack2_shunt_B[k]) # homogeneous to a reactive load (self)
= 0;


Expand Down Expand Up @@ -1013,8 +1013,8 @@ param penalty_voltage_target_low := 0.01;

minimize problem_acopf_objective:
sum{n in BUSCC_SLACK} (
penalty_invest_rea_pos * slack1_balance_Q[n]
+ penalty_invest_rea_neg * slack2_balance_Q[n]
penalty_invest_rea_pos * base100MVA * slack1_shunt_B[n]
+ penalty_invest_rea_neg * base100MVA * slack2_shunt_B[n]
)

# coeff_alpha == 1 : minimize sum of generation, all generating units vary with 1 unique variable alpha
Expand Down
25 changes: 19 additions & 6 deletions open-reac/src/main/resources/openreac/reactiveopf.run
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ if ignore_voltage_bounds >= epsilon_nominal_voltage
then printf{LOG_INFO} "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,min_plausible_low_voltage_limit,max_plausible_high_voltage_limit;
check ignore_voltage_bounds >= 0;

param buses_with_reactive_slacks symbolic default "NO_GENERATION";
param buses_with_reactive_slacks symbolic default "ALL";
if "buses_with_reactive_slacks" in PARAM_ALGO_KEYS then let buses_with_reactive_slacks := PARAM_ALGO_VALUES["buses_with_reactive_slacks"];
printf{LOG_INFO} "Parameter: choice for buses with reactive slacks in ACOPF := %Q (%s)\n", buses_with_reactive_slacks,
if buses_with_reactive_slacks == "ALL" then "every bus in connex component."
Expand Down Expand Up @@ -374,6 +374,10 @@ if "transformer_ratio_variable_scaling_factor" in PARAM_ALGO_KEYS then let trans
printf{LOG_INFO} "Parameter: scaling factor for tranformer ratio variables := %.3f\n",transformer_ratio_variable_scaling_factor;
check transformer_ratio_variable_scaling_factor > 0;

param shunt_variable_scaling_factor default 1e-1;
if "shunt_variable_scaling_factor" in PARAM_ALGO_KEYS then let shunt_variable_scaling_factor := num(PARAM_ALGO_VALUES["shunt_variable_scaling_factor"]);
printf{LOG_INFO} "Parameter: scaling factor for shunt variables := %.3f\n",shunt_variable_scaling_factor;
check shunt_variable_scaling_factor > 0;

###############################################################################
# Solver choice and options
Expand Down Expand Up @@ -971,8 +975,8 @@ let {n in BUSVV} V[n] := bus_V0[1,n];
let {n in BUSCC diff BUSVV} V[n] := voltage_lower_bound[1,bus_substation[1,n]]
+ 0.8 *(voltage_upper_bound[1,bus_substation[1,n]] - voltage_lower_bound[1,bus_substation[1,n]]);

let {n in BUSCC_SLACK} slack1_balance_Q[n] := 0;
let {n in BUSCC_SLACK} slack2_balance_Q[n] := 0;
let {n in BUSCC_SLACK} slack1_shunt_B[n] := 0;
let {n in BUSCC_SLACK} slack2_shunt_B[n] := 0;
let alpha := 0.01;
let {(g,n) in UNITON} P_bounded[g,n] := max(P_dcopf[g,n],unit_Pc[1,g,n]);
let {(g,n) in UNITON} Q[g,n] := 0.5*(corrected_unit_Qmax[g,n] + corrected_unit_Qmin[g,n]);
Expand All @@ -989,16 +993,18 @@ let tempstr := ctime();
printf{LOG_KNITRO} "\n######################################################################\n";
printf{LOG_KNITRO} "** ACopf solve: start (%s)\n\n",ctime();

option knitro_options ("opttol=1 opttolabs=1e-1 feastol=1 feastolabs=1e-3 maxit=200 outlev=3");
option knitro_options ("opttol=1 opttolabs=1e-1 feastol=1 feastolabs=1e-3 maxit=300 outlev=3");

let {i in 1.._nvars} _var[i].xscalefactor := default_variable_scaling_factor;
let {i in 1.._ncons} _con[i].cscalefactor := default_constraint_scaling_factor;

let {n in BUSCC_SLACK} slack1_balance_Q[n].xscalefactor := reactive_slack_variable_scaling_factor;
let {n in BUSCC_SLACK} slack2_balance_Q[n].xscalefactor := reactive_slack_variable_scaling_factor;
let {n in BUSCC_SLACK} slack1_shunt_B[n].xscalefactor := reactive_slack_variable_scaling_factor;
let {n in BUSCC_SLACK} slack2_shunt_B[n].xscalefactor := reactive_slack_variable_scaling_factor;

let {(qq,m,n) in BRANCHCC_REGL_VAR} branch_Ror_var[qq,m,n].xscalefactor := transformer_ratio_variable_scaling_factor;

let {(shunt,n) in SHUNT_VAR} shunt_var[shunt,n].xscalefactor := shunt_variable_scaling_factor;

# solve acopf and avoid knitro printing if user asks
if (log_level_knitro <= 1) then {
solve problem_acopf_objective > (nullDevice);
Expand All @@ -1013,6 +1019,13 @@ printf{LOG_KNITRO} "\n** ACopf solve: end (%s -> %s)\n",tempstr,ctime();
printf{LOG_KNITRO} "######################################################################\n\n";


param slack1_balance_Q{n in BUSCC_SLACK};
param slack2_balance_Q{n in BUSCC_SLACK};
for {n in BUSCC_SLACK} {
let slack1_balance_Q[n] := base100MVA * V[n]^2 * slack1_shunt_B[n].val;
let slack2_balance_Q[n] := base100MVA * V[n]^2 * slack2_shunt_B[n].val;
}

###############################################################################
# Analysis of solve_result_num
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion open-reac/src/main/resources/openreac/reactiveopfexit.run
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ printf "%s %f\n","default_variable_scaling_factor",default_variable_scaling_fact
printf "%s %f\n","default_constraint_scaling_factor",default_constraint_scaling_factor > (fileOut);
printf "%s %f\n","reactive_slack_variable_scaling_factor",reactive_slack_variable_scaling_factor > (fileOut);
printf "%s %f\n","transformer_ratio_variable_scaling_factor",transformer_ratio_variable_scaling_factor > (fileOut);

printf "%s %f\n","shunt_variable_scaling_factor",shunt_variable_scaling_factor > (fileOut);
close (fileOut);

printf "\n*** End of file reactiveopfexit.run : %s\n",ctime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ printf "%s %f\n","default_variable_scaling_factor",default_variable_scaling_fact
printf "%s %f\n","default_constraint_scaling_factor",default_constraint_scaling_factor > (fileOut);
printf "%s %f\n","reactive_slack_variable_scaling_factor",reactive_slack_variable_scaling_factor > (fileOut);
printf "%s %f\n","transformer_ratio_variable_scaling_factor",transformer_ratio_variable_scaling_factor > (fileOut);
printf "%s %f\n","shunt_variable_scaling_factor",shunt_variable_scaling_factor > (fileOut);

printf "\n" > (fileOut);
printf "%s %i\n","nb_substations",card(SUBSTATIONS) > (fileOut);
Expand Down
Loading
Loading