Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
lrennels authored Jun 8, 2023
1 parent aa2e4f3 commit 576ad17
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 222 deletions.
2 changes: 1 addition & 1 deletion data/SC validation data/create_scc_validation_file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ specs = Dict([
:last_year => [2200, 2305],
])

results = DataFrame(year = [], eta = [], prtp = [], last_year = [], SC = [])
results = DataFrame(year=[], eta=[], prtp=[], last_year=[], SC=[])

for year in specs[:year]
for eta in specs[:eta]
Expand Down
32 changes: 16 additions & 16 deletions src/MimiDICE2013.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,38 @@ function constructdice(params_dict)
end

# Set shared parameters - name is a Symbol representing the param_name, here
# we will create a shared model parameter with the same name as the component
# parameter and then connect our component parameters to this shared model parameter
# we will create a shared model parameter with the same name as the component
# parameter and then connect our component parameters to this shared model parameter

# * for convenience later, name shared model parameter same as the component
# parameters, but this is not required could give a unique name *
# * for convenience later, name shared model parameter same as the component
# parameters, but this is not required could give a unique name *

add_shared_param!(m, :fco22x, params_dict[:shared][:fco22x])
connect_param!(m, :climatedynamics, :fco22x, :fco22x)
connect_param!(m, :radiativeforcing, :fco22x, :fco22x)
add_shared_param!(m, :fco22x, params_dict[:shared][:fco22x])
connect_param!(m, :climatedynamics, :fco22x, :fco22x)
connect_param!(m, :radiativeforcing, :fco22x, :fco22x)

add_shared_param!(m, :MIU, params_dict[:shared][:MIU], dims = [:time])
connect_param!(m, :neteconomy, :MIU, :MIU)
connect_param!(m, :emissions, :MIU, :MIU)
add_shared_param!(m, :MIU, params_dict[:shared][:MIU], dims=[:time])
connect_param!(m, :neteconomy, :MIU, :MIU)
connect_param!(m, :emissions, :MIU, :MIU)

add_shared_param!(m, :l, params_dict[:shared][:l], dims = [:time])
connect_param!(m, :neteconomy, :l, :l)
connect_param!(m, :grosseconomy, :l, :l)
connect_param!(m, :welfare, :l, :l)
add_shared_param!(m, :l, params_dict[:shared][:l], dims=[:time])
connect_param!(m, :neteconomy, :l, :l)
connect_param!(m, :grosseconomy, :l, :l)
connect_param!(m, :welfare, :l, :l)

return m

end

