From 467ce3b7375a72a4ce2711d7a54f45f1860477ae Mon Sep 17 00:00:00 2001 From: parvy Date: Mon, 16 Oct 2023 12:51:43 +0200 Subject: [PATCH 1/4] Add use of log levels for AMPL printing. Signed-off-by: parvy --- .../main/resources/openreac/reactiveopf.run | 257 +++++++++--------- 1 file changed, 136 insertions(+), 121 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index a7f05e5b..75702a87 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -217,6 +217,20 @@ param: PARAM_ALGO_KEYS: PARAM_ALGO_VALUES := include param_algo.txt; model; display PARAM_ALGO_VALUES; +# Define log level of the run +set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"}; # different values of log levels +param log_level symbolic default "INFO"; +if "log_level" in PARAM_ALGO_KEYS then let log_level := PARAM_ALGO_VALUES["log_level"]; +check log_level in LOG_LEVELS; +param log_index := ord0(log_level, LOG_LEVELS); + +# Sets which will be used to chose to print or not. A void set avoid printing. +set LOG_TRACE := if log_index >= 5 then{1} else {}; +set LOG_DEBUG := if log_index >= 4 then{1} else {}; +set LOG_INFO := if log_index >= 3 then{1} else {}; +set LOG_WARNING := if log_index >= 2 then{1} else {}; +set LOG_ERROR := if log_index >= 1 then{1} else {}; +printf{LOG_INFO} "Parameter: log level = %s\n", log_level; # Absolute parameter : base 100MVA. # Never change this unless you really know what you do @@ -225,7 +239,7 @@ param base100MVA := 100; # Choice of objective function param objective_choice integer default 0; if "objective_choice" in PARAM_ALGO_KEYS then let objective_choice := num(PARAM_ALGO_VALUES["objective_choice"]); -printf "Parameter: choice for objective function := %Q (%s)\n",objective_choice, +printf{LOG_INFO} "Parameter: choice for objective function := %Q (%s)\n",objective_choice, if objective_choice==2 then "voltage targets are provided values" else if objective_choice==1 then "voltage targets are Vmin+ratio*(Vmax-Vmin)" else "active power minimization"; @@ -235,25 +249,25 @@ param ratio_voltage_target default 0.5; if "ratio_voltage_target" in PARAM_ALGO_KEYS then let ratio_voltage_target := num(PARAM_ALGO_VALUES["ratio_voltage_target"]); check ratio_voltage_target >= 0 and ratio_voltage_target <= 1; if objective_choice==1 -then printf "Parameter: ratio for voltage target is := %f (%.2f%%)\n",ratio_voltage_target,ratio_voltage_target*100; +then printf{LOG_INFO} "Parameter: ratio for voltage target is := %f (%.2f%%)\n",ratio_voltage_target,ratio_voltage_target*100; # coeff_alpha == 1 : minimize sum of generation, all generating units vary with 1 unique variable alpha # coeff_alpha == 0 : minimize sum of squared difference between target and value param coeff_alpha default 1.0; if "coeff_alpha" in PARAM_ALGO_KEYS then let coeff_alpha := num(PARAM_ALGO_VALUES["coeff_alpha"]); -printf "Parameter: coeff_alpha to choose wether generation vary homogeneously (coeff_alpha=1) or independantly (coeff_alpha=0) is := %.2f\n",coeff_alpha; +printf{LOG_INFO} "Parameter: coeff_alpha to choose wether generation vary homogeneously (coeff_alpha=1) or independantly (coeff_alpha=0) is := %.2f\n",coeff_alpha; check coeff_alpha >=0 and coeff_alpha <= 1; # Limit for detecting zero value for power param Pnull default 0.01; # MW if "Pnull" in PARAM_ALGO_KEYS then let Pnull := num(PARAM_ALGO_VALUES["Pnull"]); -printf "Parameter: threshold to decide wether an active or reactive power value is zero Pnull:=%Q (MW or Mvar or MVA)\n",Pnull; +printf{LOG_INFO} "Parameter: threshold to decide wether an active or reactive power value is zero Pnull:=%Q (MW or Mvar or MVA)\n",Pnull; check Pnull > 0 and Pnull < 1; # Parameter for detection of branches with zero impedance param Znull default 1e-4; if "Znull" in PARAM_ALGO_KEYS then let Znull := num(PARAM_ALGO_VALUES["Znull"]); -printf "Parameter: threshold to detect zero impedance branch Znull:=%Q pu\n",Znull; +printf{LOG_INFO} "Parameter: threshold to detect zero impedance branch Znull:=%Q pu\n",Znull; check Znull > 0 and Znull < 0.1; # Minimum consistency value for minimum voltage in kV @@ -261,14 +275,14 @@ check Znull > 0 and Znull < 0.1; # This value has to be >0 param epsilon_nominal_voltage default 1.0; if "epsilon_nominal_voltage" in PARAM_ALGO_KEYS then let epsilon_nominal_voltage := num(PARAM_ALGO_VALUES["epsilon_nominal_voltage"]); -printf "Parameter: for consistency checks of minimum nominal voltages epsilon_nominal_voltage:= %Q kV\n",epsilon_nominal_voltage; +printf{LOG_INFO} "Parameter: for consistency checks of minimum nominal voltages epsilon_nominal_voltage:= %Q kV\n",epsilon_nominal_voltage; check epsilon_nominal_voltage > 0; # Minimum consistency value for voltage in PU # This value has to be >0 and <1 param epsilon_min_voltage default 0.5; if "epsilon_min_voltage" in PARAM_ALGO_KEYS then let epsilon_min_voltage := num(PARAM_ALGO_VALUES["epsilon_min_voltage"]); -printf "Parameter: for consistency checks of voltage bounds eps<=Vmin 0 and epsilon_min_voltage < 1; # Ignore voltage bounds for buses with nominal voltage lower than this parameter @@ -277,7 +291,7 @@ check epsilon_min_voltage > 0 and epsilon_min_voltage < 1; param ignore_voltage_bounds default 0; if "ignore_voltage_bounds" in PARAM_ALGO_KEYS then let ignore_voltage_bounds := num(PARAM_ALGO_VALUES["ignore_voltage_bounds"]); if ignore_voltage_bounds >= epsilon_nominal_voltage -then printf "Parameter: for all busses with nominal voltage <= ignore_voltage_bounds=%.1f, voltage bounds are ignored and replaced by [%.3f;%.3f]\n",ignore_voltage_bounds,epsilon_min_voltage,2-epsilon_min_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,epsilon_min_voltage,2-epsilon_min_voltage; check ignore_voltage_bounds >= 0; # Consistency maximal value for P and Q @@ -285,32 +299,29 @@ check ignore_voltage_bounds >= 0; # Largest nuclear plant in Europe are less than 2000GW. Value 9000 might be a problem for large hydro dams in the world (22GW) param PQmax default 9000; if "PQmax" in PARAM_ALGO_KEYS then let PQmax := num(PARAM_ALGO_VALUES["PQmax"]); -printf "Parameter: maximum for generating units' parameters Pmin Pmax Qmin Qmax = %Q MW or Mvar\n",PQmax; +printf{LOG_INFO} "Parameter: maximum for generating units parameters Pmin Pmax Qmin Qmax = %Q MW or Mvar\n",PQmax; param defaultPmax default 1000; # MW if "defaultPmax" in PARAM_ALGO_KEYS then let defaultPmax := num(PARAM_ALGO_VALUES["defaultPmax"]); -printf "Parameter: %s = %Q MW\n","defaultPmax",defaultPmax; +printf{LOG_INFO} "Parameter: %s = %Q MW\n","defaultPmax",defaultPmax; param defaultPmin default 0; # MW if "defaultPmin" in PARAM_ALGO_KEYS then let defaultPmin := num(PARAM_ALGO_VALUES["defaultPmin"]); -printf "Parameter: %s = %Q MW\n","defaultPmin",defaultPmin; +printf{LOG_INFO} "Parameter: %s = %Q MW\n","defaultPmin",defaultPmin; param defaultQmaxPmaxRatio default 0.3; # Mvar/MW if "defaultQmaxPmaxRatio" in PARAM_ALGO_KEYS then let defaultQmaxPmaxRatio := num(PARAM_ALGO_VALUES["defaultQmaxPmaxRatio"]); -printf "Parameter: %s = %Q Mvar/MW\n","defaultQmaxPmaxRatio",defaultQmaxPmaxRatio; +printf{LOG_INFO} "Parameter: %s = %Q Mvar/MW\n","defaultQmaxPmaxRatio",defaultQmaxPmaxRatio; param defaultQmin := -defaultQmaxPmaxRatio * defaultPmax; -printf "Parameter: %s = %Q Mvar\n","defaultQmin",defaultQmin; +printf{LOG_INFO} "Parameter: %s = %Q Mvar\n","defaultQmin",defaultQmin; param defaultQmax := defaultQmaxPmaxRatio * defaultPmax; -printf "Parameter: %s = %Q Mvar\n","defaultQmax",defaultQmax; +printf{LOG_INFO} "Parameter: %s = %Q Mvar\n","defaultQmax",defaultQmax; param minimalQPrange default 1; # MW or Mvar; if domain is smaller, Q or P is fixed if "minimalQPrange" in PARAM_ALGO_KEYS then let minimalQPrange := num(PARAM_ALGO_VALUES["minimalQPrange"]); -printf "Parameter: %s = %Q MW or Mvar\n","minimalQPrange",minimalQPrange; - - - +printf{LOG_INFO} "Parameter: %s = %Q MW or Mvar\n","minimalQPrange",minimalQPrange; ############################################################################### @@ -391,7 +402,7 @@ check; # of generation proportionally, to ensure global balance generation=losses+load # So this "slack node" is used only for zero phase constraint # This reference bus is also used to choose on which connect component computation si performed -printf "\nComputation of bus with largest number of branches connected, in order to fix phase to 0 and to choose on which connex component reacive OPF will run\n"; +printf{LOG_INFO} "\nComputation of bus with largest number of branches connected, in order to fix phase to 0 and to choose on which connex component reacive OPF will run\n"; let temp1 := min(300,max{n in BUS2} substation_Vnomi[1,bus_substation[1,n]]); let null_phase_bus := min{n in BUS2} n; let tempo := 0; @@ -400,14 +411,14 @@ for {n in BUS2 : substation_Vnomi[1,bus_substation[1,n]] >= temp1 * 0.9} for {n in BUS2 : substation_Vnomi[1,bus_substation[1,n]] >= temp1 * 0.9 && card({(qq,mm,n) in BRANCH2} union {(qq,n,nn) in BRANCH2}) == tempo} let null_phase_bus := n; if ( tempo > 0 ) then - printf "Bus %QkV with most branches: %Q in substation %s/%s with %Q connected branches\n", + printf{LOG_INFO} "Bus %QkV with most branches: %Q in substation %s/%s with %Q connected branches\n", substation_Vnomi[1,bus_substation[1,null_phase_bus]], null_phase_bus, substation_id[1,bus_substation[1,null_phase_bus]], substation_description[1,bus_substation[1,null_phase_bus]], tempo; if ( tempo == 0 ) then - printf "Bus with most branches: not found. Take first bus (=%Q) for phase=0 constraint\n",null_phase_bus; + printf{LOG_WARNING} "Bus with most branches: not found. Take first bus (=%Q) for phase=0 constraint\n",null_phase_bus; @@ -416,13 +427,14 @@ if ( tempo == 0 ) then # Connexity checks and computation of connex components # ############################################################################### -printf "\n*** Connexity computation\n"; +printf{LOG_TRACE} "\n*** Connexity computation\n"; let PROBLEM_CCOMP := {1}; let PROBLEM_DCOPF := { }; let PROBLEM_ACOPF := { }; option presolve 0; +#option knitro_options "outlev=0"; # TODO : put conditionnal value here let tempstr := ctime(); -printf "# CCcomp solve: start (%s)\n\n",tempstr; +printf{LOG_TRACE} "# CCcomp solve: start (%s)\n\n",tempstr; # solve cccomputation_objective; # @@ -435,7 +447,7 @@ then { let final_status := "NOK"; include reactiveopfexit.run; } -printf "# CCcomp solve: end (%s -> %s)\n\n",tempstr,ctime(); +printf{LOG_TRACE} "# CCcomp solve: end (%s -> %s)\n\n",tempstr,ctime(); option presolve 10; # @@ -443,14 +455,14 @@ option presolve 10; # let BUSCC := {n in BUS2: teta_ccomputation[n].val <= 0.01}; -printf "\n*** Connexity computation\n"; +printf{LOG_INFO} "\n*** Connexity computation\n"; for{n in BUS2 diff BUSCC} - printf "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) is out of main AC CC\n", + printf{LOG_WARNING} "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) is out of main AC CC\n", bus_id[1,n], substation_id[1,bus_substation[1,n]], substation_Vnomi[1,bus_substation[1,n]], substation_country[1,bus_substation[1,n]]; -printf "Nb of busses in AC+DC CC: %i\n",card(BUS2); -printf "Nb of busses in CC %Q: %i\n",bus_id[1,null_phase_bus],card(BUSCC); -printf "Nb of busses in other CCs: %Q\n",card(BUS2)-card(BUSCC); +printf{LOG_INFO} "Nb of busses in AC+DC CC: %i\n",card(BUS2); +printf{LOG_INFO} "Nb of busses in CC %Q: %i\n",bus_id[1,null_phase_bus],card(BUSCC); +printf{LOG_INFO} "Nb of busses in other CCs: %Q\n",card(BUS2)-card(BUSCC); printf "\n"; @@ -459,17 +471,19 @@ printf "\n"; ############################################################################### # A few information ############################################################################### -display -maximal_voltage_upper_bound, minimal_voltage_lower_bound, -card(SUBSTATIONS),card(BUS),card(BUS2),card(BUSCC),card(BUS2 diff BUSCC),card(BUSVV),card(BUSCC_SLACK),card(BUSCC diff BUSCC_SLACK), -card(BRANCH),card(BRANCHCC),card(BRANCHZNULL),card(BRANCHCC diff BRANCHZNULL), -card(UNIT),card(UNITCC),card(UNITON),card(UNITON diff UNIT_FIXQ),card(UNIT_FIXQ), -card(LOAD),card(LOADCC), -card(SHUNTCC),card(SHUNT_FIX),card(SHUNT_VAR), -card(SVC),card(SVCCC),card(SVCON), -card(VSCCONV),card(VSCCONVON), -card(LCCCONV),card(LCCCONVON) +if log_index >= 3 then { + display + maximal_voltage_upper_bound, minimal_voltage_lower_bound, + card(SUBSTATIONS),card(BUS),card(BUS2),card(BUSCC),card(BUS2 diff BUSCC),card(BUSVV),card(BUSCC_SLACK),card(BUSCC diff BUSCC_SLACK), + card(BRANCH),card(BRANCHCC),card(BRANCHZNULL),card(BRANCHCC diff BRANCHZNULL), + card(UNIT),card(UNITCC),card(UNITON),card(UNITON diff UNIT_FIXQ),card(UNIT_FIXQ), + card(LOAD),card(LOADCC), + card(SHUNTCC),card(SHUNT_FIX),card(SHUNT_VAR), + card(SVC),card(SVCCC),card(SVCON), + card(VSCCONV),card(VSCCONVON), + card(LCCCONV),card(LCCCONVON) ; +} # Is the case power globally power balanced? let temp1 := sum{(c,n) in LOADCC} load_PFix[1,c,n]; @@ -478,53 +492,53 @@ let temp2 := temp2 + sum{(b,n) in BATTERYCC} battery_p0[1,b,n]; let temp3 := (sum{(vscconv,n) in VSCCONVON} vscconv_P0[1,vscconv,n])+(sum{(l,k) in LCCCONVON} lccconv_P0[1,l,k]); let global_initial_losses_ratio := (temp2-temp1-temp3)/(temp1+temp3); -printf "HVDC injections (homogeneous to loads):\n"; +printf{LOG_INFO} "HVDC injections (homogeneous to loads):\n"; for {(v,n) in VSCCONVON} - printf "VSC converter %Q in %Q: P0=%.1fMW is fixed, Q is variable\n", + printf{LOG_INFO} "VSC converter %Q in %Q: P0=%.1fMW is fixed, Q is variable\n", vscconv_id[1,v,n],substation_id[1,bus_substation[1,n]],vscconv_P0[1,v,n]; for {(l,n) in LCCCONVON} - printf "LCC converter %Q in %Q: P0=%.1fMW is fixed, Q0=%.1fMvar is fixed\n", + printf{LOG_INFO} "LCC converter %Q in %Q: P0=%.1fMW is fixed, Q0=%.1fMvar is fixed\n", lccconv_id[1,l,n],substation_id[1,bus_substation[1,n]],lccconv_P0[1,l,n],lccconv_Q0[1,l,n]; -printf "Sum of HVDC conv. H: %.0f MW\n", temp3; -printf "Sum of loads C: %.0f MW\n", temp1; -printf "Sum of generations P: %.0f MW\n", temp2; -printf " (including batteries for %.1f MW\n", sum{(b,n) in BATTERYCC} battery_p0[1,b,n]; -printf "Balance (P-C-H)/C: %.2f %% (global_initial_losses_ratio=%f)\n\n", (temp2-temp1-temp3)/temp1*100,global_initial_losses_ratio; +printf{LOG_INFO} "Sum of HVDC conv. H: %.0f MW\n", temp3; +printf{LOG_INFO} "Sum of loads C: %.0f MW\n", temp1; +printf{LOG_INFO} "Sum of generations P: %.0f MW\n", temp2; +printf{LOG_INFO} " (including batteries for %.1f MW\n", sum{(b,n) in BATTERYCC} battery_p0[1,b,n]; +printf{LOG_INFO} "Balance (P-C-H)/C: %.2f %% (global_initial_losses_ratio=%f)\n\n", (temp2-temp1-temp3)/temp1*100,global_initial_losses_ratio; # Branches with low current limits (but keep in mind they are not used; this is just for information) let temp1 := min{(qq,m,n) in BRANCHCC} Fmax[qq,m,n]; for {(qq,m,n) in BRANCHCC : Fmax[qq,m,n] <= temp1 * 1.5} - printf "Branch %Q Fmax=%.2fMW is small ; Vnom1=%ikV Vnom2=%ikV patl1=%iA patl2=%iA (Fmax not used, this is just for information)\n", + printf{LOG_WARNING} "Branch %Q Fmax=%.2fMW is small ; Vnom1=%ikV Vnom2=%ikV patl1=%iA patl2=%iA (Fmax not used, this is just for information)\n", branch_id[1,qq,m,n],Fmax[qq,m,n],substation_Vnomi[1,bus_substation[1,m]],substation_Vnomi[1,bus_substation[1,n]],branch_patl1[1,qq,m,n],branch_patl1[1,qq,m,n]; # Abnormally low nominal voltages for {(t,n) in BUS: substation_Vnomi[1,bus_substation[1,n]] < epsilon_nominal_voltage} - printf "Warning: bus %Q in substation %Q has nominal voltage %.2fkV < %QkV -> bus is ignored\n", + printf{LOG_WARNING} "Warning: bus %Q in substation %Q has nominal voltage %.2fkV < %QkV -> bus is ignored\n", bus_id[1,n], substation_id[1,bus_substation[1,n]], substation_Vnomi[1,bus_substation[1,n]], epsilon_nominal_voltage; # Voltage bounds let temp1 := min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]; for {(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0 and substation_Vmin[t,s] <= temp1*1.01} - printf "Substations %Q with lowest voltage lower bound Vnom=%ikV Vmin=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmin[t,s]; + printf{LOG_WARNING} "Substations %Q with lowest voltage lower bound Vnom=%ikV Vmin=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmin[t,s]; let temp1 := max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]; for {(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0 and substation_Vmax[t,s] >= temp1*0.99} - printf "Substations %Q with highest voltage upper bound Vnom=%ikV Vmax=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmax[t,s]; -printf "If voltage lower bounds are missing or too small, they are set to %.3fpu\n",minimal_voltage_lower_bound; -printf "If voltage upper bounds are missing or too high, they are set to %.3fpu\n",maximal_voltage_upper_bound; + printf{LOG_WARNING} "Substations %Q with highest voltage upper bound Vnom=%ikV Vmax=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmax[t,s]; +printf{LOG_WARNING} "If voltage lower bounds are missing or too small, they are set to %.3fpu\n",minimal_voltage_lower_bound; +printf{LOG_WARNING} "If voltage upper bounds are missing or too high, they are set to %.3fpu\n",maximal_voltage_upper_bound; let temp1 := card({n in BUSCC: substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds}); if temp1 > 0 then -printf "Voltage bounds for substations with nominal voltage <= %ikV are set to [%.3fpu;%.3fpu] (%i busses)\n", +printf{LOG_WARNING} "Voltage bounds for substations with nominal voltage <= %ikV are set to [%.3fpu;%.3fpu] (%i busses)\n", ignore_voltage_bounds,minimal_voltage_lower_bound,maximal_voltage_upper_bound,temp1; -printf "Maximal diameter of voltage interval: %.3f\n",max({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); -printf "Minimal diameter of voltage interval: %.3f\n",min({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); +printf{LOG_WARNING} "Maximal diameter of voltage interval: %.3f\n",max({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); +printf{LOG_WARNING} "Minimal diameter of voltage interval: %.3f\n",min({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); # # Consistency of transformers ratios # let temp1 := min{(t,r) in REGL} regl_ratio_min[1,r]; let temp2 := max{(t,r) in REGL} regl_ratio_max[1,r]; -printf "Minimal transformer ratio : %.3f\n",temp1; -printf "Maximal transformer ratio : %.3f\n",temp2; +printf{LOG_INFO} "Minimal transformer ratio : %.3f\n",temp1; +printf{LOG_INFO} "Maximal transformer ratio : %.3f\n",temp2; for {(qq,m,n) in BRANCHCC_REGL: qq in PARAM_TRANSFORMERS_RATIO_VARIABLE and not regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]] < regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]]} { @@ -535,13 +549,13 @@ for {(qq,m,n) in BRANCHCC_REGL: qq in PARAM_TRANSFORMERS_RATIO_VARIABLE substation_id[1,bus_substation[1,n]],substation_Vnomi[1,bus_substation[1,n]], branch_cstratio[1,qq,m,n], regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]],regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]]); - printf "%s\n",messageInfo; + printf{LOG_WARNING} "%s\n",messageInfo; let messagesInfo := messagesInfo union {messageInfo}; } for {(qq,m,n) in BRANCHCC_REGL: regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]] <= temp1 * 1.01 or regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]] >= temp2 * 0.99 } { - printf "Transformer %Q ratio_min=%.3f ratio_max=%.3f\n", + printf{LOG_WARNING} "Transformer %Q ratio_min=%.3f ratio_max=%.3f\n", branch_id[1,qq,m,n], regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]], regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]] @@ -564,7 +578,7 @@ for {(qq,m,n) in BRANCHCC_REGL} { branch_cstratio[1,qq,m,n],temp1,temp2, voltage_lower_bound[1,bus_substation[1,m]], voltage_upper_bound[1,bus_substation[1,n]]); - printf "%s\n",messageInfo; + printf{LOG_ERROR} "%s\n",messageInfo; let messagesInfo := messagesInfo union {messageInfo}; } if voltage_upper_bound[1,bus_substation[1,m]]*temp2*branch_cstratio[1,qq,m,n] < voltage_lower_bound[1,bus_substation[1,n]] @@ -580,7 +594,7 @@ for {(qq,m,n) in BRANCHCC_REGL} { branch_cstratio[1,qq,m,n],temp1,temp2, voltage_upper_bound[1,bus_substation[1,m]], voltage_lower_bound[1,bus_substation[1,n]]); - printf "%s\n",messageInfo; + printf{LOG_ERROR} "%s\n",messageInfo; let messagesInfo := messagesInfo union {messageInfo}; } } @@ -600,7 +614,7 @@ for {(qq,m,n) in BRANCHCC_REGL_FIX} { branch_cstratio[1,qq,m,n],temp1, voltage_lower_bound[1,bus_substation[1,m]], voltage_upper_bound[1,bus_substation[1,n]]); - printf "%s\n",messageInfo; + printf{LOG_ERROR} "%s\n",messageInfo; let messagesInfo := messagesInfo union {messageInfo}; } if voltage_upper_bound[1,bus_substation[1,m]]*temp1*branch_cstratio[1,qq,m,n] < voltage_lower_bound[1,bus_substation[1,n]] @@ -616,7 +630,7 @@ for {(qq,m,n) in BRANCHCC_REGL_FIX} { branch_cstratio[1,qq,m,n],temp1, voltage_upper_bound[1,bus_substation[1,m]], voltage_lower_bound[1,bus_substation[1,n]]); - printf "%s\n",messageInfo; + printf{LOG_ERROR} "%s\n",messageInfo; let messagesInfo := messagesInfo union {messageInfo}; } } @@ -639,19 +653,19 @@ for {(g,n) in UNITON} { if abs(unit_Pmax[1,g,n]) >= PQmax then { let corrected_unit_Pmax[g,n] := max(defaultPmax,unit_Pc[1,g,n]); - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_Pmax",unit_id[1,g,n],unit_Pmax[1,g,n],corrected_unit_Pmax[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_Pmax",unit_id[1,g,n],unit_Pmax[1,g,n],corrected_unit_Pmax[g,n]; } else let corrected_unit_Pmax[g,n] := unit_Pmax[1,g,n]; if abs(unit_Pmin[1,g,n]) >= PQmax then { let corrected_unit_Pmin[g,n] := min(defaultPmin,unit_Pc[1,g,n]); - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_Pmin",unit_id[1,g,n],unit_Pmin[1,g,n],corrected_unit_Pmin[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_Pmin",unit_id[1,g,n],unit_Pmin[1,g,n],corrected_unit_Pmin[g,n]; } else let corrected_unit_Pmin[g,n] := unit_Pmin[1,g,n]; if abs(corrected_unit_Pmax[g,n]-corrected_unit_Pmin[g,n]) <= minimalQPrange then { if abs(unit_Pc[1,g,n]) > 1 then - printf "Unit %Q has Pmin=%.1f and Pmax=%.1f too close -> we set Pmin=Pmax=Pc=%Q\n", + printf{LOG_WARNING} "Unit %Q has Pmin=%.1f and Pmax=%.1f too close -> we set Pmin=Pmax=Pc=%Q\n", unit_id[1,g,n],corrected_unit_Pmin[g,n],corrected_unit_Pmax[g,n],unit_Pc[1,g,n]; let corrected_unit_Pmin[g,n] := unit_Pc[1,g,n]; let corrected_unit_Pmax[g,n] := unit_Pc[1,g,n]; @@ -660,40 +674,40 @@ for {(g,n) in UNITON} { if abs(unit_qp[1,g,n]) >= PQmax then { let corrected_unit_qp[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; if print_units then - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n]; } else let corrected_unit_qp[g,n] := unit_qp[1,g,n]; if abs(unit_qP[1,g,n]) >= PQmax then { let corrected_unit_qP[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; if print_units then - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_qP",unit_id[1,g,n],unit_qP[1,g,n],corrected_unit_qP[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_qP",unit_id[1,g,n],unit_qP[1,g,n],corrected_unit_qP[g,n]; } else let corrected_unit_qP[g,n] := unit_qP[1,g,n]; if abs(unit_Qp[1,g,n]) >= PQmax then { let corrected_unit_Qp[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; if print_units then - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n]; } else let corrected_unit_Qp[g,n] := unit_Qp[1,g,n]; if abs(unit_QP[1,g,n]) >= PQmax then { let corrected_unit_QP[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; if print_units then - printf "%Q for %Q is %Q -> corrected to %Q\n","unit_QP",unit_id[1,g,n],unit_QP[1,g,n],corrected_unit_QP[g,n]; + printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_QP",unit_id[1,g,n],unit_QP[1,g,n],corrected_unit_QP[g,n]; } else let corrected_unit_QP[g,n] := unit_QP[1,g,n]; if corrected_unit_qp[g,n] > corrected_unit_Qp[g,n] then { - printf "Warning unit %Q : unit_qp > unit_Qp -> we invert them",unit_id[1,g,n]; + printf{LOG_WARNING} "Warning unit %Q : unit_qp > unit_Qp -> we invert them",unit_id[1,g,n]; let tempo := corrected_unit_qp[g,n]; let corrected_unit_qp[g,n] := corrected_unit_Qp[g,n]; let corrected_unit_Qp[g,n] := tempo; } if corrected_unit_qP[g,n] > corrected_unit_QP[g,n] then { - printf "Warning unit %Q : unit_qP > unit_QP -> we invert them",unit_id[1,g,n]; + printf{LOG_WARNING} "Warning unit %Q : unit_qP > unit_QP -> we invert them",unit_id[1,g,n]; let tempo := corrected_unit_qP[g,n]; let corrected_unit_qP[g,n] := corrected_unit_QP[g,n]; let corrected_unit_QP[g,n] := tempo; @@ -705,7 +719,7 @@ for {(g,n) in UNITON} { then { let tempo := 0.25*(corrected_unit_qP[g,n]+corrected_unit_QP[g,n]+corrected_unit_qp[g,n]+corrected_unit_Qp[g,n]); if print_units then - printf "Unit %Q has reactive diagram too small -> we set qp=qP=Qp=QP=%Q (Pc=%Q)\n", + printf{LOG_WARNING} "Unit %Q has reactive diagram too small -> we set qp=qP=Qp=QP=%Q (Pc=%Q)\n", unit_id[1,g,n],tempo,unit_Pc[1,g,n]; let corrected_unit_qP[g,n] := tempo; let corrected_unit_QP[g,n] := tempo; @@ -717,30 +731,30 @@ for {(g,n) in UNITON} { let corrected_unit_Qmax[g,n] := min(corrected_unit_QP[g,n],corrected_unit_Qp[g,n]); if unit_Pc[1,g,n] > corrected_unit_Pmax[g,n] or unit_Pc[1,g,n] < corrected_unit_Pmin[g,n] - then printf "Warning unit %Q Pc=%Q not in bounds [ Pmin=%Q ; Pmax=%Q ]\n", + then printf{LOG_WARNING} "Warning unit %Q Pc=%Q not in bounds [ Pmin=%Q ; Pmax=%Q ]\n", unit_id[1,g,n],unit_Pc[1,g,n],corrected_unit_Pmin[g,n],corrected_unit_Pmax[g,n]; if abs(corrected_unit_Qmin[g,n] - corrected_unit_Qmax[g,n]) >= minimalQPrange and ( corrected_unit_Qmin[g,n] > 0 or corrected_unit_Qmax[g,n] < 0 ) - then printf "Warning unit %Q: 0 not in bounds [ Qmin=%Q ; Qmax=%Q ]\n", + then printf{LOG_WARNING} "Warning unit %Q: 0 not in bounds [ Qmin=%Q ; Qmax=%Q ]\n", unit_id[1,g,n],corrected_unit_Qmin[g,n],corrected_unit_Qmax[g,n]; } printf "\n"; -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmin[1,g,n]),"unit_Pmin",max({(g,n) in UNITON} unit_Pmin[1,g,n]); -printf "Active generation: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pc[1,g,n]), "unit_Pc", max({(g,n) in UNITON} unit_Pc[1,g,n]); -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmax[1,g,n]),"unit_Pmax",max({(g,n) in UNITON} unit_Pmax[1,g,n]); -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_qP[1,g,n]), "unit_qP", max({(g,n) in UNITON} unit_qP[1,g,n]); -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_qp[1,g,n]), "unit_qp", max({(g,n) in UNITON} unit_qp[1,g,n]); -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_QP[1,g,n]), "unit_QP", max({(g,n) in UNITON} unit_QP[1,g,n]); -printf "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Qp[1,g,n]), "unit_Qp", max({(g,n) in UNITON} unit_Qp[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmin[1,g,n]),"unit_Pmin",max({(g,n) in UNITON} unit_Pmin[1,g,n]); +printf{LOG_INFO} "Active generation: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pc[1,g,n]), "unit_Pc", max({(g,n) in UNITON} unit_Pc[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmax[1,g,n]),"unit_Pmax",max({(g,n) in UNITON} unit_Pmax[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_qP[1,g,n]), "unit_qP", max({(g,n) in UNITON} unit_qP[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_qp[1,g,n]), "unit_qp", max({(g,n) in UNITON} unit_qp[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_QP[1,g,n]), "unit_QP", max({(g,n) in UNITON} unit_QP[1,g,n]); +printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Qp[1,g,n]), "unit_Qp", max({(g,n) in UNITON} unit_Qp[1,g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Pmin[g,n]),"corrected_unit_Pmin",max({(g,n) in UNITON} corrected_unit_Pmin[g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Pmax[g,n]),"corrected_unit_Pmax",max({(g,n) in UNITON} corrected_unit_Pmax[g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_qP[g,n]), "corrected_unit_qP", max({(g,n) in UNITON} corrected_unit_qP[g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_qp[g,n]), "corrected_unit_qp", max({(g,n) in UNITON} corrected_unit_qp[g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_QP[g,n]), "corrected_unit_QP", max({(g,n) in UNITON} corrected_unit_QP[g,n]); -printf "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Qp[g,n]), "corrected_unit_Qp", max({(g,n) in UNITON} corrected_unit_Qp[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Pmin[g,n]),"corrected_unit_Pmin",max({(g,n) in UNITON} corrected_unit_Pmin[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Pmax[g,n]),"corrected_unit_Pmax",max({(g,n) in UNITON} corrected_unit_Pmax[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_qP[g,n]), "corrected_unit_qP", max({(g,n) in UNITON} corrected_unit_qP[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_qp[g,n]), "corrected_unit_qp", max({(g,n) in UNITON} corrected_unit_qp[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_QP[g,n]), "corrected_unit_QP", max({(g,n) in UNITON} corrected_unit_QP[g,n]); +printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} corrected_unit_Qp[g,n]), "corrected_unit_Qp", max({(g,n) in UNITON} corrected_unit_Qp[g,n]); @@ -754,12 +768,13 @@ let PROBLEM_DCOPF := {1}; let PROBLEM_ACOPF := { }; -printf "\n######################################################################\n"; +printf{LOG_DEBUG} "\n######################################################################\n"; let tempstr := ctime(); -printf "# DCopf solve: start (%s)\n\n",tempstr; +printf{LOG_DEBUG} "# DCopf solve: start (%s)\n\n",tempstr; +#option knitro_options "outlev=0"; # TODO : add conditionnal printing here solve problem_dcopf_objective; -printf "\n# DCopf solve: end (%s -> %s)\n",tempstr,ctime(); -printf "######################################################################\n\n"; +printf{LOG_DEBUG} "\n# DCopf solve: end (%s -> %s)\n",tempstr,ctime(); +printf{LOG_DEBUG} "######################################################################\n\n"; @@ -793,7 +808,7 @@ then { display sum{n in BUSCC} (balance_pos[n] + balance_neg[n]); for{n in BUSCC: balance_pos[n] + balance_neg[n] >= Pnull} - printf "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) slacks %.2f and %.2f MW\n", + printf{LOG_ERROR} "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) slacks %.2f and %.2f MW\n", bus_id[1,n], substation_id[1,bus_substation[1,n]], substation_Vnomi[1,bus_substation[1,n]], substation_country[1,bus_substation[1,n]], balance_pos[n], balance_neg[n]; @@ -804,23 +819,23 @@ then { } # "else" is useless since there is an "exit" just above -printf "OK all slack variables for DCOPF are null\n"; +printf{LOG_INFO} "OK all slack variables for DCOPF are null\n"; let dcopf_status := "OK"; # Print flows on branches with zero impedance -for{(qq,m,n) in BRANCHZNULL} printf "Flow on zero impedance branch %Q: %.f MW\n",branch_id[1,qq,m,n],activeflow[qq,m,n]; +for{(qq,m,n) in BRANCHZNULL} printf{LOG_INFO} "Flow on zero impedance branch %Q: %.f MW\n",branch_id[1,qq,m,n],activeflow[qq,m,n]; # Print flows on most loaded lines let temp1 := max{(qq,m,n) in BRANCHCC}abs(activeflow[qq,m,n]); -printf "Maximum flow: %.2f MW\n",temp1; -for {(qq,m,n) in BRANCHCC : abs(activeflow[qq,m,n]) >= temp1*0.99} printf "Maximum flow %.2f MW is on branch %Q\n", activeflow[qq,m,n],branch_id[1,qq,m,n]; +printf{LOG_INFO} "Maximum flow: %.2f MW\n",temp1; +for {(qq,m,n) in BRANCHCC : abs(activeflow[qq,m,n]) >= temp1*0.99} printf{LOG_INFO} "Maximum flow %.2f MW is on branch %Q\n", activeflow[qq,m,n],branch_id[1,qq,m,n]; # Print generations which are very different from their target value let temp2 := max{(g,n) in UNITON} abs(P_dcopf[g,n]-unit_Pc[1,g,n]); -printf "Maximum deviation between generation and target: %.2f MW\n",temp2; +printf{LOG_INFO} "Maximum deviation between generation and target: %.2f MW\n",temp2; if temp2 >= 10 then for {(g,n) in UNITON : abs(P_dcopf[g,n]-unit_Pc[1,g,n]) >= temp2*0.99} - printf "Generating unit %Q : Pc=%.2fMW P=%.2fMW (Pmin=%.2fMW Pmax=%.2fMW)\n", + printf{LOG_INFO} "Generating unit %Q : Pc=%.2fMW P=%.2fMW (Pmin=%.2fMW Pmax=%.2fMW)\n", unit_id[1,g,n],unit_Pc[1,g,n],P_dcopf[g,n],unit_Pmin[1,g,n],unit_Pmax[1,g,n]; # Balance check @@ -828,10 +843,10 @@ let temp1 := sum{(c,n) in LOADCC} load_PFix[1,c,n]; let temp2 := sum{(g,n) in UNITON} P_dcopf[g,n]; let temp2 := temp2 + sum{(b,n) in BATTERYCC} battery_p0[1,b,n]; let temp3 := (sum{(vscconv,n) in VSCCONVON} vscconv_P0[1,vscconv,n])+(sum{(l,k) in LCCCONVON} lccconv_P0[1,l,k]); -printf "Sum of HVDC conv. H: %.0f MW\n", temp3; -printf "Sum of loads C: %.0f MW\n", temp1; -printf "Sum of generations P: %.0f MW\n", temp2; -printf "Balance (P-C-H)/C: %.2f %%\n\n", (temp2-temp1-temp3)/temp1*100; +printf{LOG_INFO} "Sum of HVDC conv. H: %.0f MW\n", temp3; +printf{LOG_INFO} "Sum of loads C: %.0f MW\n", temp1; +printf{LOG_INFO} "Sum of generations P: %.0f MW\n", temp2; +printf{LOG_INFO} "Balance (P-C-H)/C: %.2f %%\n\n", (temp2-temp1-temp3)/temp1*100; # Analysis of phases computed by DC OPF let teta_max := max({n in BUSCC} teta_dc[n].val) + 3; # radians @@ -842,9 +857,9 @@ display teta_max,teta_min,max({n in BUSCC} teta_dc[n]),min({n in BUSCC} teta_dc[ let temp1 := max({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); let temp2 := min({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); -printf"Branches with large Delta Teta:\n"; +printf{LOG_INFO}"Branches with large Delta Teta:\n"; for {(qq,m,n) in BRANCHCC: (teta_dc[m]-teta_dc[n])>temp1*0.99 or (teta_dc[m]-teta_dc[n]) solve_result_num_limit and coeff_alpha >= 0.999 then for {n in 1 .. 2} { - printf "*** change coeff_alpha from %f ",coeff_alpha; + printf{LOG_DEBUG} "*** change coeff_alpha from %f ",coeff_alpha; let coeff_alpha := 0.0; - printf " to %f\n",coeff_alpha; + printf{LOG_DEBUG} " to %f\n",coeff_alpha; solve problem_acopf_objective; let nb_iter_last := problem_acopf_objective.numiters; let nb_iter_total := nb_iter_total + nb_iter_last; @@ -943,16 +958,16 @@ param output_results binary default 0; if solve_result_num == 200 then { let output_results := 0; - let messageInfo := "Optimization was ***not*** successfull - Convergence to an infeasible solution"; - printf "%s\n", messageInfo; + let messageInfo := "Acopf optimization was ***not*** successfull - Convergence to an infeasible solution"; + printf{LOG_ERROR} "%s\n", messageInfo; let messagesInfo := messagesInfo union {messageInfo}; let final_status := "NOK"; } else if solve_result_num > 103 then { let output_results := 0; - let messageInfo := "Optimization was ***not*** successfull - no solution found"; - printf "%s\n", messageInfo; + let messageInfo := "Acopf optimization was ***not*** successfull - no solution found"; + printf{LOG_ERROR} "%s\n", messageInfo; let messagesInfo := messagesInfo union {messageInfo}; let final_status := "NOK"; } @@ -961,8 +976,8 @@ else { let final_status := "OK"; } -printf "\n# ACopf solve: end (%s -> %s)\n",tempstr,ctime(); -printf "######################################################################\n\n"; +printf{LOG_DEBUG} "\n# ACopf solve: end (%s -> %s)\n",tempstr,ctime(); +printf{LOG_DEBUG} "######################################################################\n\n"; # @@ -983,14 +998,14 @@ let temp1 := max({(qq,m,n) in BRANCHCC} (teta[m]-teta[n])); let temp2 := min({(qq,m,n) in BRANCHCC} (teta[m]-teta[n])); for {(qq,m,n) in BRANCHCC: (teta[m]-teta[n])>temp1*0.99 or (teta[m]-teta[n])Pnull}); if output_results > 0 then for {n in BUSCC_SLACK: slack1_balance_Q[n]+slack2_balance_Q[n] > Pnull} - printf "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", + printf{LOG_INFO} "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", bus_id[1,n],substation_id[1,bus_substation[1,n]],substation_Vnomi[1,bus_substation[1,n]], slack1_balance_Q[n],slack2_balance_Q[n], voltage_lower_bound[1,bus_substation[1,n]],V[n],voltage_upper_bound[1,bus_substation[1,n]]; From b33472ac7ff52f1820241a556d67d8b1a1e68578 Mon Sep 17 00:00:00 2001 From: parvy Date: Tue, 17 Oct 2023 18:41:29 +0200 Subject: [PATCH 2/4] Change some printing levels. Signed-off-by: parvy --- .../main/resources/openreac/reactiveopf.run | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index 75702a87..35e13d30 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -217,9 +217,9 @@ param: PARAM_ALGO_KEYS: PARAM_ALGO_VALUES := include param_algo.txt; model; display PARAM_ALGO_VALUES; -# Define log level of the run -set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"}; # different values of log levels -param log_level symbolic default "INFO"; +# Choice log level of the run +set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"}; # different values of log level +param log_level symbolic default "INFO"; # default value of the log level if "log_level" in PARAM_ALGO_KEYS then let log_level := PARAM_ALGO_VALUES["log_level"]; check log_level in LOG_LEVELS; param log_index := ord0(log_level, LOG_LEVELS); @@ -230,7 +230,7 @@ set LOG_DEBUG := if log_index >= 4 then{1} else {}; set LOG_INFO := if log_index >= 3 then{1} else {}; set LOG_WARNING := if log_index >= 2 then{1} else {}; set LOG_ERROR := if log_index >= 1 then{1} else {}; -printf{LOG_INFO} "Parameter: log level = %s\n", log_level; +printf "Parameter: log level = %s\n", log_level; # Absolute parameter : base 100MVA. # Never change this unless you really know what you do @@ -427,14 +427,14 @@ if ( tempo == 0 ) then # Connexity checks and computation of connex components # ############################################################################### -printf{LOG_TRACE} "\n*** Connexity computation\n"; +printf{LOG_INFO} "\n*** Connexity computation\n"; let PROBLEM_CCOMP := {1}; let PROBLEM_DCOPF := { }; let PROBLEM_ACOPF := { }; option presolve 0; #option knitro_options "outlev=0"; # TODO : put conditionnal value here let tempstr := ctime(); -printf{LOG_TRACE} "# CCcomp solve: start (%s)\n\n",tempstr; +printf{LOG_DEBUG} "# CCcomp solve: start (%s)\n\n",tempstr; # solve cccomputation_objective; # @@ -447,7 +447,7 @@ then { let final_status := "NOK"; include reactiveopfexit.run; } -printf{LOG_TRACE} "# CCcomp solve: end (%s -> %s)\n\n",tempstr,ctime(); +printf{LOG_DEBUG} "# CCcomp solve: end (%s -> %s)\n\n",tempstr,ctime(); option presolve 10; # @@ -519,18 +519,18 @@ for {(t,n) in BUS: substation_Vnomi[1,bus_substation[1,n]] < epsilon_nominal_vol # Voltage bounds let temp1 := min{(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0} substation_Vmin[t,s]; for {(t,s) in SUBSTATIONS: substation_Vmin[t,s] > 0 and substation_Vmin[t,s] <= temp1*1.01} - printf{LOG_WARNING} "Substations %Q with lowest voltage lower bound Vnom=%ikV Vmin=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmin[t,s]; + printf{LOG_INFO} "Substations %Q with lowest voltage lower bound Vnom=%ikV Vmin=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmin[t,s]; let temp1 := max{(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0} substation_Vmax[t,s]; for {(t,s) in SUBSTATIONS: substation_Vmax[t,s] > 0 and substation_Vmax[t,s] >= temp1*0.99} - printf{LOG_WARNING} "Substations %Q with highest voltage upper bound Vnom=%ikV Vmax=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmax[t,s]; -printf{LOG_WARNING} "If voltage lower bounds are missing or too small, they are set to %.3fpu\n",minimal_voltage_lower_bound; -printf{LOG_WARNING} "If voltage upper bounds are missing or too high, they are set to %.3fpu\n",maximal_voltage_upper_bound; + printf{LOG_INFO} "Substations %Q with highest voltage upper bound Vnom=%ikV Vmax=%.3fpu\n",substation_id[t,s],substation_Vnomi[t,s],substation_Vmax[t,s]; +printf{LOG_INFO} "If voltage lower bounds are missing or too small, they are set to %.3fpu\n",minimal_voltage_lower_bound; +printf{LOG_INFO} "If voltage upper bounds are missing or too high, they are set to %.3fpu\n",maximal_voltage_upper_bound; let temp1 := card({n in BUSCC: substation_Vnomi[1,bus_substation[1,n]] <= ignore_voltage_bounds}); if temp1 > 0 then printf{LOG_WARNING} "Voltage bounds for substations with nominal voltage <= %ikV are set to [%.3fpu;%.3fpu] (%i busses)\n", ignore_voltage_bounds,minimal_voltage_lower_bound,maximal_voltage_upper_bound,temp1; -printf{LOG_WARNING} "Maximal diameter of voltage interval: %.3f\n",max({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); -printf{LOG_WARNING} "Minimal diameter of voltage interval: %.3f\n",min({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); +printf{LOG_INFO} "Maximal diameter of voltage interval: %.3f\n",max({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); +printf{LOG_INFO} "Minimal diameter of voltage interval: %.3f\n",min({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); # # Consistency of transformers ratios @@ -555,7 +555,7 @@ for {(qq,m,n) in BRANCHCC_REGL: qq in PARAM_TRANSFORMERS_RATIO_VARIABLE for {(qq,m,n) in BRANCHCC_REGL: regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]] <= temp1 * 1.01 or regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]] >= temp2 * 0.99 } { - printf{LOG_WARNING} "Transformer %Q ratio_min=%.3f ratio_max=%.3f\n", + printf{LOG_INFO} "Transformer %Q ratio_min=%.3f ratio_max=%.3f\n", branch_id[1,qq,m,n], regl_ratio_min[1,branch_ptrRegl[1,qq,m,n]], regl_ratio_max[1,branch_ptrRegl[1,qq,m,n]] @@ -851,7 +851,7 @@ printf{LOG_INFO} "Balance (P-C-H)/C: %.2f %%\n\n", (temp2-temp1-temp3)/temp1* # Analysis of phases computed by DC OPF let teta_max := max({n in BUSCC} teta_dc[n].val) + 3; # radians let teta_min := min({n in BUSCC} teta_dc[n].val) - 3; # radians -display teta_max,teta_min,max({n in BUSCC} teta_dc[n]),min({n in BUSCC} teta_dc[n]), +if log_index >= 3 then display teta_max,teta_min,max({n in BUSCC} teta_dc[n]),min({n in BUSCC} teta_dc[n]), max({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])),min({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); let temp1 := max({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); @@ -984,7 +984,7 @@ printf{LOG_DEBUG} "############################################################# # Displays after solving # -display +if log_index >= 3 then display nb_iter_last,nb_iter_total, max({(qq,m,n) in BRANCHCC} branch_R[1,qq,m,n]),max({(qq,m,n) in BRANCHCC} branch_X[1,qq,m,n]), teta_max, max({n in BUSCC} teta[n]), max({n in BUSCC} teta_dc[n]), @@ -1000,9 +1000,9 @@ let temp2 := min({(qq,m,n) in BRANCHCC} (teta[m]-teta[n])); for {(qq,m,n) in BRANCHCC: (teta[m]-teta[n])>temp1*0.99 or (teta[m]-teta[n])Pnull}); if output_results > 0 then for {n in BUSCC_SLACK: slack1_balance_Q[n]+slack2_balance_Q[n] > Pnull} - printf{LOG_INFO} "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", + printf{LOG_WARNING} "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", bus_id[1,n],substation_id[1,bus_substation[1,n]],substation_Vnomi[1,bus_substation[1,n]], slack1_balance_Q[n],slack2_balance_Q[n], voltage_lower_bound[1,bus_substation[1,n]],V[n],voltage_upper_bound[1,bus_substation[1,n]]; From 5ccf443a14b0c323b4746d4d8b9f2b3eeda52758 Mon Sep 17 00:00:00 2001 From: parvy Date: Wed, 25 Oct 2023 16:43:52 +0200 Subject: [PATCH 3/4] Add knitro log level. Signed-off-by: parvy --- .../main/resources/openreac/reactiveopf.run | 204 +++++++++++------- .../resources/openreac/reactiveopfoutput.run | 18 +- 2 files changed, 140 insertions(+), 82 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index 3e73cab1..1903f685 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -150,7 +150,7 @@ reset; # Print date of start of calculation param ctime_start symbolic := ctime(); printf "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"; -printf "*** Start of file reactiveopf.run : %s\n",ctime_start; +printf "*** Start of file reactiveopf.run at %s\n",ctime_start; # Global status # Possible values : CRASH OK NOK UNKNOWN @@ -162,8 +162,15 @@ param final_status symbolic default "UNKNOWN"; # Linux or windows? ############################################################################### param operatingSystem symbolic default "unknown"; -if length($OS) > 0 then let operatingSystem := "windows"; -if length($SHELL) > 0 then let operatingSystem := "linux"; +param nullDevice symbolic default "unknown"; # null device to avoid printing when knitro log = 0 +if length($OS) > 0 then { + let operatingSystem := "windows"; + let nullDevice := "NUL"; +} +if length($SHELL) > 0 then { + let operatingSystem := "linux"; + let nullDevice := "/dev/null"; +} @@ -202,13 +209,13 @@ if operatingSystem == "windows" then { ############################################################################### -# Controls and associated parameters +# Logs, controls and associated parameters ############################################################################### # # Read main algorithm controls in file # -printf "\n*** Reading algorithmic controls and parameters in file\n"; +printf "\n** Reading algorithmic controls and parameters in file\n"; model; set PARAM_ALGO_KEYS; param PARAM_ALGO_VALUES{PARAM_ALGO_KEYS} symbolic; @@ -217,20 +224,26 @@ param: PARAM_ALGO_KEYS: PARAM_ALGO_VALUES := include param_algo.txt; model; display PARAM_ALGO_VALUES; -# Choice log level of the run -set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG", "TRACE"}; # different values of log level -param log_level symbolic default "INFO"; # default value of the log level -if "log_level" in PARAM_ALGO_KEYS then let log_level := PARAM_ALGO_VALUES["log_level"]; -check log_level in LOG_LEVELS; -param log_index := ord0(log_level, LOG_LEVELS); +# Log level of ampl printing +set LOG_LEVELS ordered = {"ERROR", "WARNING", "INFO", "DEBUG"}; # different values of log level for ampl exec +param log_level_ampl symbolic default "INFO"; # default value of log level +if "log_level_ampl" in PARAM_ALGO_KEYS then let log_level_ampl := PARAM_ALGO_VALUES["log_level_ampl"]; -# Sets which will be used to chose to print or not. A void set avoid printing. -set LOG_TRACE := if log_index >= 5 then{1} else {}; +# Sets used to print or not. A void set avoid printing +param log_index := ord0(log_level_ampl, LOG_LEVELS); set LOG_DEBUG := if log_index >= 4 then{1} else {}; set LOG_INFO := if log_index >= 3 then{1} else {}; set LOG_WARNING := if log_index >= 2 then{1} else {}; set LOG_ERROR := if log_index >= 1 then{1} else {}; -printf "Parameter: log level = %s\n", log_level; +printf{LOG_INFO} "Parameter: log level of ampl := %s\n", log_level_ampl; +check log_level_ampl in LOG_LEVELS; + +# Log level of knitro printing +param log_level_knitro integer default 2; +if "log_level_knitro" in PARAM_ALGO_KEYS then let log_level_knitro := num(PARAM_ALGO_VALUES["log_level_knitro"]); +set LOG_KNITRO := if log_level_knitro >= 1 then{1} else {}; +printf{LOG_INFO} "Parameter: log level of knitro := %i\n", log_level_knitro; +check log_level_knitro in {0, 1, 2}; # Absolute parameter : base 100MVA. # Never change this unless you really know what you do @@ -331,6 +344,7 @@ option solver knitroampl; option dual_initial_guesses 0; option presolve 10; option show_boundtol 0; +option solver_msg (log_level_knitro); suffix cfeastol IN; suffix xfeastol IN; @@ -427,17 +441,35 @@ if ( tempo == 0 ) then # Connexity checks and computation of connex components # ############################################################################### -printf{LOG_INFO} "\n*** Connexity computation\n"; let PROBLEM_CCOMP := {1}; let PROBLEM_DCOPF := { }; let PROBLEM_ACOPF := { }; -option presolve 0; -#option knitro_options "outlev=0"; # TODO : put conditionnal value here + +############################################################################### +# Solve +############################################################################### + let tempstr := ctime(); -printf{LOG_DEBUG} "# CCcomp solve: start (%s)\n\n",tempstr; -# -solve cccomputation_objective; -# +printf{LOG_KNITRO} "\n######################################################################\n"; +printf{LOG_KNITRO} "** CCcomp solve: start (%s)\n\n",tempstr; + +option presolve 0; +option knitro_options ("outlev=3");; + +# TODO : remove suffix printing +if (log_level_knitro <= 1) then { + solve cccomputation_objective > (nullDevice); +} else { + solve cccomputation_objective; +} + +printf{LOG_KNITRO} "\n** CCcomp solve: end (%s -> %s)\n",tempstr,ctime(); +printf{LOG_KNITRO} "######################################################################\n\n"; + +############################################################################### +# Analysis of solve_result_num +############################################################################### + if solve_result_num > 103 or card({n in BUS2: teta_ccomputation[n].val > 0.01 and teta_ccomputation[n].val < 0.99})>0 then { # First return codes of knitro : @@ -447,15 +479,15 @@ then { let final_status := "NOK"; include reactiveopfexit.run; } -printf{LOG_DEBUG} "# CCcomp solve: end (%s -> %s)\n\n",tempstr,ctime(); option presolve 10; -# +############################################################################### # Definition of BUSCC below was the purpose of this optimization -# +############################################################################### + let BUSCC := {n in BUS2: teta_ccomputation[n].val <= 0.01}; -printf{LOG_INFO} "\n*** Connexity computation\n"; +printf{LOG_INFO} "\n** CCcomp results\n"; for{n in BUS2 diff BUSCC} printf{LOG_WARNING} "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) is out of main AC CC\n", bus_id[1,n], substation_id[1,bus_substation[1,n]], @@ -463,15 +495,14 @@ for{n in BUS2 diff BUSCC} printf{LOG_INFO} "Nb of busses in AC+DC CC: %i\n",card(BUS2); printf{LOG_INFO} "Nb of busses in CC %Q: %i\n",bus_id[1,null_phase_bus],card(BUSCC); printf{LOG_INFO} "Nb of busses in other CCs: %Q\n",card(BUS2)-card(BUSCC); - printf "\n"; - ############################################################################### # A few information ############################################################################### -if log_index >= 3 then { + +if 1 in LOG_INFO then { display maximal_voltage_upper_bound, minimal_voltage_lower_bound, card(SUBSTATIONS),card(BUS),card(BUS2),card(BUSCC),card(BUS2 diff BUSCC),card(BUSVV),card(BUSCC_SLACK),card(BUSCC diff BUSCC_SLACK), @@ -532,9 +563,10 @@ printf{LOG_WARNING} "Voltage bounds for substations with nominal voltage <= %ikV printf{LOG_INFO} "Maximal diameter of voltage interval: %.3f\n",max({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); printf{LOG_INFO} "Minimal diameter of voltage interval: %.3f\n",min({(t,s) in SUBSTATIONS}(voltage_upper_bound[t,s] - voltage_lower_bound[t,s])); -# +############################################################################### # Consistency of transformers ratios -# +############################################################################### + let temp1 := min{(t,r) in REGL} regl_ratio_min[1,r]; let temp2 := max{(t,r) in REGL} regl_ratio_max[1,r]; printf{LOG_INFO} "Minimal transformer ratio : %.3f\n",temp1; @@ -643,9 +675,7 @@ if tempo > 0.5 then { ############################################################################### -# # Correction of units' P and Q domains -# ############################################################################### printf "\n"; param print_units := 0; # 0 or 1 for detailed prints of corrections @@ -760,7 +790,7 @@ printf{LOG_INFO} "Corrected extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNI ############################################################################### # -# Optimisation DC OPF for phase initialization and data consistency check +# Optimisation DC OPF (for phase initialization and data consistency check) # ############################################################################### let PROBLEM_CCOMP := { }; @@ -768,21 +798,31 @@ let PROBLEM_DCOPF := {1}; let PROBLEM_ACOPF := { }; -printf{LOG_DEBUG} "\n######################################################################\n"; +############################################################################### +# Solve +############################################################################### + let tempstr := ctime(); -printf{LOG_DEBUG} "# DCopf solve: start (%s)\n\n",tempstr; -#option knitro_options "outlev=0"; # TODO : add conditionnal printing here -solve problem_dcopf_objective; -printf{LOG_DEBUG} "\n# DCopf solve: end (%s -> %s)\n",tempstr,ctime(); -printf{LOG_DEBUG} "######################################################################\n\n"; +printf{LOG_KNITRO} "\n######################################################################\n"; +printf{LOG_KNITRO} "** DCopf solve: start (%s)\n\n",tempstr; + +option knitro_options ("outlev=3"); +# solve dcopf and avoid knitro printing if user asks +if (log_level_knitro <= 1) then { + solve problem_dcopf_objective > (nullDevice); +} else { + solve problem_dcopf_objective; +} + +printf{LOG_KNITRO} "\n** DCopf solve: end (%s -> %s)\n",tempstr,ctime(); +printf{LOG_KNITRO} "######################################################################\n\n"; ############################################################################### -# -# DC OPF results analysis -# +# Analysis of solve_result_num ############################################################################### + if solve_result_num > 103 then { # First return codes of knitro : @@ -817,8 +857,13 @@ then { let dcopf_status := "NOK"; include reactiveopfexit.run; } - # "else" is useless since there is an "exit" just above + +############################################################################### +# Displays after solving +############################################################################### + +printf{LOG_INFO} "\n** DCopf results\n"; printf{LOG_INFO} "OK all slack variables for DCOPF are null\n"; let dcopf_status := "OK"; @@ -851,7 +896,7 @@ printf{LOG_INFO} "Balance (P-C-H)/C: %.2f %%\n\n", (temp2-temp1-temp3)/temp1* # Analysis of phases computed by DC OPF let teta_max := max({n in BUSCC} teta_dc[n].val) + 3; # radians let teta_min := min({n in BUSCC} teta_dc[n].val) - 3; # radians -if log_index >= 3 then display teta_max,teta_min,max({n in BUSCC} teta_dc[n]),min({n in BUSCC} teta_dc[n]), +if 1 in LOG_INFO then display teta_max,teta_min,max({n in BUSCC} teta_dc[n]),min({n in BUSCC} teta_dc[n]), max({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])),min({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); let temp1 := max({(qq,m,n) in BRANCHCC} (teta_dc[m]-teta_dc[n])); @@ -880,10 +925,9 @@ let PROBLEM_DCOPF := { }; let PROBLEM_ACOPF := {1}; -# +############################################################################### # Initial values -# - +############################################################################### # DC values used as initialization for phases let {n in BUSCC} teta[n] := teta_dc[n]; @@ -903,16 +947,22 @@ let {(svc,n) in SVCON} svc_qvar[svc,n] := 0.1; let {(v,n) in VSCCONVON} vscconv_qvar[v,n] := if abs(vscconv_targetQ[1,v,n]) < PQmax then vscconv_targetQ[1,v,n] else 0; let {(qq,m,n) in BRANCHCC_REGL_VAR} branch_Ror_var[qq,m,n] := branch_Ror[qq,m,n]; -# +############################################################################### # Solve -# -printf{LOG_DEBUG} "\n######################################################################\n"; -printf{LOG_DEBUG} "# ACopf solve: start (%s)\n\n",ctime(); +############################################################################### + 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"; # TODO : Add outlev here +option knitro_options ("opttol=1 opttolabs=1e-1 feastol=1 feastolabs=1e-3 maxit=200 outlev=3"); -solve problem_acopf_objective; +# solve acopf and avoid knitro printing if user asks +if (log_level_knitro <= 1) then { + solve problem_acopf_objective > (nullDevice); +} else { + solve problem_acopf_objective; +} let nb_iter_last := problem_acopf_objective.numiters; let nb_iter_total := nb_iter_total + nb_iter_last; @@ -925,7 +975,13 @@ param solve_result_num_limit := 200; if solve_result_num > solve_result_num_limit then for {n in 1 .. 2} { - solve problem_acopf_objective; + # solve acopf and avoid knitro printing if user asks + if (log_level_knitro <= 1) then { + solve problem_acopf_objective > (nullDevice); + } else { + solve problem_acopf_objective; + } + let nb_iter_last := problem_acopf_objective.numiters; let nb_iter_total := nb_iter_total + nb_iter_last; if solve_result_num <= solve_result_num_limit then break; @@ -935,25 +991,29 @@ for {n in 1 .. 2} if solve_result_num > solve_result_num_limit and coeff_alpha >= 0.999 then for {n in 1 .. 2} { - printf{LOG_DEBUG} "*** change coeff_alpha from %f ",coeff_alpha; + printf{LOG_DEBUG} "* change coeff_alpha from %f ",coeff_alpha; let coeff_alpha := 0.0; printf{LOG_DEBUG} " to %f\n",coeff_alpha; - solve problem_acopf_objective; + + # solve acopf and avoid knitro printing if user asks + if (log_level_knitro <= 1) then { + solve problem_acopf_objective > (nullDevice); + } else { + solve problem_acopf_objective; + } let nb_iter_last := problem_acopf_objective.numiters; let nb_iter_total := nb_iter_total + nb_iter_last; if solve_result_num <= solve_result_num_limit then break; } +printf{LOG_KNITRO} "\n** ACopf solve: end (%s -> %s)\n",tempstr,ctime(); +printf{LOG_KNITRO} "######################################################################\n\n"; -# +############################################################################### # Analysis of solve_result_num -# +############################################################################### -# <= 103 : feasible -# 200 convergence to unfeasible -# > 200 : failure -# param output_results binary default 0; if solve_result_num == 200 then { @@ -976,15 +1036,13 @@ else { let final_status := "OK"; } -printf{LOG_DEBUG} "\n# ACopf solve: end (%s -> %s)\n",tempstr,ctime(); -printf{LOG_DEBUG} "######################################################################\n\n"; - -# +############################################################################### # Displays after solving -# +############################################################################### -if log_index >= 3 then display +printf{LOG_INFO} "\n** ACopf results\n"; +if 1 in LOG_INFO then display nb_iter_last,nb_iter_total, max({(qq,m,n) in BRANCHCC} branch_R[1,qq,m,n]),max({(qq,m,n) in BRANCHCC} branch_X[1,qq,m,n]), teta_max, max({n in BUSCC} teta[n]), max({n in BUSCC} teta_dc[n]), @@ -1012,12 +1070,15 @@ for {(qq,m,n) in BRANCHCC: (teta[m]-teta[n])>temp1*0.99 or (teta[m]-teta[n]) Pnull then { + + if 1 in LOG_INFO then display sum{n in BUSCC_SLACK} slack1_balance_Q[n], sum{n in BUSCC_SLACK} slack2_balance_Q[n], max{n in BUSCC_SLACK} slack1_balance_Q[n], max{n in BUSCC_SLACK} slack2_balance_Q[n], card({n in BUSCC_SLACK: slack2_balance_Q[n]+slack1_balance_Q[n]>Pnull}); + if output_results > 0 then for {n in BUSCC_SLACK: slack1_balance_Q[n]+slack2_balance_Q[n] > Pnull} printf{LOG_WARNING} "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", @@ -1029,9 +1090,7 @@ then { ############################################################################### -# # Writing results and indicators -# ############################################################################### include reactiveopfoutput.run; @@ -1076,6 +1135,5 @@ close (fileOut); # End of file ############################################################################### printf "\n"; -printf "*** End of file reactiveopf.run : Optimization %ssuccessfull\n",if output_results>0 then "" else "un"; -printf "*** Start of file reactiveopf.run : %Q\n",ctime_start; -printf "*** End of file reactiveopf.run : %Q\n",ctime(); +printf "*** End of file reactiveopf.run at %s : Optimization %ssuccessfull\n", ctime(), if output_results>0 then "" else "un"; +printf "*** Elapsed time since start : %f(s)", _ampl_elapsed_time; diff --git a/open-reac/src/main/resources/openreac/reactiveopfoutput.run b/open-reac/src/main/resources/openreac/reactiveopfoutput.run index 5fff8487..f640ac28 100644 --- a/open-reac/src/main/resources/openreac/reactiveopfoutput.run +++ b/open-reac/src/main/resources/openreac/reactiveopfoutput.run @@ -155,15 +155,15 @@ close (fileOut); } # Useful during tests to create list of transformers -if 0 then -printf {(qq,m,n) in BRANCHCC_REGL: - substation_Vnomi[1,bus_substation[1,m]]>21 and substation_Vnomi[1,bus_substation[1,m]]<300 and - substation_Vnomi[1,bus_substation[1,n]]>21 and substation_Vnomi[1,bus_substation[1,n]]<300 and - (substation_Vnomi[1,bus_substation[1,m]]>120 or substation_Vnomi[1,bus_substation[1,n]]>120) and - (substation_Vnomi[1,bus_substation[1,m]]<120 or substation_Vnomi[1,bus_substation[1,n]]<120) -} "1 %i %i %i %Q\n",qq,m,n,branch_id[1,qq,m,n] > param_transformers.txtt; - - +if 0 then { + for{(qq,m,n) in BRANCHCC_REGL: + substation_Vnomi[1,bus_substation[1,m]]>21 and substation_Vnomi[1,bus_substation[1,m]]<300 and + substation_Vnomi[1,bus_substation[1,n]]>21 and substation_Vnomi[1,bus_substation[1,n]]<300 and + (substation_Vnomi[1,bus_substation[1,m]]>120 or substation_Vnomi[1,bus_substation[1,n]]>120) and + (substation_Vnomi[1,bus_substation[1,m]]<120 or substation_Vnomi[1,bus_substation[1,n]]<120)}{ + printf{LOG_DEBUG} "1 %i %i %i %Q\n",qq,m,n,branch_id[1,qq,m,n] > param_transformers.txtt; + } +} ############################################################################### # From ec180ca80da4e4af3afd89dce8fe4ea05cc4f5b4 Mon Sep 17 00:00:00 2001 From: parvy Date: Thu, 26 Oct 2023 11:13:27 +0200 Subject: [PATCH 4/4] Refactor Signed-off-by: parvy --- .../main/resources/openreac/reactiveopf.run | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/open-reac/src/main/resources/openreac/reactiveopf.run b/open-reac/src/main/resources/openreac/reactiveopf.run index 1903f685..6450c795 100644 --- a/open-reac/src/main/resources/openreac/reactiveopf.run +++ b/open-reac/src/main/resources/openreac/reactiveopf.run @@ -485,9 +485,10 @@ option presolve 10; # Definition of BUSCC below was the purpose of this optimization ############################################################################### -let BUSCC := {n in BUS2: teta_ccomputation[n].val <= 0.01}; +printf{LOG_INFO} "\n######################################################################\n"; +printf{LOG_INFO} "** CCcomp results\n"; -printf{LOG_INFO} "\n** CCcomp results\n"; +let BUSCC := {n in BUS2: teta_ccomputation[n].val <= 0.01}; for{n in BUS2 diff BUSCC} printf{LOG_WARNING} "Bus %Q in substation %Q (Vnomi=%.2fkV, country=%Q) is out of main AC CC\n", bus_id[1,n], substation_id[1,bus_substation[1,n]], @@ -539,7 +540,7 @@ printf{LOG_INFO} "Balance (P-C-H)/C: %.2f %% (global_initial_losses_ratio= # Branches with low current limits (but keep in mind they are not used; this is just for information) let temp1 := min{(qq,m,n) in BRANCHCC} Fmax[qq,m,n]; for {(qq,m,n) in BRANCHCC : Fmax[qq,m,n] <= temp1 * 1.5} - printf{LOG_WARNING} "Branch %Q Fmax=%.2fMW is small ; Vnom1=%ikV Vnom2=%ikV patl1=%iA patl2=%iA (Fmax not used, this is just for information)\n", + printf{LOG_INFO} "Branch %Q Fmax=%.2fMW is small ; Vnom1=%ikV Vnom2=%ikV patl1=%iA patl2=%iA (Fmax not used, this is just for information)\n", branch_id[1,qq,m,n],Fmax[qq,m,n],substation_Vnomi[1,bus_substation[1,m]],substation_Vnomi[1,bus_substation[1,n]],branch_patl1[1,qq,m,n],branch_patl1[1,qq,m,n]; # Abnormally low nominal voltages @@ -677,8 +678,7 @@ if tempo > 0.5 then { ############################################################################### # Correction of units' P and Q domains ############################################################################### -printf "\n"; -param print_units := 0; # 0 or 1 for detailed prints of corrections +printf{LOG_WARNING} "\nWARNING Correction of P/Q units domains:\n"; for {(g,n) in UNITON} { if abs(unit_Pmax[1,g,n]) >= PQmax then { @@ -703,29 +703,25 @@ for {(g,n) in UNITON} { if abs(unit_qp[1,g,n]) >= PQmax then { let corrected_unit_qp[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; - if print_units then - printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n]; + printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_qp",unit_id[1,g,n],unit_qp[1,g,n],corrected_unit_qp[g,n]; } else let corrected_unit_qp[g,n] := unit_qp[1,g,n]; if abs(unit_qP[1,g,n]) >= PQmax then { let corrected_unit_qP[g,n] := -defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; - if print_units then - printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_qP",unit_id[1,g,n],unit_qP[1,g,n],corrected_unit_qP[g,n]; + printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_qP",unit_id[1,g,n],unit_qP[1,g,n],corrected_unit_qP[g,n]; } else let corrected_unit_qP[g,n] := unit_qP[1,g,n]; if abs(unit_Qp[1,g,n]) >= PQmax then { let corrected_unit_Qp[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; - if print_units then - printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n]; + printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_Qp",unit_id[1,g,n],unit_Qp[1,g,n],corrected_unit_Qp[g,n]; } else let corrected_unit_Qp[g,n] := unit_Qp[1,g,n]; if abs(unit_QP[1,g,n]) >= PQmax then { let corrected_unit_QP[g,n] := defaultQmaxPmaxRatio * corrected_unit_Pmax[g,n]; - if print_units then - printf{LOG_WARNING} "%Q for %Q is %Q -> corrected to %Q\n","unit_QP",unit_id[1,g,n],unit_QP[1,g,n],corrected_unit_QP[g,n]; + printf{LOG_DEBUG} "%Q for %Q is %Q -> corrected to %Q\n","unit_QP",unit_id[1,g,n],unit_QP[1,g,n],corrected_unit_QP[g,n]; } else let corrected_unit_QP[g,n] := unit_QP[1,g,n]; @@ -748,8 +744,7 @@ for {(g,n) in UNITON} { and abs(corrected_unit_QP[g,n]-corrected_unit_qp[g,n]) <= minimalQPrange then { let tempo := 0.25*(corrected_unit_qP[g,n]+corrected_unit_QP[g,n]+corrected_unit_qp[g,n]+corrected_unit_Qp[g,n]); - if print_units then - printf{LOG_WARNING} "Unit %Q has reactive diagram too small -> we set qp=qP=Qp=QP=%Q (Pc=%Q)\n", + printf{LOG_DEBUG} "Unit %Q has reactive diagram too small -> we set qp=qP=Qp=QP=%Q (Pc=%Q)\n", unit_id[1,g,n],tempo,unit_Pc[1,g,n]; let corrected_unit_qP[g,n] := tempo; let corrected_unit_QP[g,n] := tempo; @@ -770,7 +765,7 @@ for {(g,n) in UNITON} { unit_id[1,g,n],corrected_unit_Qmin[g,n],corrected_unit_Qmax[g,n]; } -printf "\n"; +printf{LOG_INFO} "\nFew information on P/Q units domains:\n"; printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmin[1,g,n]),"unit_Pmin",max({(g,n) in UNITON} unit_Pmin[1,g,n]); printf{LOG_INFO} "Active generation: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pc[1,g,n]), "unit_Pc", max({(g,n) in UNITON} unit_Pc[1,g,n]); printf{LOG_INFO} "Raw extremal values: %Q <= %Q <= %Q\n",min({(g,n) in UNITON} unit_Pmax[1,g,n]),"unit_Pmax",max({(g,n) in UNITON} unit_Pmax[1,g,n]); @@ -863,7 +858,8 @@ then { # Displays after solving ############################################################################### -printf{LOG_INFO} "\n** DCopf results\n"; +printf{LOG_INFO} "\n######################################################################\n"; +printf{LOG_INFO} "** DCopf results\n"; printf{LOG_INFO} "OK all slack variables for DCOPF are null\n"; let dcopf_status := "OK"; @@ -1041,7 +1037,8 @@ else { # Displays after solving ############################################################################### -printf{LOG_INFO} "\n** ACopf results\n"; +printf{LOG_INFO} "\n######################################################################\n"; +printf{LOG_INFO} "** ACopf results\n"; if 1 in LOG_INFO then display nb_iter_last,nb_iter_total, max({(qq,m,n) in BRANCHCC} branch_R[1,qq,m,n]),max({(qq,m,n) in BRANCHCC} branch_X[1,qq,m,n]), @@ -1080,6 +1077,7 @@ then { card({n in BUSCC_SLACK: slack2_balance_Q[n]+slack1_balance_Q[n]>Pnull}); if output_results > 0 then + if card({n in BUSCC_SLACK: slack1_balance_Q[n]+slack2_balance_Q[n] > Pnull}) > 0 then printf{LOG_WARNING} "WARNING buses with non zero reactive slack :\n"; for {n in BUSCC_SLACK: slack1_balance_Q[n]+slack2_balance_Q[n] > Pnull} printf{LOG_WARNING} "Bus %Q in substation %Q (%ikV) has non zero reactive slacks %.1f %.1f, Vmin=%.3f Vopt=%.3f Vmax=%.3f \n", bus_id[1,n],substation_id[1,bus_substation[1,n]],substation_Vnomi[1,bus_substation[1,n]],