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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed May 14 13:31:34 CEST 2025


Author: jedick
Date: 2025-05-14 13:31:33 +0200 (Wed, 14 May 2025)
New Revision: 899

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/AD.R
   pkg/CHNOSZ/R/water.R
   pkg/CHNOSZ/inst/NEWS.Rd
   pkg/CHNOSZ/inst/tinytest/test-water.R
   pkg/CHNOSZ/man/water.Rd
Log:
Make water() with IAPWS95 respect Psat_floor (renamed from P1)


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/DESCRIPTION	2025-05-14 11:31:33 UTC (rev 899)
@@ -1,6 +1,6 @@
 Date: 2025-05-14
 Package: CHNOSZ
-Version: 2.1.0-70
+Version: 2.1.0-71
 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/AD.R
===================================================================
--- pkg/CHNOSZ/R/AD.R	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/R/AD.R	2025-05-14 11:31:33 UTC (rev 899)
@@ -122,7 +122,7 @@
   f1 <- exp ( (GH2O_P - GH2O_1) / (8.31441 * T) )
   # For Psat, calculate the real liquid-vapor curve (not floored at 1 bar)
   if(isPsat) {
-    P <- water("Psat", T = T, P = "Psat", P1 = FALSE)$Psat
+    P <- water("Psat", T = T, P = "Psat", Psat_floor = NULL)$Psat
     f1[P < 1] <- P[P < 1]
   }
   f1

Modified: pkg/CHNOSZ/R/water.R
===================================================================
--- pkg/CHNOSZ/R/water.R	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/R/water.R	2025-05-14 11:31:33 UTC (rev 899)
@@ -2,7 +2,7 @@
 # Calculate thermodynamic and electrostatic properties of H2O
 # 20061016 jmd
 
