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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 6 15:31:48 CET 2024


Author: jedick
Date: 2024-02-06 15:31:48 +0100 (Tue, 06 Feb 2024)
New Revision: 825

Modified:
   pkg/CHNOSZ/DESCRIPTION
   pkg/CHNOSZ/R/affinity.R
   pkg/CHNOSZ/R/subcrt.R
   pkg/CHNOSZ/inst/tinytest/test-affinity.R
   pkg/CHNOSZ/inst/tinytest/test-subcrt.R
Log:
Add tests for return.sout in affinity() and below Ttr in subcrt()


Modified: pkg/CHNOSZ/DESCRIPTION
===================================================================
--- pkg/CHNOSZ/DESCRIPTION	2024-02-06 13:27:35 UTC (rev 824)
+++ pkg/CHNOSZ/DESCRIPTION	2024-02-06 14:31:48 UTC (rev 825)
@@ -1,6 +1,6 @@
 Date: 2024-02-06
 Package: CHNOSZ
-Version: 2.0.0-44
+Version: 2.0.0-45
 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/affinity.R
===================================================================
--- pkg/CHNOSZ/R/affinity.R	2024-02-06 13:27:35 UTC (rev 824)
+++ pkg/CHNOSZ/R/affinity.R	2024-02-06 14:31:48 UTC (rev 825)
@@ -110,7 +110,7 @@
     affinity_values <- energy_result$a
     energy_sout <- energy_result$sout
 
-    if(return.sout) return(sout)
+    if(return.sout) return(energy_sout)
 
     # More buffer stuff
     if(buffer) {

Modified: pkg/CHNOSZ/R/subcrt.R
===================================================================
--- pkg/CHNOSZ/R/subcrt.R	2024-02-06 13:27:35 UTC (rev 824)
+++ pkg/CHNOSZ/R/subcrt.R	2024-02-06 14:31:48 UTC (rev 825)
@@ -353,24 +353,24 @@
         # Name and state
         myname <- reaction$name[i]
         mystate <- reaction$state[i]
-#        # If we are considering multiple polymorphs, and if this polymorph is cr2 or higher, check if we're below the transition temperature
-#        if(length(iphases) > length(ispecies) & i > 1) {
-#          if(!(reaction$state[i] %in% c("liq", "cr", "gas")) & reaction$name[i-1] == reaction$name[i]) {
-#            # After add.OBIGT("SUPCRT92"), quartz cr and cr2 are not next to each other in thermo()$OBIGT,
-#            # so use iphases[i-1] here, not iphases[i]-1  20181107
-#            Ttr <- Ttr(iphases[i-1], iphases[i], P = P, dPdT = dPdTtr(iphases[i-1], iphases[i]))
-#            if(all(is.na(Ttr))) next
-#            if(any(T <= Ttr)) {
-#              status.Ttr <- "(extrapolating G)"
-#              if(!exceed.Ttr) {
-#                # put NA into the value of G
-#                p.cgl[[ncgl[i]]]$G[T <= Ttr] <- NA
-#                status.Ttr <- "(using NA for G)"
-#              } 
-#              #message(paste("subcrt: some points below transition temperature for", myname, mystate, status.Ttr))
-#            }
-#          }
-#        }
+        # If we are considering multiple polymorphs, and if this polymorph is cr2 or higher, check if we're below the transition temperature
+        if(length(iphases) > length(ispecies) & i > 1) {
+          if(!(reaction$state[i] %in% c("liq", "cr", "gas")) & reaction$name[i-1] == reaction$name[i]) {
+            # After add.OBIGT("SUPCRT92"), quartz cr and cr2 are not next to each other in thermo()$OBIGT,
+            # so use iphases[i-1] here, not iphases[i]-1  20181107
+            Ttr <- Ttr(iphases[i-1], iphases[i], P = P, dPdT = dPdTtr(iphases[i-1], iphases[i]))
+            if(all(is.na(Ttr))) next
+            if(any(T <= Ttr)) {
+              status.Ttr <- "(extrapolating G)"
+              if(!exceed.Ttr) {
+                # put NA into the value of G
+                p.cgl[[ncgl[i]]]$G[T <= Ttr] <- NA
+                status.Ttr <- "(using NA for G)"
+              } 
+              #message(paste("subcrt: some points below transition temperature for", myname, mystate, status.Ttr))
+            }
+          }
+        }
 
         # Check for a polymorphic transition
         is.polymorphic.transition <- FALSE

Modified: pkg/CHNOSZ/inst/tinytest/test-affinity.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-affinity.R	2024-02-06 13:27:35 UTC (rev 824)
+++ pkg/CHNOSZ/inst/tinytest/test-affinity.R	2024-02-06 14:31:48 UTC (rev 825)
@@ -194,3 +194,13 @@
 a1 <- affinity(T = c(0, 100))
 a2 <- affinity(T = c(0, 100), sout = a0$sout)
 expect_equal(a1$values, a2$values, info = info)
+
+info <- "return.sout = TRUE returns output of subcrt()"
+# 20240206
+# Caught by Mosaic Stacking 2 in multi-metal.Rmd
+# (returned value was NULL in CHNOSZ_2.0.0-43,
+#  creating weirdness in mineral-aqueous boundaries on diagram)
+basis("CHNOS+")
+species("CO2")
+a <- affinity(return.sout = TRUE)
+expect_equal(names(a), c("species", "out"), info = info)

Modified: pkg/CHNOSZ/inst/tinytest/test-subcrt.R
===================================================================
--- pkg/CHNOSZ/inst/tinytest/test-subcrt.R	2024-02-06 13:27:35 UTC (rev 824)
+++ pkg/CHNOSZ/inst/tinytest/test-subcrt.R	2024-02-06 14:31:48 UTC (rev 825)
@@ -250,6 +250,16 @@
 sres <- subcrt("acetate", 1, IS = 1)
 expect_length(sres$out$loggam, 15)
 
+# Added on 20240206
+info <- "High-temperature polymorph is not shown as stable below the transition temperature"
+# This checks that the below-transition temperature code in subcrt() is working.
+# If not, then cr2 is incorrectly identified as stable at 25 and 103 degC
+# (that is, cr2 has a lower Delta G0, than cr at those temperature,
+#  but should only be shown as stable above the transition temperature of 377 K)
+T <- c(25, 50, 103, 104)
+sout <- subcrt("carrollite", T = T, P = 1)$out[[1]]
+expect_equal(sout$polymorph, c(1, 1, 1, 2), info = info)
+
 # References
 
 # Amend, J. P. and Shock, E. L. (2001) 



More information about the CHNOSZ-commits mailing list