Skip to content

Commit d73a657

Browse files
committed
Merge branch 'develop'
2 parents 622fe38 + b0761f5 commit d73a657

File tree

15 files changed

+460
-210
lines changed

15 files changed

+460
-210
lines changed

src/ParserPWF.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ include("pwf2pm/correct/anarede.jl")
2222

2323
include("pwf2pm/pwf2pm.jl")
2424

25-
function parse_file(filename::String; validate::Bool=true, software = ANAREDE, pm::Bool = true)
26-
pm ? parse_pwf_to_powermodels(filename, validate = validate, software = software) : parse_pwf(filename)
25+
function parse_file(filename::String; validate::Bool=true, software = ANAREDE, pm::Bool = true, add_control_data::Bool=false)
26+
pm ? parse_pwf_to_powermodels(filename, validate = validate, software = software, add_control_data = add_control_data) : parse_pwf(filename)
2727
end
2828

2929
function parse_file(io::IO; validate::Bool=true, software = ANAREDE, pm::Bool = true)
30-
pm ? parse_pwf_to_powermodels(io, validate = validate, software = software) : parse_pwf(filename)
30+
pm ? parse_pwf_to_powermodels(io, validate = validate, software = software, add_control_data = add_control_data) : parse_pwf(filename)
3131
end
3232

3333
export parse_file

src/pwf.jl

Lines changed: 105 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const _dshl_dtypes = [("FROM BUS", Int64, 1:5), ("OPERATION", Int64, 7),
8585
("SHUNT TO", Float64, 24:29), ("STATUS FROM", String, 31:32), ("STATUS TO", String, 34:35)]
8686

8787
const _dcba_dtypes = [("NUMBER", Int64, 1:4), ("OPERATION", Int64, 6), ("TYPE", Int64, 8),
88-
("POLARITY", String, 9), ("NAME", String, 10:21), ("VOLTAGE LIMIT GROUP", String, 22:23),
88+
("POLARITY", Char, 9), ("NAME", String, 10:21), ("VOLTAGE LIMIT GROUP", String, 22:23),
8989
("VOLTAGE", Float64, 24:28), ("GROUND ELECTRODE", Float64, 67:71), ("DC LINK", Int64, 72:75)]
9090

