[CHNOSZ-commits] r214 - in pkg/CHNOSZ: . R inst man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 25 11:01:21 CEST 2017


Author: jedick
Date: 2017-09-25 11:01:21 +0200 (Mon, 25 Sep 2017)
New Revision: 214

Added:
   pkg/CHNOSZ/man/DEW.Rd
Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/NAMESPACE
   pkg/CHNOSZ/R/DEW.R
   pkg/CHNOSZ/R/water.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/water.Rd
Log:
add water.DEW()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/DESCRIPTION	2017-09-25 09:01:21 UTC (rev 214)
@@ -1,6 +1,6 @@
 Date: 2017-09-25
 Package: CHNOSZ
-Version: 1.1.0-12
+Version: 1.1.0-13
 Title: Thermodynamic Calculations for Geobiochemistry
 Author: Jeffrey Dick
 Maintainer: Jeffrey Dick <j3ffdick at gmail.com>

Modified: pkg/CHNOSZ/NAMESPACE
===================================================================
--- pkg/CHNOSZ/NAMESPACE	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/NAMESPACE	2017-09-25 09:01:21 UTC (rev 214)
@@ -57,7 +57,8 @@
   "water.SUPCRT92", "water.props", "eqdata", "plot_findit",
   "nonideal", "anim.TCA", "uniprot.aa", "run.guess",
 # added 20170301 or later
-  "GHS_Tr", "calculateDensity", "calculateGibbsOfWater", "calculateEpsilon", "calculateQ"
+  "GHS_Tr", "calculateDensity", "calculateGibbsOfWater",
+  "calculateEpsilon", "calculateQ", "water.DEW"
 )
 
 # Load shared objects

Modified: pkg/CHNOSZ/R/DEW.R
===================================================================
--- pkg/CHNOSZ/R/DEW.R	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/R/DEW.R	2017-09-25 09:01:21 UTC (rev 214)
@@ -2,7 +2,7 @@
 # R functions for the Deep Earth Water model
 # 20170924 jmd
 
-# Most code was translated from VBA macros in the DEW spreadsheet (DEW_May19_2017_11.0.2 .xlsm)
+# Most code here was translated from VBA macros in the DEW spreadsheet (DEW_May19_2017_11.0.2 .xlsm)
 # Comments starting with ' were transferred from the DEW spreadsheet
 # In the original, functions return zero for invalid input; here, NA is used instead
 
@@ -60,7 +60,6 @@
 
   # 'Equation created by Brandon Harrison. This models data for the Gibbs energy at 1 kb as a function of temperature,
   # 'then defines the gibbs free energy as the integral over the volume as a function of temperature.
-
   myfunction <- function(pressure, temperature) {
     # 'Gibbs Free Energy of water at 1 kb. This equation is a polynomial fit to data as a function of temperature.
     # 'It is valid in the range of 100 to 1000 C.

Modified: pkg/CHNOSZ/R/water.R
===================================================================
--- pkg/CHNOSZ/R/water.R	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/R/water.R	2017-09-25 09:01:21 UTC (rev 214)
@@ -303,3 +303,25 @@
   message("")
   return(w.out)
 }
+
+# get water properties from DEW model for use by subcrt() 20170925
+water.DEW <- function(property, T = 373.15, P = 1000) {
+  # convert temperature units
+  pressure <- P
+  temperature <- convert(T, "C")
+  # initialize output data frame with NA for all properties and conditions
+  ncond <- max(length(T), length(P))
+  out <- matrix(NA, ncol=length(property), nrow=ncond)
+  out <- as.data.frame(out)
+  colnames(out) <- property
+  # calculate rho if it's needed for any other properties
+  if(any(c("rho", "V", "QBorn", "diel") %in% property)) rho <- calculateDensity(pressure, temperature)
+  # fill in columns with values
+  if("rho" %in% property) out$rho <- rho
+  if("V" %in% property) out$V <- 18.01528/rho
+  if("G" %in% property) out$G <- calculateGibbsOfWater(pressure, temperature)
+  if("QBorn" %in% property) out$QBorn <- calculateQ(rho, temperature)
+  if("diel" %in% property) out$diel <- calculateEpsilon(rho, temperature)
+  out
+}
+

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/inst/NEWS	2017-09-25 09:01:21 UTC (rev 214)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.0-12 (2017-09-25)
+CHANGES IN CHNOSZ 1.1.0-13 (2017-09-25)
 ---------------------------------------
 
 - water.lines() now works for diagrams of Eh, pe, logfO2, logaO2,
