Skip to content

Commit

Permalink
address response to pr 758
Browse files Browse the repository at this point in the history
  • Loading branch information
kdorheim committed Dec 4, 2024
1 parent 95b3196 commit 7058e56
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 78 deletions.
2 changes: 1 addition & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @describeIn emissions Emissions hydrogen gas (\code{"Tg H2"})
NULL

#' @describeIn oh coefficent for the h2 emissions
#' @describeIn oh coefficient for the h2 emissions
NULL

#' @describeIn msgtype Message type for retrieving data from a component
Expand Down
10 changes: 5 additions & 5 deletions inst/include/component_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@
// oh component
#define D_LIFETIME_OH "TAU_OH"
#define D_INITIAL_LIFETIME_OH "TOH0"
#define D_COEFFICENT_NOX "CNOX"
#define D_COEFFICENT_CH4 "CCH4"
#define D_COEFFICENT_NMVOC "CNMVOC"
#define D_COEFFICENT_CO "CCO"
#define D_COEFFICENT_H2 "CH2"
#define D_COEFFICIENT_NOX "CNOX"
#define D_COEFFICIENT_CH4 "CCH4"
#define D_COEFFICIENT_NMVOC "CNMVOC"
#define D_COEFFICIENT_CO "CCO"
#define D_COEFFICIENT_H2 "CH2"
#define D_EMISSIONS_H2 "H2_emissions"


