-
Notifications
You must be signed in to change notification settings - Fork 16
/
gf.jl
105 lines (86 loc) · 2.8 KB
/
gf.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Definitions for running a feasible gas flow
"entry point into running the gas flow feasability problem"
function run_gf(file, model_type, optimizer; kwargs...)
return run_model(
file,
model_type,
optimizer,
build_gf;
solution_processors = [
sol_psqr_to_p!,
sol_compressor_p_to_r!,
sol_regulator_p_to_r!,
],
kwargs...,
)
end
""
function run_soc_gf(file, optimizer; kwargs...)
return run_gf(file, CRDWPGasModel, optimizer; kwargs...)
end
""
function run_dwp_gf(file, optimizer; kwargs...)
return run_gf(file, DWPGasModel, optimizer; kwargs...)
end
"construct the gas flow feasbility problem"
function build_gf(gm::AbstractGasModel)
bounded_compressors = Dict(
x for x in ref(gm, :compressor) if
_calc_is_compressor_energy_bounded(
get_specific_heat_capacity_ratio(gm.data),
get_gas_specific_gravity(gm.data),
get_temperature(gm.data),
x.second
)
)
variable_pressure(gm)
variable_pressure_sqr(gm)
variable_flow(gm)
variable_on_off_operation(gm)
variable_load_mass_flow(gm)
variable_production_mass_flow(gm)
variable_transfer_mass_flow(gm)
variable_compressor_ratio_sqr(gm; compressors = bounded_compressors)
variable_storage(gm)
variable_form_specific(gm)
for (i, junction) in ref(gm, :junction)
constraint_mass_flow_balance(gm, i)
if (junction["junction_type"] == 1)
constraint_pressure(gm, i)
end
end
for i in ids(gm, :pipe)
constraint_pipe_pressure(gm, i)
constraint_pipe_mass_flow(gm, i)
constraint_pipe_weymouth(gm, i)
end
for i in ids(gm, :resistor)
constraint_resistor_pressure(gm, i)
constraint_resistor_mass_flow(gm,i)
constraint_resistor_darcy_weisbach(gm,i)
end
for i in ids(gm, :loss_resistor)
constraint_loss_resistor_pressure(gm, i)
constraint_loss_resistor_mass_flow(gm, i)
end
for i in ids(gm, :short_pipe)
constraint_short_pipe_pressure(gm, i)
constraint_short_pipe_mass_flow(gm, i)
end
for i in ids(gm, :compressor)
constraint_compressor_ratios(gm, i)
constraint_compressor_mass_flow(gm, i)
end
for i in keys(bounded_compressors)
constraint_compressor_ratio_value(gm, i)
constraint_compressor_energy(gm, i)
end
for i in ids(gm, :valve)
constraint_on_off_valve_mass_flow(gm, i)
constraint_on_off_valve_pressure(gm, i)
end
for i in ids(gm, :regulator)
constraint_on_off_regulator_mass_flow(gm, i)
constraint_on_off_regulator_pressure(gm, i)
end
end