[CHNOSZ-commits] r667 - in pkg/CHNOSZ: . R inst inst/extdata/OBIGT man tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 7 12:20:48 CEST 2021


Author: jedick
Date: 2021-04-07 12:20:48 +0200 (Wed, 07 Apr 2021)
New Revision: 667

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/add.OBIGT.R
   pkg/CHNOSZ/R/subcrt.R
   pkg/CHNOSZ/R/util.data.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/inst/TODO
   pkg/CHNOSZ/inst/extdata/OBIGT/AkDi.csv
   pkg/CHNOSZ/man/add.OBIGT.Rd
   pkg/CHNOSZ/man/eos.Rd
   pkg/CHNOSZ/tests/testthat/test-eos.R
   pkg/CHNOSZ/tests/testthat/test-info.R
   pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R
Log:
Use abbrv = "AkDi" to activate Akinfiev-Diamond model


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/DESCRIPTION	2021-04-07 10:20:48 UTC (rev 667)
@@ -1,6 +1,6 @@
 Date: 2021-04-07
 Package: CHNOSZ
-Version: 1.4.0-36
+Version: 1.4.0-37
 Title: Thermodynamic Calculations and Diagrams for Geochemistry
 Authors at R: c(
     person("Jeffrey", "Dick", , "j3ffdick at gmail.com", role = c("aut", "cre"),

Modified: pkg/CHNOSZ/R/add.OBIGT.R
===================================================================
--- pkg/CHNOSZ/R/add.OBIGT.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/R/add.OBIGT.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -65,15 +65,6 @@
       # transmit the error from makeup
       stop(e)
     }
-    # for aqueous species, supply a value for Z if it is missing, otherwise NA triggers AkDi model 20190224
-    isaq <- newrows$state == "aq"
-    if(any(isaq)) {
-      mnrf <- makeup(newrows$formula)
-      if(nrow(newrows)==1) mnrf <- list(mnrf)
-      Z <- sapply(mnrf, "[", "Z")
-      Z[is.na(Z)] <- 0
-      newrows$z.T[isaq] <- Z[isaq]
-    }
     # assign to thermo()$OBIGT
     thermo$OBIGT <- rbind(thermo$OBIGT, newrows)
     rownames(thermo$OBIGT) <- NULL

Modified: pkg/CHNOSZ/R/subcrt.R
===================================================================
--- pkg/CHNOSZ/R/subcrt.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/R/subcrt.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -284,8 +284,10 @@
   if(TRUE %in% isaq) {
     # 20110808 get species parameters using OBIGT2eos() (faster than using info())
     param <- OBIGT2eos(thermo$OBIGT[iphases[isaq],], "aq", fixGHS = TRUE, tocal = TRUE)
-    # aqueous species with NA for Z use the AkDi model
-    isAkDi <- is.na(param$Z)
+    # Aqueous species with abbrv = "AkDi" use the AkDi model 20210407
+    abbrv <- thermo$OBIGT$abbrv[iphases[isaq]]
+    abbrv[is.na(abbrv)] <- ""
+    isAkDi <- abbrv == "AkDi"
     # always get density
     H2O.props <- "rho"
     # calculate A_DH and B_DH if we're using the B-dot (Helgeson) equation

Modified: pkg/CHNOSZ/R/util.data.R
===================================================================
--- pkg/CHNOSZ/R/util.data.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/R/util.data.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -405,8 +405,10 @@
   # remove scaling factors from EOS parameters
   # and apply column names depending on the EOS
   if(identical(state, "aq")) {
-    # species in the Akinfiev-Diamond model (AkDi) have NA for Z 20190219
-    isAkDi <- is.na(OBIGT[, 21])
+    # Aqueous species with abbrv = "AkDi" use the AkDi model 20210407
+    abbrv <- OBIGT$abbrv
+    abbrv[is.na(abbrv)] <- ""
+    isAkDi <- abbrv == "AkDi"
     # remove scaling factors for the HKF species, but not for the AkDi species
     # protect this by an if statement to workaround error in subassignment to empty subset of data frame in R < 3.6.0
     # (https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17483) 20190302

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2021-04-07 10:20:48 UTC (rev 667)
@@ -10,7 +10,7 @@
 \newcommand{\s}{\ifelse{latex}{\eqn{_{#1}}}{\ifelse{html}{\out{<sub>#1</sub>}}{#1}}}
 \newcommand{\S}{\ifelse{latex}{\eqn{^{#1}}}{\ifelse{html}{\out{<sup>#1</sup>}}{^#1}}}
 
-\section{Changes in CHNOSZ version 1.4.0-35 (2021-04-07)}{
+\section{Changes in CHNOSZ version 1.4.0-37 (2021-04-07)}{
 
   \subsection{NEW FEATURES}{
     \itemize{
@@ -101,6 +101,11 @@
       \code{ionize.aa()} were incorrectly affected by the setting of
       \code{E.units()}.
 
+      \item The Akinfiev-Diamond model is now activated by setting \code{abbrv
+        = "AkDi"} for any aqueous species, instead of setting the charge
+      (\code{z}) to NA. This simplifies the more common use case of adding a
+      custom aqueous species to OBIGT with mostly NA parameters.
+      
     }
   }
 

Modified: pkg/CHNOSZ/inst/TODO
===================================================================
--- pkg/CHNOSZ/inst/TODO	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/inst/TODO	2021-04-07 10:20:48 UTC (rev 667)
@@ -44,8 +44,3 @@
 [20210306]
 
 - Remove 'bases2' argument from mosaic() (old backward compatibility)
-
-[20210312]
-
-- Don't use z.T = NA to trigger AkDi model (makes the more common use case of
-  just adding a simple aqueous species more tricky).

Modified: pkg/CHNOSZ/inst/extdata/OBIGT/AkDi.csv
===================================================================
--- pkg/CHNOSZ/inst/extdata/OBIGT/AkDi.csv	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/inst/extdata/OBIGT/AkDi.csv	2021-04-07 10:20:48 UTC (rev 667)
@@ -1,25 +1,25 @@
 name,abbrv,formula,state,ref1,ref2,date,E_units,G,H,S,Cp,V,a1.a,a2.b,a3.c,a4.d,c1.e,c2.f,omega.lambda,z.T
-Ar,NA,Ar,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.5139,11.921,0.0733,NA,NA,NA,NA,NA
-H2S,NA,H2S,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-13.4046,13.8582,-0.2029,NA,NA,NA,NA,NA
-O2,NA,O2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-9.754,12.9411,0.026,NA,NA,NA,NA,NA
-N2,NA,N2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-11.538,14.6278,-0.032,NA,NA,NA,NA,NA
-NH3,NA,NH3,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-4.7245,4.9782,-0.0955,NA,NA,NA,NA,NA
-H2,NA,H2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.4596,10.8301,0.309,NA,NA,NA,NA,NA
-CH4,NA,CH4,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-11.8462,14.8615,-0.1131,NA,NA,NA,NA,NA
-CO2,NA,CO2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.8321,11.2684,-0.085,NA,NA,NA,NA,NA
-benzene,NA,C6H6,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-21.0084,22.934,-1.101,NA,NA,NA,NA,NA
-HCl,NA,HCl,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,11.642,-7.4244,-0.28,NA,NA,NA,NA,NA
-Ne,NA,Ne,aq,AD03.2,NA,2019-02-21,cal,4565,NA,16.74,NA,20.4,1.0014,4.7976,0.5084,NA,NA,NA,NA,NA
-ethylene,NA,C2H4,aq,AD03.2,NA,2019-02-21,cal,19450,NA,28.7,NA,45.5,-16.8037,18.846,-0.4499,NA,NA,NA,NA,NA
-ethane,NA,C2H6,aq,AD03.2,NA,2019-02-21,cal,-4141,NA,26.75,NA,51.2,-16.3482,20.0628,-0.6091,NA,NA,NA,NA,NA
-propane,NA,C3H8,aq,AD03.2,NA,2019-02-21,cal,-2021,NA,33.49,NA,67,-25.3879,28.2616,-1.1471,NA,NA,NA,NA,NA
-butane,NA,C4H10,aq,AD03.2,NA,2019-02-21,cal,99,NA,39.66,NA,82.8,-33.8492,36.1457,-1.6849,NA,NA,NA,NA,NA
-benzene,NA,C6H6,aq,AD03.2,NA,2019-02-21,cal,32000,NA,35.62,NA,83.5,-39.109,37.5421,-1.9046,NA,NA,NA,NA,NA
-HF,NA,HF,aq,AD03.2,NA,2019-02-21,cal,-71662,NA,22.5,NA,12.5,3.0888,-3.5714,0.1008,NA,NA,NA,NA,NA
-SO2,NA,SO2,aq,AD03.2,NA,2019-02-21,cal,-71980,NA,38.7,NA,38.5,-14.5223,14.3512,-0.4295,NA,NA,NA,NA,NA
-B(OH)3,NA,B(OH)3,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,-4.2561,4.0194,-1.057,NA,NA,NA,NA,NA
-Si(OH)4,NA,Si(OH)4,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,0.9285,-0.9409,-1.8933,NA,NA,NA,NA,NA
-As(OH)3,NA,As(OH)3,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,-9.903,7.6818,-1.23,NA,NA,NA,NA,NA
-B(OH)3,NA,B(OH)3,gas,AP14,NA,2019-02-22,cal,-222523.9,NA,66.589,NA,0,46.7734,-0.097,0.5932,-522.4665,0,0,0,1000
-Si(OH)4,NA,Si(OH)4,gas,AP14,NA,2019-02-22,cal,-296285.9,NA,82.784,NA,0,22.9685,37.6434,-4.4407,0,-2.7782,7.923E-09,3,1000
-As(OH)3,NA,As(OH)3,gas,AP14,NA,2019-02-22,cal,-143112.8,NA,73.599,NA,0,22.6338,-16.3623,-3.7213,0,-1.0194,2.7414E-09,3,1000
+Ar,AkDi,Ar,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.5139,11.921,0.0733,NA,NA,NA,NA,NA
+H2S,AkDi,H2S,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-13.4046,13.8582,-0.2029,NA,NA,NA,NA,NA
+O2,AkDi,O2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-9.754,12.9411,0.026,NA,NA,NA,NA,NA
+N2,AkDi,N2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-11.538,14.6278,-0.032,NA,NA,NA,NA,NA
+NH3,AkDi,NH3,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-4.7245,4.9782,-0.0955,NA,NA,NA,NA,NA
+H2,AkDi,H2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.4596,10.8301,0.309,NA,NA,NA,NA,NA
+CH4,AkDi,CH4,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-11.8462,14.8615,-0.1131,NA,NA,NA,NA,NA
+CO2,AkDi,CO2,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-8.8321,11.2684,-0.085,NA,NA,NA,NA,NA
+benzene,AkDi,C6H6,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,-21.0084,22.934,-1.101,NA,NA,NA,NA,NA
+HCl,AkDi,HCl,aq,AD03.1,NA,2019-02-20,cal,NA,NA,NA,NA,NA,11.642,-7.4244,-0.28,NA,NA,NA,NA,NA
+Ne,AkDi,Ne,aq,AD03.2,NA,2019-02-21,cal,4565,NA,16.74,NA,20.4,1.0014,4.7976,0.5084,NA,NA,NA,NA,NA
+ethylene,AkDi,C2H4,aq,AD03.2,NA,2019-02-21,cal,19450,NA,28.7,NA,45.5,-16.8037,18.846,-0.4499,NA,NA,NA,NA,NA
+ethane,AkDi,C2H6,aq,AD03.2,NA,2019-02-21,cal,-4141,NA,26.75,NA,51.2,-16.3482,20.0628,-0.6091,NA,NA,NA,NA,NA
+propane,AkDi,C3H8,aq,AD03.2,NA,2019-02-21,cal,-2021,NA,33.49,NA,67,-25.3879,28.2616,-1.1471,NA,NA,NA,NA,NA
+butane,AkDi,C4H10,aq,AD03.2,NA,2019-02-21,cal,99,NA,39.66,NA,82.8,-33.8492,36.1457,-1.6849,NA,NA,NA,NA,NA
+benzene,AkDi,C6H6,aq,AD03.2,NA,2019-02-21,cal,32000,NA,35.62,NA,83.5,-39.109,37.5421,-1.9046,NA,NA,NA,NA,NA
+HF,AkDi,HF,aq,AD03.2,NA,2019-02-21,cal,-71662,NA,22.5,NA,12.5,3.0888,-3.5714,0.1008,NA,NA,NA,NA,NA
+SO2,AkDi,SO2,aq,AD03.2,NA,2019-02-21,cal,-71980,NA,38.7,NA,38.5,-14.5223,14.3512,-0.4295,NA,NA,NA,NA,NA
+B(OH)3,AkDi,B(OH)3,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,-4.2561,4.0194,-1.057,NA,NA,NA,NA,NA
+Si(OH)4,AkDi,Si(OH)4,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,0.9285,-0.9409,-1.8933,NA,NA,NA,NA,NA
+As(OH)3,AkDi,As(OH)3,aq,AP14,NA,2019-02-22,cal,NA,NA,NA,NA,NA,-9.903,7.6818,-1.23,NA,NA,NA,NA,NA
+B(OH)3,AkDi,B(OH)3,gas,AP14,NA,2019-02-22,cal,-222523.9,NA,66.589,NA,0,46.7734,-0.097,0.5932,-522.4665,0,0,0,1000
+Si(OH)4,AkDi,Si(OH)4,gas,AP14,NA,2019-02-22,cal,-296285.9,NA,82.784,NA,0,22.9685,37.6434,-4.4407,0,-2.7782,7.923E-09,3,1000
+As(OH)3,AkDi,As(OH)3,gas,AP14,NA,2019-02-22,cal,-143112.8,NA,73.599,NA,0,22.6338,-16.3623,-3.7213,0,-1.0194,2.7414E-09,3,1000

Modified: pkg/CHNOSZ/man/add.OBIGT.Rd
===================================================================
--- pkg/CHNOSZ/man/add.OBIGT.Rd	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/man/add.OBIGT.Rd	2021-04-07 10:20:48 UTC (rev 667)
@@ -38,14 +38,15 @@
 As a result, retrieving the properties of an added aqueous species using \code{\link{info}} requires an explicit \code{state="aq"} argument to that function if a species with the same name is present in one of the cr, liq or gas states.
 
 \code{mod.OBIGT} changes one or more of the properties of species or adds species to the thermodynamic database.
-These changes are lost if you reload the database by calling \code{\link{data}(thermo)} or if you quit the \R session without saving it.
+These changes are lost if you reload the database by calling \code{\link{reset}} or \code{\link{OBIGT}} or if you quit the \R session without saving it.
 The name of the species to add or change must be supplied as the first argument of \code{...} or as a named argument (named \samp{name}).
 When adding new species, a chemical formula should be included along with the values of any of the thermodynamic properties.
 The formula is taken from the \samp{formula} argument, or if that is missing, is taken to be the same as the \samp{name} of the species.
 An error results if the formula is not valid (i.e. can not be parsed by \code{\link{makeup}}).
-Additional arguments refer to the name of the property(s) to be updated and are matched to any part of compound column names in \code{\link{thermo}$OBIGT}, such as \samp{z} or \samp{T} in \samp{z.T}.
-Unless \samp{state} is specified as one of the properties, its value is taken from \code{thermo()$opt$state}.
-When adding species, properties that are not specified become NA, except for \samp{state}, which takes a default value from \code{thermo()$opt$state}, and \samp{z.T}, which for aqueous species is set to the charge calculated from the chemical formula (otherwise, NA charge for newly added species would trigger the \code{\link{AkDi}} model).
+
+Additional arguments to \code{mod.OBIGT} refer to the name of the property(s) to be updated and are matched to any part of compound column names in \code{\link{thermo}()$OBIGT}.
+For instance, either \samp{z} or \samp{T} matches the \samp{z.T} column.
+When adding species, properties that are not specified become NA, except for \samp{state}, which takes a default value from \code{thermo()$opt$state}.
 The values provided should have energy units correponding to the current setting (\code{\link{E.units}}), but this can be overridden by giving a value for \samp{E_units} in the new data.
 The values provided should also include any order-of-magnitude scaling factors (see \code{\link{thermo}}).
 }

Modified: pkg/CHNOSZ/man/eos.Rd
===================================================================
--- pkg/CHNOSZ/man/eos.Rd	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/man/eos.Rd	2021-04-07 10:20:48 UTC (rev 667)
@@ -47,8 +47,9 @@
 For both \code{hkf} and \code{cgl}, if at least one equations-of-state parameter for a species is provided, any NA values of the other parameters are reset to zero.
 If all equations-of-state parameters are NA, but values of \samp{Cp} and/or \samp{V} are available, those values are used in the integration of \samp{G}, \samp{H} and \samp{S} as a function of temperature. 
 
-\code{AkDi} provides the Akinfiev-Diamond model for aqueous species (Akinfiev and Diamond, 2003).
-To run this code, the database must also include the corresponding gasesous species (with the same name or chemical formula).
+\code{AkDi} implements the Akinfiev-Diamond model for aqueous species (Akinfiev and Diamond, 2003).
+This model is activated by setting \code{abbrv = "AkDi"} in \code{thermo()$OBIGT} for a given aqueous species.
+The database must also include the corresponding gasesous species (with the same name or chemical formula).
 Currently, only the standard chemical potential (Gibbs energy) is calculated.
 
 }

Modified: pkg/CHNOSZ/tests/testthat/test-eos.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-eos.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/tests/testthat/test-eos.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -80,8 +80,8 @@
 
 test_that("AkDi produces expected results", {
   # 20190220
-  # modify aqueous CO2 to use the AkDi model: it has NA for Z
-  iCO2 <- mod.OBIGT("CO2", a=-8.8321, b=11.2684, c=-0.0850, z=NA)
+  # modify aqueous CO2 to use the AkDi model
+  iCO2 <- mod.OBIGT("CO2", abbrv = "AkDi", a=-8.8321, b=11.2684, c=-0.0850)
   # do the properties we calculate match previously calculated values?
   P <- "Psat"
   T <- seq(50, 350, 100)

Modified: pkg/CHNOSZ/tests/testthat/test-info.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-info.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/tests/testthat/test-info.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -35,8 +35,8 @@
 })
 
 test_that("info() gives correct column names for species using the AkDi model", {
-  # add an aqueous species conforming to the AkDi model: it has NA for Z
-  iCO2 <- mod.OBIGT("CO2", a = -8.8321, b = 11.2684, c = -0.0850, z = NA)
+  # add an aqueous species conforming to the AkDi model
+  iCO2 <- mod.OBIGT("CO2", abbrv = "AkDi", a = -8.8321, b = 11.2684, c = -0.0850)
   params <- info(iCO2)
   expect_equal(params$a, -8.8321)
   expect_equal(params$b, 11.2684)

Modified: pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R	2021-04-07 06:38:16 UTC (rev 666)
+++ pkg/CHNOSZ/tests/testthat/test-mod.OBIGT.R	2021-04-07 10:20:48 UTC (rev 667)
@@ -11,8 +11,6 @@
                "please supply a valid chemical formula")
   # the default state is aq
   expect_message(itest <- mod.OBIGT("test", formula="Z0", date=as.character(Sys.Date())), "added test\\(aq\\)")
-  # set the charge so following test use hkf() rather than AkDi()
-  mod.OBIGT("test", z = 0)
   # we should get NA values of G for a species with NA properties 
   expect_true(all(is.na(subcrt(itest)$out[[1]]$G)))
   # a single value of G comes through to subcrt



More information about the CHNOSZ-commits mailing list