[CHNOSZ-commits] r225 - in pkg/CHNOSZ: . R data demo inst man tests/testthat

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 29 08:24:08 CEST 2017


Author: jedick
Date: 2017-09-29 08:24:07 +0200 (Fri, 29 Sep 2017)
New Revision: 225

Added:
   pkg/CHNOSZ/data/CHNOSZ.R
   pkg/CHNOSZ/data/OBIGT.R
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/EOSregress.R
   pkg/CHNOSZ/R/add.obigt.R
   pkg/CHNOSZ/R/cgl.R
   pkg/CHNOSZ/R/hkf.R
   pkg/CHNOSZ/R/subcrt.R
   pkg/CHNOSZ/R/util.misc.R
   pkg/CHNOSZ/demo/DEW.R
   pkg/CHNOSZ/demo/adenine.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/add.obigt.Rd
   pkg/CHNOSZ/man/data.Rd
   pkg/CHNOSZ/man/eos.Rd
   pkg/CHNOSZ/man/water.Rd
   pkg/CHNOSZ/tests/testthat/test-subcrt.R
Log:
add data(OBIGT) and data(CHNOSZ)


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/DESCRIPTION	2017-09-29 06:24:07 UTC (rev 225)
@@ -1,6 +1,6 @@
-Date: 2017-09-28
+Date: 2017-09-29
 Package: CHNOSZ
-Version: 1.1.0-23
+Version: 1.1.0-24
 Title: Thermodynamic Calculations for Geobiochemistry
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/R/EOSregress.R
===================================================================
--- pkg/CHNOSZ/R/EOSregress.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/EOSregress.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -5,14 +5,14 @@
 
 Cp_s_var <- function(T=298.15, P=1, omega.PrTr=0, Z=0) {
   # solvation contribution to heat capacity in the HKF EOS, divided by omega(Pr,Tr) (calories)
-  Cp_s <- hkf("Cp", T=T, P=P, parameters=data.frame(omega=omega.PrTr, Z=Z), contrib="s")$aq
+  Cp_s <- hkf("Cp", parameters=data.frame(omega=omega.PrTr, Z=Z), T=T, P=P, contrib="s")$aq
   return(Cp_s[[1]][, 1]/omega.PrTr)
 }
 
 V_s_var <- function(T=298.15, P=1, omega.PrTr=0, Z=0) {
   # solvation contribution to volume in the HKF EOS, divided by omega(Pr,Tr) (cm3.bar)
   # [the negative sign on this term as written in the HKF EOS is accounted for by hkf()]
-  V_s <- hkf("V", T=T, P=P, parameters=data.frame(omega=omega.PrTr, Z=Z), contrib="s")$aq
+  V_s <- hkf("V", parameters=data.frame(omega=omega.PrTr, Z=Z), T=T, P=P, contrib="s")$aq
   return(V_s[[1]][, 1]/convert(omega.PrTr, "cm3bar"))
 }
 

Modified: pkg/CHNOSZ/R/add.obigt.R
===================================================================
--- pkg/CHNOSZ/R/add.obigt.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/add.obigt.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -108,6 +108,13 @@
   sysnosuffix <- sapply(strsplit(sysfiles, "\\."), "[", 1)
   isys <- match(file, sysnosuffix)
   if(!is.na(isys)) file <- system.file(paste0("extdata/OBIGT/", sysfiles[isys]), package="CHNOSZ")
+  else {
+    # we also match single system files with the state suffix removed
+    # (e.g. "DEW" for "DEW_aq", but not "organic" because we have "organic_aq", "organic_cr", etc.)
+    sysnostate <- sapply(strsplit(sysnosuffix, "_"), "[", 1)
+    isys <- which(file==sysnostate)
+    if(length(isys)==1) file <- system.file(paste0("extdata/OBIGT/", sysfiles[isys]), package="CHNOSZ")
+  }
   # read data from the file
   to2 <- read.csv(file, as.is=TRUE)
   # load only selected species if requested

