The UFZ services GitLab and Mattermost will be unavailable on Monday, December 06 from 06:00 AM to 08:00 AM due to maintenance work.

Commit 52d64d26 authored by Markus Millinger's avatar Markus Millinger
Browse files

Updated/generalized gamsVarCreate2 to work with all dimensions

parent 8aeaf11e
This diff is collapsed.
No preview for this file type
......@@ -179,90 +179,28 @@ ghgRef = q.referenceGHGemission.*[ones(s.runTime,1)';
zeros(s.runTime,1)';
zeros(s.runTime,1)']';
gamsTemp.costMarg = gamsVarCreate2('costMarg',q.fuelMargCost,s.year,s.techNames,'parameter'); %M/PJ
gamsTemp.costInv = gamsVarCreate2('costInv',q.plantInvCost,s.year,s.techNames,'parameter'); %M/GW
gamsTemp.costInvLevel = gamsVarCreate2('costInvLevel',q.plantInvCostLevel,s.year,s.techNames,'parameter'); %M/GW
gamsTemp.ghgEmisFeed = gamsVarCreate2('ghgEmisFeed',r.ghgCultivationTotGJfeed,s.year,f.feedNames,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
gamsTemp.ghgEmisGateWheel = gamsVarCreate2('ghgEmisGateWheel',q.fuelGHGemission,s.year,s.techNames,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
gamsTemp.ghgRef = gamsVarCreate2('ghgRef',ghgRef,s.year,s.sectorNames,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
% gamsTemp.powerMixEmis = gamsVarCreate2('powerMixEmis',q.ghgEFPower./(3.6/1000),s.year,0,'parameter'); %kgCO2eq/kWh * [kWh/GJ]^-1 => kgCO2eq/GJ = ktCO2eq/PJ
% gamsTemp.ghgEmisT1 = gamsVarCreate2('ghgEmisT1',r.ghgTransport1GJfeed(:,1),s.year,0,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ %Not yet feedstock specific
gamsTemp.residualLoad.uels = {strsplit(num2str(g.timeStepsIntraYear)),strsplit(num2str(s.year))};
gamsTemp.residualLoad.name = 'residualLoad';
gamsTemp.residualLoad.type = 'parameter';
gamsTemp.residualLoad.form = 'full';
gamsTemp.residualLoad.val = q.surplusPowerVar.*3.6;%g.residualLoad3.*3.6; %PJ/timestep
% Positive residual load = demand for dispatchable power
gamsTemp.posResLoad.uels = {strsplit(num2str(g.timeStepsIntraYear)),strsplit(num2str(s.year))};
gamsTemp.posResLoad.name = 'posResLoad';
gamsTemp.posResLoad.type = 'parameter';
gamsTemp.posResLoad.form = 'full';
gamsTemp.posResLoad.val = q.posResLoad.*3.6;%g.residualLoad3.*3.6; %PJ/timestep
% Conversion efficiency
gamsTemp.convEta.uels = {strsplit(num2str(s.year)), s.techNames};
gamsTemp.convEta.name = 'convEta';
gamsTemp.convEta.type = 'parameter';
gamsTemp.convEta.form = 'full';
gamsTemp.convEta.val = q.plantConvEta; %PJ_energy per PJ_crop
%GHG emissions transport to gate
gamsTemp.ghgEmisT1.uels = {strsplit(num2str(s.year))}; %ADD! , f.feedNames
gamsTemp.ghgEmisT1.name = 'ghgEmisT1';
gamsTemp.ghgEmisT1.type = 'parameter';
gamsTemp.ghgEmisT1.form = 'full';
gamsTemp.ghgEmisT1.val = r.ghgTransport1GJfeed(:,1); %kgCo2eq/GJ = ktCo2eq/PJ
% Conversion efficiency biomass specific
gamsTemp.convEtaBiomSpec.uels = {strsplit(num2str(s.year)), f.feedNames, s.techNames};
gamsTemp.convEtaBiomSpec.name = 'convEtaBiomSpec';
gamsTemp.convEtaBiomSpec.type = 'parameter';
gamsTemp.convEtaBiomSpec.form = 'full';
gamsTemp.convEtaBiomSpec.val = q.convEtaBiomSpec; %PJ_energy per PJ_crop
% Capacity factor
gamsTemp.capF.uels = {strsplit(num2str(s.year)), s.techNames};
gamsTemp.capF.name = 'capF';
gamsTemp.capF.type = 'parameter';
gamsTemp.capF.form = 'full';
gamsTemp.capF.val = q.plantCapacityFactor; % dimensionless - full load hours per year divided by hours/year
% Capacity of initial stock for first years of lifetime
gamsTemp.cap0.uels = {strsplit(num2str(s.year)), s.techNames};
gamsTemp.cap0.name = 'cap0';
gamsTemp.cap0.type = 'parameter';
gamsTemp.cap0.form = 'full';
gamsTemp.cap0.val = q.cap0.*10^-3;%[GW]6./q.plantCapacityFactor; %[PJ]
% Demand
gamsTemp.demand.uels = {strsplit(num2str(s.year)), s.sectorNames};
gamsTemp.demand.name = 'demand';
gamsTemp.demand.type = 'parameter';
gamsTemp.demand.form = 'full';
gamsTemp.demand.val = g.Demand'; %[PJ]
% Passenger road vehicle km minus EVs
gamsTemp.vehicleKMroadTot.uels = {strsplit(num2str(s.year))};
gamsTemp.vehicleKMroadTot.name = 'vehicleKMroadTot';
gamsTemp.vehicleKMroadTot.type = 'parameter';
gamsTemp.vehicleKMroadTot.form = 'full';
gamsTemp.vehicleKMroadTot.val = s.passengerVehicleKMtot.*10^-9; %[Mrd. vehicle-km]
gamsTemp.costMarg = gamsVarCreate2('costMarg',q.fuelMargCost,s.year,s.techNames,0,'parameter'); %M/PJ
gamsTemp.costInv = gamsVarCreate2('costInv',q.plantInvCost,s.year,s.techNames,0,'parameter'); %M/GW
gamsTemp.costInvLevel = gamsVarCreate2('costInvLevel',q.plantInvCostLevel,s.year,s.techNames,0,'parameter'); %M/GW
gamsTemp.ghgEmisFeed = gamsVarCreate2('ghgEmisFeed',r.ghgCultivationTotGJfeed,s.year,f.feedNames,0,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
gamsTemp.ghgEmisGateWheel = gamsVarCreate2('ghgEmisGateWheel',q.fuelGHGemission,s.year,s.techNames,0,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
gamsTemp.ghgRef = gamsVarCreate2('ghgRef',ghgRef,s.year,s.sectorNames,0,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ
gamsTemp.powerMixEmis = gamsVarCreate2('powerMixEmis',q.ghgEFPower./(3.6/1000),s.year,0,0,'parameter'); %kgCO2eq/kWh * [kWh/GJ]^-1 => kgCO2eq/GJ = ktCO2eq/PJ
gamsTemp.ghgEmisT1 = gamsVarCreate2('ghgEmisT1',r.ghgTransport1GJfeed(:,1),s.year,0,0,'parameter'); %kgCo2eq/GJ = ktCo2eq/PJ %Not yet feedstock specific
gamsTemp.residualLoad = gamsVarCreate2('residualLoad',q.surplusPowerVar.*3.6,g.timeStepsIntraYear,s.year,0,'parameter'); %PJ/timestep
gamsTemp.posResLoad = gamsVarCreate2('posResLoad',q.posResLoad.*3.6,g.timeStepsIntraYear,s.year,0,'parameter'); %PJ/timestep
gamsTemp.convEta = gamsVarCreate2('convEta',q.plantConvEta,s.year,s.techNames,0,'parameter'); %PJ_energy per PJ_feed
gamsTemp.convEtaBiomSpec = gamsVarCreate2('convEtaBiomSpec',q.convEtaBiomSpec,s.year,f.feedNames,s.techNames,'parameter'); %PJ_energy per PJ_feed
gamsTemp.capF = gamsVarCreate2('capF',q.plantCapacityFactor,s.year,s.techNames,0,'parameter'); % dimensionless - full load hours per year divided by hours/year
gamsTemp.cap0 = gamsVarCreate2('cap0',q.cap0.*10^-3,s.year,s.techNames,0,'parameter'); %[GW]
gamsTemp.demand = gamsVarCreate2('demand',g.Demand',s.year,s.sectorNames,0,'parameter'); %[PJ]
gamsTemp.vehicleKMroadTot = gamsVarCreate2('vehicleKMroadTot',s.passengerVehicleKMtot.*10^-9,s.year,0,0,'parameter'); %[Mrd. vehicle-km]
% Passenger road fuel economy baseline
gamsTemp.MJperKMavgICEV.uels = {strsplit(num2str(s.year))};
gamsTemp.MJperKMavgICEV.name = 'MJperKMavgICEV';
gamsTemp.MJperKMavgICEV.type = 'parameter';
gamsTemp.MJperKMavgICEV.form = 'full';
gamsTemp.MJperKMavgICEV.val = s.MJperKMavgICEV; %PJ/Mrd. km for average ICEV
% relative fuel economy of fuel types
gamsTemp.relativeFuelEconomy.uels = {s.techNames, s.sectorNames};
gamsTemp.relativeFuelEconomy.name = 'relativeFuelEconomy';
gamsTemp.relativeFuelEconomy.type = 'parameter';
gamsTemp.relativeFuelEconomy.form = 'full';
gamsTemp.relativeFuelEconomy.val = s.relativeFuelEconomy; %[frac compared to reference in each sector -> GJ/vehicle-km or tonne-km]
gamsTemp.MJperKMavgICEV = gamsVarCreate2('MJperKMavgICEV',s.MJperKMavgICEV,s.year,0,0,'parameter'); %PJ/Mrd. km for average ICEV
% relative fuel economy of fuel types %[frac compared to reference in each sector -> GJ/vehicle-km or tonne-km]
gamsTemp.relativeFuelEconomy= gamsVarCreate2('relativeFuelEconomy',s.relativeFuelEconomy,s.techNames,s.sectorNames,0,'parameter'); %[PJ]
% Historic Vehicle Fuel Demand
gamsTemp.historicFuelDemand.uels = {strsplit(num2str(s.year)), s.fuelNames(1:3)};
......@@ -427,13 +365,6 @@ gamsTemp.dMax.type = 'parameter';
gamsTemp.dMax.val = max(g.timeStepsIntraYear);
% Power mix GHG emissions
gamsTemp.powerMixEmis.uels = {strsplit(num2str(s.year))};
gamsTemp.powerMixEmis.name = 'powerMixEmis';
gamsTemp.powerMixEmis.type = 'parameter';
gamsTemp.powerMixEmis.form = 'full';
gamsTemp.powerMixEmis.val = q.ghgEFPower./(3.6/1000); %kgCO2eq/kWh * [kWh/GJ]^-1 => kgCO2eq/GJ = ktCO2eq/PJ
% Goal function
gamsTemp.solveOption.name = 'solveOption';
gamsTemp.solveOption.type = 'parameter';
......
......@@ -21,18 +21,26 @@
% Creation of GAMS variables
%
function gamsVarOut = gamsVarCreate2(name,inputVar,x,y,type)
function gamsVarOut = gamsVarCreate2(name,inputVar,x,y,z,type)
% gamsVarOut = gamsVarIn;
% gamsVarOut(end+1) = setfield(name,name);
if contains(type,'param')
if isnumeric(x)
x = strsplit(num2str(x));
elseif isnumeric(y)
y = num2str(y);
end
gamsVarOut.uels = {x, y};
if isnumeric(y)
y = strsplit(num2str(y));
end
if isnumeric(z)
z = num2str(z);
end
if isequal(size(y),[1 1]) %if y is not a vector, make uels one dimensional
gamsVarOut.uels = {x};
elseif isequal(size(z),[1 1]) %if z is not a vector, make uels two dimensional
gamsVarOut.uels = {x, y};
else
gamsVarOut.uels = {x, y, z};
end
gamsVarOut.name = name;
gamsVarOut.type = 'parameter';
gamsVarOut.form = 'full';
......
......@@ -123,6 +123,7 @@ for scenario=1
print(gcf,'-painters','-depsc','-loose',picName)
saveas(gcf,picName,'tif') % possibly 'pdf' or 'epsc'
end
%% Fuel deployment across sectors and scenarios
figure(123456789)
for scenario=1:noScenarios
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment