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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 2 12:54:47 CET 2019


Author: jedick
Date: 2019-02-02 12:54:46 +0100 (Sat, 02 Feb 2019)
New Revision: 379

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/mosaic.R
   pkg/CHNOSZ/demo/go-IU.R
   pkg/CHNOSZ/demo/mosaic.R
   pkg/CHNOSZ/inst/NEWS
   pkg/CHNOSZ/man/mosaic.Rd
   pkg/CHNOSZ/man/solubility.Rd
   pkg/CHNOSZ/tests/testthat/test-mosaic.R
   pkg/CHNOSZ/vignettes/mklinks.sh
Log:
mosaic(): change defaults to blend = TRUE and mixing = TRUE


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/DESCRIPTION	2019-02-02 11:54:46 UTC (rev 379)
@@ -1,6 +1,6 @@
-Date: 2019-02-01
+Date: 2019-02-02
 Package: CHNOSZ
-Version: 1.1.3-86
+Version: 1.1.3-87
 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/mosaic.R
===================================================================
--- pkg/CHNOSZ/R/mosaic.R	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/R/mosaic.R	2019-02-02 11:54:46 UTC (rev 379)
@@ -10,7 +10,7 @@
 #source("util.args.R")
 
 # function to calculate affinities with mosaic of basis species