@@ -34,8 +34,9 @@
   subcrt().
 
 - Add equations from the Deep Earth Water (DEW) model (Sverjensky
-  et al., 2014) in the exported functions calculateDensity(),
-  calculateGibbsofWater(), calculateEpsilon(), and calculateQ().
+  et al., 2014) in the functions calculateDensity(),
+  calculateGibbsofWater(), calculateEpsilon(), calculateQ(), and
+  the interface function water.DEW() for use by subcrt().
 
 CHANGES IN CHNOSZ 1.1.0 (2017-05-04)
 ------------------------------------

Added: pkg/CHNOSZ/man/DEW.Rd
===================================================================
--- pkg/CHNOSZ/man/DEW.Rd	                        (rev 0)
+++ pkg/CHNOSZ/man/DEW.Rd	2017-09-25 09:01:21 UTC (rev 214)
@@ -0,0 +1,57 @@
+\encoding{UTF-8}
+\name{DEW}
+\alias{DEW}
+\alias{calculateDensity}
+\alias{calculateGibbsOfWater}
+\alias{calculateEpsilon}
+\alias{calculateQ}
+\title{Deep Earth Water (DEW) Model}
+\description{
+Calculate thermodynamic properties of water using the Deep Earth Water (DEW) model.
+}
+
+\usage{
+  calculateDensity(pressure, temperature, error = 0.01)
+  calculateGibbsOfWater(pressure, temperature)
+  calculateEpsilon(density, temperature)
+  calculateQ(density, temperature)
+}
+
+\arguments{
+  \item{pressure}{numeric, pressure (bar)}
+  \item{temperature}{numeric, temperature (\degC)}
+  \item{error}{numeric, residual error for bisection calculation}
+  \item{density}{numeric, density (g/cm^3)}
+}
+
+\details{
+The Deep Earth Water (DEW) model, described by Sverjensky et al., 2014, extends the applicability of the revised HKF equations of state to 60 kbar.
+This implementation of DEW is based on the VBA macro code in the May, 2017 version of the DEW spreadsheet downloaded from \url{http://dewcommunity.org}.
+The spreadsheet provides multiple options for some calculations; here the default equations for density of water (Zhang and Duan, 2005), dielectric constant (Sverjensky et al., 2014) and Gibbs energy of water (integral of volume, equation created by Brandon Harrison) are used.
+
+Comments in the original code indicate that \code{calculateGibbsOfWater} is valid for 100 \le \T \le 1000 \degC and \P \ge 1000 bar.
+}
+
+\value{
+The calculated values of density, Gibbs energy, and the Q Born coefficient have units of g/cm^3, cal/mol, and bar^-1 (epsilon is dimensionless).
+}
+
+\seealso{
+}
+
+\examples{
+pressure <- c(1000, 60000)
+temperature <- c(100, 1000)
+calculateGibbsOfWater(pressure, temperature)
+(density <- calculateDensity(pressure, temperature))
+calculateEpsilon(density, temperature)
+calculateQ(density, temperature)
+}
+
+\references{
+Sverjensky, D. A., Harrison, B. and Azzolini, D. (2014) Water in the deep Earth: The dielectric constant and the solubilities of quartz and corundum to 60 kb and 1,200 \degC. \emph{Geochim. Cosmochim. Acta} \bold{129}, 125--145. \url{https://doi.org/10.1016/j.gca.2013.12.019}
+
+Zhang, Z. and Duan, Z. (2005) Prediction of the \emph{PVT} properties of water over wide range of temperatures and pressures from molecular dynamics simulation. \emph{Phys. Earth Planet. Inter.} \bold{149}, 335--354. \url{https://doi.org/10.1016/j.pepi.2004.11.003}
+}
+
+\concept{Secondary thermodynamic modeling}

Modified: pkg/CHNOSZ/man/water.Rd
===================================================================
--- pkg/CHNOSZ/man/water.Rd	2017-09-25 08:11:41 UTC (rev 213)
+++ pkg/CHNOSZ/man/water.Rd	2017-09-25 09:01:21 UTC (rev 214)
@@ -4,6 +4,7 @@
 \alias{water.props}
 \alias{water.SUPCRT92}
 \alias{water.IAPWS95}
+\alias{water.DEW}
 \title{Properties of Water}
 \description{
 Calculate thermodynamic and electrostatic properties of water.
@@ -14,6 +15,7 @@
   water.props(formulation = get("thermo")$opt$water)
   water.SUPCRT92(property, T = 298.15, P = 1)
   water.IAPWS95(property, T = 298.15, P = 1)
+  water.DEW(property, T = 373.15, P = 1000)
 }
 
 \arguments{
@@ -25,53 +27,61 @@
 
 \details{
 
-These functions compute the thermodynamic (Gibbs energy and it derivatives) and electrostatic (dielectric constant and its derivatives) properties of liquid or supercritical \H2O using equations of state taken from the literature.
-The high-level function \code{water} accepts two major computational alternatives.
-The default option (i.e., \code{\link{thermo}$opt$water} equal to \samp{SUPCRT92}) is retrieve thermodynamic and electrostatic properties as a function of temperature and pressure using a FORTRAN subroutine taken from the \acronym{SUPCRT92} software package (Johnson et al., 1992).
-If \code{thermo$opt$water} is set to \samp{IAPWS95}, the thermodynamic properties are calculated using an implementation in \R code of the IAPWS-95 formulation (Wagner and Pruss, 2002), and electrostatic properties are calculated using the equations of Archer and Wang, 1990.
+These functions compute the thermodynamic (Gibbs energy and it derivatives) and electrostatic (dielectric constant and its derivatives) properties of liquid or supercritical \H2O as a function of temperature and pressure using equations of state taken from the literature.
+The high-level function \code{water} performs different computations, depending on the setting of \code{\link{thermo}$opt$water}:
 
+\describe{
+
+  \item{\samp{SUPCRT92}}{(Default) Thermodynamic and electrostatic properties are calculated using a FORTRAN subroutine taken from the \acronym{SUPCRT92} software package (Johnson et al., 1992). See more information below.}
+
+  \item{\samp{IAPWS95}}{Thermodynamic properties are calculated using an implementation in \R code of the \acronym{IAPWS-95} formulation (Wagner and Pruss, 2002), and electrostatic properties are calculated using the equations of Archer and Wang, 1990. See \code{\link{IAPWS95}} and more information below.}
+
+  \item{\samp{DEW}}{Thermodynamic and electrostatic properties are calculated using the Deep Earth Water (\acronym{DEW}) model (Sverjensky et al., 2014). The defaults for \code{T} and \code{P} reflect the minimum values for applicability of the model. See \code{\link{DEW}}.}
+
+}
+
 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 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.
 
-  \tabular{lllll}{
-     Property \tab Description \tab Units \tab IAPWS95 \tab SUPCRT92 \cr
-     \code{A} \tab Helmholtz energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{G} \tab Gibbs energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{S} \tab Entropy \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{U} \tab Internal energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{H} \tab Enthalpy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{Cv} \tab Isochoric heat capacity \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{Cp} \tab Isobaric heat capacity \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{Speed} \tab Speed of sound \tab cm s\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{alpha} \tab Coefficient of isobaric expansivity \tab K\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{beta} \tab Coefficient of isothermal compressibility \tab bar\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{diel} \tab Dielectric constant \tab dimensionless \tab NA \tab * \cr
-     \code{visc} \tab Dynamic viscosity \tab g cm\eqn{^{-1}}{^-1} s\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{tcond} \tab Thermal conductivity \tab cal cm\eqn{^{-1}}{^-1} s\eqn{^{-1}}{^-1} K\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{tdiff} \tab Thermal diffusivity \tab cm\eqn{^2} s\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{Prndtl} \tab Prandtl number \tab dimensionless \tab NA \tab * \cr
-     \code{visck} \tab Kinematic viscosity \tab cm\eqn{^2} s\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{albe} \tab Isochoric expansivity \tab bar K\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \tab -compressibility \tab \tab \tab \cr
-     \code{ZBorn} \tab Z Born function \tab dimensionless \tab NA \tab * \cr
-     \code{YBorn} \tab Y Born function \tab K\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{QBorn} \tab Q Born function \tab bar\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{daldT} \tab Isobaric temperature derivative \tab K\eqn{^{-2}}{^-2} \tab NA \tab * \cr
-     \tab of expansibility \tab \tab \tab \cr
-     \code{XBorn} \tab X Born function \tab K\eqn{^{-2}}{^-2} \tab * \tab * \cr
-     \code{NBorn} \tab N Born function \tab bar\eqn{^{-2}}{^-2} \tab * \tab NA \cr
-     \code{UBorn} \tab U Born function \tab bar\eqn{^{-1}}{^-1} K\eqn{^{-1}}{^-1} \tab * \tab NA \cr
-     \code{V} \tab Volume \tab cm\eqn{^3} mol\eqn{^{-1}}{^-1} \tab * \tab * \cr
-     \code{rho} \tab Density \tab kg cm\eqn{^3} \tab * \tab * \cr     
-     \code{Psat} \tab Saturation vapor pressure \tab bar \tab * \tab * \cr
-     \code{E} \tab Isobaric expansivity \tab cm\eqn{^3} K\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{kT} \tab Isothermal compressibility \tab cm\eqn{^3} bar\eqn{^{-1}}{^-1} \tab NA \tab * \cr
-     \code{de.dT} \tab Temperature derivative \tab K\eqn{^{-1}}{^-1} \tab * \tab NA \cr
-     \tab of dielectric constant \tab \tab \tab \cr
-     \code{de.dP} \tab Pressure derivative \tab bar\eqn{^{-1}}{^-1} \tab * \tab NA \cr
-     \tab of dielectric constant \tab \tab \tab \cr
-     \code{P} \tab Pressure \tab bar \tab * \tab NA \cr
+  \tabular{llllll}{
+     Property \tab Description \tab Units \tab IAPWS95 \tab SUPCRT92 \tab DEW \cr
+     \code{A} \tab Helmholtz energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{G} \tab Gibbs energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \tab * \cr
+     \code{S} \tab Entropy \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{U} \tab Internal energy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{H} \tab Enthalpy \tab cal mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{Cv} \tab Isochoric heat capacity \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{Cp} \tab Isobaric heat capacity \tab cal K\eqn{^{-1}}{^-1} mol\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{Speed} \tab Speed of sound \tab cm s\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{alpha} \tab Coefficient of isobaric expansivity \tab K\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{beta} \tab Coefficient of isothermal compressibility \tab bar\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{diel} \tab Dielectric constant \tab dimensionless \tab NA \tab * \tab * \cr
+     \code{visc} \tab Dynamic viscosity \tab g cm\eqn{^{-1}}{^-1} s\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{tcond} \tab Thermal conductivity \tab cal cm\eqn{^{-1}}{^-1} s\eqn{^{-1}}{^-1} K\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{tdiff} \tab Thermal diffusivity \tab cm\eqn{^2} s\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{Prndtl} \tab Prandtl number \tab dimensionless \tab NA \tab * \tab NA \cr
+     \code{visck} \tab Kinematic viscosity \tab cm\eqn{^2} s\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{albe} \tab Isochoric expansivity \tab bar K\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \tab -compressibility \tab \tab \tab \tab \cr
+     \code{ZBorn} \tab Z Born function \tab dimensionless \tab NA \tab * \tab NA \cr
+     \code{YBorn} \tab Y Born function \tab K\eqn{^{-1}}{^-1} \tab * \tab * \tab NA \cr
+     \code{QBorn} \tab Q Born function \tab bar\eqn{^{-1}}{^-1} \tab * \tab * \tab * \cr
+     \code{daldT} \tab Isobaric temperature derivative \tab K\eqn{^{-2}}{^-2} \tab NA \tab * \tab NA \cr
+     \tab of expansibility \tab \tab \tab \tab \cr
+     \code{XBorn} \tab X Born function \tab K\eqn{^{-2}}{^-2} \tab * \tab * \tab NA \cr
+     \code{NBorn} \tab N Born function \tab bar\eqn{^{-2}}{^-2} \tab * \tab NA \tab NA \cr
+     \code{UBorn} \tab U Born function \tab bar\eqn{^{-1}}{^-1} K\eqn{^{-1}}{^-1} \tab * \tab NA \tab NA \cr
+     \code{V} \tab Volume \tab cm\eqn{^3} mol\eqn{^{-1}}{^-1} \tab * \tab * \tab * \cr
+     \code{rho} \tab Density \tab kg cm\eqn{^3} \tab * \tab * \tab * \cr     
+     \code{Psat} \tab Saturation vapor pressure \tab bar \tab * \tab * \tab NA \cr
+     \code{E} \tab Isobaric expansivity \tab cm\eqn{^3} K\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{kT} \tab Isothermal compressibility \tab cm\eqn{^3} bar\eqn{^{-1}}{^-1} \tab NA \tab * \tab NA \cr
+     \code{de.dT} \tab Temperature derivative \tab K\eqn{^{-1}}{^-1} \tab * \tab NA \tab NA \cr
+     \tab of dielectric constant \tab \tab \tab \tab \cr
+     \code{de.dP} \tab Pressure derivative \tab bar\eqn{^{-1}}{^-1} \tab * \tab NA \tab NA \cr
+     \tab of dielectric constant \tab \tab \tab \tab \cr
+     \code{P} \tab Pressure \tab bar \tab * \tab NA \tab NA \cr
   }
 
 \code{water.props} returns the names of the available properties listed in this table, reflecting the current setting of \code{thermo$opt$water}.
@@ -97,7 +107,7 @@
 
 
 \value{
-For \code{water} and \code{water.SUPCRT92} a data frame the number of rows of which corresponds to the number of input temperature, pressure and/or density values.
+A data frame, the number of rows of which corresponds to the number of input temperature-pressure pairs.
 }
 
 \seealso{
@@ -139,7 +149,7 @@
 }
 
 \references{
-Archer, D. G. and Wang, P. M. (1990) The dielectric constant of water and Debye-Huckel limiting law slopes. \emph{J. Phys. Chem. Ref. Data} \bold{19}, 371--411. \url{https://doi.org/10.1063/1.555853}
+Archer, D. G. and Wang, P. M. (1990) The dielectric constant of water and Debye-Hückel limiting law slopes. \emph{J. Phys. Chem. Ref. Data} \bold{19}, 371--411. \url{https://doi.org/10.1063/1.555853}
 
 Haar, L., Gallagher, J. S. and Kell, G. S. (1984) \emph{NBS/NRC Steam Tables}. Hemisphere, Washington, D. C., 320 p. \url{http://www.worldcat.org/oclc/301304139}
 
@@ -151,6 +161,8 @@
 
 Levelt-Sengers, J. M. H., Kamgarparsi, B., Balfour, F. W. and Sengers, J. V. (1983) Thermodynamic properties of steam in the critical region. \emph{J. Phys. Chem. Ref. Data} \bold{12}, 1--28. \url{https://doi.org/10.1063/1.555676}
 
+Sverjensky, D. A., Harrison, B. and Azzolini, D. (2014) Water in the deep Earth: The dielectric constant and the solubilities of quartz and corundum to 60 kb and 1,200 \degC. \emph{Geochim. Cosmochim. Acta} \bold{129}, 125--145. \url{https://doi.org/10.1016/j.gca.2013.12.019}
+
 Wagner, W. and Pruss, A. (2002) The IAPWS formulation 1995 for the thermodynamic properties of ordinary water substance for general and scientific use. \emph{J. Phys. Chem. Ref. Data} \bold{31}, 387--535. \url{https://doi.org/10.1063/1.1461829}
 }
 



More information about the CHNOSZ-commits mailing list