Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate h2 truck from code flow by setting 'ModelH2Trucks' #7

Merged
merged 4 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PrintModel: 0 # Write the model formulation as an output; 0 = active; 1 = not ac
SystemCO2Constraint: 2 # CO2 emissions constraint representation; 1 = Separate emissions constraint for HSC and Power; 2 = Combined emissions constraint for HSC and Power sectors (i.e. allow trading, with constraint form adopted from genx_settings)
Solver: Gurobi # Available solvers: Gurobi, CPLEX, CLP, Cbc
WriteShadowPrices: 1 # Write shadow prices of LP or relaxed MILP; 0 = not active; 1 = active
OperationWrapping: 1 # Sets temporal resolution of the model; 0 = single period to represent the full year, with first-last time step linked; 1 = multiple representative periods
OperationWrapping: 0 # Sets temporal resolution of the model; 0 = single period to represent the full year, with first-last time step linked; 1 = multiple representative periods
TimeDomainReductionFolder: "TDR_Results" # Directory name where results from time domain reduction will be saved. If results already exist here, these will be used without running time domain reduction script again.
TimeDomainReduction: 0 # Time domain reduce (i.e. cluster) inputs based on Load_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 0 = active (cluster input data, or use data that has already been clustered)
TimeDomainReduction: 1 # Time domain reduce (i.e. cluster) inputs based on Load_data.csv, Generators_variability.csv, and Fuels_data.csv; 0 = not active (use input data as provided); 1 = active (cluster input data, or use data that has already been clustered)

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ModelH2: 1 #Flag to turn or off Hydrogen Supply Chain modelling capabilities - 0 - no HSC, 1- HSC modeled
H2PipeInteger: 0 # Whether to model pipeline capacity as discrete or integer - 0 - continuous capacity, 1- discrete capacity
ModelH2Pipelines: 0
H2GenCommit: 0 # Continuous or discrete capacity representaiton of H2 production technologies with unit commitment; 0 = modeled as continuous variables; 1 = modeled as integer variables;
H2NetworkExpansion: 0 # Transmission network expansionl; 0 = not active; 1 = active systemwide
ModelH2Pipelines: 0 # Whether to model pipeline in hydrogen supply chain - 0 - not included, 1 - included
ModelH2Trucks: 0 # Whether to model truck in hydrogen supply chain - 0 - not included, 1 - included
H2GenCommit: 0 # Continuous or discrete capacity representation of H2 production technologies with unit commitment; 0 = modeled as continuous variables; 1 = modeled as integer variables;
H2NetworkExpansion: 0 # Transmission network expansional; 0 = not active; 1 = active systemwide
H2CO2Cap: 1 # CO2 emissions cap for HSC only; 0 = not active (no CO2 emission limit); 1 = mass-based emission limit constraint; 2 = load + rate-based emission limit constraint; 3 = generation + rate-based emission limit constraint; 4 = emissions penalized via a carbon price
13 changes: 6 additions & 7 deletions src/HSC/load_inputs/load_H2_inputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@ function load_h2_inputs(inputs::Dict,setup::Dict,path::AbstractString)
inputs["H2_P"] = 0
end

# Read input data about hydrogen trasport truck types
if isfile(string(path,sep,"HSC_truck.csv"))
# Create flag for other parts of the code
setup["ModelH2Trucks"] = 1
inputs = load_h2_truck(path, sep, inputs)
else
setup["ModelH2Trucks"] = 0
# Read input data about hydrogen transport truck types
if setup["ModelH2Trucks"] == 1
if isfile(string(path,sep,"HSC_truck.csv"))
# Create flag for other parts of the code
inputs = load_h2_truck(path, sep, inputs)
end
end