-mosaic <- function(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...) {
+mosaic <- function(bases, bases2 = NULL, blend = TRUE, mixing = TRUE, ...) {
 
   # argument recall 20190120
   # if the first argument is the result from a previous mosaic() calculation,

Modified: pkg/CHNOSZ/demo/go-IU.R
===================================================================
--- pkg/CHNOSZ/demo/go-IU.R	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/demo/go-IU.R	2019-02-02 11:54:46 UTC (rev 379)
@@ -98,9 +98,9 @@
 bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
 # calculate affinties of formation reactions using the speciated S basis species
 res <- 300
-# we "blend" the transitions with pH, unlike LZ11's diagram where
+# the default has blend = TRUE, unlike LZ11's diagram where
 # it appears the S-basis species are switched in an on/off fashion
-m <- mosaic(bases, pH=c(0, 14, res), Eh=c(-0.8, 0.8, res), blend=TRUE)
+m <- mosaic(bases, pH=c(0, 14, res), Eh=c(-0.8, 0.8, res))
 # adjust colors and names
 fill <- rev(heat.colors(nrow(species())))
 fill[11:15] <- "darkgrey"

Modified: pkg/CHNOSZ/demo/mosaic.R
===================================================================
--- pkg/CHNOSZ/demo/mosaic.R	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/demo/mosaic.R	2019-02-02 11:54:46 UTC (rev 379)
@@ -9,8 +9,8 @@
 mod.obigt(c("SO4-2", "HS-", "H2S", "HSO4-"), G = c(-177340, 3010, -6540, -179940))
 mod.obigt(c("CO2", "HCO3-", "CO3-2"), G = c(-92310, -140310, -126220))
 # conditions and system definition
-pH <- c(0, 14, 400)
-Eh <- c(-1, 1, 400)
+pH <- c(0, 14, 500)
+Eh <- c(-1, 1, 500)
 T <- 25
 basis(c("FeO", "SO4-2", "H2O", "H+", "e-", "CO3-2"))
 basis("SO4-2", -6)
@@ -22,16 +22,16 @@
 # speciate CO3-2, HCO3-, CO2 as a function of pH
 bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
 bases2 <- c("CO3-2", "HCO3-", "CO2")
-# calculate affinities using the predominant basis species
-# using blend=TRUE we get curvy lines, particularly at the boundaries with siderite
-# compare with the plot in Garrels and Christ, 1965
-m1 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
+# calculate affinities using the relative abundances of different basis species
+# (using default blend = TRUE)
+# note curved lines, particularly at the boundaries with siderite
+m1 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
 # make a diagram and add water stability lines
 diagram(m1$A.species, lwd = 2)
 water.lines(m1$A.species, col = "seagreen", lwd = 1.5)
 # show lines for Fe(aq) = 10^-4 M
 species(c("Fe+2", "Fe+3"), -4)
-m2 <- mosaic(bases, bases2, blend = TRUE, pH = pH, Eh = Eh, T = T)
+m2 <- mosaic(bases, bases2, pH = pH, Eh = Eh, T = T)
 diagram(m2$A.species, add = TRUE, names = NULL)
 title(main=paste("Iron oxides, sulfides and carbonate in water, log(total S) = -6,",
   "log(total C)=0, after Garrels and Christ, 1965", sep = "\n"))

Modified: pkg/CHNOSZ/inst/NEWS
===================================================================
--- pkg/CHNOSZ/inst/NEWS	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/inst/NEWS	2019-02-02 11:54:46 UTC (rev 379)
@@ -1,4 +1,4 @@
-CHANGES IN CHNOSZ 1.1.3-86 (2019-02-01)
+CHANGES IN CHNOSZ 1.1.3-87 (2019-02-02)
 ---------------------------------------
 
 BUG FIXES
@@ -15,10 +15,6 @@
   NA where the density of H2O is less than 0.35 g/cm3, avoiding the
   output of bogus values in this region. Thanks to Evgeniy Bastrakov.
 
-- In mosaic() with blend = TRUE, add a previously missing term for
-  Gibbs energy of mixing. An example using mosaic() to calculate the
-  pH-dependent solubility of calcite has been added to solubility.Rd.
-
 - For systems where no basis species is present in all formation
   reactions, and the user hasn't provided balance coefficients, stop
   with an error instead of setting the balance cofficients to 1.
@@ -78,6 +74,12 @@
 - mosaic() has been rewritten to handle more than two changing groups
   of basis species.
 
+- mosaic() gets a new argument 'mixing' (default TRUE), indicating
+  whether the Gibbs energy of ideal mixing should be included in the
+  calculations with blend = TRUE. As a test of this change, an example
+  using mosaic() to calculate the pH-dependent solubility of calcite
+  has been added to solubility.Rd.
+
 DOCUMENTATION
 
 - Add demo/gold.R for calculations of Au solubility in hydrothermal

Modified: pkg/CHNOSZ/man/mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/mosaic.Rd	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/man/mosaic.Rd	2019-02-02 11:54:46 UTC (rev 379)
@@ -7,7 +7,7 @@
 }
 
 \usage{
-  mosaic(bases, bases2 = NULL, blend = FALSE, mixing = FALSE, ...)
+  mosaic(bases, bases2 = NULL, blend = TRUE, mixing = TRUE, ...)
 }
 
 \arguments{
@@ -20,24 +20,21 @@
 
 \details{
 
-\code{mosaic} can be used to calculate the reaction affinities when the basis species listed in \code{bases} change in relative abundance over the range of conditions, due to e.g. ionization, complexation or redox reactions.
-Chemical activity or predominance diagrams constructed by assembling sub-diagrams corresponding to the predominant basis species have sometimes been described as \dQuote{mosaic diagrams} in the literature.
+\code{mosaic} can be used to calculate the affinities of formation of species when the relative abundances of basis species listed in \code{bases} changes over the range of conditions, due to e.g. ionization, complexation or redox reactions.
 This is a way to \dQuote{speciate the basis species}.
 For example, the speciation of sulfur (\samp{SO4-2}, \samp{HSO4-}, \samp{HS-} and \samp{H2S}) as a function of Eh and pH affects the formation affinities, and therefore relative stabilities of iron oxide and sulfide minerals.
+Chemical activity diagrams constructed by assembling sub-diagrams corresponding to the predominant basis species can described as \dQuote{mosaic diagrams}.
 
-The function calculates the affinities using each basis species listed in \code{bases} in turn, changing them via \code{\link{swap.basis}}.
-The first species listed in \code{bases} should be in the current basis definition.
+The function calculates the affinities using all combination of basis species given as vector arguments to \code{bases} and \code{bases2}.
+The first species listed in each group should be in the current basis definition, and all the basis species in each group should be related to the first basis species there (i.e. all share the same element).
+A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
 The arguments in \code{...} are passed to \code{affinity} to specify the conditions.
-If \code{blend} is FALSE (the default), the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition.
-If \code{blend} is TRUE, the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition.
-Additionally, if \code{mixing} is TRUE, a term is included to account for the Gibbs energy of mixing.
+
+If \code{blend} is TRUE (the default), the function combines the affinities of the formation reactions in proportion to the relative abundances of the basis species at each condition.
+Additionally, if \code{mixing} is TRUE (the default), a term is included to account for the Gibbs energy of ideal mixing.
 See the second example in \code{\link{solubility}} for a numerical test of the calculations using \code{blend} and \code{mixing}.
+If \code{blend} is FALSE, the function returns the affinities calculated using the single predominant basis species in \code{bases} at each condition (in this case, the \code{mixing} argument has no effect).
 
-The basis species listed in \code{bases} should all be related to the first basis species there (i.e. all share the same element).
-A second, independent set of basis species can be provided in \code{bases2} (for example \samp{CO3-2}, \samp{HCO3-}, \samp{CO2}, if the first set of basis species are the sulfur-bearing ones listed above).
-The function then works recursively, by calling itself instead of \code{affinity}, so that the inner loop changes the basis species in \code{bases2}.
-In this way, all possible combinations of the two sets of basis species are used in the calculation.
-
 A more flexible method of specifying multiple sets of basis species is now available.
 Instead of using \code{bases} and \code{bases2}, supply a list for just the \code{bases} argument.
 The list should contain any number of vectors specifying the groups of basis species.
@@ -48,19 +45,19 @@
 
 \value{
 A list containing \code{A.species} (affinities of formation of the species with changing basis species) and \code{A.bases} (affinities of formation of the basis species in terms of the first basis species), each having same structure as the list returned by \code{\link{affinity}}.
-If \code{bases2} is provided, the list also contains \code{A.bases2} (affinities of formation of the second set of basis species, in terms of the first one in that set).
+If \code{bases2} is provided, the list also contains \code{A.bases2} (affinities of formation of the second set of basis species).
 }
 
 \seealso{
-\code{demo("mosaic")}, extending the example below by addition of carbonate species in \code{bases2}, with \code{blend} set to TRUE, and using thermodynamic data from Garrels and Christ, 1965.
+\code{demo("mosaic")}, extending the example below by addition of carbonate species in \code{bases2}, and using thermodynamic data from Garrels and Christ, 1965.
 }
 
 \examples{
 \dontshow{data(thermo)}# Fe-minerals and aqueous species in Fe-S-O-H system
 # speciate SO4-2, HSO4-, HS-, H2S as a function of Eh and pH
 # after Garrels and Christ, 1965 Figure 7.20
-pH <- c(0, 14, 200)
-Eh <- c(-1, 1, 200)
+pH <- c(0, 14, 500)
+Eh <- c(-1, 1, 500)
 T <- 25
 basis(c("FeO", "SO4-2", "H2O", "H+", "e-"))
 basis("SO4-2", -6)
@@ -68,15 +65,17 @@
 species(c("pyrrhotite", "pyrite", "hematite", "magnetite"))
 # the basis species we'll swap through
 bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
-# calculate affinities using the predominant basis species
-m1 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
+# calculate affinities using the relative abundances of the basis species
+# NOTE: set blend = FALSE for sharp transitions between the basis species
+# (looks more like the diagram in GC65)
+m1 <- mosaic(bases, pH = pH, Eh = Eh, T = T)
 # make a diagram and add water stability lines
-d <- diagram(m1$A.species, lwd=2)
-water.lines(d, col="seagreen", lwd=1.5)
+d <- diagram(m1$A.species, lwd = 2)
+water.lines(d, col = "seagreen", lwd = 1.5)
 # show lines for Fe(aq) = 10^-4 M
 species(c("Fe+2", "Fe+3"), -4)
-m2 <- mosaic(bases, pH=pH, Eh=Eh, T=T)
-diagram(m2$A.species, add=TRUE, names=NULL)
+m2 <- mosaic(bases, pH = pH, Eh = Eh, T = T)
+diagram(m2$A.species, add = TRUE, names = NULL)
 title(main=paste("Iron oxides and sulfides in water, log(total S) = -6",
   "After Garrels and Christ, 1965", sep="\n"))
 # we could overlay the basis species predominance fields

Modified: pkg/CHNOSZ/man/solubility.Rd
===================================================================
--- pkg/CHNOSZ/man/solubility.Rd	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/man/solubility.Rd	2019-02-02 11:54:46 UTC (rev 379)
@@ -121,7 +121,7 @@
 ## method 2: CO2 and carbonate species as basis species
 basis(c("calcite", "CO2", "H2O", "O2", "H+"))
 species(c("Ca+2"))
-m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14), blend = TRUE, mixing = TRUE)
+m <- mosaic(c("CO2", "HCO3-", "CO3-2"), pH = c(3, 14))
 sm0 <- solubility(m)
 smI <- solubility(m, find.IS = TRUE)
 ## plot the results

Modified: pkg/CHNOSZ/tests/testthat/test-mosaic.R
===================================================================
--- pkg/CHNOSZ/tests/testthat/test-mosaic.R	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/tests/testthat/test-mosaic.R	2019-02-02 11:54:46 UTC (rev 379)
@@ -6,18 +6,18 @@
   a25 <- affinity()
   # this is a degenerate case because we only allow NH3 to swap for NH3, and CO2 for CO2;
   # however it still exercises the affinity scaling and summing code
-  m1_25 <- mosaic("NH3", "CO2", blend=TRUE)
+  m1_25 <- mosaic("NH3", "CO2")
   # this failed before we divided by loga.tot to get _relative_ abundances of basis species in mosaic.R
   expect_equal(a25$values, m1_25$A.species$values)
   # the next call failed when which.pmax(), called by diagram(), choked on a list of length one
-  m2_25 <- mosaic("NH3", "CO2")
+  m2_25 <- mosaic("NH3", "CO2", blend = FALSE)
   expect_equal(a25$values, m2_25$A.species$values)
   # make sure the function works when all affinities are NA
   a500 <- affinity(T=500)
   # using blend=TRUE was failing prior to version 1.1.3-37
-  m1_500 <- mosaic("NH3", "CO2", blend=TRUE, T=500)
+  m1_500 <- mosaic("NH3", "CO2", T=500)
   expect_equal(a500$values, m1_500$A.species$values)
-  m2_500 <- mosaic("NH3", "CO2", T=500)
+  m2_500 <- mosaic("NH3", "CO2", blend = FALSE, T=500)
   expect_equal(a500$values, m2_500$A.species$values)
 })
 