Expand Down
10 changes: 5 additions & 5 deletions inst/include/oh_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class OHComponent : public IModelComponent {
unitval M0; // initial CH4 concentration
unitval TOH0; // preindustrial OH lifetime

double CCO; // coefficent for CO
double CNMVOC; // coefficent for NMVOC
double CNOX; // coefficent for NOX
double CCH4; // coefficent for CH4
unitval CH2; // coefficent for CH4
double CCO; // coefficient for CO
double CNMVOC; // coefficient for NMVOC
double CNOX; // coefficient for NOX
double CCH4; // coefficient for CH4
unitval CH2; // coefficient for CH4


// logger
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp119.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time se


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2

;------------------------------------------------------------------------
[ozone]
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp126.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ NMVOC_emissions=csv:tables/ssp126_emiss-constraints_rf.csv ; emissions time se
H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time series

TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp245.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time se


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp370.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time se


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down
16 changes: 8 additions & 8 deletions inst/input/hector_ssp434.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
;nonpf.npp_flux0=50.6

veg_c=550 ; initial vegetation pool, Pg C
Expand Down Expand Up @@ -73,7 +73,7 @@ f_litterd=0.98 ; Fraction of litter flux to detritus (balance to soil)
;nonpf.f_litterd=0.98

; Anthropogenic contributions: emissions, direct air carbon capture and storage, and land use change, Pg C/yr
ffi_emissions=csv:tables/ssp434_emiss-constraints_rf.csv
ffi_emissions=csv:tables/ssp434_emiss-constraints_rf.csv
daccs_uptake=csv:tables/ssp434_emiss-constraints_rf.csv
luc_emissions=csv:tables/ssp434_emiss-constraints_rf.csv
luc_uptake=csv:tables/ssp434_emiss-constraints_rf.csv
Expand Down Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time se


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down Expand Up @@ -236,7 +236,7 @@ delta_HFC32=0.0 ; tropospheric adjustments scalar unitless (7.3.2.4 IPCC AR6
molarMass=52.0 ; grams
HFC32_emissions=csv:tables/ssp434_emiss-constraints_rf.csv

[HFC4310_halocarbon]
[HFC4310_halocarbon]
; This is equivalent to HFC-43-10mee
tau=17.0 ; lifetime in years (Table 7.SM.7 IPPC AR6)
rho_HFC4310=0.000357 ; radiative efficiencies W/m2/ppt (Table 7.SM.7 IPPC AR6)
Expand Down
16 changes: 8 additions & 8 deletions inst/input/hector_ssp460.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ preind_interdeep_c=37100 ; intermediate and deep ocean C, IPCC AR6 Figure 5.12
atmos_co2=590.33 ; initial atmospheric carbon pool Pg C of CO2 size used in spin up, consistent with C0
C0=277.15 ; preindustrial CO2 from table 7.SM.1 IPCC AR6; CO2 radiative forcing is calibrated to this value
npp_flux0=56.2 ; preindustrial net primary production, Pg C/yr from Ito et al. 2011
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
;pf.npp_flux0=5.6 ; cf. Figure 3 in Chen et al. 2017 10.1088/1748-9326/aa8978
;nonpf.npp_flux0=50.6

veg_c=550 ; initial vegetation pool, Pg C
Expand Down Expand Up @@ -73,7 +73,7 @@ f_litterd=0.98 ; Fraction of litter flux to detritus (balance to soil)
;nonpf.f_litterd=0.98

; Anthropogenic contributions: emissions, direct air carbon capture and storage, and land use change, Pg C/yr
ffi_emissions=csv:tables/ssp460_emiss-constraints_rf.csv
ffi_emissions=csv:tables/ssp460_emiss-constraints_rf.csv
daccs_uptake=csv:tables/ssp460_emiss-constraints_rf.csv
luc_emissions=csv:tables/ssp460_emiss-constraints_rf.csv
luc_uptake=csv:tables/ssp460_emiss-constraints_rf.csv
Expand Down Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time se


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down Expand Up @@ -236,7 +236,7 @@ delta_HFC32=0.0 ; tropospheric adjustments scalar unitless (7.3.2.4 IPCC AR6
molarMass=52.0 ; grams
HFC32_emissions=csv:tables/ssp460_emiss-constraints_rf.csv

[HFC4310_halocarbon]
[HFC4310_halocarbon]
; This is equivalent to HFC-43-10mee
tau=17.0 ; lifetime in years (Table 7.SM.7 IPPC AR6)
rho_HFC4310=0.000357 ; radiative efficiencies W/m2/ppt (Table 7.SM.7 IPPC AR6)
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp534-over.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions ti


TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions inst/input/hector_ssp585.ini
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ NMVOC_emissions=csv:tables/ssp585_emiss-constraints_rf.csv ; emissions time se
H2_emissions=csv:tables/ssp119_emiss-constraints_rf.csv ; emissions time series

TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CH2=-0.00044625 ; coefficent for H2
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4
CH2=-0.00044625 ; coefficient for H2 TODO-H2


;------------------------------------------------------------------------
Expand Down
30 changes: 15 additions & 15 deletions src/oh_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ void OHComponent::init(Core *coreptr) {

// Inform core what data we can provide
core->registerCapability(D_LIFETIME_OH, getComponentName());
core->registerCapability(D_COEFFICENT_H2, getComponentName());
core->registerCapability(D_COEFFICIENT_H2, getComponentName());
// Register inputs accepted. Note that more than one component
// can accept an input
core->registerInput(D_EMISSIONS_CO, getComponentName());
core->registerInput(D_EMISSIONS_NMVOC, getComponentName());
core->registerInput(D_EMISSIONS_NOX, getComponentName());
core->registerInput(D_EMISSIONS_H2, getComponentName());
core->registerInput(D_COEFFICENT_H2, getComponentName());
core->registerInput(D_COEFFICIENT_H2, getComponentName());


}
Expand Down Expand Up @@ -108,19 +108,19 @@ void OHComponent::setData(const string &varName, const message_data &data) {
} else if (varName == D_INITIAL_LIFETIME_OH) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
TOH0 = data.getUnitval(U_YRS);
} else if (varName == D_COEFFICENT_CH4) {
} else if (varName == D_COEFFICIENT_CH4) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
CCH4 = data.getUnitval(U_UNDEFINED);
} else if (varName == D_COEFFICENT_CO) {
} else if (varName == D_COEFFICIENT_CO) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
CCO = data.getUnitval(U_UNDEFINED);
} else if (varName == D_COEFFICENT_NMVOC) {
} else if (varName == D_COEFFICIENT_NMVOC) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
CNMVOC = data.getUnitval(U_UNDEFINED);
} else if (varName == D_COEFFICENT_NOX) {
} else if (varName == D_COEFFICIENT_NOX) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
CNOX = data.getUnitval(U_UNDEFINED);
} else if (varName == D_COEFFICENT_H2) {
} else if (varName == D_COEFFICIENT_H2) {
H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed");
CH2 = data.getUnitval(U_UNDEFINED);
} else {
Expand Down Expand Up @@ -162,28 +162,28 @@ void OHComponent::run(const double runToDate) {
const double previous_ch4 =
core->sendMessage(M_GETDATA, D_CH4_CONC, oldDate).value(U_PPBV_CH4);

// toh is a sum of coefficients in an exponential representation of OH lifetime
double toh = 0.0;
if (previous_ch4 != M0) // if we are not at the first time
{
const double a =
const double toh_ch4 =
CCH4 * ((1.0 * log(previous_ch4)) - log(M0.value(U_PPBV_CH4)));
const double b =
const double toh_nox =
CNOX * ((1.0 * current_nox) -
NOX_emissions.get(NOX_emissions.firstdate()).value(U_TG_N));
const double c =
const double toh_co =
CCO * ((1.0 * +current_co) -
CO_emissions.get(CO_emissions.firstdate()).value(U_TG_CO));
const double d =
const double toh_nmvoc =
CNMVOC *
((1.0 * +current_nmvoc) -
NMVOC_emissions.get(NMVOC_emissions.firstdate()).value(U_TG_NMVOC));
const double f =
const double toh_h2 =
CH2 *
((1.0 * +current_h2) -
H2_emissions.get(H2_emissions.firstdate()).value(U_TG_H2));


toh = a + b + c + d + f;
toh = toh_ch4 + toh_nox + toh_co + toh_nmvoc + toh_h2;
H_LOG(logger, Logger::DEBUG)
<< "Year " << runToDate << " toh = " << toh << std::endl;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ unitval OHComponent::getData(const std::string &varName, const double date) {
H_ASSERT(date != Core::undefinedIndex(),
"Date required for NMVOC emissions");
returnval = NMVOC_emissions.get(date);
} else if (varName == D_COEFFICENT_H2) {
} else if (varName == D_COEFFICIENT_H2) {
H_ASSERT(date == Core::undefinedIndex(), "Date not allowed for H2 coefficent");
returnval = CH2 ;
} else if (varName == D_EMISSIONS_H2) {
Expand Down
4 changes: 2 additions & 2 deletions src/rcpp_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,7 @@ String FLUX_INTERIOR() { return D_FLUX_INTERIOR; }
String HEAT_FLUX() { return D_HEAT_FLUX; }


//' @describeIn oh coefficent for the h2 emissions
//' @describeIn oh coefficient for the h2 emissions
//' @export
// [[Rcpp::export]]
String COEFF_H2() { return D_COEFFICENT_H2; }
String COEFF_H2() { return D_COEFFICIENT_H2; }
8 changes: 4 additions & 4 deletions tests/testthat/input/luc_pulse.ini
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ CO_emissions=csv:luc_pulse_tables.csv ; emissions time series
NMVOC_emissions=csv:luc_pulse_tables.csv ; emissions time series

TOH0=6.6 ; inital OH lifetime (years)
CNOX=0.0042 ; coefficent for NOX
CCO=-0.000105 ; coefficent for CO
CNMVOC=-0.000315 ; coefficent for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficent for CH4
CNOX=0.0042 ; coefficient for NOX
CCO=-0.000105 ; coefficient for CO
CNMVOC=-0.000315 ; coefficient for NMVOC (non methane VOC)
CCH4=-0.32 ; coefficient for CH4

;------------------------------------------------------------------------
[ozone]
Expand Down

0 comments on commit 7058e56

Please sign in to comment.