From 2203297777b7eaa075c9b7bc7bc72b830015a96e Mon Sep 17 00:00:00 2001 From: kdorheim Date: Mon, 4 Nov 2024 17:44:37 -0500 Subject: [PATCH 1/7] use more conservative code to define a constant --- src/ch4_component.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ch4_component.cpp b/src/ch4_component.cpp index d20c920e6..36af4d43a 100644 --- a/src/ch4_component.cpp +++ b/src/ch4_component.cpp @@ -165,7 +165,7 @@ void CH4Component::run(const double runToDate) { << std::endl; // Permafrost thaw produces CH4 emissions -#define PG_C_TO_TG_CH4 (1000.0 * 16.04 / 12.01) + const double PG_C_TO_TG_CH4 (1000.0 * 16.04 / 12.01); const double rh_ch4 = core->sendMessage(M_GETDATA, D_RH_CH4).value(U_PGC_YR) * PG_C_TO_TG_CH4; From a46e14e1243f3849e27eb2f08a2dd18a47afe47b Mon Sep 17 00:00:00 2001 From: kdorheim Date: Wed, 6 Nov 2024 13:03:28 -0500 Subject: [PATCH 2/7] increase the version index so that it is easier to keep track of errors in the gcam coupling --- DESCRIPTION | 2 +- NEWS.md | 4 ++++ inst/include/h_util.hpp | 2 +- src/oh_component.cpp | 10 +++++++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b0feeb110..b92616faa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: hector Title: The Hector Simple Climate Model -Version: 3.2.0 +Version: 3.3.0.9999999 Authors@R: c(person("Kalyn", "Dorheim", email = "kalyn.dorheim@pnnl.gov", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index 101ca4ef9..56bac6059 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# hector 3.3.0.9999999 + +* under development for the H2 integration, increasing the version index though will be ensure that the right version of hector is being run with gcam + # hector 3.2.0 [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.10698028.svg)](https://doi.org/10.5281/zenodo.10698028) * Correct aerosol forcing coefficients based on Zelinka et al. (2023) diff --git a/inst/include/h_util.hpp b/inst/include/h_util.hpp index 11f4c7d56..57d7c8f67 100644 --- a/inst/include/h_util.hpp +++ b/inst/include/h_util.hpp @@ -26,7 +26,7 @@ * \brief The model version number to be included in logs and outputs. * \note Manually update the git tag to match this. */ -#define MODEL_VERSION "3.2.0" +#define MODEL_VERSION "3.3.0.9999999" #define OUTPUT_DIRECTORY "output/" diff --git a/src/oh_component.cpp b/src/oh_component.cpp index 418f7ee2c..811a54112 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -149,6 +149,8 @@ void OHComponent::run(const double runToDate) { unitval current_nox = NOX_emissions.get(runToDate); unitval current_co = CO_emissions.get(runToDate); unitval current_nmvoc = NMVOC_emissions.get(runToDate); + unitval current_h2 = H2_emissions.get(runToDate); + // get this from CH4 component, this is last year's value const double previous_ch4 = @@ -169,7 +171,13 @@ void OHComponent::run(const double runToDate) { CNMVOC * ((1.0 * +current_nmvoc) - NMVOC_emissions.get(NMVOC_emissions.firstdate()).value(U_TG_NMVOC)); - toh = a + b + c + d; + const double e = + (-0.00044625) * + ((1.0 * +current_h2) - + H2_emissions.get(H2_emissions.firstdate()).value(U_TG_H2)); + + + toh = a + b + c + d + e; H_LOG(logger, Logger::DEBUG) << "Year " << runToDate << " toh = " << toh << std::endl; } From ec1511ff1eb341f8cdc2b4244fe6fd548bf12e4b Mon Sep 17 00:00:00 2001 From: kdorheim Date: Wed, 6 Nov 2024 13:59:40 -0500 Subject: [PATCH 3/7] implement the H2 coeff for the OH componet as something that can be read in from teh ini file --- inst/include/component_data.hpp | 1 + inst/include/oh_component.hpp | 2 ++ inst/input/hector_ssp119.ini | 1 + inst/input/hector_ssp126.ini | 2 ++ inst/input/hector_ssp245.ini | 2 ++ inst/input/hector_ssp370.ini | 2 ++ inst/input/hector_ssp434.ini | 2 ++ inst/input/hector_ssp460.ini | 2 ++ inst/input/hector_ssp534-over.ini | 2 ++ inst/input/hector_ssp585.ini | 2 ++ src/oh_component.cpp | 5 ++++- 11 files changed, 22 insertions(+), 1 deletion(-) diff --git a/inst/include/component_data.hpp b/inst/include/component_data.hpp index f22b6c2c5..e2766a459 100644 --- a/inst/include/component_data.hpp +++ b/inst/include/component_data.hpp @@ -281,6 +281,7 @@ #define D_COEFFICENT_CH4 "CCH4" #define D_COEFFICENT_NMVOC "CNMVOC" #define D_COEFFICENT_CO "CCO" +#define D_COEFFICENT_H2 "CH2" #define D_EMISSIONS_H2 "H2_emissions" diff --git a/inst/include/oh_component.hpp b/inst/include/oh_component.hpp index 7c39d7623..4b022bc8f 100644 --- a/inst/include/oh_component.hpp +++ b/inst/include/oh_component.hpp @@ -71,6 +71,8 @@ class OHComponent : public IModelComponent { double CNMVOC; // coefficent for NMVOC double CNOX; // coefficent for NOX double CCH4; // coefficent for CH4 + double CH2; // coefficent for CH4 + // logger Logger logger; diff --git a/inst/input/hector_ssp119.ini b/inst/input/hector_ssp119.ini index 4a226a9fd..dca52ea81 100644 --- a/inst/input/hector_ssp119.ini +++ b/inst/input/hector_ssp119.ini @@ -138,6 +138,7 @@ 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 ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp126.ini b/inst/input/hector_ssp126.ini index 1b2e92698..7be816dd3 100644 --- a/inst/input/hector_ssp126.ini +++ b/inst/input/hector_ssp126.ini @@ -137,6 +137,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp245.ini b/inst/input/hector_ssp245.ini index 30667b965..f44837eaa 100644 --- a/inst/input/hector_ssp245.ini +++ b/inst/input/hector_ssp245.ini @@ -138,6 +138,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp370.ini b/inst/input/hector_ssp370.ini index 8f70ff60c..80aa3a484 100644 --- a/inst/input/hector_ssp370.ini +++ b/inst/input/hector_ssp370.ini @@ -138,6 +138,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp434.ini b/inst/input/hector_ssp434.ini index bd810229e..532a9e8f1 100644 --- a/inst/input/hector_ssp434.ini +++ b/inst/input/hector_ssp434.ini @@ -138,6 +138,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp460.ini b/inst/input/hector_ssp460.ini index 02231d1b1..acffa23cf 100644 --- a/inst/input/hector_ssp460.ini +++ b/inst/input/hector_ssp460.ini @@ -138,6 +138,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp534-over.ini b/inst/input/hector_ssp534-over.ini index 278fbc646..68cd577fd 100644 --- a/inst/input/hector_ssp534-over.ini +++ b/inst/input/hector_ssp534-over.ini @@ -138,6 +138,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/inst/input/hector_ssp585.ini b/inst/input/hector_ssp585.ini index 9051bcb93..9abb26ea1 100644 --- a/inst/input/hector_ssp585.ini +++ b/inst/input/hector_ssp585.ini @@ -137,6 +137,8 @@ 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 + ;------------------------------------------------------------------------ [ozone] diff --git a/src/oh_component.cpp b/src/oh_component.cpp index 811a54112..0f0be81a1 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -117,6 +117,9 @@ void OHComponent::setData(const string &varName, const message_data &data) { } else if (varName == D_COEFFICENT_NOX) { H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed"); CNOX = data.getUnitval(U_UNDEFINED); + } else if (varName == D_COEFFICENT_H2) { + H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed"); + CH2 = data.getUnitval(U_UNDEFINED); } else { H_THROW("Unknown variable name while parsing " + getComponentName() + ": " + varName); @@ -172,7 +175,7 @@ void OHComponent::run(const double runToDate) { ((1.0 * +current_nmvoc) - NMVOC_emissions.get(NMVOC_emissions.firstdate()).value(U_TG_NMVOC)); const double e = - (-0.00044625) * + CH2 * ((1.0 * +current_h2) - H2_emissions.get(H2_emissions.firstdate()).value(U_TG_H2)); From 42479b7473e63349bab49c2fbfc0b06f23f17a71 Mon Sep 17 00:00:00 2001 From: kdorheim Date: Mon, 11 Nov 2024 13:13:01 -0500 Subject: [PATCH 4/7] saving wip --- R/RcppExports.R | 7 +++++++ inst/include/oh_component.hpp | 2 +- src/RcppExports.cpp | 11 +++++++++++ src/oh_component.cpp | 10 ++++++++-- src/rcpp_constants.cpp | 6 ++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index e4a7bde03..1f34d9d42 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -4,6 +4,9 @@ #' @describeIn emissions Emissions hydrogen gas (\code{"Tg H2"}) NULL +#' @describeIn oh coefficent for the h2 emissions +NULL + #' @describeIn msgtype Message type for retrieving data from a component #' @keywords internal GETDATA <- function() { @@ -1571,6 +1574,10 @@ HEAT_FLUX <- function() { .Call('_hector_HEAT_FLUX', PACKAGE = 'hector') } +COEFF_H2 <- function() { + .Call('_hector_COEFF_H2', PACKAGE = 'hector') +} + newcore_impl <- function(inifile, loglevel, suppresslogging, name) { .Call('_hector_newcore_impl', PACKAGE = 'hector', inifile, loglevel, suppresslogging, name) } diff --git a/inst/include/oh_component.hpp b/inst/include/oh_component.hpp index 4b022bc8f..f9fc20b2d 100644 --- a/inst/include/oh_component.hpp +++ b/inst/include/oh_component.hpp @@ -71,7 +71,7 @@ class OHComponent : public IModelComponent { double CNMVOC; // coefficent for NMVOC double CNOX; // coefficent for NOX double CCH4; // coefficent for CH4 - double CH2; // coefficent for CH4 + unitval CH2; // coefficent for CH4 // logger diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index fd1b82e30..9ade15016 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -2627,6 +2627,16 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// COEFF_H2 +String COEFF_H2(); +RcppExport SEXP _hector_COEFF_H2() { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + rcpp_result_gen = Rcpp::wrap(COEFF_H2()); + return rcpp_result_gen; +END_RCPP +} // newcore_impl Environment newcore_impl(String inifile, int loglevel, bool suppresslogging, String name); RcppExport SEXP _hector_newcore_impl(SEXP inifileSEXP, SEXP loglevelSEXP, SEXP suppressloggingSEXP, SEXP nameSEXP) { @@ -3035,6 +3045,7 @@ static const R_CallMethodDef CallEntries[] = { {"_hector_FLUX_MIXED", (DL_FUNC) &_hector_FLUX_MIXED, 0}, {"_hector_FLUX_INTERIOR", (DL_FUNC) &_hector_FLUX_INTERIOR, 0}, {"_hector_HEAT_FLUX", (DL_FUNC) &_hector_HEAT_FLUX, 0}, + {"_hector_COEFF_H2", (DL_FUNC) &_hector_COEFF_H2, 0}, {"_hector_newcore_impl", (DL_FUNC) &_hector_newcore_impl, 4}, {"_hector_shutdown", (DL_FUNC) &_hector_shutdown, 1}, {"_hector_reset", (DL_FUNC) &_hector_reset, 2}, diff --git a/src/oh_component.cpp b/src/oh_component.cpp index 0f0be81a1..f53965364 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -57,12 +57,15 @@ void OHComponent::init(Core *coreptr) { // Inform core what data we can provide core->registerCapability(D_LIFETIME_OH, getComponentName()); + core->registerCapability(D_COEFFICENT_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()); + } @@ -178,8 +181,8 @@ void OHComponent::run(const double runToDate) { CH2 * ((1.0 * +current_h2) - H2_emissions.get(H2_emissions.firstdate()).value(U_TG_H2)); - - + + toh = a + b + c + d + e; H_LOG(logger, Logger::DEBUG) << "Year " << runToDate << " toh = " << toh << std::endl; @@ -212,6 +215,9 @@ 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) { + H_ASSERT(date == Core::undefinedIndex(), "Date not allowed for ECS"); + returnval = CH2; } else if (varName == D_EMISSIONS_H2) { H_ASSERT(date != Core::undefinedIndex(), "Date required for H2 emissions"); returnval = H2_emissions.get(date); diff --git a/src/rcpp_constants.cpp b/src/rcpp_constants.cpp index 9b566bf32..fbd22ab57 100644 --- a/src/rcpp_constants.cpp +++ b/src/rcpp_constants.cpp @@ -1503,3 +1503,9 @@ String FLUX_INTERIOR() { return D_FLUX_INTERIOR; } //' @export // [[Rcpp::export]] String HEAT_FLUX() { return D_HEAT_FLUX; } + + +//' @describeIn oh coefficent for the h2 emissions + //' @export + // [[Rcpp::export]] + String COEFF_H2() { return D_COEFFICENT_H2; } From 8ed3f3e78f6dd6b0cf15d03a530a9a4ad776e833 Mon Sep 17 00:00:00 2001 From: kdorheim Date: Tue, 26 Nov 2024 18:41:47 -0500 Subject: [PATCH 5/7] Correct warning message --- src/oh_component.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/oh_component.cpp b/src/oh_component.cpp index f53965364..29dbaee18 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -103,8 +103,8 @@ void OHComponent::setData(const string &varName, const message_data &data) { H_ASSERT(data.date != Core::undefinedIndex(), "date required"); NMVOC_emissions.set(data.date, data.getUnitval(U_TG_NMVOC)); } else if (varName == D_EMISSIONS_H2) { - H_ASSERT(data.date != Core::undefinedIndex(), "date required"); - H2_emissions.set(data.date, data.getUnitval(U_TG_H2)); + H_ASSERT(data.date != Core::undefinedIndex(), "date required"); + H2_emissions.set(data.date, data.getUnitval(U_TG_H2)); } else if (varName == D_INITIAL_LIFETIME_OH) { H_ASSERT(data.date == Core::undefinedIndex(), "date not allowed"); TOH0 = data.getUnitval(U_YRS); @@ -216,11 +216,11 @@ unitval OHComponent::getData(const std::string &varName, const double date) { "Date required for NMVOC emissions"); returnval = NMVOC_emissions.get(date); } else if (varName == D_COEFFICENT_H2) { - H_ASSERT(date == Core::undefinedIndex(), "Date not allowed for ECS"); - returnval = CH2; + H_ASSERT(date == Core::undefinedIndex(), "Date not allowed for H2 coefficent"); + returnval = CH2 ; } else if (varName == D_EMISSIONS_H2) { - H_ASSERT(date != Core::undefinedIndex(), "Date required for H2 emissions"); - returnval = H2_emissions.get(date); + H_ASSERT(date != Core::undefinedIndex(), "Date required for H2 emissions"); + returnval = H2_emissions.get(date); } else { H_THROW("Caller is requesting unknown variable: " + varName); } From 95b31964c1ab4fabd067371cad17abdace0aa582 Mon Sep 17 00:00:00 2001 From: kdorheim Date: Mon, 2 Dec 2024 15:52:18 -0500 Subject: [PATCH 6/7] feedback from ben --- src/ch4_component.cpp | 2 +- src/oh_component.cpp | 4 ++-- tests/testthat/test-h2.R | 17 +++++++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ch4_component.cpp b/src/ch4_component.cpp index 36af4d43a..5abf7c924 100644 --- a/src/ch4_component.cpp +++ b/src/ch4_component.cpp @@ -165,7 +165,7 @@ void CH4Component::run(const double runToDate) { << std::endl; // Permafrost thaw produces CH4 emissions - const double PG_C_TO_TG_CH4 (1000.0 * 16.04 / 12.01); + #define PG_C_TO_TG_CH4 (1000.0 * 16.04 / 12.01); const double rh_ch4 = core->sendMessage(M_GETDATA, D_RH_CH4).value(U_PGC_YR) * PG_C_TO_TG_CH4; diff --git a/src/oh_component.cpp b/src/oh_component.cpp index 29dbaee18..b57047859 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -177,13 +177,13 @@ void OHComponent::run(const double runToDate) { CNMVOC * ((1.0 * +current_nmvoc) - NMVOC_emissions.get(NMVOC_emissions.firstdate()).value(U_TG_NMVOC)); - const double e = + const double f = CH2 * ((1.0 * +current_h2) - H2_emissions.get(H2_emissions.firstdate()).value(U_TG_H2)); - toh = a + b + c + d + e; + toh = a + b + c + d + f; H_LOG(logger, Logger::DEBUG) << "Year " << runToDate << " toh = " << toh << std::endl; } diff --git a/tests/testthat/test-h2.R b/tests/testthat/test-h2.R index 07d5466d1..30039f4d6 100644 --- a/tests/testthat/test-h2.R +++ b/tests/testthat/test-h2.R @@ -25,9 +25,9 @@ test_that("tau ", { test_that("H2 emissions ", { - # Check to make sure that can fetch and set the H2 emissions although - # at this point changing the emissions will have no impact on - # [ch4] dynamics but in the future it should... + # Check to make sure that can fetch and set the H2 emissions and + # that the effects of adding some H2 emissions change thigns + # now that we have the CH4 indrect effects implement. hc <- newcore(ini) run(hc) @@ -45,12 +45,13 @@ test_that("H2 emissions ", { diff <- abs(out$value - out2$value) - # As of now the [CH4] and tau oh should not change - expect_equal(mean(diff[out$variable == CONCENTRATIONS_CH4()]), 0) - expect_equal(mean(diff[out$variable == LIFETIME_OH()]), 0) + # Now we do expect to see changes in CH4 concentrations in response + # to H2 emissions + expect_gt(mean(diff[out$variable == CONCENTRATIONS_CH4()]), 0) + expect_gt(mean(diff[out$variable == LIFETIME_OH()]), 0) - # But if we can change the H2 emissions we should see a difference in - # H2 emissions between the two new runs! + # Since we are working off of some default H2 emissions = 0, then + # changing the H2 emissions we should see a difference. expect_equal(mean(diff[out$variable == EMISSIONS_H2()]), new_val) }) From 7058e568252f00e111725ed8d75fbbfee58ff9e1 Mon Sep 17 00:00:00 2001 From: kdorheim Date: Wed, 4 Dec 2024 13:36:31 -0500 Subject: [PATCH 7/7] address response to pr 758 --- R/RcppExports.R | 2 +- inst/include/component_data.hpp | 10 +++++----- inst/include/oh_component.hpp | 10 +++++----- inst/input/hector_ssp119.ini | 10 +++++----- inst/input/hector_ssp126.ini | 10 +++++----- inst/input/hector_ssp245.ini | 10 +++++----- inst/input/hector_ssp370.ini | 10 +++++----- inst/input/hector_ssp434.ini | 16 ++++++++-------- inst/input/hector_ssp460.ini | 16 ++++++++-------- inst/input/hector_ssp534-over.ini | 10 +++++----- inst/input/hector_ssp585.ini | 10 +++++----- src/oh_component.cpp | 30 +++++++++++++++--------------- src/rcpp_constants.cpp | 4 ++-- tests/testthat/input/luc_pulse.ini | 8 ++++---- 14 files changed, 78 insertions(+), 78 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index 1f34d9d42..d269dff1d 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -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 diff --git a/inst/include/component_data.hpp b/inst/include/component_data.hpp index e2766a459..595d271b9 100644 --- a/inst/include/component_data.hpp +++ b/inst/include/component_data.hpp @@ -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" diff --git a/inst/include/oh_component.hpp b/inst/include/oh_component.hpp index f9fc20b2d..ab916f21b 100644 --- a/inst/include/oh_component.hpp +++ b/inst/include/oh_component.hpp @@ -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 diff --git a/inst/input/hector_ssp119.ini b/inst/input/hector_ssp119.ini index dca52ea81..e3ad719f9 100644 --- a/inst/input/hector_ssp119.ini +++ b/inst/input/hector_ssp119.ini @@ -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] diff --git a/inst/input/hector_ssp126.ini b/inst/input/hector_ssp126.ini index 7be816dd3..0373b3b9b 100644 --- a/inst/input/hector_ssp126.ini +++ b/inst/input/hector_ssp126.ini @@ -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 ;------------------------------------------------------------------------ diff --git a/inst/input/hector_ssp245.ini b/inst/input/hector_ssp245.ini index f44837eaa..976a76619 100644 --- a/inst/input/hector_ssp245.ini +++ b/inst/input/hector_ssp245.ini @@ -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 ;------------------------------------------------------------------------ diff --git a/inst/input/hector_ssp370.ini b/inst/input/hector_ssp370.ini index 80aa3a484..855a88c5d 100644 --- a/inst/input/hector_ssp370.ini +++ b/inst/input/hector_ssp370.ini @@ -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 ;------------------------------------------------------------------------ diff --git a/inst/input/hector_ssp434.ini b/inst/input/hector_ssp434.ini index 532a9e8f1..79f73bb15 100644 --- a/inst/input/hector_ssp434.ini +++ b/inst/input/hector_ssp434.ini @@ -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 @@ -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 @@ -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 ;------------------------------------------------------------------------ @@ -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) diff --git a/inst/input/hector_ssp460.ini b/inst/input/hector_ssp460.ini index acffa23cf..287e2a950 100644 --- a/inst/input/hector_ssp460.ini +++ b/inst/input/hector_ssp460.ini @@ -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 @@ -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 @@ -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 ;------------------------------------------------------------------------ @@ -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) diff --git a/inst/input/hector_ssp534-over.ini b/inst/input/hector_ssp534-over.ini index 68cd577fd..203633c2f 100644 --- a/inst/input/hector_ssp534-over.ini +++ b/inst/input/hector_ssp534-over.ini @@ -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 ;------------------------------------------------------------------------ diff --git a/inst/input/hector_ssp585.ini b/inst/input/hector_ssp585.ini index 9abb26ea1..1aca8f4fa 100644 --- a/inst/input/hector_ssp585.ini +++ b/inst/input/hector_ssp585.ini @@ -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 ;------------------------------------------------------------------------ diff --git a/src/oh_component.cpp b/src/oh_component.cpp index b57047859..9d9fe19aa 100644 --- a/src/oh_component.cpp +++ b/src/oh_component.cpp @@ -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()); } @@ -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 { @@ -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; } @@ -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) { diff --git a/src/rcpp_constants.cpp b/src/rcpp_constants.cpp index fbd22ab57..1850f9a92 100644 --- a/src/rcpp_constants.cpp +++ b/src/rcpp_constants.cpp @@ -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; } diff --git a/tests/testthat/input/luc_pulse.ini b/tests/testthat/input/luc_pulse.ini index 98a3c2e45..0fe761ef5 100644 --- a/tests/testthat/input/luc_pulse.ini +++ b/tests/testthat/input/luc_pulse.ini @@ -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]