9191
const _dcli_dtypes = [("FROM BUS", Int64, 1:4), ("OPERATION", Int64, 6), ("TO BUS", Int64, 9:12),
@@ -169,7 +169,7 @@ const _dcai_dtypes = [("BUS", Int64, 1:5), ("OPERATION", Char, 7), ("GROUP", Int
169169
("ACTIVE CHARGE", Float64, 23:27), ("REACTIVE CHARGE", Float64, 29:33),
170170
("PARAMETER A", Float64, 35:37), ("PARAMETER B", Float64, 39:41),
171171
("PARAMETER C", Float64, 43:45), ("PARAMETER D", Float64, 47:49), ("VOLTAGE", Float64, 51:55),
172-
("VOLTAGE FOR CHARGE DEFINITION", Float64, 57:60)]
172+
("CHARGE DEFINITION VOLTAGE", Float64, 57:60)]
173173

174174
const _dgei_dtypes = [("BUS", Int64, 1:5), ("OPERATION", Char, 7), ("AUTOMATIC MODE", Char, 8),
175175
("GROUP", Int64, 10:11), ("STATUS", Char, 13), ("UNITIES", Int64, 14:16),
@@ -178,7 +178,7 @@ const _dgei_dtypes = [("BUS", Int64, 1:5), ("OPERATION", Char, 7), ("AUTOMATIC M
178178
("MINIMUM REACTIVE GENERATION", Float64, 33:37), ("MAXIMUM REACTIVE GENERATION", Float64, 38:42),
179179
("ELEVATOR TRANSFORMER REACTANCE", Float64, 43:48), ("XD", Float64, 50:54, 53),
180180
("XQ", Float64, 55:59, 58), ("XL", Float64, 60:64, 63), ("POWER FACTOR", Float64, 66:69, 67),
181-
("APARENT POWER", Float64, 70:74, 72), ("MECHANICAL LIMIT", Float64, 75:79, 77)]
181+
("APPARENT POWER", Float64, 70:74, 72), ("MECHANICAL LIMIT", Float64, 75:79, 77)]
182182

183183
const _dmot_dtypes = [("BUS", Int64, 1:5), ("OPERATION", Char, 7), ("STATUS", Char, 8),
184184
("GROUP", Int64, 10:11), ("SIGN", Char, 12), ("LOADING FACTOR", Float64, 13:15),
@@ -191,7 +191,7 @@ const _dmot_dtypes = [("BUS", Int64, 1:5), ("OPERATION", Char, 7), ("STATUS", Ch
191191
const _dcmt_dtypes = [("COMMENTS", String, 1:80)]
192192

193193
const _dinj_dtypes = [("NUMBER", Int64, 1:5), ("OPERATION", Char, 7),
194-
("EQUIVALENT ACTIVE INJECITON", Float64, 9:15), ("EQUIVALENT REACTIVE INJECTION", Float64, 16:22),
194+
("EQUIVALENT ACTIVE INJECTION", Float64, 9:15), ("EQUIVALENT REACTIVE INJECTION", Float64, 16:22),
195195
("EQUIVALENT SHUNT", Float64, 23:29), ("EQUIVALENT PARTICIPATION FACTOR", Float64, 30:36)]
196196

197197
const _pwf_dtypes = Dict("DBAR" => _dbar_dtypes, "DLIN" => _dlin_dtypes, "DGBT" => _dgbt_dtypes,
@@ -233,12 +233,12 @@ const _default_dbar = Dict("NUMBER" => nothing, "OPERATION" => 'A', "STATUS" =>
233233
"AGGREGATOR 10" => nothing)
234234

235235
const _default_dlin = Dict("FROM BUS" => nothing, "OPENING FROM BUS" => 'L',
236-
"OPERATION" => 'A', "OPENING TO BUS" => 'L', "TO BUS" => nothing, "CIRCUIT" => nothing,
236+
"OPERATION" => 'A', "OPENING TO BUS" => 'L', "TO BUS" => nothing, "CIRCUIT" => 0,
237237
"STATUS" => 'L', "OWNER" => 'F', "RESISTANCE" => 0.0, "REACTANCE" => nothing,
238238
"SHUNT SUSCEPTANCE" => 0.0, "TAP" => 1.0, "MINIMUM TAP" => nothing,
239239
"MAXIMUM TAP" => nothing, "LAG" => 0.0, "CONTROLLED BUS" => nothing,
240-
"NORMAL CAPACITY" => Inf, "EMERGENCY CAPACITY" => Inf, "NUMBER OF TAPS" => 33,
241-
"EQUIPAMENT CAPACITY" => Inf, "AGGREGATOR 1" => nothing, "AGGREGATOR 2" => nothing,
240+
"NORMAL CAPACITY" => Inf, "EMERGENCY CAPACITY" => nothing, "NUMBER OF TAPS" => 33,
241+
"EQUIPAMENT CAPACITY" => nothing, "AGGREGATOR 1" => nothing, "AGGREGATOR 2" => nothing,
242242
"AGGREGATOR 3" => nothing, "AGGREGATOR 4" => nothing, "AGGREGATOR 5" => nothing,
243243
"AGGREGATOR 6" => nothing, "AGGREGATOR 7" => nothing, "AGGREGATOR 8" => nothing,
244244
"AGGREGATOR 9" => nothing, "AGGREGATOR 10" => nothing)
@@ -274,11 +274,11 @@ const _default_dshl = Dict("FROM BUS" => nothing, "OPERATION" => 'A', "TO BUS" =
274274
"STATUS FROM" => " L", "STATUS TO" => " L")
275275

276276
const _default_dcba = Dict("NUMBER" => nothing, "OPERATION" => 'A', "TYPE" => 0,
277-
"POLARITY" => nothing, "NAME" => nothing, "VOLTAGE LIMIT GROUP" => nothing,
277+
"POLARITY" => nothing, "NAME" => nothing, "VOLTAGE LIMIT GROUP" => " 0",
278278
"VOLTAGE" => 0, "GROUND ELECTRODE" => 0.0, "DC LINK" => 1)
279279

280280
const _default_dcli = Dict("FROM BUS" => nothing, "OPERATION" => 'A', "TO BUS" => nothing,
281-
"CIRCUIT" => nothing, "OWNER" => nothing, "RESISTANCE" => nothing, "INDUCTANCE" => 0.0,
281+
"CIRCUIT" => 0, "OWNER" => nothing, "RESISTANCE" => nothing, "INDUCTANCE" => 0.0,
282282
"CAPACITY" => Inf)
283283

284284
const _default_dcnv = Dict("NUMBER" => nothing, "OPERATION" => 'A', "AC BUS" => nothing,
@@ -317,14 +317,15 @@ const _default_fagr_2 = Dict("NUMBER" => nothing, "OPERATION" => 'A', "DESCRIPTI
317317

318318
const _default_fagr_1 = Dict("NUMBER" => nothing, "DESCRIPTION" => nothing, "OCCURENCES" => _default_fagr_2)
319319

320-
const _default_dcsc = Dict("FROM BUS" => nothing, "OPERATION" => nothing, "TO BUS" => nothing,
321-
"CIRCUIT" => nothing, "STATUS" => 'L', "OWNER" => 'F', "BYPASS" => 'D',
320+
const _default_dcsc = Dict("FROM BUS" => nothing, "OPERATION" => 'A', "TO BUS" => nothing,
321+
"CIRCUIT" => 0, "STATUS" => 'L', "OWNER" => 'F', "BYPASS" => 'D',
322322
"MINIMUM VALUE" => -9999.0, "MAXIMUM VALUE" => 9999.0, "INITIAL VALUE" => nothing,
323323
"CONTROL MODE" => 'X', "SPECIFIED VALUE" => nothing, "MEASUREMENT EXTREMITY" => nothing,
324324
"NUMBER OF STAGES" => nothing, "NORMAL CAPACITY" => Inf, "EMERGENCY CAPACITY" => Inf,
325325
"EQUIPAMENT CAPACITY" => Inf, "AGGREGATOR 1" => nothing, "AGGREGATOR 2" => nothing,
326326
"AGGREGATOR 3" => nothing, "AGGREGATOR 4" => nothing, "AGGREGATOR 5" => nothing,
327-
"AGGREGATOR 6" => nothing)
327+
"AGGREGATOR 6" => nothing, "AGGREGATOR 8" => nothing, "AGGREGATOR 7" => nothing,
328+
"AGGREGATOR 9" => nothing, "AGGREGATOR 10" => nothing)
328329

329330
const _default_dcar = Dict("ELEMENT 1 TYPE" => nothing, "ELEMENT 1 IDENTIFICATION" => nothing,
330331
"CONDITION 1" => nothing, "ELEMENT 2 TYPE" => nothing, "ELEMENT 2 IDENTIFICATION" => nothing,
@@ -342,23 +343,23 @@ const _default_dctr = Dict("FROM BUS" => nothing, "OPERATION" => 'A', "TO BUS" =
342343
const _default_dare = Dict("NUMBER" => nothing, "NET INTERCHANGE" => 0.0, "NAME" => nothing,
343344
"MINIMUM INTERCHANGE" => 0.0, "MAXIMUM INTERCHANGE" => 0.0)
344345

345-
const _default_dtpf_circ = Dict("FROM BUS 1" => nothing, "TO BUS 1" => nothing, "CIRCUIT 1" => nothing,
346-
"FROM BUS 2" => nothing, "TO BUS 2" => nothing, "CIRCUIT 2" => nothing,
347-
"FROM BUS 3" => nothing, "TO BUS 3" => nothing, "CIRCUIT 3" => nothing,
348-
"FROM BUS 4" => nothing, "TO BUS 4" => nothing, "CIRCUIT 4" => nothing,
349-
"FROM BUS 5" => nothing, "TO BUS 5" => nothing, "CIRCUIT 5" => nothing, "OPERATION" => 'A')
346+
const _default_dtpf_circ = Dict("FROM BUS 1" => nothing, "TO BUS 1" => nothing, "CIRCUIT 1" => 0,
347+
"FROM BUS 2" => nothing, "TO BUS 2" => nothing, "CIRCUIT 2" => 0,
348+
"FROM BUS 3" => nothing, "TO BUS 3" => nothing, "CIRCUIT 3" => 0,
349+
"FROM BUS 4" => nothing, "TO BUS 4" => nothing, "CIRCUIT 4" => 0,
350+
"FROM BUS 5" => nothing, "TO BUS 5" => nothing, "CIRCUIT 5" => 0, "OPERATION" => 'A')
350351

351352
const _default_dmte = Dict("ELEMENT 1 TYPE" => nothing, "ELEMENT 1 IDENTIFICATION" => nothing,
352353
"CONDITION 1" => nothing, "ELEMENT 2 TYPE" => nothing, "ELEMENT 2 IDENTIFICATION" => nothing,
353354
"MAIN CONDITION" => nothing, "ELEMENT 3 TYPE" => nothing, "ELEMENT 3 IDENTIFICATION" => nothing,
354355
"CONDITION 2" => nothing, "ELEMENT 4 TYPE" => nothing, "ELEMENT 4 IDENTIFICATION" => nothing,
355356
"OPERATION" => 'A', "BOUNDARIES" => 'T')
356357

357-
const _default_dmfl_circ = Dict("FROM BUS 1" => nothing, "TO BUS 1" => nothing, "CIRCUIT 1" => nothing,
358-
"FROM BUS 2" => nothing, "TO BUS 2" => nothing, "CIRCUIT 2" => nothing,
359-
"FROM BUS 3" => nothing, "TO BUS 3" => nothing, "CIRCUIT 3" => nothing,
360-
"FROM BUS 4" => nothing, "TO BUS 4" => nothing, "CIRCUIT 4" => nothing,
361-
"FROM BUS 5" => nothing, "TO BUS 5" => nothing, "CIRCUIT 5" => nothing, "OPERATION" => 'A')
358+
const _default_dmfl_circ = Dict("FROM BUS 1" => nothing, "TO BUS 1" => nothing, "CIRCUIT 1" => 0,
359+
"FROM BUS 2" => nothing, "TO BUS 2" => nothing, "CIRCUIT 2" => 0,
360+
"FROM BUS 3" => nothing, "TO BUS 3" => nothing, "CIRCUIT 3" => 0,
361+
"FROM BUS 4" => nothing, "TO BUS 4" => nothing, "CIRCUIT 4" => 0,
362+
"FROM BUS 5" => nothing, "TO BUS 5" => nothing, "CIRCUIT 5" => 0, "OPERATION" => 'A')
362363

363364
const _default_dbre = Dict()
364365

@@ -371,8 +372,8 @@ const _default_dgei = Dict("BUS" => nothing, "OPERATION" => 'A', "AUTOMATIC MODE
371372
"GROUP" => nothing, "STATUS" => 'L', "UNITIES" => 1, "OPERATING UNITIES" => 1,
372373
"MINIMUM OPERATING UNITIES" => 1, "ACTIVE GENERATION" => 0.0, "REACTIVE GENERATION" => 0.0,
373374
"MINIMUM REACTIVE GENERATION" => -9999.0, "MAXIMUM REACTIVE GENERATION" => 99999.0,
374-
"TRANSFORMER ELEVATOR REACTANCE" => nothing, "XD" => 0.0, "XQ" => 0.0, "XL" => 0.0,
375-
"POWER FACTOR" => 1.0, "APARENT POWER" => 99999.0, "MECHANICAL LIMIT" => 99999.0)
375+
"ELEVATOR TRANSFORMER REACTANCE" => nothing, "XD" => 0.0, "XQ" => 0.0, "XL" => 0.0,
376+
"POWER FACTOR" => 1.0, "APPARENT POWER" => 99999.0, "MECHANICAL LIMIT" => 99999.0)
376377

377378
const _default_dmot = Dict("BUS" => nothing, "OPERATION" => 'A', "STATUS" => 'L',
378379
"GROUP" => nothing, "SIGN" => '+', "LOADING FACTOR" => 100.0, "UNITIES" => 1,
@@ -384,7 +385,7 @@ const _default_dmot = Dict("BUS" => nothing, "OPERATION" => 'A', "STATUS" => 'L'
384385
const _default_dcmt = Dict("COMMENTS" => nothing)
385386

386387
const _default_dinj = Dict("NUMBER" => nothing, "OPERATION" => 'A',
387-
"EQUIVALENT ACTIVE INJECITON" => 0.0, "EQUIVALENT REACTIVE INJECITON" => 0.0,
388+
"EQUIVALENT ACTIVE INJECTION" => 0.0, "EQUIVALENT REACTIVE INJECTION" => 0.0,
388389
"EQUIVALENT SHUNT" => 0.0, "EQUIVALENT PARTICIPATION FACTOR" => 0.0)
389390

390391
const _default_titu = ""
@@ -704,17 +705,34 @@ function _handle_special_defaults!(pwf_data::Dict{String, Any}, section::String,
704705
pwf_data[section][i][component] = pwf_data[section][i]["FROM BUS"] # Default: the bus itself
705706
end
706707

708+
if section == "DLIN" && component in ["EMERGENCY CAPACITY", "EQUIPAMENT CAPACITY"]
709+
normal_capacity = pwf_data[section][i]["NORMAL CAPACITY"]
710+
normal_capacity = isa(normal_capacity, AbstractString) && _needs_default(normal_capacity) ? _pwf_defaults[section]["NORMAL CAPACITY"] : normal_capacity
711+
pwf_data[section][i][component] = normal_capacity
712+
end
713+
707714
if section == "DBSH" && component == "MINIMUM VOLTAGE"
708715
ctrl_bus = pwf_data[section][i]["CONTROLLED BUS"]
716+
ctrl_bus = !isa(ctrl_bus, Int64) ? pwf_data[section][i]["FROM BUS"] : ctrl_bus
709717
group = pwf_data["DBAR"]["$ctrl_bus"]["VOLTAGE LIMIT GROUP"]
718+
group = isa(group, AbstractString) && _needs_default(group) ? " 0" : group
710719
group_idx = findfirst(x -> x["GROUP"] == group, pwf_data["DGLT"])
711-
pwf_data[section][i][component] = pwf_data["DGLT"][group_idx]["LOWER BOUND"]
720+
lower_bound = pwf_data["DGLT"][group_idx]["LOWER BOUND"]
721+
lower_bound = isa(lower_bound, AbstractString) && _needs_default(lower_bound) ? 0.8 : lower_bound
722+
pwf_data[section][i][component] = lower_bound
712723
end
713724
if section == "DBSH" && component == "MAXIMUM VOLTAGE"
714725
ctrl_bus = pwf_data[section][i]["CONTROLLED BUS"]
726+
ctrl_bus = !isa(ctrl_bus, Int64) ? pwf_data[section][i]["FROM BUS"] : ctrl_bus
715727
group = pwf_data["DBAR"]["$ctrl_bus"]["VOLTAGE LIMIT GROUP"]
728+
group = isa(group, AbstractString) && _needs_default(group) ? " 0" : group
716729
group_idx = findfirst(x -> x["GROUP"] == group, pwf_data["DGLT"])
717-
pwf_data[section][i][component] = pwf_data["DGLT"][group_idx]["UPPER BOUND"]
730+
upper_bound = pwf_data["DGLT"][group_idx]["UPPER BOUND"]
731+
upper_bound = isa(upper_bound, AbstractString) && _needs_default(upper_bound) ? 1.2 : upper_bound
732+
pwf_data[section][i][component] = upper_bound
733+
end
734+
if section == "DBSH" && component == "CONTROLLED BUS"
735+
pwf_data[section][i][component] = pwf_data[section][i]["FROM BUS"]
718736
end
719737

720738
if section == "DCTR" && component in ["MINIMUM VOLTAGE", "MAXIMUM VOLTAGE"]
@@ -723,6 +741,66 @@ function _handle_special_defaults!(pwf_data::Dict{String, Any}, section::String,
723741
if section == "DCTR" && component in ["MINIMUM PHASE", "MAXIMUM PHASE"]
724742
pwf_data[section][i]["PHASE CONTROL"] = false
725743
end
744+
745+
if section == "DCTR" && component == "MEASUREMENT EXTREMITY"
746+
pwf_data[section][i][component] = pwf_data[section][i]["FROM BUS"]
747+
end
748+
749+
if section == "DGLT" && component == "LOWER EMERGENCY BOUND"
750+
pwf_data[section][i][component] = pwf_data[section][i]["LOWER BOUND"]
751+
end
752+
if section == "DGLT" && component == "UPPER EMERGENCY BOUND"
753+
pwf_data[section][i][component] = pwf_data[section][i]["UPPER BOUND"]
754+
end
755+
756+
if section == "DCBA" && component == "VOLTAGE"
757+
if pwf_data[section][i]["POLARITY"] == '0'
758+
pwf_data[section][i][component] = 0.0
759+
else
760+
pwf_data[section][i][component] = 1.0
761+
end
762+
end
763+
764+
if section == "DCCV" && component == "TAP HI MVAR MODE"
765+
step = (pwf_data[section][i]["MAXIMUM TRANSFORMER TAP"] - pwf_data[section][i]["MINIMUM TRANSFORMER TAP"]) / pwf_data[section][i]["TRANSFORMER TAP NUMBER OF STEPS"]
766+
pwf_data[section][i][component] = pwf_data[section][i]["MAXIMUM TRANSFORMER TAP"] - step
767+
end
768+
769+
if section == "DELO" && component == "BASE" && haskey(pwf_data, "DCTE")
770+
pwf_data[section][i][component] = pwf_data["DCTE"]["DASE"]
771+
end
772+
773+
if section == "DCER" && component == "CONTROLLED BUS"
774+
pwf_data[section][i][component] = pwf_data[section][i]["BUS"]
775+
end
776+
777+
if section == "DCSC" && component == "INITIAL VALUE"
778+
pwf_data[section][i][component] = pwf_data[section][i]["MAXIMUM VALUE"]
779+
end
780+
if section == "DCSC" && component == "MEASUREMENT EXTREMITY"
781+
pwf_data[section][i][component] = pwf_data[section][i]["FROM BUS"]
782+
end
783+
784+
if section == "DCAR" && component == "VOLTAGE" && haskey(pwf_data, "DCTE")
785+
pwf_data[section][i][component] = pwf_data["DCTE"]["VFLD"]
786+
end
787+
788+
if section == "DCAI" && component == "OPERATING UNITIES"
789+
pwf_data[section][i][component] = pwf_data[section][i]["UNITIES"]
790+
end
791+
if section == "DCAI" && component == "VOLTAGE" && haskey(pwf_data, "DCTE")
792+
vfld = pwf_data["DCTE"]["VFLD"]
793+
vfld = isa(vfld, AbstractString) && _needs_default(vfld) ? 70 : vfld
794+
pwf_data[section][i][component] = vfld
795+
end
796+
if section == "DGEI" && component == "OPERATING UNITIES"
797+
pwf_data[section][i][component] = pwf_data[section][i]["UNITIES"]
798+
end
799+
if section == "REACTANCE GROUPS" && component == "OPERATING UNITIES"
800+
unities = pwf_data[section][i]["UNITIES"]
801+
unities = isa(unities, AbstractString) && _needs_default(unities) ? 1 : unities
802+
pwf_data[section][i][component] = unities
803+
end
726804
end
727805

728806
function _handle_transformer_default!(pwf_data::Dict{String, Any}, section::String, i::String)

0 commit comments

Comments
 (0)