Modified: pkg/CHNOSZ/R/cgl.R
===================================================================
--- pkg/CHNOSZ/R/cgl.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/cgl.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -2,7 +2,7 @@
 # calculate standard thermodynamic properties of non-aqueous species
 # 20060729 jmd
 
-cgl <- function(property=NULL,T=298.15,P=1,parameters=NULL) {
+cgl <- function(property=NULL,parameters=NULL,T=298.15,P=1) {
   # calculate properties of crystalline, liquid (except H2O) and gas species
   # argument handling
   thermo <- get("thermo")

Modified: pkg/CHNOSZ/R/hkf.R
===================================================================
--- pkg/CHNOSZ/R/hkf.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/hkf.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -5,7 +5,7 @@
 ## if this file is interactively sourced, the following is also needed to provide unexported functions:
 #source("util.args.R")
 
-hkf <- function(property = NULL, T = 298.15, P = 1, parameters = NULL,
+hkf <- function(property = NULL, parameters = NULL, T = 298.15, P = 1,
   contrib = c('n', 's', 'o'), H2O.props="rho") {
   # calculate G, H, S, Cp, V, kT, and/or E using
   # the revised HKF equations of state

Modified: pkg/CHNOSZ/R/subcrt.R
===================================================================
--- pkg/CHNOSZ/R/subcrt.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/subcrt.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -282,7 +282,7 @@
     H2O.props <- "rho"
     # get other properties for H2O only if it's in the reaction
     if(any(isH2O)) H2O.props <- c(H2O.props, eosprop)
-    hkfstuff <- hkf(eosprop, T = T, P = P, parameters = si, H2O.props=H2O.props)
+    hkfstuff <- hkf(eosprop, parameters = si, T = T, P = P, H2O.props=H2O.props)
     p.aq <- hkfstuff$aq
     H2O.PT <- hkfstuff$H2O
     if(any(IS != 0)) p.aq <- nonideal(inpho[isaq], p.aq, newIS, T)
@@ -299,7 +299,7 @@
   if(TRUE %in% iscgl) {
     #si <- info(inpho[iscgl],quiet=TRUE)
     si <- obigt2eos(thermo$obigt[inpho[iscgl],], "cgl", fixGHS = TRUE)
-    p.cgl <- cgl(eosprop, T = T, P = P, parameters = si)
+    p.cgl <- cgl(eosprop, parameters = si, T = T, P = P)
     # replace Gibbs energies with NA where the
     # phases are beyond their temperature range
     if('g' %in% eosprop) {

Modified: pkg/CHNOSZ/R/util.misc.R
===================================================================
--- pkg/CHNOSZ/R/util.misc.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/R/util.misc.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -48,18 +48,18 @@
       # set the starting GHS to 0 (in case they're NA - we only need the increments over temperature)
       thisinfo$G <- thisinfo$H <- thisinfo$S <- 0
       # the HS increments from 298.15 to Ttr
-      HSinc <- cgl(c("H", "S"), T=c(298.15, Ttr), parameters=thisinfo)
+      HSinc <- cgl(c("H", "S"), parameters=thisinfo, T=c(298.15, Ttr))
       Hf_Tr <- c(Hf_Tr, Hf - diff(HSinc[[1]]$H))
       S_Tr <- c(S_Tr, S - diff(HSinc[[1]]$S))
       # plug in the calculated S_Tr to calculate the G increment correctly
       thisinfo$S <- tail(S_Tr, 1)
-      Ginc <- cgl("G", T=c(298.15, Ttr), parameters=thisinfo)
+      Ginc <- cgl("G", parameters=thisinfo, T=c(298.15, Ttr))
       Gf_Tr <- c(Gf_Tr, Gf - diff(Ginc[[1]]$G))
     }
     # the temperature of the next transition
     Ttr <- thisinfo$T
     # the GHS increments from Tprev to Ttr
-    GHCinc <- cgl(c("G", "H", "S"), T=c(Tprev, Ttr), parameters=thisinfo)
+    GHCinc <- cgl(c("G", "H", "S"), parameters=thisinfo, T=c(Tprev, Ttr))
     # the GHS + transition at Tr
     Gf <- Gf + diff(GHCinc[[1]]$G)
     Hf <- Hf + diff(GHCinc[[1]]$H) + Htr[i]

Added: pkg/CHNOSZ/data/CHNOSZ.R
===================================================================
--- pkg/CHNOSZ/data/CHNOSZ.R	                        (rev 0)
+++ pkg/CHNOSZ/data/CHNOSZ.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -0,0 +1,21 @@
+# CHNOSZ/data/CHNOSZ.R
+# clear system settings (basis/species)
+
+# we only work if the CHNOSZ environment exists
+if(!"CHNOSZ" %in% search()) {
+  message("data(CHNOSZ): please run data(thermo) first")
+} else {
+
+  local({
+    # get thermo from CHNOSZ environment
+    thermo <- get("thermo", "CHNOSZ")
+    # set basis,species components
+    thermo$basis <- NULL
+    thermo$species <- NULL
+    # place it in CHNOSZ environment
+    assign("thermo", thermo, "CHNOSZ")
+  })
+
+  message("data(CHNOSZ): cleared basis and species settings")
+
+}

Added: pkg/CHNOSZ/data/OBIGT.R
===================================================================
--- pkg/CHNOSZ/data/OBIGT.R	                        (rev 0)
+++ pkg/CHNOSZ/data/OBIGT.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -0,0 +1,40 @@
+# CHNOSZ/data/OBIGT.R
+# default thermodynamic data (OBIGT) in thermo
+
+# we only work if the CHNOSZ environment exists
+if(!"CHNOSZ" %in% search()) {
+  message("data(OBIGT): please run data(thermo) first")
+} else {
+
+  local({
+    # create obigt data frame
+    sources_aq <- paste0(c("H2O", "inorganic", "organic", "biotic"), "_aq")
+    sources_cr <- paste0(c("inorganic", "organic"), "_cr")
+    sources_liq <- paste0(c("organic"), "_liq")
+    sources_gas <- paste0(c("inorganic", "organic"), "_gas")
+    OBIGTdir <- system.file("extdata/OBIGT/", package="CHNOSZ")
+    # need explicit "/" for Windows
+    sourcefiles <- paste0(OBIGTdir, "/", c(sources_aq, sources_cr, sources_liq, sources_gas), ".csv.xz")
+    datalist <- lapply(sourcefiles, read.csv, as.is=TRUE)
+    obigt <- do.call(rbind, datalist)
+    # get thermo from CHNOSZ environment
+    thermo <- get("thermo", "CHNOSZ")
+    # set obigt component
+    thermo$obigt <- obigt
+    # place thermo in CHNOSZ environment
+    assign("thermo", thermo, "CHNOSZ")
+  })
+
+  # give a summary of some of the data
+  message(paste("thermo$obigt:",
+    nrow(thermo$obigt[thermo$obigt$state=="aq",]),
+    "aqueous,", nrow(thermo$obigt), "total species"))
+
+  # warn if there are duplicated species
+  local({
+    idup <- duplicated(paste(thermo$obigt$name, thermo$obigt$state))
+    if(any(idup)) warning("thermo$obigt: duplicated species: ", 
+      paste(thermo$obigt$name[idup], "(", thermo$obigt$state[idup], ")", sep="", collapse=" "))
+  })
+
+}

Modified: pkg/CHNOSZ/demo/DEW.R
===================================================================
--- pkg/CHNOSZ/demo/DEW.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/demo/DEW.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -4,7 +4,7 @@
 par(mfrow = c(2, 2), mar=c(3.0, 3.5, 2.5, 1.0), mgp=c(1.7, 0.3, 0), las=1, tcl=0.3, xaxs="i", yaxs="i")
 
 # activate DEW model
-water("DEW")
+oldwat <- water("DEW")
 
 #### plot 1: quartz solubility at high pressure
 ## after Figure 7D of Sverjensky et al., 2014 
@@ -52,7 +52,7 @@
 # load the fitted parameters for species as used by SHA14
 # TODO: also use their Ca+2??
 # NOTE: don't load NaCl, NH4+, or HS- here because the DEW spreadsheet lists a1 from the correlation
-add.obigt("DEW_aq", c("CO3-2", "BO2-", "MgCl+", "SiO2", "HCO3-", "Si2O4"))
+add.obigt("DEW", c("CO3-2", "BO2-", "MgCl+", "SiO2", "HCO3-", "Si2O4"))
 # set up the plot
 V0nlab <- expression(Delta * italic(V) * degree[n]~~(cm^3~mol^-1))
 a1lab <- expression(italic(a)[1]%*%10~~(cal~mol~bar^-1))
@@ -63,7 +63,7 @@
   par <- info(info(species))
   a1 <- par$a1 * 10
   # get the nonsolvation volume
-  Vn <- unlist(hkf("V", parameters=par, contrib="n")$aq)
+  Vn <- unlist(hkf("V", par, contrib="n")$aq)
   points(Vn, a1, col=col, pch=pch, cex=cex)
   for(i in 1:length(species)) text(Vn[i], a1[i]+dy, expr.species(species[i]))
   arrows(Vn, a1 - error, Vn, a1 + error, length = 0.03, angle = 90, code = 3, col=col)
@@ -104,6 +104,7 @@
 }
 
 # first plot: CHNOSZ default database
+data(OBIGT)
 dfun()
 t1 <- quote("CHNOSZ default database"[])
 t2 <- quote("(not recommended for high"~italic(P)*")")
@@ -115,5 +116,6 @@
 DEWexpr <- substitute("DEW data for"~x, list(x=CO2quote))
 mtitle(as.expression(c(DEWexpr, "and methane")))
 
-# reset the database (including the default water computational option)
-data(thermo)
+# reset the database and previous water computational option
+data(OBIGT)
+water(oldwat)

Modified: pkg/CHNOSZ/demo/adenine.R
===================================================================
--- pkg/CHNOSZ/demo/adenine.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/demo/adenine.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -113,5 +113,5 @@
   legend=c("HKF model (LaRowe and Helgeson, 2006)",
   "density model (Lowe et al., 2017)", "HKF model (fit by Lowe et al., 2017 using CHNOSZ)")
 )
-# reset database
+# reset database and computational settings
 data(thermo)

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/inst/NEWS	2017-09-29 06:24:07 UTC (rev 225)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.0-23 (2017-09-28)
+CHANGES IN CHNOSZ 1.1.0-24 (2017-09-29)
 ---------------------------------------
 
 MAJOR CHANGES:
@@ -8,7 +8,7 @@
   calculateGibbsofWater(), calculateEpsilon(), calculateQ(), and
   water.DEW().
 
-- The computational option for water (thermo$opt$par) can now be
+- The computational setting for water (thermo$opt$par) can now be
   set using water("DEW"), water("IAPWS"), etc.
 
 - Add demo DEW.R.
@@ -17,6 +17,11 @@
   logfH2, or logaH2 vs pH, T, or P. It is possible to have T or P on
   either the x- or y-axis.
 
+- Add data(OBIGT) and data(CHNOSZ) commands to reset only the
+  thermodynamic database (OBIGT) or system settings (CHNOSZ: basis and
+  species) to their defaults. data(thermo) is still used to reset
+  *everything* (the database and all computational and system settings).
+
 DATABASE UPDATES:
 
 - Add DEW_aq.csv with aqueous species data from the DEW spreadsheet

Modified: pkg/CHNOSZ/man/add.obigt.Rd
===================================================================
--- pkg/CHNOSZ/man/add.obigt.Rd	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/man/add.obigt.Rd	2017-09-29 06:24:07 UTC (rev 225)
@@ -23,11 +23,14 @@
 }
 
 \details{
-
 \code{\link{add.obigt}} is used to update the thermodynamic database (\code{\link{thermo}$obigt}) in the running session.
-The format (column names) of the file must be the same as the \code{extdata/OBIGT/*.csv} files provided with CHNOSZ.
-\code{file} can be the path to a user-supplied file or the name, sans any file suffixes, of any file in the \code{extdata/OBIGT} directory packaged with CHNOSZ (e.g. \samp{DEW_aq} or \samp{organic_aq}).
+The format (column names) of the specified file must be the same as the \code{extdata/OBIGT/*.csv} files provided with CHNOSZ.
 
+\code{file} is first matched against the names of files in the \code{extdata/OBIGT} directory packaged with CHNOSZ.
+In this case, the filename suffixes are removed, so \samp{DEW_aq}, \samp{organic_aq}, and \samp{organic_cr} are valid names.
+The function also accepts single matches with the state suffix dropped (\samp{DEW} but not \samp{organic}).
+If there are no matches to a system file, then \code{file} is interpreted as the path a user-supplied file.
+
 If \code{species} is NULL (default), all species listed in the file are used.
 If \code{species} is given and matches the name(s) of species in the file, only those species are added to the database.
 
@@ -75,7 +78,7 @@
 # retrieve the species data (thermodynamic properties in this toy example are NA)
 info(info("C60"))
 # reset database
-data(thermo)
+data(OBIGT)
 
 # using add.obigt():
 # compare stepwise stability constants of cadmium chloride complexes
@@ -92,7 +95,8 @@
   subcrt(c(Cdspecies[i], "Cl-", Cdspecies[i+1]),
     c(-1, -1, 1), T=25, P=P)$out$logK
 })
-data(thermo)
+# reset default database
+data(OBIGT)
 matplot(P, do.call(cbind, SSH97), type="l")
 matplot(P, do.call(cbind, BZA10), type="l", add=TRUE, lwd=2)
 legend("topleft", legend=c("", "", "Sverjensky et al., 1997",

Modified: pkg/CHNOSZ/man/data.Rd
===================================================================
--- pkg/CHNOSZ/man/data.Rd	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/man/data.Rd	2017-09-29 06:24:07 UTC (rev 225)
@@ -3,27 +3,39 @@
 \docType{data}
 \alias{thermo}
 \alias{OBIGT}
+\alias{CHNOSZ}
 \alias{opt}
 \alias{element}
 \alias{refs}
 \alias{groups}
 \alias{buffers}
-\title{Thermodynamic Database and System Definition}
+\title{Thermodynamic Database and System Settings}
 \description{
-Data files provided with CHNOSZ are in the \code{data} and \code{extdata} directories of the package.
-The \code{*.csv} files under \code{data} and \code{extdata/OBIGT} are used to build the \code{thermo} data object on loading the package.
-Other data files, supporting the examples and vignettes, are documented separately at \code{\link{extdata}}. 
+Run \code{data(thermo)} to initialize all of the data used in CHNOSZ.
+This includes the computational settings, thermodynamic database, and system settings (chemical species).
 
-The \code{thermo} object holds the thermodynamic database of properties of species, some thermodynamic constants and operational parameters for functions in CHNOSZ, the properties of elements, references to literature sources of thermodynamic data, compositions of chemical activity buffers, and amino acid compositions of proteins.
-The \code{thermo} object also holds intermediate data used in calculations, in particular the definitions of basis species and species of interest input by the user, and the calculated properties of \code{\link{water}} so that subsequent calculations at the same temperature-pressure conditions can be accelerated.
+The system settings are changed using \code{\link{basis}} and \code{\link{species}}.
+To restore the default system settings (no species loaded), use \code{data(CHNOSZ)}.
 
-The \code{thermo} object is a \code{\link{list}} composed of \code{\link{data.frame}}s or lists each representing a class of data.
-The object is created in an environment named \code{thermo}.
-At any time, the user can restore the data object to its initial state by calling \code{data(thermo)}.
-This is sometimes a useful command to use during an interactive session, when previous definitions of basis species and species of interest are longer desired.
+The thermodynamic database is changed using \code{\link{add.obigt}} and \code{\link{mod.obigt}}.
+To restore the default database, use \code{data(OBIGT)}.
+
+The computational settings are changed using \code{\link{water}}, \code{\link{P.units}}, \code{\link{T.units}}, \code{\link{E.units}} or by direct manipulation of \code{thermo$opt}, as well as some other commands (e.g. \code{\link{mod.buffer}}).
+To restore the default computational settings, thermodynamic database, and system settings, use \code{data(thermo)}.
+
+In an interactive session, use \code{data(thermo)} to restore the thermodynamic database and computational and system settings to their initial state.
+Or, use \code{data(CHNOSZ)} to clear the system settings (basis and species), or \code{data(OBIGT)} to restore the default database.
+
+The data files provided with CHNOSZ are in the \code{data} and \code{extdata/OBIGT} directories of the package.
+The \code{*.csv} files in these directories are used to build the \code{thermo} data object in an environment named \code{CHNOSZ}.
+The structure of the \code{thermo} object is described below.
 }
 
-\usage{data(thermo)}
+\usage{
+  data(thermo)
+  data(OBIGT)
+  data(CHNOSZ)
+}
 
 \format{
 
@@ -212,7 +224,9 @@
 
 } % end of format
 
-\seealso{ \code{\link{add.obigt}} }
+\seealso{
+Other data files, supporting the examples and vignettes, are documented separately at \code{\link{extdata}}. 
+}
 
 \examples{
 \dontshow{data(thermo)}

Modified: pkg/CHNOSZ/man/eos.Rd
===================================================================
--- pkg/CHNOSZ/man/eos.Rd	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/man/eos.Rd	2017-09-29 06:24:07 UTC (rev 225)
@@ -8,16 +8,16 @@
 }
 
 \usage{
-  cgl(property = NULL, T = 298.15, P = 1, parameters = NULL)
-  hkf(property = NULL, T = 298.15, P = 1, parameters = NULL,
+  cgl(property = NULL, parameters = NULL, T = 298.15, P = 1)
+  hkf(property = NULL, parameters = NULL, T = 298.15, P = 1,
     contrib = c("n", "s", "o"), H2O.props = "rho")
 }
 
 \arguments{
   \item{property}{character, name(s) of properties to calculate}
+  \item{parameters}{dataframe, species parameters as one or more rows from \code{thermo$obigt}}
   \item{T}{numeric, temperature(s) at which to calculate properties (K)}
   \item{P}{numeric, pressure(s) at which to calculate properties (bar)}
-  \item{parameters}{dataframe, species parameters as one or more rows from \code{thermo$obigt}}
   \item{contrib}{character, which contributions to consider in the revised HKF equations equations of state: (\code{n})onsolvation, (\code{s})olvation (the \eqn{\omega}{omega} terms), or (o)rigination contributions (i.e., the property itself at 25 \eqn{^{\circ}}{°}C and 1 bar). Default is \code{c("n","s","o")}, for all contributions}
   \item{H2O.props}{character, properties to calculate for water}
 }

Modified: pkg/CHNOSZ/man/water.Rd
===================================================================
--- pkg/CHNOSZ/man/water.Rd	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/man/water.Rd	2017-09-29 06:24:07 UTC (rev 225)
@@ -19,7 +19,7 @@
 }
 
 \arguments{
-  \item{property}{character, name(s) of property(s) to calculate, or name of computational option}
+  \item{property}{character, computational setting or property(s) to calculate}
   \item{T}{numeric, temperature (K)}
   \item{P}{numeric, pressure (bar), or \samp{Psat} for vapor-liquid saturation}
   \item{formulation}{character, name of formulation for which to return names of available properties}
@@ -40,11 +40,11 @@
 
 }
 
-Calling the function with no arguments returns the current computational option.
-Use e.g. \code{water("DEW")} to set the option; the previous option (at the time of the function call) is returned invisibly.
-Subsequent calculations with \code{water}, or other functions such as \code{subcrt} and \code{affinity}, will use that option.
+Calling the function with no arguments returns the current computational setting.
+Use e.g. \code{water("DEW")} to make the setting; the previous setting (at the time of the function call) is returned invisibly.
+Subsequent calculations with \code{water}, or other functions such as \code{subcrt} and \code{affinity}, will use that setting.
 
-The allowed \code{property}s for \code{water} are one or more of those given below, depending on the computational option; availability is shown by an asterisk.
+The allowed \code{property}s for \code{water} are one or more of those given below, depending on the computational setting; availability is shown by an asterisk.
 The names of properties in the arguments are not case sensitive. Note that some of the properties that can actually be calculated using the different formulations are not implemented here.
 Except for \code{rho}, the units are those used by Johnson and Norton, 1991.
 

Modified: pkg/CHNOSZ/tests/testthat/test-subcrt.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-subcrt.R	2017-09-28 06:21:10 UTC (rev 224)
+++ pkg/CHNOSZ/tests/testthat/test-subcrt.R	2017-09-29 06:24:07 UTC (rev 225)
@@ -95,6 +95,38 @@
   water(oldwat)
 })
 
+test_that("calculations for quartz are consistent with SUPCRT92", {
+  # output from SUPCRT92 for reaction specified as "1 QUARTZ" run at 1 bar
+  # (SUPCRT shows phase transition at 574.850 deg C, and does not give Cp values around the transition)
+  S92_1bar <- read.table(header = TRUE, text = "
+      T       G       H    S       V
+    572	-214482	-209535	24.7	23.3
+    573	-214507	-209517	24.7	23.3
+    574	-214532	-209499	24.8	23.3
+    575	-214557	-209192	25.1	23.7
+    576	-214582	-209176	25.1	23.7
+    577	-214607	-209159	25.2	23.7
+  ")
+  CHNOSZ_1bar <- subcrt("quartz", T=seq(572, 577), P=1)$out[[1]]
+  expect_equal(CHNOSZ_1bar$G, S92_1bar$G, tolerance = 1e-5)
+  expect_equal(CHNOSZ_1bar$H, S92_1bar$H, tolerance = 1e-5)
+  expect_equal(CHNOSZ_1bar$S, S92_1bar$S, tolerance = 1e-2)
+#  expect_equal(CHNOSZ_1bar$V, S92_1bar$V, tolerance = 1e-2)
+
+  # output from SUPCRT92 for reaction specified as "1 QUARTZ" run at 500 bar
+  # (SUPCRT shows phase transition at 587.811 deg C)
+  S92_500bar <- read.table(header = TRUE, text = "
+      T       G       H    S       V
+    585	-214523	-209335	24.6	23.3
+    586	-214548	-209318	24.7	23.3
+    587	-214573	-209301	24.7	23.3
+    588	-214602	-208700	25.4	23.7
+    589	-214627	-208684	25.4	23.7
+    590	-214653	-208668	25.4	23.7
+  ")
+  CHNOSZ_500bar <- subcrt("quartz", T=seq(585, 590), P=500)$out[[1]]
+})
+
 # references
 
 # Amend, J. P. and Shock, E. L. (2001) 



More information about the CHNOSZ-commits mailing list