@@ -34,9 +34,9 @@
   bases <- c("SO4-2", "HSO4-", "HS-", "H2S")         
   # calculate affinities using the predominant basis species
   pH <- c(0, 14, 29)
-  m1 <- mosaic(bases, pH = pH)
+  m1 <- mosaic(bases, pH = pH, blend = FALSE)
   # calculate affinities with smooth transitions between basis species, including a mixing energy
-  m2 <- mosaic(bases, pH = pH, blend = TRUE, mixing = TRUE)
+  m2 <- mosaic(bases, pH = pH)
   # these species have no S so the results should be similar,
   # 20190121 except for a negative free energy of mixing (positive affinity)
   expect_true(all(m2$A.species$values[[1]] - m1$A.species$values[[1]] > 0))
@@ -44,8 +44,8 @@
   expect_equal(unique(sign(diff(as.numeric(m2$A.species$values[[1]] - m1$A.species$values[[1]])))), c(1, -1))
   # now with S-bearing species ...
   species(c("pyrrhotite", "pyrite"))
-  m3 <- mosaic(bases, pH=pH)
-  m4 <- mosaic(bases, pH=pH, blend=TRUE)
+  m3 <- mosaic(bases, pH = pH, blend = FALSE)
+  m4 <- mosaic(bases, pH = pH)
   # the results are different ...
   expect_equal(sapply(m3$A.species$values, "[", 13), sapply(m4$A.species$values, "[", 13), tol=1e-1)
   # but more similar at extreme pH values

