• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GenXProject / GenX / #380

09 Dec 2023 03:57AM UTC coverage: 0.102%. First build
#380

Pull #600

travis-ci

Pull Request #600: Gen x retrofit mit

0 of 793 new or added lines in 67 files covered. (0.0%)

4 of 3904 relevant lines covered (0.1%)

0.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/load_inputs/load_network_data.jl
1
@doc raw"""
2
    load_network_data!(setup::Dict, path::AbstractString, inputs_nw::Dict)
3

4
Function for reading input parameters related to the electricity transmission network
5
"""
6
function load_network_data!(setup::Dict, path::AbstractString, inputs_nw::Dict)
7
    scale_factor = setup["ParameterScale"] == 1 ? ModelScalingFactor : 1
8

9
    filename = "Network.csv"
10
    network_var = load_dataframe(joinpath(path, filename))
11

12
    as_vector(col::Symbol) = collect(skipmissing(network_var[!, col]))
13
    to_floats(col::Symbol) = convert(Array{Float64}, as_vector(col))
14

15
    # Number of zones in the network
16
    Z = length(as_vector(:Network_zones))
17
    inputs_nw["Z"] = Z
18
    # Number of lines in the network
19
    L = length(as_vector(:Network_Lines))
20
    inputs_nw["L"] = L
21

22
    # Topology of the network source-sink matrix
23
    inputs_nw["pNet_Map"] = load_network_map(network_var, Z, L)
×
24

25
    # Transmission capacity of the network (in MW)
×
26
    inputs_nw["pTrans_Max"] = to_floats(:Line_Max_Flow_MW) / scale_factor  # convert to GW
27

×
NEW
28
    if setup["Trans_Loss_Segments"] == 1
×
29
        # Line percentage Loss - valid for case when modeling losses as a fixed percent of absolute value of power flows
30
        inputs_nw["pPercent_Loss"] = to_floats(:Line_Loss_Percentage)
×
31
    elseif setup["Trans_Loss_Segments"] >= 2
×
32
        # Transmission line voltage (in kV)
33
        inputs_nw["kV"] = to_floats(:Line_Voltage_kV)
34
        # Transmission line resistance (in Ohms) - Used when modeling quadratic transmission losses
×
35
        inputs_nw["Ohms"] = to_floats(:Line_Resistance_Ohms)
×
36
    end
37

×
38
    ## Inputs for the DC-OPF 
×
39
    if setup["DC_OPF"] == 1
40
        if setup["NetworkExpansion"] == 1
41
            @warn("Because the DC_OPF flag is active, GenX will not allow any transmission capacity expansion. Set the DC_OPF flag to 0 if you want to optimize tranmission capacity expansion.")
×
42
            setup["NetworkExpansion"] = 0
43
        end
44
        println("Reading DC-OPF values...")
×
45
        # Transmission line voltage (in kV)
46
        line_voltage_kV = to_floats(:Line_Voltage_kV)
×
47
        # Transmission line reactance (in Ohms)
48
        line_reactance_Ohms = to_floats(:Line_Reactance_Ohms)
×
49
        # Line angle limit (in radians)
×
50
        inputs_nw["Line_Angle_Limit"] = to_floats(:Angle_Limit_Rad)
51
        # DC-OPF coefficient for each line (in MW when not scaled, in GW when scaled) 
×
52
        # MW = (kV)^2/Ohms 
53
        inputs_nw["pDC_OPF_coeff"] = ((line_voltage_kV .^ 2) ./ line_reactance_Ohms) /
×
54
                                     scale_factor
55
    end
56

57
    # Maximum possible flow after reinforcement for use in linear segments of piecewise approximation
×
58
    inputs_nw["pTrans_Max_Possible"] = inputs_nw["pTrans_Max"]
59

×
60
    if setup["NetworkExpansion"] == 1
61
        # Read between zone network reinforcement costs per peak MW of capacity added
×
62
        inputs_nw["pC_Line_Reinforcement"] = to_floats(:Line_Reinforcement_Cost_per_MWyr) /
63
                                             scale_factor # convert to million $/GW/yr with objective function in millions
64
        # Maximum reinforcement allowed in MW
×
65
        #NOTE: values <0 indicate no expansion possible
×
66
        inputs_nw["pMax_Line_Reinforcement"] = map(x -> max(0, x),
67
            to_floats(:Line_Max_Reinforcement_MW)) / scale_factor # convert to GW
68
        inputs_nw["pTrans_Max_Possible"] += inputs_nw["pMax_Line_Reinforcement"]
69
    end
×
70

71
    # Multi-Stage
×
72
    if setup["MultiStage"] == 1
×
73
        # Weighted Average Cost of Capital for Transmission Expansion
×
74
        if setup["NetworkExpansion"] >= 1
75
            inputs_nw["transmission_WACC"] = to_floats(:WACC)
76
            inputs_nw["Capital_Recovery_Period_Trans"] = to_floats(:Capital_Recovery_Period)
77
        end
×
78

79
        # Max Flow Possible on Each Line
80
        inputs_nw["pLine_Max_Flow_Possible_MW"] = to_floats(:Line_Max_Flow_Possible_MW) /