function getdiceexcel(;datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE_2013_Excel.xlsm"))
function getdiceexcel(; datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE_2013_Excel.xlsm"))
params_dict = getdice2013excelparameters(datafile)

m = constructdice(params_dict)

return m
end

function getdicegams(;datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE2013_IAMF_Parameters.xlsx"))
function getdicegams(; datafile=joinpath(dirname(@__FILE__), "..", "data", "DICE2013_IAMF_Parameters.xlsx"))
params_dict = getdice2013gamsparameters(datafile)

m = constructdice(params_dict)
Expand Down
18 changes: 9 additions & 9 deletions src/components/climatedynamics_component.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@defcomp climatedynamics begin
TATM = Variable(index=[time]) # Increase in temperature of atmosphere (degrees C from 1900)
TOCEAN = Variable(index=[time]) # Increase in temperature of lower oceans (degrees C from 1900)
TATM = Variable(index=[time]) # Increase in temperature of atmosphere (degrees C from 1900)
TOCEAN = Variable(index=[time]) # Increase in temperature of lower oceans (degrees C from 1900)

FORC = Parameter(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
t2xco2 = Parameter() # Equilibrium temp impact (oC per doubling CO2)
tatm0 = Parameter() # Initial atmospheric temp change (C from 1900)
FORC = Parameter(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
t2xco2 = Parameter() # Equilibrium temp impact (oC per doubling CO2)
tatm0 = Parameter() # Initial atmospheric temp change (C from 1900)
tocean0 = Parameter() # Initial lower stratum temp change (C from 1900)

# Transient TSC Correction ("Speed of Adjustment Parameter")
Expand All @@ -18,14 +18,14 @@
if is_first(t)
v.TATM[t] = p.tatm0
else
v.TATM[t] = v.TATM[t - 1] + p.c1 * ((p.FORC[t] - (p.fco22x / p.t2xco2) * v.TATM[t - 1]) - (p.c3 * (v.TATM[t - 1] - v.TOCEAN[t - 1])))
v.TATM[t] = v.TATM[t-1] + p.c1 * ((p.FORC[t] - (p.fco22x / p.t2xco2) * v.TATM[t-1]) - (p.c3 * (v.TATM[t-1] - v.TOCEAN[t-1])))
end

# Define function for TOCEAN
if is_first(t)
v.TOCEAN[t] = p.tocean0
else
v.TOCEAN[t] = v.TOCEAN[t - 1] + p.c4 * (v.TATM[t - 1] - v.TOCEAN[t - 1])
v.TOCEAN[t] = v.TOCEAN[t-1] + p.c4 * (v.TATM[t-1] - v.TOCEAN[t-1])
end
end
end
end
34 changes: 17 additions & 17 deletions src/components/co2cycle_component.jl
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
@defcomp co2cycle begin
MAT = Variable(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
ML = Variable(index=[time]) # Carbon concentration increase in lower oceans (GtC from 1750)
MU = Variable(index=[time]) # Carbon concentration increase in shallow oceans (GtC from 1750)
MAT = Variable(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
ML = Variable(index=[time]) # Carbon concentration increase in lower oceans (GtC from 1750)
MU = Variable(index=[time]) # Carbon concentration increase in shallow oceans (GtC from 1750)

E = Parameter(index=[time]) # Total CO2 emissions (GtCO2 per year)
mat0 = Parameter() # Initial Concentration in atmosphere 2010 (GtC)
ml0 = Parameter() # Initial Concentration in lower strata 2010 (GtC)
mu0 = Parameter() # Initial Concentration in upper strata 2010 (GtC)
E = Parameter(index=[time]) # Total CO2 emissions (GtCO2 per year)
mat0 = Parameter() # Initial Concentration in atmosphere 2010 (GtC)
ml0 = Parameter() # Initial Concentration in lower strata 2010 (GtC)
mu0 = Parameter() # Initial Concentration in upper strata 2010 (GtC)

# Parameters for long-run consistency of carbon cycle
b11 = Parameter() # Carbon cycle transition matrix atmosphere to atmosphere
b12 = Parameter() # Carbon cycle transition matrix atmosphere to shallow ocean
b21 = Parameter() # Carbon cycle transition matrix biosphere/shallow oceans to atmosphere
b22 = Parameter() # Carbon cycle transition matrix shallow ocean to shallow oceans
b23 = Parameter() # Carbon cycle transition matrix shallow to deep ocean
b32 = Parameter() # Carbon cycle transition matrix deep ocean to shallow ocean
b33 = Parameter() # Carbon cycle transition matrix deep ocean to deep oceans
b11 = Parameter() # Carbon cycle transition matrix atmosphere to atmosphere
b12 = Parameter() # Carbon cycle transition matrix atmosphere to shallow ocean
b21 = Parameter() # Carbon cycle transition matrix biosphere/shallow oceans to atmosphere
b22 = Parameter() # Carbon cycle transition matrix shallow ocean to shallow oceans
b23 = Parameter() # Carbon cycle transition matrix shallow to deep ocean
b32 = Parameter() # Carbon cycle transition matrix deep ocean to shallow ocean
b33 = Parameter() # Carbon cycle transition matrix deep ocean to deep oceans

function run_timestep(p, v, d, t)
# Define function for MAT
if is_first(t)
v.MAT[t] = p.mat0
else
v.MAT[t] = v.MAT[t - 1] * p.b11 + v.MU[t - 1] * p.b21 + (p.E[t - 1] * (5 / 3.666))
v.MAT[t] = v.MAT[t-1] * p.b11 + v.MU[t-1] * p.b21 + (p.E[t-1] * (5 / 3.666))
end

# Define function for MU
if is_first(t)
v.MU[t] = p.mu0
else
v.MU[t] = v.MAT[t - 1] * p.b12 + v.MU[t - 1] * p.b22 + v.ML[t - 1] * p.b32
v.MU[t] = v.MAT[t-1] * p.b12 + v.MU[t-1] * p.b22 + v.ML[t-1] * p.b32
end

# Define function for ML
if is_first(t)
v.ML[t] = p.ml0
else
v.ML[t] = v.ML[t - 1] * p.b33 + v.MU[t - 1] * p.b23
v.ML[t] = v.ML[t-1] * p.b33 + v.MU[t-1] * p.b23
end
end
end
14 changes: 7 additions & 7 deletions src/components/damages_component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
DAMAGES = Variable(index=[time]) # Damages (trillions 2005 USD per year)
DAMFRAC = Variable(index=[time]) # Damages (fraction of gross output)

TATM = Parameter(index=[time]) # Increase temperature of atmosphere (degrees C from 1900)
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
a1 = Parameter() # Damage coefficient
a2 = Parameter() # Damage quadratic term
a3 = Parameter() # Damage exponent
damadj = Parameter() # Adjustment exponent in damage function
TATM = Parameter(index=[time]) # Increase temperature of atmosphere (degrees C from 1900)
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
a1 = Parameter() # Damage coefficient
a2 = Parameter() # Damage quadratic term
a3 = Parameter() # Damage exponent
damadj = Parameter() # Adjustment exponent in damage function
usedamadj = Parameter{Bool}() # Only the Excel version uses the damadj parameter

function run_timestep(p, v, d, t)
# Define function for DAMFRAC
v.DAMFRAC[t] = p.a1 * p.TATM[t] + p.a2 * p.TATM[t]^p.a3

# Define function for DAMAGES
if p.usedamadj
# Excel version
Expand Down
22 changes: 11 additions & 11 deletions src/components/emissions_component.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
@defcomp emissions begin
CCA = Variable(index=[time]) # Cumulative indiustrial emissions
E = Variable(index=[time]) # Total CO2 emissions (GtCO2 per year)
EIND = Variable(index=[time]) # Industrial emissions (GtCO2 per year)
CCA = Variable(index=[time]) # Cumulative indiustrial emissions
E = Variable(index=[time]) # Total CO2 emissions (GtCO2 per year)
EIND = Variable(index=[time]) # Industrial emissions (GtCO2 per year)

etree = Parameter(index=[time]) # Emissions from deforestation
MIU = Parameter(index=[time]) # Emission control rate GHGs
sigma = Parameter(index=[time]) # CO2-equivalent-emissions output ratio
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
cca0 = Parameter() # Initial cumulative industrial emissions
etree = Parameter(index=[time]) # Emissions from deforestation
MIU = Parameter(index=[time]) # Emission control rate GHGs
sigma = Parameter(index=[time]) # CO2-equivalent-emissions output ratio
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
cca0 = Parameter() # Initial cumulative industrial emissions

function run_timestep(p, v, d, t)
# Define function for EIND
v.EIND[t] = p.sigma[t] * p.YGROSS[t] * (1 - p.MIU[t])

# Define function for E
v.E[t] = v.EIND[t] + p.etree[t]

# Define function for CCA
if is_first(t)
v.CCA[t] = p.cca0
else
v.CCA[t] = v.CCA[t - 1] + v.EIND[t - 1] * 5 / 3.666
v.CCA[t] = v.CCA[t-1] + v.EIND[t-1] * 5 / 3.666
end

end
Expand Down
18 changes: 9 additions & 9 deletions src/components/grosseconomy_component.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
@defcomp grosseconomy begin
K = Variable(index=[time]) # Capital stock (trillions 2005 US dollars)
YGROSS = Variable(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
K = Variable(index=[time]) # Capital stock (trillions 2005 US dollars)
YGROSS = Variable(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)

al = Parameter(index=[time]) # Level of total factor productivity
I = Parameter(index=[time]) # Investment (trillions 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
dk = Parameter() # Depreciation rate on capital (per year)
gama = Parameter() # Capital elasticity in production function
k0 = Parameter() # Initial capital value (trill 2005 USD)
al = Parameter(index=[time]) # Level of total factor productivity
I = Parameter(index=[time]) # Investment (trillions 2005 USD per year)
l = Parameter(index=[time]) # Level of population and labor
dk = Parameter() # Depreciation rate on capital (per year)
gama = Parameter() # Capital elasticity in production function
k0 = Parameter() # Initial capital value (trill 2005 USD)

function run_timestep(p, v, d, t)
# Define function for K
if is_first(t)
v.K[t] = p.k0
else
v.K[t] = (1 - p.dk)^5 * v.K[t - 1] + 5 * p.I[t - 1]
v.K[t] = (1 - p.dk)^5 * v.K[t-1] + 5 * p.I[t-1]
end

# Define function for YGROSS
Expand Down
50 changes: 25 additions & 25 deletions src/components/neteconomy_component.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
@defcomp neteconomy begin

ABATECOST = Variable(index=[time]) # Cost of emissions reductions (trillions 2005 USD per year)
C = Variable(index=[time]) # Consumption (trillions 2005 US dollars per year)
CPC = Variable(index=[time]) # Per capita consumption (thousands 2005 USD per year)
CPRICE = Variable(index=[time]) # Carbon price (2005$ per ton of CO2)
I = Variable(index=[time]) # Investment (trillions 2005 USD per year)
MCABATE = Variable(index=[time]) # Marginal cost of abatement (2005$ per ton CO2)
Y = Variable(index=[time]) # Gross world product net of abatement and damages (trillions 2005 USD per year)
YNET = Variable(index=[time]) # Output net of damages equation (trillions 2005 USD per year)

cost1 = Parameter(index=[time]) # Abatement cost function coefficient
DAMAGES = Parameter(index=[time]) # Damages (Trillion $)
l = Parameter(index=[time]) # Level of population and labor
MIU = Parameter(index=[time]) # Emission control rate GHGs
partfract = Parameter(index=[time]) # Fraction of emissions in control regime
pbacktime = Parameter(index=[time]) # Backstop price
S = Parameter(index=[time]) # Gross savings rate as fraction of gross world product
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
expcost2 = Parameter() # Exponent of control cost function
ABATECOST = Variable(index=[time]) # Cost of emissions reductions (trillions 2005 USD per year)
C = Variable(index=[time]) # Consumption (trillions 2005 US dollars per year)
CPC = Variable(index=[time]) # Per capita consumption (thousands 2005 USD per year)
CPRICE = Variable(index=[time]) # Carbon price (2005$ per ton of CO2)
I = Variable(index=[time]) # Investment (trillions 2005 USD per year)
MCABATE = Variable(index=[time]) # Marginal cost of abatement (2005$ per ton CO2)
Y = Variable(index=[time]) # Gross world product net of abatement and damages (trillions 2005 USD per year)
YNET = Variable(index=[time]) # Output net of damages equation (trillions 2005 USD per year)

cost1 = Parameter(index=[time]) # Abatement cost function coefficient
DAMAGES = Parameter(index=[time]) # Damages (Trillion $)
l = Parameter(index=[time]) # Level of population and labor
MIU = Parameter(index=[time]) # Emission control rate GHGs
partfract = Parameter(index=[time]) # Fraction of emissions in control regime
pbacktime = Parameter(index=[time]) # Backstop price
S = Parameter(index=[time]) # Gross savings rate as fraction of gross world product
YGROSS = Parameter(index=[time]) # Gross world product GROSS of abatement and damages (trillions 2005 USD per year)
expcost2 = Parameter() # Exponent of control cost function

function run_timestep(p, v, d, t)
# Define function for YNET
v.YNET[t] = p.YGROSS[t] - p.DAMAGES[t]

# Define function for ABATECOST
v.ABATECOST[t] = p.YGROSS[t] * p.cost1[t] * (p.MIU[t]^p.expcost2) * (p.partfract[t]^(1 - p.expcost2))

# Define function for MCABATE (equation from GAMS version)
v.MCABATE[t] = p.pbacktime[t] * p.MIU[t]^(p.expcost2 - 1)

# Define function for Y
v.Y[t] = v.YNET[t] - v.ABATECOST[t]

# Define function for I
v.I[t] = p.S[t] * v.Y[t]

# Define function for C
v.C[t] = v.Y[t] - v.I[t]

# Define function for CPC
v.CPC[t] = 1000 * v.C[t] / p.l[t]

# Define function for CPRICE (equation from GAMS version of DICE2013)
v.CPRICE[t] = p.pbacktime[t] * (p.MIU[t] / p.partfract[t])^(p.expcost2 - 1)
end
Expand Down
10 changes: 5 additions & 5 deletions src/components/radiativeforcing_component.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
@defcomp radiativeforcing begin
FORC = Variable(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)
FORC = Variable(index=[time]) # Increase in radiative forcing (watts per m2 from 1900)

forcoth = Parameter(index=[time]) # Exogenous forcing for other greenhouse gases
MAT = Parameter(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
eqmat = Parameter() # Equilibrium concentration of CO2 in atmosphere (GTC)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)
forcoth = Parameter(index=[time]) # Exogenous forcing for other greenhouse gases
MAT = Parameter(index=[time]) # Carbon concentration increase in atmosphere (GtC from 1750)
eqmat = Parameter() # Equilibrium concentration of CO2 in atmosphere (GTC)
fco22x = Parameter() # Forcings of equilibrium CO2 doubling (Wm-2)

function run_timestep(p, v, d, t)
# Define function for FORC
Expand Down
Loading

0 comments on commit 576ad17

Please sign in to comment.