Skip to content

Commit

Permalink
fix bugs after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
qluo0320github committed Sep 25, 2023
1 parent f998ec4 commit b0d2ec2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/model/core/co2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ function co2!(EP::Model, inputs::Dict)
(1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction]) * EP[:vFuel][y, t] * fuel_CO2[dfGen[y,:Fuel]]+
(1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction_Startup]) * EP[:vStartFuel][y, t] * fuel_CO2[dfGen[y,:Fuel]]
else
sum((1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction]) * EP[:vMulFuel][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])+
sum((1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction_Startup]) * EP[:vMulStartFuel][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])
sum((1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction]) * EP[:vMulFuels][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])+
sum((1-dfGen[y, :Biomass] - dfGen[y, :CO2_Capture_Fraction_Startup]) * EP[:vMulStartFuels][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])
end)

# CO2 captured from power plants in "Generators_data.csv"
Expand All @@ -94,8 +94,8 @@ function co2!(EP::Model, inputs::Dict)
dfGen[y, :CO2_Capture_Fraction] * EP[:vFuel][y, t] * fuel_CO2[dfGen[y,:Fuel]]+
dfGen[y, :CO2_Capture_Fraction_Startup] * EP[:eStartFuel][y, t] * fuel_CO2[dfGen[y,:Fuel]]
else
sum(dfGen[y, :CO2_Capture_Fraction] * EP[:vMulFuel][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])+
sum(dfGen[y, :CO2_Capture_Fraction_Startup] * EP[:vMulStartFuel][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])
sum(dfGen[y, :CO2_Capture_Fraction] * EP[:vMulFuels][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])+
sum(dfGen[y, :CO2_Capture_Fraction_Startup] * EP[:vMulStartFuels][y, i, t] * fuel_CO2[dfGen[y, inputs["FUEL_COLS"][i]]] for i = 1:inputs["MAX_NUM_FUELS"])
end)

@expression(EP, eEmissionsCaptureByPlantYear[y=1:G],
Expand Down
11 changes: 6 additions & 5 deletions src/model/core/fuel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ function fuel!(EP::Model, inputs::Dict, setup::Dict)
if y in SINGLE_FUEL
(inputs["fuel_costs"][dfGen[y,:Fuel]][t] * EP[:vStartFuel][y, t])
else
sum(eCFuelOut_multi_start for i in 1:inputs["MAX_NUM_FUELS"])
sum(EP[:eCFuelOut_multi_start][y, i, t] for i in 1:inputs["MAX_NUM_FUELS"])
end)

# plant level start-up fuel cost for output
@expression(EP, ePlantCFuelStart[y = 1:G],
sum(inputs["omega"][t] * EP[:eCFuelStart][y, t] for t in 1:T))
Expand All @@ -184,7 +185,7 @@ function fuel!(EP::Model, inputs::Dict, setup::Dict)
end

@expression(EP, eCFuelOut[y = 1:G, t = 1:T],
if y in SINGLE
if y in SINGLE_FUEL
(inputs["fuel_costs"][dfGen[y,:Fuel]][t] * EP[:vFuel][y, t])
else
sum(EP[:eCFuelOut_multi][y, i, t] for i in 1:inputs["MAX_NUM_FUELS"])
Expand Down Expand Up @@ -216,7 +217,7 @@ function fuel!(EP::Model, inputs::Dict, setup::Dict)

@expression(EP, eFuelConsumption_single[f in 1:NUM_FUEL, t in 1:T],
sum(EP[:vFuel][y, t] + EP[:eStartFuel][y,t]
for y in intersect(resources_with_fuel(dfGen, fuels[f]))), SINGLE_FUEL)
for y in intersect(resources_with_fuel(dfGen, fuels[f]), SINGLE_FUEL)))

@expression(EP, eFuelConsumption[f in 1:NUM_FUEL, t in 1:T],
if !isempty(MULTI_FUELS)
Expand All @@ -232,11 +233,11 @@ function fuel!(EP::Model, inputs::Dict, setup::Dict)
### Constraint ###
### only apply constraint to generators with fuel type other than None

@constraint(EP, cFuelCalculation_single[y in intersect(SINGLE_FUEL,setdiff(HAS_FUEL, THERM_COMMIT)), t = 1:T],
@constraint(EP, cFuelCalculation_single[y in intersect(SINGLE_FUEL, setdiff(HAS_FUEL, THERM_COMMIT)), t = 1:T],
EP[:vFuel][y, t] - EP[:vP][y, t] * dfGen[y, :Heat_Rate_MMBTU_per_MWh] == 0)

if !isempty(MULTI_FUELS)
@constraint(EP, cFuelCalculation_multi[y in intersect(MULTI_FUELS,setdiff(HAS_FUEL, THERM_COMMIT)), t = 1:T],
@constraint(EP, cFuelCalculation_multi[y in intersect(MULTI_FUELS, setdiff(HAS_FUEL, THERM_COMMIT)), t = 1:T],
sum(EP[:vMulFuels][y, i, t]/inputs["HEAT_RATES"][i][y] for i in 1:inputs["MAX_NUM_FUELS"]) - EP[:vP][y, t] == 0
)
end
Expand Down
12 changes: 2 additions & 10 deletions src/write_outputs/write_costs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
Z = inputs["Z"] # Number of zones
T = inputs["T"] # Number of time steps (hours)
VRE_STOR = inputs["VRE_STOR"]

ELECTROLYZER = inputs["ELECTROLYZER"]

cost_list = ["cTotal", "cFix", "cVar", "cFuel" ,"cNSE", "cStart", "cUnmetRsv", "cNetworkExp", "cUnmetPolicyPenalty", "cCO2"]
Expand All @@ -21,8 +22,7 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
end
dfCost = DataFrame(Costs = cost_list)

cVar = value(EP[:eTotalCVarOut]) + (!isempty(inputs["STOR_ALL"]) ? value(EP[:eTotalCVarIn]) : 0.0) + (!isempty(inputs["FLEX"]) ? value(EP[:eTotalCVarFlexIn]) : 0.0)
cFuel = value.(EP[:eTotalCFuelOut])
cVar = value(EP[:eTotalCVarOut]) + (!isempty(inputs["STOR_ALL"]) ? value(EP[:eTotalCVarIn]) : 0.0) + (!isempty(inputs["FLEX"]) ? value(EP[:eTotalCVarFlexIn]) : 0.0)
cFix = value(EP[:eTotalCFix]) + (!isempty(inputs["STOR_ALL"]) ? value(EP[:eTotalCFixEnergy]) : 0.0) + (!isempty(inputs["STOR_ASYMMETRIC"]) ? value(EP[:eTotalCFixCharge]) : 0.0)

cFuel = value.(EP[:eTotalCFuelOut])
Expand Down Expand Up @@ -77,10 +77,6 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
dfCost[9,2] += value(EP[:eTotalCMinCapSlack])
end

if any(x -> x != 0, dfGen.CO2_Capture_Rate)
dfCost[10,2] += value(EP[:eTotaleCCO2Sequestration])
end

if !isempty(VRE_STOR)
dfCost[!,2][11] = value(EP[:eTotalCGrid]) * (setup["ParameterScale"] == 1 ? ModelScalingFactor^2 : 1)
end
Expand All @@ -104,7 +100,6 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
tempCFuel = 0.0
tempCStart = 0.0
tempCNSE = 0.0
tempCCO2 = 0.0
tempHydrogenValue = 0.0
tempCCO2 = 0.0

Expand All @@ -125,9 +120,6 @@ function write_costs(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
tempCFuel = sum(value.(EP[:ePlantCFuelOut][Y_ZONE,:]))
tempCTotal += tempCFuel

tempCFuel = sum(value.(EP[:ePlantCFuelOut][Y_ZONE,:]))
tempCTotal += tempCFuel

if !isempty(STOR_ALL_ZONE)
eCVar_in = sum(value.(EP[:eCVar_in][STOR_ALL_ZONE,:]))
tempCVar += eCVar_in
Expand Down
15 changes: 9 additions & 6 deletions src/write_outputs/write_fuel_consumption.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function write_fuel_consumption_plant(path::AbstractString,inputs::Dict, setup::
dfGen = inputs["dfGen"]
G = inputs["G"]
HAS_FUEL = inputs["HAS_FUEL"]
MULTI_FUELS = inputs["MULTI_FUELS"]
# Fuel consumption cost by each resource, including start up fuel
dfPlantFuel = DataFrame(Resource = inputs["RESOURCES"][HAS_FUEL],
Fuel = dfGen[HAS_FUEL, :Fuel],
Expand All @@ -29,10 +30,10 @@ function write_fuel_consumption_plant(path::AbstractString,inputs::Dict, setup::
tempannualsum_fuel_heat_multi_total = zeros(length(HAS_FUEL))
tempannualsum_fuel_cost_multi = zeros(length(HAS_FUEL))
for g in MULTI_FUELS
tempannualsum_fuel_heat_multi_generation[g] = value.(EP[:ePlantFuelConsumptionYear_multi_generation][g,i])
tempannualsum_fuel_heat_multi_start[g] = value.(EP[:ePlantFuelConsumptionYear_multi_start][g,i])
tempannualsum_fuel_heat_multi_total[g] = value.(EP[:ePlantFuelConsumptionYear_multi][g,i])
tempannualsum_fuel_cost_multi[g] = value.(EP[:ePlantCFuelOut_multi][g,i]) + value.(EP[:ePlantCFuelOut_multi_start][g,i])
tempannualsum_fuel_heat_multi_generation[findfirst(x->x==g, HAS_FUEL)] = value.(EP[:ePlantFuelConsumptionYear_multi_generation][g,i])
tempannualsum_fuel_heat_multi_start[findfirst(x->x==g, HAS_FUEL)] = value.(EP[:ePlantFuelConsumptionYear_multi_start][g,i])
tempannualsum_fuel_heat_multi_total[findfirst(x->x==g, HAS_FUEL)] = value.(EP[:ePlantFuelConsumptionYear_multi][g,i])
tempannualsum_fuel_cost_multi[findfirst(x->x==g, HAS_FUEL)] = value.(EP[:ePlantCFuelOut_multi][g,i]) + value.(EP[:ePlantCFuelOut_multi_start][g,i])
end
if setup["ParameterScale"] == 1
tempannualsum_fuel_heat_multi_generation *= ModelScalingFactor
Expand All @@ -41,7 +42,7 @@ function write_fuel_consumption_plant(path::AbstractString,inputs::Dict, setup::
tempannualsum_fuel_cost_multi *= ModelScalingFactor^2
end

dfPlantFuel[!, inputs["FUEL_COLS"][i]] = dfGen[!, inputs["FUEL_COLS"][i]]
dfPlantFuel[!, inputs["FUEL_COLS"][i]] = dfGen[HAS_FUEL, inputs["FUEL_COLS"][i]]
dfPlantFuel[!, Symbol(string(inputs["FUEL_COLS"][i],"_AnnualSum_Fuel_HeatInput_Generation"))] = tempannualsum_fuel_heat_multi_generation
dfPlantFuel[!, Symbol(string(inputs["FUEL_COLS"][i],"_AnnualSum_Fuel_HeatInput_Start"))] = tempannualsum_fuel_heat_multi_start
dfPlantFuel[!, Symbol(string(inputs["FUEL_COLS"][i],"_AnnualSum_Fuel_HeatInput_Total"))] = tempannualsum_fuel_heat_multi_total
Expand All @@ -60,9 +61,11 @@ end
function write_fuel_consumption_ts(path::AbstractString, inputs::Dict, setup::Dict, EP::Model)
T = inputs["T"] # Number of time steps (hours)
HAS_FUEL = inputs["HAS_FUEL"]
MULTI_FUELS = inputs["MULTI_FUELS"]

# Fuel consumption by each resource per time step, unit is MMBTU
dfPlantFuel_TS = DataFrame(Resource = inputs["RESOURCES"][HAS_FUEL])
tempts = value.(EP[:vFuel] + EP[:eStartFuel])[HAS_FUEL,:]
tempts = value.(EP[:ePlantFuel_generation] + EP[:ePlantFuel_start])[HAS_FUEL,:]
if setup["ParameterScale"] == 1
tempts *= ModelScalingFactor # kMMBTU to MMBTU
end
Expand Down

0 comments on commit b0d2ec2

Please sign in to comment.