Modified: pkg/CHNOSZ/vignettes/mklinks.sh
===================================================================
--- pkg/CHNOSZ/vignettes/mklinks.sh	2019-02-01 05:42:24 UTC (rev 378)
+++ pkg/CHNOSZ/vignettes/mklinks.sh	2019-02-02 11:54:46 UTC (rev 379)
@@ -6,7 +6,7 @@
 # set background-image:none to remove underlines (from bootstrap theme)
 sed -i 's/<code>?`CHNOSZ-package`<\/code>/<code><a href="..\/html\/CHNOSZ-package.html" style="background-image:none;">?`CHNOSZ-package`<\/a><\/code>/g' anintro.html
 sed -i 's/<code>?basis<\/code>/<code><a href="..\/html\/basis.html" style="background-image:none;">?basis<\/a><\/code>/g' anintro.html
-sed -i 's/<code>?mosaic<\/code>/<code><a href="..\/html\/eos.html" style="background-image:none;">?mosaic<\/a><\/code>/g' anintro.html
+sed -i 's/<code>?mosaic<\/code>/<code><a href="..\/html\/mosaic.html" style="background-image:none;">?mosaic<\/a><\/code>/g' anintro.html
 sed -i 's/<code>?buffer<\/code>/<code><a href="..\/html\/buffer.html" style="background-image:none;">?buffer<\/a><\/code>/g' anintro.html
 sed -i 's/<code>?solubility<\/code>/<code><a href="..\/html\/solubility.html" style="background-image:none;">?solubility<\/a><\/code>/g' anintro.html
 sed -i 's/<code>?ionize.aa<\/code>/<code><a href="..\/html\/ionize.aa.html" style="background-image:none;">?ionize.aa<\/a><\/code>/g' anintro.html



More information about the CHNOSZ-commits mailing list