diff --git a/scripts/australian_pv/single_law_sweep.jl b/scripts/australian_pv/single_law_sweep.jl new file mode 100644 index 00000000..b05fb6da --- /dev/null +++ b/scripts/australian_pv/single_law_sweep.jl @@ -0,0 +1,85 @@ +# Single-law sweep: the same LV3_55bus feeder, every inverter running the same +# volt-var/volt-watt law, swept over the upstream source voltage. +# +# Study changes relative to the matched benchmark (declared, not measured): +# - every one of the 12 customers has a 6 kVA three-phase inverter with 5 kW PV; +# - each customer bus also carries a fixed single-phase PV export on phase C +# (unity PF, no volt-var), standing in for neighbouring single-phase rooftops; +# - source voltage swept; 2 % negative-sequence source voltage rotated -120 deg so +# that phase C is the high phase (the benchmark uses 1 % at 0 deg). +# Local fixed point only (no OPF). Illustrative, one feeder, one snapshot per point. +# +# usage: julia --project=. scripts/australian_pv/single_law_sweep.jl output [phase_c_pv_W] [source_pu,...] +include("run_engineering_benchmark.jl") + +const SWEEP_LAWS=("mean_vv_vw","worst_vv_vw","phase_vv_vw") + +function single_law_fleet(net,case,label;limits=ENGINEERING_OPERATING_LIMITS,p_available=5000.) + four=four_leg_fleet(net,case.pv_fraction) + devices=Dict{String,ControlledDevice}();requests=Dict{String,InverterControlRequest}() + modes=Dict{String,Symbol}();labels=Dict{String,String}() + for id in sort!(collect(keys(net["ibr"]))) + labels[id]=label + base=label=="phase_vv_vw" ? four.devices[id].device : plant(id,net["ibr"][id]["bus"];settings=TERMINAL_CONTROL_SETTINGS) + fields=NamedTuple{fieldnames(AdvancedInverter)}(Tuple(getfield(base,k) for k in fieldnames(AdvancedInverter))) + inv=AdvancedInverter(;merge(fields,(pwm_strategy=:CENTERED,f_sw=10000.,dc_energy_model=:nonlinear))...) + law=label=="phase_vv_vw" ? four.devices[id].controller : + controller(label;design=(kappa=0.,phi2=0.),settings=TERMINAL_CONTROL_SETTINGS) + devices[id]=ControlledDevice(engineering_plant(inv;limits),law) + net["ibr"][id]["topology"]=label=="phase_vv_vw" ? "FOUR_LEG" : "THREE_LEG" + net["ibr"][id]["terminal_map"]=label=="phase_vv_vw" ? ["a","b","c","n"] : ["a","b","c"] + requests[id]=InverterControlRequest(p_available=p_available,p_rated=HARDWARE.s_max,q_scale=HARDWARE.s_max) + modes[id]=:energized + end + (spec=ControlledInverterFleetSpec(devices,requests),modes=modes,labels=labels) +end + +function add_phase_c_pv!(net,watts) + for id in collect(keys(net["load"])) + endswith(id,"_c") || continue + rec=deepcopy(net["load"][id]);rec["p_nom"]=[-watts];rec["q_nom"]=[0.] + net["load"][replace(id,r"_c$"=>"_pv1ph_c")]=rec + end + net +end + +function run_single_law_sweep(output;phase_c_pv=4000.,sources=(1.00,1.01,1.02,1.03,1.04,1.05),source_vuf=.02,source_angle=-2pi/3) + mkpath(joinpath(output,"points")) + base=parse_bmopf(joinpath(ROOT,"networks","LV3_55bus.bmopf.json")) + rows=NamedTuple[];cases=NamedTuple[] + for src in sources, label in SWEEP_LAWS + cond=(case_id="sweep_$(label)_$(round(Int,1000src))",model=:energy,pv_fraction=1.,source_pu=src, + source_vuf=source_vuf,source_negative_angle_rad=source_angle,phase_shares=(.60,.25,.15),load_scale=1.,operation=:energized) + net=add_phase_c_pv!(voltage_aware_network(base,cond),phase_c_pv) + fleet=single_law_fleet(net,cond,label) + t=@elapsed res=solve_voltage_aware_inverter_fleet(net,fleet.spec;operating_modes=fleet.modes, + s_base=VA_BASE,solver_options=ENGINEERING_OPTIONS) + ok=res.solve.publishable + println("source=$(src) law=$(label) publishable=$(ok) reason=$(res.reason) t=$(round(t,digits=1))s") + ok || (push!(cases,(source_pu=src,law=label,accepted=false,elapsed_s=t));continue) + point=engineering_point(res,cond;voltage_max=nothing) + write_engineering_json(joinpath(output,"points",cond.case_id*".json"),point) + m=engineering_record_metrics(point,fleet;mode="local") + for r in m.rows + push!(rows,merge((source_pu=src,law=label),r)) + end + push!(cases,(source_pu=src,law=label,accepted=m.accepted,elapsed_s=t, + p_poc_W=sum(r.p_poc_W for r in m.rows),q_poc_var=sum(r.q_poc_var for r in m.rows), + curtailment_W=sum(r.curtailment_W for r in m.rows), + maximum_lv_voltage_V=engineering_lv_voltage_max(point,net), + maximum_sensed_V=maximum(r.vmax_sensed_V for r in m.rows), + maximum_vuf_percent=maximum(r.vuf_percent for r in m.rows))) + write_csv(joinpath(output,"devices.csv"),rows);write_csv(joinpath(output,"cases.csv"),cases) + end + write_engineering_json(joinpath(output,"environment.json"),Dict("laws"=>SWEEP_LAWS,"sources_pu"=>sources, + "phase_c_single_phase_pv_W_per_bus"=>phase_c_pv,"p_available_W_per_site"=>5000., + "load_phase_shares"=>(.60,.25,.15),"source_vuf"=>source_vuf,"source_negative_angle_rad"=>source_angle,"control_settings"=>TERMINAL_CONTROL_SETTINGS, + "git_revision"=>strip(read(`git -C $(normpath(joinpath(ROOT,"..",".."))) rev-parse HEAD`,String)))) + cases +end + +if abspath(PROGRAM_FILE)==abspath(@__FILE__) + pv=length(ARGS)>=2 ? parse(Float64,ARGS[2]) : 4000. + src=length(ARGS)>=3 ? Tuple(parse.(Float64,split(ARGS[3],","))) : (1.00,1.01,1.02,1.03,1.04,1.05) + run_single_law_sweep(ARGS[1];phase_c_pv=pv,sources=src) +end diff --git a/scripts/australian_pv/two_bus_street.jl b/scripts/australian_pv/two_bus_street.jl new file mode 100644 index 00000000..148323ce --- /dev/null +++ b/scripts/australian_pv/two_bus_street.jl @@ -0,0 +1,87 @@ +# Two-bus teaching case: the LV3_55bus source and 500 kVA transformer feed one +# 4-wire overhead line to a single "street" bus. At the street bus sit `homes` +# identical customers, each with a 6 kVA three-phase inverter (5 kW PV) and the +# study's 1.5 kW 60/25/15 % A/B/C load, plus neighbours' single-phase PV on +# phase C (unity PF, no volt-var). Balanced source: all unbalance is local. +# +# Declared, illustrative construction: one bus, one snapshot per point, local +# fixed point only. Not a generalised feeder result. +# +# usage: julia --project=. scripts/australian_pv/two_bus_street.jl output +include("single_law_sweep.jl") + +const STREET_LAWS=("mean_vv_vw","worst_vv_vw","phase_vv_vw") + +function two_bus_base(base;homes=8,length_m=250.,linecode="abc4x95_lv_oh_4w_bundled") + net=deepcopy(base) + template=first(values(base["line"])) + net["bus"]=Dict(b=>base["bus"][b] for b in ("b804","b641")) + net["bus"]["street"]=Dict("perfectly_grounded_terminals"=>String[],"terminal_names"=>["a","b","c","n"]) + line=deepcopy(template);line["bus_from"]="b641";line["bus_to"]="street";line["length"]=length_m + line["linecode"]=linecode + net["line"]=Dict("street_line"=>line);net["switch"]=Dict{String,Any}() + net["shunt"]=Dict("street_grounding"=>Dict("B_1_1"=>0,"G_1_1"=>0.1,"bus"=>"street","terminal_map"=>["n"])) + ld=first(values(base["load"])) + net["load"]=Dict{String,Any}() + for k in 1:homes + rec=deepcopy(ld);rec["bus"]="street";net["load"]["home$(lpad(k,2,'0'))"]=rec + end + net +end + +street_fleet(net,cond,label)=single_law_fleet(net,cond,label) + +function run_two_bus_street(output;homes=8,length_m=250.,source_pu=1.0, + neighbour_pv_W=(0.,250.,500.,750.,1000.,1250.,1500.),laws=STREET_LAWS) + mkpath(joinpath(output,"points")) + base=two_bus_base(parse_bmopf(joinpath(ROOT,"networks","LV3_55bus.bmopf.json"));homes,length_m) + rows=NamedTuple[];cases=NamedTuple[] + vmag(ts,p)=abs(phasor(ts[p])-phasor(ts["n"])) + for pv in neighbour_pv_W, label in laws + cond=(case_id="street_$(label)_$(round(Int,pv))",model=:energy,pv_fraction=1.,source_pu=source_pu, + source_vuf=0.,source_negative_angle_rad=0.,phase_shares=(.60,.25,.15),load_scale=1.,operation=:energized) + net=add_phase_c_pv!(voltage_aware_network(base,cond),pv) + fleet=street_fleet(net,cond,label) + # Damped retries for the fixed point near the volt-watt knee (253 V). + res=nothing;t=0.;relax=1. + for (relax,iters) in ((1.,30),(.5,120),(.25,300)) + t+=@elapsed res=solve_voltage_aware_inverter_fleet(net,fleet.spec;operating_modes=fleet.modes, + s_base=VA_BASE,solver_options=ENGINEERING_OPTIONS,relaxation=relax,max_iterations=iters) + res.solve.publishable && break + end + ok=res.solve.publishable + println("neighbour_pv=$(pv) law=$(label) publishable=$(ok) reason=$(res.reason) iterations=$(res.iterations) t=$(round(t,digits=1))s") + ok || continue + point=engineering_point(res,cond;voltage_max=nothing) + write_engineering_json(joinpath(output,"points",cond.case_id*".json"),point) + m=engineering_record_metrics(point,fleet;mode="local") + street=point["bus"]["street"];head=point["bus"]["b641"] + id=first(sort!(collect(keys(fleet.spec.devices)))) + d=point["devices"][id] + gv=[complex(z...) for z in d["grid_current"]] + vv=[phasor(street[p])-phasor(street["n"]) for p in ("a","b","c")] + sp=vv.*conj.(gv) + for r in m.rows + push!(rows,merge((neighbour_pv_W=pv,law=label),r)) + end + push!(cases,(neighbour_pv_W=pv,law=label,accepted=m.accepted, + va=vmag(street,"a"),vb=vmag(street,"b"),vc=vmag(street,"c"), + head_va=vmag(head,"a"),head_vb=vmag(head,"b"),head_vc=vmag(head,"c"), + p_home_a=real(sp[1]),p_home_b=real(sp[2]),p_home_c=real(sp[3]), + q_home_a=imag(sp[1]),q_home_b=imag(sp[2]),q_home_c=imag(sp[3]), + p_poc_W=sum(r.p_poc_W for r in m.rows),q_poc_var=sum(r.q_poc_var for r in m.rows), + curtailment_W=sum(r.curtailment_W for r in m.rows), + maximum_vuf_percent=maximum(r.vuf_percent for r in m.rows))) + write_csv(joinpath(output,"devices.csv"),rows);write_csv(joinpath(output,"cases.csv"),cases) + end + write_engineering_json(joinpath(output,"environment.json"),Dict("laws"=>laws,"homes"=>homes, + "line_length_m"=>length_m,"linecode"=>"abc4x95_lv_oh_4w_bundled","source_pu"=>source_pu, + "neighbour_single_phase_pv_W_per_home_on_phase_c"=>neighbour_pv_W,"fixed_point_retries"=>"relaxation 1/0.5/0.25, max iterations 30/120/300","p_available_W_per_home"=>5000., + "load_per_home"=>"1.5 kW PF 0.95, 60/25/15 % A/B/C","source_vuf"=>0., + "git_revision"=>strip(read(`git -C $(normpath(joinpath(ROOT,"..",".."))) rev-parse HEAD`,String)))) + cases +end + +if abspath(PROGRAM_FILE)==abspath(@__FILE__) + run_two_bus_street(ARGS[1]) +end