-water <- function(property = NULL, T = 298.15, P = "Psat", P1 = TRUE) {
+water <- function(property = NULL, T = 298.15, P = "Psat", Psat_floor = 1) {
   # Calculate the properties of liquid H2O as a function of T and P
   # T in Kelvin, P in bar
   if(is.null(property)) return(get("thermo", CHNOSZ)$opt$water)
@@ -34,11 +34,11 @@
     # Change 273.15 K to 273.16 K (needed for water.SUPCRT92 at Psat)
     if(identical(P, "Psat")) T[T == 273.15] <- 273.16
     # Get properties using SUPCRT92
-    w.out <- water.SUPCRT92(property, T, P, P1)
+    w.out <- water.SUPCRT92(property, T, P, Psat_floor)
   }
   if(grepl("IAPWS", wopt)) {
     # Get properties using IAPWS-95 
-    w.out <- water.IAPWS95(property, T, P)
+    w.out <- water.IAPWS95(property, T, P, Psat_floor)
   }
   if(grepl("DEW", wopt)) {
     # Use the Deep Earth Water (DEW) model
@@ -47,7 +47,7 @@
   w.out
 }
 
-water.SUPCRT92 <- function(property = NULL, T = 298.15, P = 1, P1 = TRUE) {
+water.SUPCRT92 <- function(property = NULL, T = 298.15, P = 1, Psat_floor = 1) {
   ### Interface to H2O92D.f: FORTRAN subroutine taken from 
   ### SUPCRT92 for calculating the thermodynamic and 
   ### electrostatic properties of H2O. 
@@ -113,9 +113,9 @@
       if(identical(P, "Psat")) {
         w.P <- H2O[[2]][2]
         w.P[w.P == 0] <- NA
-        # By default, the value of Psat is floored at 1 bar; P1 = FALSE means
-        # that we want the actual values of vapor-liquid saturation pressure
-        if(P1) w.P[w.P < 1] <- 1
+        # Use Psat_floor to NULL or NA to get the actual values of vapor-liquid saturation pressure
+        # (not floored at 1 bar)
+        if(is.numeric(Psat_floor)) w.P[w.P < Psat_floor] <- Psat_floor
         P.out[i] <- w.P
       }
     }
@@ -162,7 +162,7 @@
   w.out
 }
 
-water.IAPWS95 <- function(property = NULL, T = 298.15, P = 1) {
+water.IAPWS95 <- function(property = NULL, T = 298.15, P = 1, Psat_floor = 1) {
   available_properties <- c("A", "G", "S", "U", "H", "Cv", "Cp",
     "Speed", "epsilon",
     "YBorn", "QBorn", "XBorn", "NBorn", "UBorn",
@@ -176,7 +176,8 @@
   # Psat stuff
   Psat <- function() {
     P <- WP02.auxiliary("P.sigma", T)
-    P[T < 373.124] <- 0.1
+    # Convert Psat_floor from bar to MPa
+    if(is.numeric(Psat_floor)) P[P < Psat_floor / 10] <- Psat_floor / 10
     return(convert(P, "bar"))
   }
   ## Thermodynamic properties

Modified: pkg/CHNOSZ/inst/NEWS.Rd
===================================================================
--- pkg/CHNOSZ/inst/NEWS.Rd	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/inst/NEWS.Rd	2025-05-14 11:31:33 UTC (rev 899)
@@ -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-68 (2025-05-11)}{
+\section{Changes in CHNOSZ version 2.1.0-71 (2025-05-14)}{
 
   \subsection{OBIGT DEFAULT DATA}{
     \itemize{
@@ -156,6 +156,9 @@
       \item Fix using Eh in transect mode of \code{affinity()} (feature was not
       working since at least version 0.9-7).
 
+      \item \code{water()} with the IAPWS95 model now respects the value of
+      \strong{Psat_floor}, making it possible to remove the floor of 1 bar.
+
     }
   }
 
@@ -186,6 +189,9 @@
       \item Merge \file{extdata/adds} and \file{extdata/cpetc} into
       \file{extdata/misc}.
 
+      \item In \code{water()}, rename \strong{P1} logical argument to
+      \strong{Psat_floor} numeric argument.
+
     }
   }
 

Modified: pkg/CHNOSZ/inst/tinytest/test-water.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-water.R	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/inst/tinytest/test-water.R	2025-05-14 11:31:33 UTC (rev 899)
@@ -29,6 +29,31 @@
 # We can't do it for DEW because it needs higher pressure
 #expect_equal(round(as.numeric(water.DEW(c("G", "H", "S", "Cp")))), round(G.H.S.Cp_ref), info = info)
 
+# Added 20250514
+info <- "IAPWS95 respects Psat_floor setting"
+water("IAPWS95")
+TC <- seq(99.5, 99.7, 0.01)
+T <- convert(TC, "K")
+# Psat floored at 1 bar is the default
+Psat_floored <- water("Psat", T = T)$Psat
+# Remove the floor
+Psat <- water("Psat", T = T, Psat_floor = NULL)$Psat
+# Psat_floored is higher than Psat up to about 99.60 degrees C
+Tmax <- TC[max(which(Psat_floored > Psat))]
+expect_equal(Tmax, 99.60, info = info)
+
+info <- "SUPCRT92 respects Psat_floor setting"
+water("SUPCRT92")
+TC <- seq(99.5, 99.7, 0.01)
+T <- convert(TC, "K")
+# Psat floored at 1 bar is the default
+Psat_floored <- water("Psat", T = T)$Psat
+# Remove the floor
+Psat <- water("Psat", T = T, Psat_floor = NULL)$Psat
+# Psat_floored is higher than Psat up to about 99.63 degrees C
+Tmax <- TC[max(which(Psat_floored > Psat))]
+expect_equal(Tmax, 99.63, info = info)
+
 # Reference
 
 # Fine, R. A. and Millero, F. J. (1973)

Modified: pkg/CHNOSZ/man/water.Rd
===================================================================
--- pkg/CHNOSZ/man/water.Rd	2025-05-14 00:48:10 UTC (rev 898)
+++ pkg/CHNOSZ/man/water.Rd	2025-05-14 11:31:33 UTC (rev 899)
@@ -10,9 +10,9 @@
 }
 
 \usage{
-  water(property = NULL, T = 298.15, P = "Psat", P1 = TRUE)
-  water.SUPCRT92(property=NULL, T = 298.15, P = 1, P1 = TRUE)
-  water.IAPWS95(property=NULL, T = 298.15, P = 1)
+  water(property = NULL, T = 298.15, P = "Psat", Psat_floor = 1)
+  water.SUPCRT92(property=NULL, T = 298.15, P = 1, Psat_floor = 1)
+  water.IAPWS95(property=NULL, T = 298.15, P = 1, Psat_floor = 1)
   water.DEW(property=NULL, T = 373.15, P = 1000)
 }
 
@@ -20,7 +20,7 @@
   \item{property}{character, computational setting or property(s) to calculate}
   \item{T}{numeric, temperature (K)}
   \item{P}{numeric, pressure (bar), or \samp{Psat} for the greater of 1 bar or the vapor-liquid saturation pressure for \H2O (when P1 is TRUE)}
-  \item{P1}{logical, if TRUE, uses the greater of 1 bar or the vapor-liquid saturation pressure for \samp{Psat}; if FALSE, uses the vapor-liquid saturation pressure for \samp{Psat}}
+  \item{Psat_floor}{numeric, the vapor-liquid saturation curve for \samp{Psat} is floored at this value (in bar); set to NULL or NA to remove the floor}
 }
 
 \details{



More information about the CHNOSZ-commits mailing list