Skip to content

Commit

Permalink
Merge pull request #26 from lanl-ansi/matpower_conversion
Browse files Browse the repository at this point in the history
Matpower conversion
  • Loading branch information
rb004f authored Jul 12, 2018
2 parents 5bc5dfc + 64692bf commit 2dad31f
Show file tree
Hide file tree
Showing 63 changed files with 28,305 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ deps/deps.jl
test/test-mixed-units.jl
test/test-gmd-gic.jl
test/gmd.log

src/scratch
9 changes: 5 additions & 4 deletions src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ end
"Adds the data structures that are specific for GMD modeling"
function build_gmd_ref(pm::GenericPowerModel)
nws = pm.ref[:nw]

if pm.data["multinetwork"]
nws_data = pm.data["nw"]
data = pm.data

if InfrastructureModels.ismultinetwork(data)
nws_data = data["nw"]
else
nws_data = Dict{String,Any}("0" => pm.data)
nws_data = Dict{String,Any}("0" => data)
end

for (n,nw_data) in nws_data
Expand Down
29 changes: 14 additions & 15 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function constraint_dc_current_mag_gwye_delta_xf{T}(pm::GenericPowerModel{T}, n:
ieff = pm.var[:nw][n][:i_dc_mag][k]
ihi = pm.var[:nw][n][:dc][(kh,ih,jh)]

c = @constraint(pm.model, ieff >= ihi)
c = @constraint(pm.model, ieff >= -ihi)
@constraint(pm.model, ieff >= ihi)
@constraint(pm.model, ieff >= -ihi)
end

"DC current on ungrounded gwye-gwye transformers"
Expand All @@ -31,8 +31,8 @@ function constraint_dc_current_mag_gwye_gwye_xf{T}(pm::GenericPowerModel{T}, n::
ihi = pm.var[:nw][n][:dc][(kh,ih,jh)]
ilo = pm.var[:nw][n][:dc][(kl,il,jl)]

c = @constraint(pm.model, ieff >= (a*ihi + ilo)/a)
c = @constraint(pm.model, ieff >= -(a*ihi + ilo)/a)
@constraint(pm.model, ieff >= (a*ihi + ilo)/a)
@constraint(pm.model, ieff >= -(a*ihi + ilo)/a)
end

"DC current on ungrounded gwye-gwye auto transformers"
Expand All @@ -41,10 +41,9 @@ function constraint_dc_current_mag_gwye_gwye_auto_xf{T}(pm::GenericPowerModel{T}
is = pm.var[:nw][n][:dc][(ks,is,js)]
ic = pm.var[:nw][n][:dc][(kc,ic,jc)]

c = @constraint(pm.model, ieff >= (a*is + ic)/(a + 1.0))
c = @constraint(pm.model, ieff >= -(a*is + ic)/(a + 1.0))
c = @constraint(pm.model, ieff >= 0.0)

@constraint(pm.model, ieff >= (a*is + ic)/(a + 1.0))
@constraint(pm.model, ieff >= -(a*is + ic)/(a + 1.0))
@constraint(pm.model, ieff >= 0.0)
end

"The KCL constraint for DC (GIC) circuits"
Expand Down Expand Up @@ -74,16 +73,16 @@ function constraint_qloss_constant_v{T}(pm::GenericPowerModel{T}, n::Int, k, i,
qloss = pm.var[:nw][n][:qloss]

# K is per phase
c = @constraint(pm.model, qloss[(k,i,j)] == K*V*i_dc_mag/(3.0*branchMVA))
c = @constraint(pm.model, qloss[(k,j,i)] == 0.0)
@constraint(pm.model, qloss[(k,i,j)] == K*V*i_dc_mag/(3.0*branchMVA))
@constraint(pm.model, qloss[(k,j,i)] == 0.0)
end

"Constraint for computing qloss assuming DC voltage is constant"
function constraint_qloss_constant_v{T}(pm::GenericPowerModel{T}, n::Int, k, i, j)
qloss = pm.var[:nw][n][:qloss]

c = @constraint(pm.model, qloss[(k,i,j)] == 0.0)
c = @constraint(pm.model, qloss[(k,j,i)] == 0.0)
@constraint(pm.model, qloss[(k,i,j)] == 0.0)
@constraint(pm.model, qloss[(k,j,i)] == 0.0)
end

"Constraint for turning generators on and off"
Expand Down Expand Up @@ -139,14 +138,14 @@ end
"DC current on normal lines"
function constraint_dc_current_mag_line{T}(pm::GenericPowerModel{T}, n::Int, k)
ieff = pm.var[:nw][n][:i_dc_mag]
c = @constraint(pm.model, ieff[k] >= 0.0)
@constraint(pm.model, ieff[k] >= 0.0)
end
constraint_dc_current_mag_line{T}(pm::GenericPowerModel{T}, k) = constraint_dc_current_mag_line(pm, pm.cnw, k)

"DC current on grounded transformers"
function constraint_dc_current_mag_grounded_xf{T}(pm::GenericPowerModel{T}, n::Int, k)
ieff = pm.var[:nw][n][:i_dc_mag]
c = @constraint(pm.model, ieff[k] >= 0.0)
@constraint(pm.model, ieff[k] >= 0.0)
end
constraint_dc_current_mag_grounded_xf{T}(pm::GenericPowerModel{T}, k) = constraint_dc_current_mag_grounded_xf(pm, pm.cnw, k)

Expand All @@ -169,7 +168,7 @@ function constraint_dc_current_mag{T}(pm::GenericPowerModel{T}, n::Int, k)
constraint_dc_current_mag_gwye_gwye_auto_xf(pm,n,k)
else
ieff = pm.var[:nw][n][:i_dc_mag]
c = @constraint(pm.model, ieff[k] >= 0.0)
@constraint(pm.model, ieff[k] >= 0.0)
end
end
constraint_dc_current_mag{T}(pm::GenericPowerModel{T}, k) = constraint_dc_current_mag(pm, pm.cnw, k)
6 changes: 3 additions & 3 deletions src/core/constraint_template.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function constraint_dc_ohms{T}(pm::GenericPowerModel{T}, n::Int, i)
bus1 = pm.ref[:nw][n][:gmd_bus][f_bus]
bus2 = pm.ref[:nw][n][:gmd_bus][t_bus]

dkm = branch["len_km"]
# dkm = branch["len_km"]
vs = branch["br_v"] # line dc series voltage

if branch["br_r"] === nothing
Expand All @@ -140,7 +140,7 @@ function constraint_dc_ohms{T}(pm::GenericPowerModel{T}, n::Int, i)
gs = 1.0/branch["br_r"] # line dc series resistance
end

debug(LOGGER, @sprintf "branch %d: (%d,%d): d (mi) = %0.3f, vs = %0.3f, gs = %0.3f\n" i f_bus t_bus dkm vs gs)
debug(LOGGER, @sprintf "branch %d: (%d,%d): vs = %0.3f, gs = %0.3f\n" i f_bus t_bus vs gs)

constraint_dc_ohms(pm, n, i, f_bus, t_bus, vs, gs)
end
Expand Down Expand Up @@ -276,7 +276,7 @@ function constraint_dc_ohms_on_off{T}(pm::GenericPowerModel{T}, n::Int, i)
bus1 = pm.ref[:nw][n][:gmd_bus][f_bus]
bus2 = pm.ref[:nw][n][:gmd_bus][t_bus]

dkm = branch["len_km"]
# dkm = branch["len_km"]

vs = branch["br_v"] # line dc series voltage

Expand Down
30 changes: 27 additions & 3 deletions src/core/data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function calculate_qloss(branch, case, solution)
i_dc_mag = abs(br_soln["gmd_idc"])

if "gmd_k" in keys(branch)

ibase = branch["baseMVA"]*1000.0*sqrt(2.0)/(bus["base_kv"]*sqrt(3.0))
K = branch["gmd_k"]*data["baseMVA"]/ibase

Expand Down Expand Up @@ -149,9 +150,32 @@ function calc_branch_thermal_coeff{T}(pm::GenericPowerModel{T}, i, n::Int=pm.cnw
if !(branch["type"] == "xf")
return NaN
end

x0 = pm.data["thermal_cap_x0"]./calc_branch_ibase(pm,i,n) #branch["ibase"]
y0 = pm.data["thermal_cap_y0"]./100 # convert to %

# A hack for now....
thermal_cap_x0 = pm.data["thermal_cap_x0"]
if isa(thermal_cap_x0, Dict)
thermal_cap_x0 = []
for (key, value) in sort(pm.data["thermal_cap_x0"]["1"])
if key == "index"
continue
end
push!(thermal_cap_x0, value)
end
end

thermal_cap_y0 = pm.data["thermal_cap_y0"]
if isa(thermal_cap_y0, Dict)
thermal_cap_y0 = []
for (key, value) in sort(pm.data["thermal_cap_y0"]["1"])
if key == "index"
continue
end
push!(thermal_cap_y0, value)
end
end

x0 = thermal_cap_x0./calc_branch_ibase(pm,i,n) #branch["ibase"]
y0 = thermal_cap_y0./100 # convert to %

y = calc_ac_mag_max(pm,i,n) .* y0 # branch["ac_mag_max"] .* y0
x = x0
Expand Down
3 changes: 3 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Pajarito 0.4.2
Gurobi

Memento 0.5.0

PowerModels 0.7 0.8-
InfrastructureModels 0.0.4 0.2-
1 change: 0 additions & 1 deletion test/data/b4gic.json

This file was deleted.

70 changes: 70 additions & 0 deletions test/data/b4gic.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
%% MATPOWER Case Format : Version 2
mpc.version = '2';

%%----- Power Flow Data -----%%
%% system MVA base
mpc.baseMVA = 100;

%% bus data
% bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
mpc.bus = [
1 1 0 0 0 0 1 1.100000 0.000000 765 1 1.3 0.7
2 1 0 0 0 0 1 1.100000 0.000000 765 1 1.3 0.7
3 1 1000 200 0 0 1 1.100000 0.000000 20 1 1.3 0.7
4 3 0 0 0 0 1 1.100000 0.000000 20 1 1 0.7
];

%% generator data
% bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
mpc.gen = [
4 0.0 0.0 2000.0 -2000.0 1.1 100 1 2000.0 0.0 0 0 0 0 0 0 0 0 0 -1000 0
];

%% branch data
% fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
mpc.branch = [
1 3 0.0001 0.004 0 9000.0 0.0 0.0 1 0.0 1 -30.0 30.0
1 2 0.000513 0.01 0 9000.0 0.0 0.0 1 0.0 1 -30.0 30.0
2 4 0.0001 0.004 0 9000.0 0.0 0.0 1 0.0 1 -30.0 30.0
];

%%----- OPF Data -----%%
%% generator cost data
% 1 startup shutdown n x1 y1 ... xn yn
% 2 startup shutdown n c(n-1) ... c0
mpc.gencost = [
2 0 0 3 0.11 5.0 0
];

%column_names% parent_index g_gnd name
mpc.gmd_bus = {
1 5 'dc_sub1'
2 5 'dc_sub2'
1 0 'dc_bus1'
2 0 'dc_bus2'
3 0 'dc_bus3'
4 0 'dc_bus4'
};

%column_names% f_bus t_bus parent_index br_status br_r br_v len_km name
mpc.gmd_branch = {
3 1 1 1 0.1 0 0 'dc_xf1_hi'
3 4 2 1 1.00073475 170.78806587354 170.78806587354 'dc_br1'
4 2 3 1 0.1 0 0 'dc_xf2_hi'
};

%column_names% hi_bus lo_bus gmd_br_hi gmd_br_lo gmd_k gmd_br_series gmd_br_common baseMVA type config
mpc.branch_gmd = {
1 3 1 -1 1.793 -1 -1 100 'xf' 'gwye-delta'
1 2 -1 -1 0 -1 -1 100 'line' 'none'
2 4 3 -1 1.793 -1 -1 100 'xf' 'gwye-delta'
};

%column_names% lat lon
mpc.bus_gmd = {
40 -89
40 -87
40 -89
40 -87
};

Loading

0 comments on commit 2dad31f

Please sign in to comment.