81
                                                  scale_factor # Convert to GW
×
82
    end
×
83

×
84
    # Transmission line (between zone) loss coefficient (resistance/voltage^2)
×
85
    inputs_nw["pTrans_Loss_Coef"] = zeros(Float64, L)
86
    if setup["Trans_Loss_Segments"] == 1
×
87
        inputs_nw["pTrans_Loss_Coef"] = inputs_nw["pPercent_Loss"]
88
    elseif setup["Trans_Loss_Segments"] >= 2
89
        # If zones are connected, loss coefficient is R/V^2 where R is resistance in Ohms and V is voltage in Volts
90
        inputs_nw["pTrans_Loss_Coef"] = (inputs_nw["Ohms"] / 10^6) ./
×
91
                                        (inputs_nw["kV"] / 10^3)^2 * scale_factor # 1/GW ***
×
92
    end
93

×
94
    ## Sets and indices for transmission losses and expansion
95
    inputs_nw["TRANS_LOSS_SEGS"] = setup["Trans_Loss_Segments"] # Number of segments used in piecewise linear approximations quadratic loss functions
×
96
    inputs_nw["LOSS_LINES"] = findall(inputs_nw["pTrans_Loss_Coef"] .!= 0) # Lines for which loss coefficients apply (are non-zero);
×
97

98
    if setup["NetworkExpansion"] == 1
99
        # Network lines and zones that are expandable have non-negative maximum reinforcement inputs
×
100
        inputs_nw["EXPANSION_LINES"] = findall(inputs_nw["pMax_Line_Reinforcement"] .>= 0)
101
        inputs_nw["NO_EXPANSION_LINES"] = findall(inputs_nw["pMax_Line_Reinforcement"] .< 0)
×
102
    end
103

104
    println(filename * " Successfully Read!")
105

106
    return network_var
107
end
108

109
@doc raw"""
110
    load_network_map_from_list(network_var::DataFrame, Z, L, list_columns)
111

112
Loads the network map from a list-style interface
113
```
114
..., Network_Lines, Start_Zone, End_Zone, ...
×
115
                 1,           1,       2,
×
116
                 2,           1,       3,
×
117
```
×
118
"""
×
119
function load_network_map_from_list(network_var::DataFrame, Z, L, list_columns)
×
120
    start_col, end_col = list_columns
×
121
    mat = zeros(L, Z)
×
122
    start_zones = collect(skipmissing(network_var[!, start_col]))
123
    end_zones = collect(skipmissing(network_var[!, end_col]))
×
124
    for l in 1:L
125
        mat[l, start_zones[l]] = 1
126
        mat[l, end_zones[l]] = -1
127
    end
128
    mat
129
end
130

131
@doc raw"""
132
    load_network_map_from_matrix(network_var::DataFrame, Z, L)
133

134
Loads the network map from a matrix-style interface
135
```
136
..., Network_Lines, z1, z2, z3, ...
137
                 1,  1, -1,  0,
138
                 2,  1,  0, -1,
×
139
```
140
This is equivalent to the list-style interface where the zone zN with entry +1 is the
×
141
starting zone of the line and the zone with entry -1 is the ending zone of the line.
×
142
"""
143
function load_network_map_from_matrix(network_var::DataFrame, Z, L)
144
    # Topology of the network source-sink matrix
×
145
    network_map_matrix_format_deprecation_warning()
×
146
    col = findall(s -> s == "z1", names(network_var))[1]
147
    mat = Matrix{Float64}(network_var[1:L, col:(col + Z - 1)])
×
148
end
×
149

150
function load_network_map(network_var::DataFrame, Z, L)
×
151
    columns = names(network_var)
×
152

153
    list_columns = ["Start_Zone", "End_Zone"]
×
154
    has_network_list = all([c in columns for c in list_columns])
155

156
    zones_as_strings = ["z" * string(i) for i in 1:Z]
157
    has_network_matrix = all([c in columns for c in zones_as_strings])
×
158

×
159
    instructions = """The transmission network should be specified in the form of a matrix
×
160
           (with columns z1, z2, ... zN) or in the form of lists (with Start_Zone, End_Zone),
×
161
           but not both. See the documentation for examples."""
×
162

×
163
    if has_network_list && has_network_matrix
×
164
        error("two types of transmission network map were provided.\n" * instructions)
×
165
    elseif !(has_network_list || has_network_matrix)
166
        error("no transmission network map was detected.\n" * instructions)
167
    elseif has_network_list
168
        load_network_map_from_list(network_var, Z, L, list_columns)
169
    elseif has_network_matrix
170
        load_network_map_from_matrix(network_var, Z, L)
171
    end
172
end
173

174
function network_map_matrix_format_deprecation_warning()
175
    @warn """Specifying the network map as a matrix is deprecated as of v0.4
176
  and will be removed in v0.5. Instead, use the more compact list-style format.
177

178
  ..., Network_Lines, Start_Zone, End_Zone, ...
179
                   1,          1,        2,
180
                   2,          1,        3,
181
                   3,          2,        3,
182
  """ maxlog=1
183
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc