[CHNOSZ-commits] r881 - in pkg/CHNOSZ: . R inst inst/tinytest
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Apr 21 12:34:30 CEST 2025
Author: jedick
Date: 2025-04-21 12:34:30 +0200 (Mon, 21 Apr 2025)
New Revision: 881
Modified:
pkg/CHNOSZ/DESCRIPTION
pkg/CHNOSZ/R/util.affinity.R
pkg/CHNOSZ/inst/NEWS.Rd
pkg/CHNOSZ/inst/tinytest/test-affinity.R
Log:
Fix using Eh in transect mode of affinity()
Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION 2025-04-19 05:04:43 UTC (rev 880)
+++ pkg/CHNOSZ/DESCRIPTION 2025-04-21 10:34:30 UTC (rev 881)
@@ -1,6 +1,6 @@
-Date: 2025-04-19
+Date: 2025-04-21
Package: CHNOSZ
-Version: 2.1.0-52
+Version: 2.1.0-53
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/util.affinity.R
===================================================================
--- pkg/CHNOSZ/R/util.affinity.R 2025-04-19 05:04:43 UTC (rev 880)
+++ pkg/CHNOSZ/R/util.affinity.R 2025-04-21 10:34:30 UTC (rev 881)
@@ -182,8 +182,7 @@
# To get logK or subcrt props or other values into the dimensions we are using
dim.fun <- function(x, idim = NULL) {
if(is.null(idim)) {
- if(transect) idim <- 1
- else if(is.null(grid)) {
+ if(is.null(grid)) {
# One of T, P, IS
ivar <- which(vars %in% c("T", "P", "IS"))
if(length(ivar) == 0) ivar <- 1
@@ -195,6 +194,8 @@
idim <- ivars(ivar2, ivars(ivar1))
}
}
+ # For working Eh in transect mode, this should not be nested in the above if(is.null(idim)) 20250421
+ if(transect) idim <- 1
return(aperm(array(x, mydim[idim]), idim))
}
# Properties of all species
Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd 2025-04-19 05:04:43 UTC (rev 880)
+++ pkg/CHNOSZ/inst/NEWS.Rd 2025-04-21 10:34:30 UTC (rev 881)
@@ -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-48 (2025-04-07)}{
+\section{Changes in CHNOSZ version 2.1.0-53 (2025-04-21)}{
\subsection{OBIGT DEFAULT DATA}{
\itemize{
@@ -136,7 +136,15 @@
}
}
+ \subsection{BUG FIXES}{
+ \itemize{
+ \item Fix using Eh in transect mode of \code{affinity()} (feature was not
+ working since at least version 0.9-7).
+
+ }
+ }
+
\subsection{OTHER CHANGES}{
\itemize{
Modified: pkg/CHNOSZ/inst/tinytest/test-affinity.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-affinity.R 2025-04-19 05:04:43 UTC (rev 880)
+++ pkg/CHNOSZ/inst/tinytest/test-affinity.R 2025-04-21 10:34:30 UTC (rev 881)
@@ -54,13 +54,6 @@
a129 <- affinity(pH = pH, Eh = c(Eh, 129))
expect_equal(length(a129$vals[[2]]), 129, info = info)
-## TODO: a transect of hotter, more oxidizing and more acidic
-## has not been working since at least 0.9-7
-##T <- c(25, 50, 100, 125, 150)
-##Eh <- c(-1, -0.5, 0, 0.5, 1)
-##pH <- c(10, 8, 6, 4, 2)
-##a <- affinity(T = T, Eh = Eh, pH = pH)
-
info <- "affinity() in 3D returns values consistent with manual calculation"
# Our "manual" calculation will be for H2(aq) + 0.5O2(aq) = H2O(l)
# The equilibrium constants at 25 and 100 degrees C
@@ -204,3 +197,25 @@
species("CO2")
a <- affinity(return.sout = TRUE)
expect_equal(names(a), c("species", "out"), info = info)
+
+# Test added 20250421
+info <- "Using Eh works in transect mode of affinity()"
+basis("CHNOSe")
+species(c("NO3-", "NO2-", "NH4+", "NH3"))
+T <- c(25, 50, 100, 125, 150)
+Eh <- c(-1, -0.5, 0, 0.5, 1)
+pH <- c(10, 8, 6, 4, 2)
+# Calculate values on transect
+a <- affinity(T = T, Eh = Eh, pH = pH)
+# Calculate values at first point on transect
+basis("Eh", -1)
+basis("pH", 10)
+a1 <- affinity(T = 25)
+expect_equal(sapply(a$values, "[", 1), unlist(a1$values), info = info)
+# Calculate values at last point on transect
+# nb. we can't use basis("Eh", 1) because that uses pe at T = 25 C
+pe <- convert(1, "pe", T = convert(150, "K"))
+basis("pe", pe)
+basis("pH", 2)
+a5 <- affinity(T = 150)
+expect_equal(sapply(a$values, "[", 5), unlist(a5$values), info = info)
More information about the CHNOSZ-commits
mailing list