JGCRI / hector

The Hector Simple Climate Model
http://jgcri.github.io/hector/
GNU General Public License v3.0
107 stars 45 forks source link

Fix if else statement in RF CO2 that causes errors #661

Closed kdorheim closed 1 year ago

kdorheim commented 1 year ago

Bug change - there should be no change in Hector outputs

An if-else statement in the forcing_componet is throwing an error when [CO2] is held constant at pre-industrial values which causes major problems when trying to run idealized runs (abrupt steps, pi control, 1pct etc).

This change prevents that error.

# Set up a Hector core
ini_file <- here::here("inst", "input", "hector_ssp245.ini")
hc <- newcore(ini_file)

# Fetch the pre-industrial value
prei_co2 <- fetchvars(hc, dates = NA, vars = PREINDUSTRIAL_CO2())

# Read in constant [CO2]
df <- data.frame(year = 1745:2100,
                 value = prei_co2$value)
setvar(hc, dates = df$year, values = df$value, var = CO2_CONSTRAIN(), unit = getunits(CO2_CONSTRAIN()))
reset(hc)
run(hc)

Throws the following error

The script returns the following error
> run(hc)
Error in run(hc) :
    Error while running hector:  msg:   Caller is requesting unknown condition for CO2 SARF
func:   run
file:   forcing_component.cpp
ffile:  forcing_component.cpp

line:   340
Called from: run(hc)

co2_rf_bug.txt R script ^^