# If emissions flag is on, read in emissions related inputs
Expand Down
2 changes: 1 addition & 1 deletion src/HSC/load_inputs/load_h2_truck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function load_h2_truck(path::AbstractString, sep::AbstractString, inputs_truck::
# Set of H2 truck types eligible for new energy capacity
inputs_truck["NEW_CAP_H2_TRUCK_ENERGY"] = h2_truck_in[h2_truck_in.New_Build .== 1, :T_TYPE]
# Set of H2 truck types eligible for energy capacity retirement
inputs_truck["RET_CAP_H2_TRUCK_ENERGY"] = intersect(h2_truck_in[h2_truck_in.New_Build .!= -1, :T_TYPE], h2_truck_in[h2_truck_in.Existing_Number .>=0, :T_TYPE])
inputs_truck["RET_CAP_H2_TRUCK_ENERGY"] = intersect(h2_truck_in[h2_truck_in.New_Build .!= -1, :T_TYPE], h2_truck_in[h2_truck_in.Existing_Number .> 0, :T_TYPE])

# Store DataFrame of truck input data for use in model
inputs_truck["dfH2Truck"] = h2_truck_in
Expand Down
2 changes: 1 addition & 1 deletion src/HSC/model/truck/h2_truck_investment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function h2_truck_investment(EP::Model, inputs::Dict, setup::Dict)
# New installed energy capacity of truck type "j" on zone "z"
@variable(EP, vH2CAPTRUCKENERGY[z = 1:Z, j in NEW_CAP_H2_TRUCK_ENERGY] >= 0)

# Retired energy capacity of truck type "s" on zone "z" from existing capacity
# Retired energy capacity of truck type "j" on zone "z" from existing capacity
@variable(EP, vH2RETCAPTRUCKENERGY[z = 1:Z, j in RET_CAP_H2_TRUCK_ENERGY] >= 0)

# Total available charging capacity in tonnes/hour
Expand Down
9 changes: 5 additions & 4 deletions src/HSC/write_outputs/write_HSC_outputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ function write_HSC_outputs(EP::Model, path::AbstractString, setup::Dict, inputs:
write_h2_capacity(path, sep, inputs, setup, EP)
write_h2_gen(path, sep, inputs, setup, EP)
write_h2_nse(path, sep, inputs, setup, EP)
write_h2_costs(path, sep, inputs, setup, EP)
# write_h2_costs(path, sep, inputs, setup, EP)
write_h2_balance(path,sep,inputs, setup, EP)
write_h2_pipeline_flow(path, sep, inputs, setup, EP)
write_h2_pipeline_expansion(path, sep, inputs, setup, EP)
# write_h2_pipeline_flow(path, sep, inputs, setup, EP)
# write_h2_pipeline_expansion(path, sep, inputs, setup, EP)
write_h2_emissions(path, sep, inputs, setup, EP)
write_h2_charge(path, sep, inputs, setup, EP)
write_h2_storage(path, sep, inputs, setup, EP)
if setup["ModelH2Trucks"] == 1
write_h2_truck_capacity(path, sep, inputs, setup, EP)
write_h2_truck_flow(path, sep, inputs, setup, EP)

end
## Print confirmation
println("Wrote outputs HSC outputs to $path$sep")

Expand Down
13 changes: 11 additions & 2 deletions src/HSC/write_outputs/write_h2_truck_capacity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ function write_h2_truck_capacity(path::AbstractString, sep::AbstractString, inpu
H2_TRUCK_TYPES = inputs["H2_TRUCK_TYPES"]
NEW_CAP_H2_TRUCK_CHARGE = inputs["NEW_CAP_H2_TRUCK_CHARGE"]
RET_CAP_H2_TRUCK_CHARGE = inputs["RET_CAP_H2_TRUCK_CHARGE"]
NEW_CAP_H2_TRUCK_ENERGY = inputs["NEW_CAP_H2_TRUCK_ENERGY"]
RET_CAP_H2_TRUCK_ENERGY = inputs["RET_CAP_H2_TRUCK_ENERGY"]

dfH2Truck = inputs["dfH2Truck"]
Z = inputs["Z"]

Expand Down Expand Up @@ -31,15 +34,21 @@ function write_h2_truck_capacity(path::AbstractString, sep::AbstractString, inpu
dfH2TruckCap[!, Symbol("StartTruckEnergyZone$z")] = dfH2Truck[!, Symbol("Existing_Energy_Cap_tonne_z$z")]
tempEnergy = zeros(size(H2_TRUCK_TYPES))
for j in H2_TRUCK_TYPES
tempEnergy[j] = value(EP[:vH2CAPTRUCKENERGY][z,j])
if j in NEW_CAP_H2_TRUCK_ENERGY
tempEnergy[j] = value(EP[:vH2CAPTRUCKENERGY][z,j])
end
end
dfH2TruckCap[!,Symbol("NewTruckEnergyZone$z")] = tempEnergy

tempEnergy = zeros(size(H2_TRUCK_TYPES))
for j in H2_TRUCK_TYPES
tempEnergy[j] = value(EP[:vH2RETCAPTRUCKENERGY][z,j])
if j in RET_CAP_H2_TRUCK_ENERGY
tempEnergy[j] = value(EP[:vH2RETCAPTRUCKENERGY][z,j])
end
end
dfH2TruckCap[!,Symbol("RetTruckEnergyZone$z")] = tempEnergy

tempEnergy = zeros(size(H2_TRUCK_TYPES))
for j in H2_TRUCK_TYPES
tempEnergy[j] = value(EP[:eTotalH2CapTruckEnergy][z,j])
end
Expand Down
25 changes: 13 additions & 12 deletions src/HSC/write_outputs/write_h2_truck_flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,29 @@ function write_h2_truck_flow(path::AbstractString, sep::AbstractString, inputs::
if (isdir(truck_state_path) == false)
mkdir(truck_state_path)
end
dfH2TruckAvailFull = DataFrame(Time = 1:T)
dfH2TruckAvailEmpty = DataFrame(Time = 1:T)
dfH2TruckCharged = DataFrame(Time = 1:T)
dfH2TruckDischarged = DataFrame(Time = 1:T)
for j in H2_TRUCK_TYPES
dfH2TruckAvailFull = DataFrame(Time = 1:T)
dfH2TruckAvailEmpty = DataFrame(Time = 1:T)
dfH2TruckCharged = DataFrame(Time = 1:T)
dfH2TruckDischarged = DataFrame(Time = 1:T)
for z in 1:Z
dfH2TruckAvailFull[!,Symbol(H2_TRUCK_TYPE_NAMES[j])] = value.(EP[:vH2Navail_full])[z,j,:]
dfH2TruckAvailEmpty[!,Symbol(H2_TRUCK_TYPE_NAMES[j])] = value.(EP[:vH2Navail_empty])[z,j,:]
dfH2TruckCharged[!,Symbol(H2_TRUCK_TYPE_NAMES[j])] = value.(EP[:vH2Ncharged])[z,j,:]
dfH2TruckDischarged[!,Symbol(H2_TRUCK_TYPE_NAMES[j])] = value.(EP[:vH2Ndischarged])[z,j,:]
dfH2TruckAvailFull[!,Symbol(string("Zone$z-",H2_TRUCK_TYPE_NAMES[j]))] = value.(EP[:vH2Navail_full])[z,j,:]
dfH2TruckAvailEmpty[!,Symbol(string("Zone$z-",H2_TRUCK_TYPE_NAMES[j]))] = value.(EP[:vH2Navail_empty])[z,j,:]
dfH2TruckCharged[!,Symbol(string("Zone$z-",H2_TRUCK_TYPE_NAMES[j]))] = value.(EP[:vH2Ncharged])[z,j,:]
dfH2TruckDischarged[!,Symbol(string("Zone$z-",H2_TRUCK_TYPE_NAMES[j]))] = value.(EP[:vH2Ndischarged])[z,j,:]
end
CSV.write(string(truck_state_path, sep, string("H2TruckAvailFull_",H2_TRUCK_TYPE_NAMES[j],".csv")), dfH2TruckAvailFull)
CSV.write(string(truck_state_path, sep, string("H2TruckAvailEmpty_",H2_TRUCK_TYPE_NAMES[j],".csv")), dfH2TruckAvailEmpty)
CSV.write(string(truck_state_path, sep, string("H2TruckCharged_",H2_TRUCK_TYPE_NAMES[j],".csv")), dfH2TruckCharged)
CSV.write(string(truck_state_path, sep, string("H2TruckDischarged_",H2_TRUCK_TYPE_NAMES[j],".csv")), dfH2TruckDischarged)
end
CSV.write(string(truck_state_path, sep, string("H2TruckAvailFull.csv")), dfH2TruckAvailFull)
CSV.write(string(truck_state_path, sep, string("H2TruckAvailEmpty.csv")), dfH2TruckAvailEmpty)
CSV.write(string(truck_state_path, sep, string("H2TruckCharged.csv")), dfH2TruckCharged)
CSV.write(string(truck_state_path, sep, string("H2TruckDischarged.csv")), dfH2TruckDischarged)

# H2 truck transit
truck_transit_path = string(path, sep, "H2Transit")
if (isdir(truck_transit_path) == false)
mkdir(truck_transit_path)
end

dfH2TruckTravelFull = DataFrame(Time = 1:T)
dfH2TruckArriveFull = DataFrame(Time = 1:T)
dfH2TruckDepartFull = DataFrame(Time = 1:T)
Expand Down