[CHNOSZ-commits] r867 - in pkg/CHNOSZ: . R demo inst inst/tinytest man tests vignettes
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jan 8 07:29:47 CET 2025
Author: jedick
Date: 2025-01-08 07:29:46 +0100 (Wed, 08 Jan 2025)
New Revision: 867
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/NaCl.R
pkg/CHNOSZ/demo/contour.R
pkg/CHNOSZ/demo/gold.R
pkg/CHNOSZ/demo/minsol.R
pkg/CHNOSZ/demo/sphalerite.R
pkg/CHNOSZ/demo/sum_S.R
pkg/CHNOSZ/demo/uranyl.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/inst/tinytest/test-mosaic.R
pkg/CHNOSZ/man/NaCl.Rd
pkg/CHNOSZ/man/stack_mosaic.Rd
pkg/CHNOSZ/tests/stack_mosaic.R
pkg/CHNOSZ/tests/stack_mosaic.pdf
pkg/CHNOSZ/tests/stack_solubility.R
pkg/CHNOSZ/tests/stack_solubility.pdf
pkg/CHNOSZ/vignettes/multi-metal.Rmd
Log:
Rename 'm_tot' argument in NaCl() to 'm_NaCl'
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/DESCRIPTION 2025-01-08 06:29:46 UTC (rev 867)
@@ -1,6 +1,6 @@
-Date: 2025-01-07
+Date: 2025-01-08
Package: CHNOSZ
-Version: 2.1.0-38
+Version: 2.1.0-39
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/NaCl.R
===================================================================
--- pkg/CHNOSZ/R/NaCl.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/R/NaCl.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -2,11 +2,11 @@
# Calculate ionic strength and molalities of species given a total molality of NaCl
# 20181102 First version (jmd)
# 20181106 Use activity coefficients of Na+ and Nacl
-# 20221122 Make it work with m_tot = 0
+# 20221122 Make it work with m_NaCl = 0
# 20221210 Rewritten to include pH dependence;
# uses affinity() and equilibrate() instead of algebraic equations
-NaCl <- function(m_tot = 1, T = 25, P = "Psat", pH = NA, attenuate = FALSE) {
+NaCl <- function(m_NaCl = 1, T = 25, P = "Psat", pH = NA, attenuate = FALSE) {
# Store existing thermo data frame
thermo <- get("thermo", CHNOSZ)
@@ -16,17 +16,17 @@
pH <- rep(pH, length.out = nTP)
# Start with complete dissociation into Na+ and Cl-,
- # so ionic strength and molality of Na+ are equal to m_tot
- m_Na <- IS <- m_tot
+ # so ionic strength and molality of Na+ are equal to m_NaCl
+ m_Naplus <- IS <- m_NaCl
# Make them same length as T and P
IS <- rep(IS, length.out = nTP)
- m_Na <- rep(m_Na, length.out = nTP)
- # Set tolerance for convergence to 1/100th of m_tot
- tolerance <- m_tot / 100
+ m_Naplus <- rep(m_Naplus, length.out = nTP)
+ # Set tolerance for convergence to 1/100th of m_NaCl
+ tolerance <- m_NaCl / 100
- # If m_tot is 0, return 0 for all variables 20221122
+ # If m_NaCl is 0, return 0 for all variables 20221122
zeros <- rep(0, nTP)
- if(m_tot == 0) return(list(IS = zeros, m_Na = zeros, m_Cl = zeros, m_NaCl = zeros, m_HCl = zeros))
+ if(m_NaCl == 0) return(list(IS = zeros, m_Naplus = zeros, m_Clminus = zeros, m_NaCl0 = zeros, m_HCl0 = zeros))
maxiter <- 100
for(i in 1:maxiter) {
@@ -34,33 +34,33 @@
if(identical(pH.arg, NA)) {
basis(c("Na+", "Cl-", "e-"))
species(c("Cl-", "NaCl"))
- a <- suppressMessages(affinity(T = T, P = P, "Na+" = log10(m_Na), IS = IS, transect = TRUE))
+ a <- suppressMessages(affinity(T = T, P = P, "Na+" = log10(m_Naplus), IS = IS, transect = TRUE))
} else {
basis(c("Na+", "Cl-", "H+", "e-"))
species(c("Cl-", "NaCl", "HCl"))
- a <- suppressMessages(affinity(T = T, P = P, pH = pH, "Na+" = log10(m_Na), IS = IS, transect = TRUE))
+ a <- suppressMessages(affinity(T = T, P = P, pH = pH, "Na+" = log10(m_Naplus), IS = IS, transect = TRUE))
}
# Speciate Cl-
- e <- suppressMessages(equilibrate(a, loga.balance = log10(m_tot)))
+ e <- suppressMessages(equilibrate(a, loga.balance = log10(m_NaCl)))
# Get molality of each Cl-bearing species
- m_Cl <- 10^e$loga.equil[[1]]
- m_NaCl <- 10^e$loga.equil[[2]]
- if(identical(pH.arg, NA)) m_HCl <- NA else m_HCl <- 10^e$loga.equil[[3]]
+ m_Clminus <- 10^e$loga.equil[[1]]
+ m_NaCl0 <- 10^e$loga.equil[[2]]
+ if(identical(pH.arg, NA)) m_HCl0 <- NA else m_HCl0 <- 10^e$loga.equil[[3]]
# Store previous ionic strength and molality of Na+
IS_prev <- IS
- m_Na_prev <- m_Na
+ m_Naplus_prev <- m_Naplus
# Calculate new molality of Na+ and deviation
- m_Na <- m_tot - m_NaCl
+ m_Naplus <- m_NaCl - m_NaCl0
# Only go halfway to avoid overshoot
- if(attenuate) m_Na <- (m_Na_prev + m_Na) / 2
- dm_Na <- m_Na - m_Na_prev
+ if(attenuate) m_Naplus <- (m_Naplus_prev + m_Naplus) / 2
+ dm_Naplus <- m_Naplus - m_Naplus_prev
# Calculate ionic strength and deviation
- IS <- (m_Na + m_Cl) / 2
+ IS <- (m_Naplus + m_Clminus) / 2
dIS <- IS - IS_prev
# Keep going until the deviations in ionic strength and molality of Na+ at all temperatures are less than tolerance
- converged <- abs(dIS) < tolerance & abs(dm_Na) < tolerance
+ converged <- abs(dIS) < tolerance & abs(dm_Naplus) < tolerance
if(all(converged)) {
- # Add one step without attenuating the deviation of m_Na
+ # Add one step without attenuating the deviation of m_Naplus
if(attenuate) attenuate <- FALSE else break
}
}
@@ -72,6 +72,6 @@
# Restore thermo data frame
assign("thermo", thermo, CHNOSZ)
# Return the calculated values
- list(IS = IS, m_Na = m_Na, m_Cl = m_Cl, m_NaCl = m_NaCl, m_HCl = m_HCl)
+ list(IS = IS, m_Naplus = m_Naplus, m_Clminus = m_Clminus, m_NaCl0 = m_NaCl0, m_HCl0 = m_HCl0)
}
Modified: pkg/CHNOSZ/demo/contour.R
===================================================================
--- pkg/CHNOSZ/demo/contour.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/contour.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -20,15 +20,18 @@
# This gets us close to total S = 0.01 m
basis("H2S", -2)
# Calculate solution composition for 1 mol/kg NaCl
-NaCl <- NaCl(m_tot = 1, T = T, P = P)
-basis("Cl-", log10(NaCl$m_Cl))
+NaCl <- NaCl(m_NaCl = 1, T = T, P = P)
+basis("Cl-", log10(NaCl$m_Clminus))
# Calculate affinity with changing basis species
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
m <- mosaic(bases, pH = c(2, 10, res), O2 = c(-41, -29, res), T = T, P = P, IS = NaCl$IS, blend = blend)
# Show predominance fields for S-species
-diagram(m$A.bases, col = 4, col.names = 4, lty = 2, italic = TRUE)
+diagram(m$A.bases, col = 8, col.names = 8, lty = 2, italic = TRUE)
# Show predominance fields for Au-species
-diagram(m$A.species, add=TRUE, col = 2, col.names = 2, lwd = 2, bold = TRUE)
+# Plot multiple times to get deeper color
+diagram(m$A.species, add=TRUE, col = 7, col.names = 7, lwd = 2, bold = TRUE)
+diagram(m$A.species, add=TRUE, col = 7, col.names = 7, lwd = 2, bold = TRUE)
+diagram(m$A.species, add=TRUE, col = 7, col.names = 7, lwd = 2, bold = TRUE)
# Calculate and plot solubility of Au (use named 'bases' argument to trigger mosaic calculation)
species("Au")
Modified: pkg/CHNOSZ/demo/gold.R
===================================================================
--- pkg/CHNOSZ/demo/gold.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/gold.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -102,12 +102,12 @@
# NaCl solution with total chloride equal to specified NaCl + KCl solution,
# then estimate the molality of K+ in that solution 20181109
chloride <- function(T, P, m_NaCl, m_KCl) {
- NaCl <- NaCl(m_tot = m_NaCl + m_KCl, T = T, P = P)
+ NaCl <- NaCl(m_NaCl = m_NaCl + m_KCl, T = T, P = P)
# Calculate logK of K+ + Cl- = KCl, adjusted for ionic strength
logKadj <- subcrt(c("K+", "Cl-", "KCl"), c(-1, -1, 1), T = T, P = P, IS = NaCl$IS)$out$logK
# What is the molality of K+ from 0.5 mol KCl in solution with 2 mol total Cl
- m_K <- m_KCl / (10^logKadj * NaCl$m_Cl + 1)
- list(IS = NaCl$IS, m_Cl = NaCl$m_Cl, m_K = m_K)
+ m_Kplus <- m_KCl / (10^logKadj * NaCl$m_Clminus + 1)
+ list(IS = NaCl$IS, m_Clminus = NaCl$m_Clminus, m_Kplus = m_Kplus)
}
# log(m_Au)-T diagram like Fig. 2B of Williams-Jones et al., 2009
@@ -123,7 +123,7 @@
# Calculate solubility of gold
species("Au")
iaq <- info(c("Au(HS)2-", "AuHS", "AuOH", "AuCl2-"))
- s <- solubility(iaq, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Cl), `K+` = log10(chl$m_K), P = 1000, IS = chl$IS)
+ s <- solubility(iaq, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Clminus), `K+` = log10(chl$m_Kplus), P = 1000, IS = chl$IS)
# Make diagram and show total log molality
diagram(s, type = "loga.equil", ylim = c(-10, -3), col = col, lwd = 2, lty = 1)
diagram(s, add = TRUE, lwd = 3, lty = 2)
@@ -154,10 +154,10 @@
# Calculate solubility of gold
species("Au")
iaq <- info(c("Au(HS)2-", "AuHS", "AuOH", "AuCl2-"))
- s <- solubility(iaq, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Cl), `K+` = log10(chl$m_K), P = 1000, IS = chl$IS)
+ s <- solubility(iaq, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Clminus), `K+` = log10(chl$m_Kplus), P = 1000, IS = chl$IS)
# # Uncomment to calculate solubility considering speciation of sulfur
# bases <- c("H2S", "HS-", "SO4-2", "HSO4-")
-# s <- solubility(iaq, bases = bases, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Cl), `K+` = log10(chl$m_K), P = 1000, IS = chl$IS)
+# s <- solubility(iaq, bases = bases, T = seq(150, 550, 10), `Cl-` = log10(chl$m_Clminus), `K+` = log10(chl$m_Kplus), P = 1000, IS = chl$IS)
# Make diagram and show total log molality
diagram(s, type = "loga.equil", ylim = c(-10, -3), col = col, lwd = 2, lty = 1)
diagram(s, add = TRUE, lwd = 3, lty = 2)
Modified: pkg/CHNOSZ/demo/minsol.R
===================================================================
--- pkg/CHNOSZ/demo/minsol.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/minsol.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -26,8 +26,8 @@
# Molality of NaCl
mNaCl <- 1000 * wNaCl / (mass("NaCl") * (1 - wNaCl))
# Estimate ionic strength and molality of Cl-
-sat <- NaCl(m_tot = mNaCl, T = T)
-basis("Cl-", log10(sat$m_Cl))
+NaCl <- NaCl(m_NaCl = mNaCl, T = T)
+basis("Cl-", log10(NaCl$m_Clminus))
# Add minerals and aqueous species
icr <- retrieve(metal, c("Cl", "S", "O"), state = "cr")
@@ -38,9 +38,9 @@
# Calculate affinities and make diagram
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
-m <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = sat$IS)
+m <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = NaCl$IS)
d <- diagram(m$A.species, bold = TRUE)
-diagram(m$A.bases, add = TRUE, col = "slategray", lwd = 2, lty = 3, names = NA)
+diagram(m$A.bases, add = TRUE, col = 8, col.names = 8, lty = 3, italic = TRUE)
title(bquote(log * italic(m)[.(metal)*"(aq) species"] == .(logm_metal)))
label.figure("A")
@@ -62,7 +62,7 @@
# Make diagram for minerals only 20201007
species(icr)
-mcr <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = sat$IS)
+mcr <- mosaic(bases, pH = pH, O2 = O2, T = T, P = P, IS = NaCl$IS)
diagram(mcr$A.species, col = 2)
label.figure("B")
@@ -69,7 +69,7 @@
# Calculate *minimum* solubility among all the minerals 20201008
# (i.e. saturation condition for the solution)
# Use solubility() 20210303
-s <- solubility(iaq, bases = bases, pH = pH, O2 = O2, T = T, P = P, IS = sat$IS, in.terms.of = metal)
+s <- solubility(iaq, bases = bases, pH = pH, O2 = O2, T = T, P = P, IS = NaCl$IS, in.terms.of = metal)
# Specify contour levels
levels <- seq(-12, 9, 3)
diagram(s, levels = levels, contour.method = "flattest")
Modified: pkg/CHNOSZ/demo/sphalerite.R
===================================================================
--- pkg/CHNOSZ/demo/sphalerite.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/sphalerite.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -11,15 +11,15 @@
iaq <- retrieve("Zn", c("O", "H", "Cl", "S"), "aq")
# A function to make a single plot
-plotfun <- function(T = 400, P = 500, m_tot = 0.1, pHmin = 4, logppmmax = 3) {
+plotfun <- function(T = 400, P = 500, m_NaCl = 0.1, pHmin = 4, logppmmax = 3) {
# Get pH values
res <- 100
pH <- seq(pHmin, 10, length.out = res)
# Calculate speciation in NaCl-H2O system at given pH
- NaCl <- NaCl(m_tot = m_tot, T = T, P = P, pH = pH)
+ NaCl <- NaCl(m_NaCl = m_NaCl, T = T, P = P, pH = pH)
# Calculate solubility with mosaic (triggered by bases argument) to account for HS- and H2S speciation
- s <- solubility(iaq, bases = c("H2S", "HS-"), pH = pH, "Cl-" = log10(NaCl$m_Cl), T = T, P = P, IS = NaCl$IS)
+ s <- solubility(iaq, bases = c("H2S", "HS-"), pH = pH, "Cl-" = log10(NaCl$m_Clminus), T = T, P = P, IS = NaCl$IS)
# Convert log activity to log ppm
sp <- convert(s, "logppm")
@@ -31,7 +31,7 @@
abline(v = pKw / 2, lty = 2, lwd = 2, col = "blue1")
# Add legend
- l <- lex(lNaCl(m_tot), lTP(T, P))
+ l <- lex(lNaCl(m_NaCl), lTP(T, P))
legend("topright", legend = l, bty = "n")
}
@@ -48,13 +48,13 @@
T <- c(400, 400, 250, 250, 100, 100)
# Use a list to be able to mix numeric and character values for P
P <- list(500, 500, "Psat", "Psat", "Psat", "Psat")
- m_tot <- c(0.1, 1, 0.1, 1, 0.1, 1)
+ m_NaCl <- c(0.1, 1, 0.1, 1, 0.1, 1)
# The plots have differing limits
pHmin <- c(4, 4, 2, 2, 2, 2)
logppmmax <- c(3, 3, 2, 2, 0, 0)
# Make the plots
par(mfrow = c(3, 2))
- for(i in 1:6) plotfun(T = T[i], P = P[[i]], m_tot = m_tot[i], pHmin = pHmin[i], logppmmax = logppmmax[i])
+ for(i in 1:6) plotfun(T = T[i], P = P[[i]], m_NaCl = m_NaCl[i], pHmin = pHmin[i], logppmmax = logppmmax[i])
}
# A function to make a png file with all the plots
Modified: pkg/CHNOSZ/demo/sum_S.R
===================================================================
--- pkg/CHNOSZ/demo/sum_S.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/sum_S.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -17,7 +17,7 @@
# Calculate solution composition for 0.8 mol/kg NaCl
# Based on activity of Cl- from Fig. 18 of Skirrow and Walsh (2002)
m_NaCl = 0.8
-NaCl <- NaCl(m_tot = m_NaCl, T = T, P = P, pH = pH)
+NaCl <- NaCl(m_NaCl = m_NaCl, T = T, P = P, pH = pH)
IS <- NaCl$IS
# Setup chemical system
@@ -24,7 +24,7 @@
# Use oxygen instead of O2 to get the gas
basis(c("Fe", "SO4-2", "oxygen", "H+", "Cl-", "H2O"))
basis("pH", pH)
-basis("Cl-", log10(NaCl$m_Cl))
+basis("Cl-", log10(NaCl$m_Clminus))
# Add minerals as formed species
species(c("pyrrhotite", "pyrite", "hematite", "magnetite"))
@@ -38,7 +38,7 @@
# Plot diagram for Fe minerals and show sulfur species
d <- diagram(m$A.species, bold = TRUE, lwd = 2)
- diagram(m$A.bases[[1]], add = TRUE, col = 4, col.names = 4, lty = 4, dx = -2.5, dy = c(-4, 0, 0, 6))
+ diagram(m$A.bases[[1]], add = TRUE, col = 8, col.names = 8, lty = 4, dx = -2.5, dy = c(-4, 0, 0, 6), italic = TRUE)
# Add water stability limit
water.lines(d)
Modified: pkg/CHNOSZ/demo/uranyl.R
===================================================================
--- pkg/CHNOSZ/demo/uranyl.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/demo/uranyl.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -5,7 +5,7 @@
# Conditions
logm_U <- log10(3.16e-5)
-m_tot <- 1 # mol NaCl / kg H2O
+m_NaCl <- 1 # mol NaCl / kg H2O
T <- 200
P <- "Psat"
pH_lim <- c(2, 10)
@@ -13,22 +13,22 @@
res <- 500
# Calculations for NaCl
-NaCl <- NaCl(m_tot = m_tot, T = T, P = P)
+NaCl <- NaCl(m_NaCl = m_NaCl, T = T, P = P)
IS <- NaCl$IS
-logm_Na <- log10(NaCl$m_Na)
-logm_Cl <- log10(NaCl$m_Cl)
+logm_Naplus <- log10(NaCl$m_Naplus)
+logm_Clminus <- log10(NaCl$m_Clminus)
# Total carbonate-pH
iaq <- retrieve("U", ligands = c("C", "O", "H", "Cl", "Na"), state = "aq")
icr <- retrieve("U", ligands = c("C", "O", "H", "Cl", "Na"), state = "cr")
basis(c("UO2+2", "CO3-2", "Na+", "Cl-", "H+", "H2O", "O2"))
-basis(c("Na+", "Cl-"), c(logm_Na, logm_Cl))
+basis(c("Na+", "Cl-"), c(logm_Naplus, logm_Clminus))
species(iaq, logm_U)
species(icr, add = TRUE)
bases <- c("CO3-2", "HCO3-", "CO2")
m <- mosaic(bases, pH = c(pH_lim, res), "CO3-2" = c(CS_lim, res), T = T, P = P, IS = IS)
diagram(m$A.species)
-diagram(m$A.bases, add = TRUE, col = 2, lty = 2, col.names = 2)
+diagram(m$A.bases, add = TRUE, col = 8, lty = 2, col.names = 8, italic = TRUE)
title("Uranyl-carbonate complexation at 200 \u00b0C, after Migdisov et al., 2024", font.main = 1)
# Total sulfate-pH
@@ -35,11 +35,11 @@
iaq <- retrieve("U", ligands = c("S", "O", "H", "Cl", "Na"), state = "aq")
icr <- retrieve("U", ligands = c("S", "O", "H", "Cl", "Na"), state = "cr")
basis(c("UO2+2", "SO4-2", "Na+", "Cl-", "H+", "H2O", "O2"))
-basis(c("Na+", "Cl-"), c(logm_Na, logm_Cl))
+basis(c("Na+", "Cl-"), c(logm_Naplus, logm_Clminus))
species(iaq, logm_U)
species(icr, add = TRUE)
bases <- c("SO4-2", "HSO4-", "HS-", "H2S")
m <- mosaic(bases, pH = c(pH_lim, res), "SO4-2" = c(CS_lim, res), T = T, P = P, IS = IS)
diagram(m$A.species)
-diagram(m$A.bases, add = TRUE, col = 2, lty = 2, col.names = 2)
+diagram(m$A.bases, add = TRUE, col = 8, lty = 2, col.names = 8, italic = TRUE)
title("Uranyl-sulfate complexation at 200 \u00b0C, after Migdisov et al., 2024", font.main = 1)
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2025-01-08 06:29:46 UTC (rev 867)
@@ -15,7 +15,7 @@
\newcommand{\Cp}{\ifelse{latex}{\eqn{C_P}}{\ifelse{html}{\out{<I>C<sub>P</sub></I>}}{Cp}}}
\newcommand{\DG0}{\ifelse{latex}{\eqn{{\Delta}G^{\circ}}}{\ifelse{html}{\out{Δ<I>G</I>°}}{ΔG°}}}
-\section{Changes in CHNOSZ version 2.1.0-38 (2025-01-07)}{
+\section{Changes in CHNOSZ version 2.1.0-39 (2025-01-08)}{
\subsection{OBIGT DEFAULT DATA}{
\itemize{
@@ -110,11 +110,16 @@
\item Merge \file{extdata/adds} and \file{extdata/cpetc} into
\file{extdata/misc}.
- \item In \code{diagram}, the default for the \strong{type} argument when
- using the output from \code{solubility} is now \code{loga.balance} (sum
- of activities of aqueous species) rather than \code{loga.equil}
+ \item In \code{diagram()}, the default for the \strong{type} argument
+ when using the output from \code{solubility()} is now \code{loga.balance}
+ (sum of activities of aqueous species) rather than \code{loga.equil}
(activities of individual aqueous species).
+ \item In \code{NaCl()}, rename \strong{m_tot} to \strong{m_NaCl} (moles
+ of of NaCl added to 1 kg H\s{2}O) and rename output with \samp{m_Naplus},
+ \samp{m_Clminus}, \samp{m_NaCl0}, and \samp{m_HCl0} (molalities of
+ aqueous species).
+
}
}
Modified: pkg/CHNOSZ/inst/tinytest/test-mosaic.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-mosaic.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/inst/tinytest/test-mosaic.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -88,8 +88,8 @@
# Set a low logfO2 to get into H2S - HS- fields
basis("O2", -40)
# Calculate solution composition for 1 mol/kg NaCl
-NaCl <- NaCl(T = T, P = P, m_tot = 1)
-basis("Cl-", log10(NaCl$m_Cl))
+NaCl <- NaCl(m_NaCl = 1, T = T, P = P)
+basis("Cl-", log10(NaCl$m_Clminus))
# Calculate affinity with changing basis species
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
m <- mosaic(bases, pH = c(2, 10), T = 250, P = 500, IS = NaCl$IS)
Modified: pkg/CHNOSZ/man/NaCl.Rd
===================================================================
--- pkg/CHNOSZ/man/NaCl.Rd 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/man/NaCl.Rd 2025-01-08 06:29:46 UTC (rev 867)
@@ -7,11 +7,11 @@
}
\usage{
- NaCl(m_tot = 1, T = 25, P = "Psat", pH = NA, attenuate = FALSE)
+ NaCl(m_NaCl = 1, T = 25, P = "Psat", pH = NA, attenuate = FALSE)
}
\arguments{
- \item{m_tot}{numeric, total molality of NaCl (single value)}
+ \item{m_NaCl}{numeric, moles of NaCl added to 1 kg \H2O}
\item{T}{numeric, temperature in \degC}
\item{P}{numeric, pressure in bar}
\item{pH}{numeric, pH}
@@ -20,13 +20,13 @@
\details{
Thermodynamic models for metal solubility and speciation involving chloride complexes are commonly specified in terms of amount of NaCl rather than activity (or molality) of Cl\S{-} as an independent variable.
-This function calculates distribution of species and ionic strength in a simple aqueous solution given a total amount (\code{m_tot}, in mol/kg) of NaCl.
+This function calculates distribution of species and ionic strength in a simple aqueous solution given a total amount (\code{m_NaCl}, in mol/kg) of NaCl.
The aqueous Cl-bearing species considered in the system are Cl\S{-}, NaCl, and optionally HCl.
Na\S{+} is present as a basis species, but the formation of Na-bearing species such as NaOH is not considered.
The activity coefficients of charged species are calculated using the extended Debye-Hückel equation (see \code{\link{nonideal}}) via the \code{IS} argument of \code{\link{affinity}}.
-The function first sets the molality of Na\S{+} and ionic strength equal to \code{m_tot}, then calculates the distribution of Cl-bearing species.
+The function first sets the molality of Na\S{+} and ionic strength equal to \code{m_NaCl}, then calculates the distribution of Cl-bearing species.
Based on mass balance of Na atoms, the molality of NaCl is then used to recalculate the molality of Na\S{+}, followed by ionic strength.
-To find a solution, the function iterates until the change of molality of Na\S{+} and ionic strength are both less than \code{m_tot} / 100.
+To find a solution, the function iterates until the change of molality of Na\S{+} and ionic strength are both less than \code{m_NaCl} / 100.
At very high NaCl concentrations, which are beyond the applicability limits of the extended Debye-Hückel model and therefore not recommended for normal use, the iterations tend to oscillate without converging.
Setting \code{attenuate} to TRUE, which halves the amount of change in each step, may help with convergence.
@@ -33,7 +33,7 @@
If a solution is not found after 100 iterations, the function stops with an error.
If \code{pH} is NA (the default), then HCl is not included in the calculation and its molality in the output is also assigned NA.
-Note that only a single value is accepted for \code{m_tot}, but the other numeric arguments can have length > 1, allowing multiple combinations \code{T}, \code{P}, and \code{pH} in a single function call.
+Note that only a single value is accepted for \code{m_NaCl}, but the other numeric arguments can have length > 1, allowing multiple combinations \code{T}, \code{P}, and \code{pH} in a single function call.
However, due to limitations in \code{\link{affinity}}, only one of \code{T} and \code{P} can have length > 1.
}
@@ -43,7 +43,7 @@
}
\value{
-A list with components \samp{IS} (ionic strength calculated from molalities of Na\S{+} and Cl\S{-}), \samp{m_Cl}, \samp{m_Cl}, \samp{m_NaCl}, and \samp{m_HCl} (molalities of Na\S{+}, Cl\S{-}, NaCl, and HCl).
+A list with components \samp{IS} (ionic strength calculated from molalities of Na\S{+} and Cl\S{-}), \samp{m_Naplus}, \samp{m_Clminus}, \samp{m_NaCl0}, and \samp{m_HCl0} (molalities of Na\S{+}, Cl\S{-}, NaCl, and HCl).
}
\seealso{
@@ -59,13 +59,13 @@
`300` = c(0.807, 1.499, 2.136, 2.739, 3.317, 3.875),
`500` = c(0.311, 0.590, 0.861, 1.125, 1.385, 1.642))
# Total molality in the calculation with NaCl()
-m_tot <- seq(1, 6, 0.5)
-N <- length(m_tot)
+m_NaCl <- seq(1, 6, 0.5)
+N <- length(m_NaCl)
# Where we'll put the calculated values
IS.calc <- data.frame(`100` = numeric(N), `300` = numeric(N), `500` = numeric(N))
-# NaCl() is *not* vectorized over m_tot, so we use a loop here
-for(i in 1:length(m_tot)) {
- NaCl.out <- NaCl(m_tot[i], c(100, 300, 500), P = 1000)
+# NaCl() is *not* vectorized over m_NaCl, so we use a loop here
+for(i in 1:length(m_NaCl)) {
+ NaCl.out <- NaCl(m_NaCl[i], c(100, 300, 500), P = 1000)
IS.calc[i, ] <- NaCl.out$IS
}
# Plot ionic strength from HCh and NaCl() as points and lines
@@ -76,7 +76,7 @@
# for the properties of NaCl(aq) (HCh: B.Ryhzenko model;
# CHONSZ: revised HKF with parameters from Shock et al., 1997)
points(m.HCh, IS.HCh[[i]], col = col[i])
- lines(m_tot, IS.calc[, i], col = col[i])
+ lines(m_NaCl, IS.calc[, i], col = col[i])
}
# Add legend and title
dprop <- describe.property(rep("T", 3), c(100, 300, 500))
Modified: pkg/CHNOSZ/man/stack_mosaic.Rd
===================================================================
--- pkg/CHNOSZ/man/stack_mosaic.Rd 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/man/stack_mosaic.Rd 2025-01-08 06:29:46 UTC (rev 867)
@@ -74,8 +74,8 @@
basis(c("pyrite", "Cu", "Cl-", "H2S", "H2O", "oxygen", "H+"))
basis("H2S", -2)
# Calculate solution composition for 1 mol/kg NaCl
-NaCl <- NaCl(m_tot = 1, T = T, P = P)
-basis("Cl-", log10(NaCl$m_Cl))
+NaCl <- NaCl(m_NaCl = 1, T = T, P = P)
+basis("Cl-", log10(NaCl$m_Clminus))
# Define arguments for stack_mosaic: Speciate aqueous sulfur
bases <- c("H2S", "HS-", "HSO4-", "SO4-2")
Modified: pkg/CHNOSZ/tests/stack_mosaic.R
===================================================================
--- pkg/CHNOSZ/tests/stack_mosaic.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/tests/stack_mosaic.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -27,7 +27,7 @@
Fe.aq <- info(iFe.aq)$name
iCu.aq <- retrieve("Cu", c("S", "O", "H", "Cl"), "aq")
Cu.aq <- info(iCu.aq)$name
-nacl <- NaCl(T = T, P = "Psat", m_tot = m_NaCl)
+NaCl <- NaCl(m_NaCl = m_NaCl, T = T, P = "Psat")
setup <- function() {
reset()
@@ -34,7 +34,7 @@
# Setup basis species
basis(c("Cu+", "pyrite", "H2S", "oxygen", "H2O", "H+", "Cl-"))
basis("H2S", logmS)
- basis("Cl-", log10(nacl$m_Cl))
+ basis("Cl-", log10(NaCl$m_Clminus))
}
ref_Cu_craq <- function() {
@@ -43,7 +43,7 @@
# Add aqueous species 20210220
species(iCu.aq, logm_aq, add = TRUE)
- mCu <- mosaic(list(S.aq), pH = pH, O2 = O2, T = T, IS = nacl$IS)
+ mCu <- mosaic(list(S.aq), pH = pH, O2 = O2, T = T, IS = NaCl$IS)
diagram(mCu$A.species)
}
@@ -50,13 +50,13 @@
ref_FeCu_cr <- function() {
# Load Fe-bearing minerals
species(Fe.cr)
- mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+ mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dFe <- diagram(mFe$A.species, lwd = 0, names = FALSE, plot.it = FALSE)
# Load Cu-bearing minerals
species(c(FeCu.cr, Cu.cr))
# Mosaic with all Fe species as basis species
- mFeCu <- mosaic(list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant))
+ mFeCu <- mosaic(list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant))
diagram(mFeCu$A.species)
}
@@ -66,7 +66,7 @@
species(Fe.cr)
# Add aqueous species 20210220
species(iFe.aq, logm_aq, add = TRUE)
- mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+ mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dFe <- diagram(mFe$A.species, lwd = 0, names = FALSE, plot.it = FALSE)
# Load Cu-bearing minerals
@@ -95,7 +95,7 @@
mod.OBIGT(iFe.aq, G = G.new)
# Mosaic with all Fe species as basis species
- mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant))
+ mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant))
diagram(mFeCu$A.species)
}
@@ -108,7 +108,7 @@
# c(NA, logm_aq) means to use:
# basis()'s value for logact of aqueous S species
# logm_aq for logact of aqueous Fe species
- mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
+ mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
diagram(mFeCu$A.species)
}
@@ -127,7 +127,7 @@
# Cu-bearing aqueous species
species2 <- c(species2, Cu.aq)
- sm <- stack_mosaic(bases, species1, species2, species12, pH = pH, O2 = O2, T = T, IS = nacl$IS, loga_aq = logm_aq, plot.it = FALSE)
+ sm <- stack_mosaic(bases, species1, species2, species12, pH = pH, O2 = O2, T = T, IS = NaCl$IS, loga_aq = logm_aq, plot.it = FALSE)
diagram(sm[[2]])
}
Modified: pkg/CHNOSZ/tests/stack_mosaic.pdf
===================================================================
(Binary files differ)
Modified: pkg/CHNOSZ/tests/stack_solubility.R
===================================================================
--- pkg/CHNOSZ/tests/stack_solubility.R 2025-01-07 12:58:35 UTC (rev 866)
+++ pkg/CHNOSZ/tests/stack_solubility.R 2025-01-08 06:29:46 UTC (rev 867)
@@ -50,29 +50,29 @@
iCu.aq <- retrieve("Cu", c("S", "O", "H", "Cl"), "aq")
Cu.aq <- info(iCu.aq)$name
# Apply NaCl concentration
-nacl <- NaCl(T = T, P = "Psat", m_tot = m_NaCl)
+NaCl <- NaCl(m_NaCl = m_NaCl, T = T, P = "Psat")
### Setup basis species for Fe-Cu stacks
reset()
basis(c("Cu+", "pyrite", "H2S", "oxygen", "H2O", "H+", "Cl-"))
basis("H2S", logmS)
-basis("Cl-", log10(nacl$m_Cl))
+basis("Cl-", log10(NaCl$m_Clminus))
## Diagram 1: Only Fe-bearing minerals
species(Fe.cr)
# Mosaic with S species as basis species
-mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dFe <- diagram(mFe$A.species, col = 2)
## Diagram 2: Cu- (and FeCu-) bearing minerals and aqueous species
species(c("chalcopyrite", Cu.cr))
species(Cu.aq, -6, add = TRUE)
-mFeCu <- mosaic(list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant))
+mFeCu <- mosaic(list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant))
diagram(mFeCu$A.species)
## Diagram 2a: Overlay single solubility contour
species(c("chalcopyrite", Cu.cr))
-sout1 <- solubility(iCu.aq, bases = list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant))
+sout1 <- solubility(iCu.aq, bases = list(S.aq, Fe.cr), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant))
diagram(sout1, add = TRUE, col = 4, lwd = 2, levels = -6)
mtext("Stack 1: Fe minerals only -> Cu(Fe) minerals and Cu aqueous", adj = 1.1, line = 1.1)
@@ -80,18 +80,18 @@
## Diagram 3: Fe-bearing minerals and aqueous species
species(Fe.cr)
species(Fe.aq, -6, add = TRUE)
-mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+mFe <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dFe <- diagram(mFe$A.species, col = 2)
## Diagram 4: Cu- (and FeCu-) bearing minerals and aqueous species
species(c("chalcopyrite", Cu.cr))
species(Cu.aq, -6, add = TRUE)
-mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
+mFeCu <- mosaic(list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
diagram(mFeCu$A.species)
## Diagram 4a: Overlay single solubility contour
species(c("chalcopyrite", Cu.cr))
-sout2 <- solubility(iCu.aq, bases = list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
+sout2 <- solubility(iCu.aq, bases = list(S.aq, c(Fe.cr, Fe.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dFe$predominant), loga_aq = c(NA, logm_aq))
diagram(sout2, add = TRUE, col = 4, lwd = 2, levels = -6)
mtext("Stack 2: Fe minerals and aqueous -> Cu(Fe) minerals and Cu aqueous", adj = 1, line = 1.1)
@@ -100,22 +100,22 @@
reset()
basis(c("Fe+2", "copper", "H2S", "oxygen", "H2O", "H+", "Cl-"))
basis("H2S", logmS)
-basis("Cl-", log10(nacl$m_Cl))
+basis("Cl-", log10(NaCl$m_Cl))
## Diagram 5: Only Cu-bearing minerals
species(Cu.cr)
-mCu <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+mCu <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dCu <- diagram(mCu$A.species, col = 4)
## Diagram 6: Fe- (and CuFe-) bearing minerals and aqueous species
species(c("chalcopyrite", Fe.cr))
species(Fe.aq, -6, add = TRUE)
-mCuFe <- mosaic(list(S.aq, Cu.cr), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dCu$predominant))
+mCuFe <- mosaic(list(S.aq, Cu.cr), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dCu$predominant))
diagram(mCuFe$A.species)
## Diagram 6a: Overlay single solubility contour
species(c("chalcopyrite", Fe.cr))
-sout3 <- solubility(iFe.aq, bases = list(S.aq, Cu.cr), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dCu$predominant))
+sout3 <- solubility(iFe.aq, bases = list(S.aq, Cu.cr), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dCu$predominant))
diagram(sout3, add = TRUE, col = 2, lwd = 2, levels = -6)
mtext("Stack 3: Cu minerals only -> Fe(Cu) minerals and Fe aqueous", adj = 1.1, line = 1.1)
@@ -123,18 +123,18 @@
## Diagram 7: Cu-bearing minerals and aqueous species
species(Cu.cr)
species(Cu.aq, -6, add = TRUE)
-mCu <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = nacl$IS)
+mCu <- mosaic(S.aq, pH = pH, O2 = O2, T = T, IS = NaCl$IS)
dCu <- diagram(mCu$A.species, col = 4)
## Diagram 8: Fe- (and CuFe-) bearing minerals and aqueous species
species(c("chalcopyrite", Fe.cr))
species(Fe.aq, -6, add = TRUE)
-mCuFe <- mosaic(list(S.aq, c(Cu.cr, Cu.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dCu$predominant), loga_aq = c(NA, logm_aq))
+mCuFe <- mosaic(list(S.aq, c(Cu.cr, Cu.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dCu$predominant), loga_aq = c(NA, logm_aq))
diagram(mCuFe$A.species)
## Diagram 8a: Overlay single solubility contour
species(c("chalcopyrite", Fe.cr))
-sout4 <- solubility(iFe.aq, bases = list(S.aq, c(Cu.cr, Cu.aq)), pH = pH, O2 = O2, T = T, IS = nacl$IS, stable = list(NULL, dCu$predominant), loga_aq = c(NA, logm_aq))
+sout4 <- solubility(iFe.aq, bases = list(S.aq, c(Cu.cr, Cu.aq)), pH = pH, O2 = O2, T = T, IS = NaCl$IS, stable = list(NULL, dCu$predominant), loga_aq = c(NA, logm_aq))
diagram(sout4, add = TRUE, col = 2, lwd = 2, levels = -6)
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/chnosz -r 867
More information about the CHNOSZ-commits
mailing list