data(thermo)
## set temperature, density
T <- 500; rho <- 838.0235
# calculate pressure
P <- as.numeric(water.IAPWS95('P',T=T,rho=rho))
# output table of test values
water.IAPWS95('test')
# calculate dielectric constant
water.AW90(T=T,rho=rho,P=P)
# find water density for this T, P
water('rho',T=T,P=convert(P,'bar'))
## density along saturation curve
T <- seq(273.15,623.15,25)
water.WP02(T=T) # liquid from WP02
water.WP02('rho.vapor',T) # steam from WP02
water('rho',T=T,P='Psat') # liquid from SUPCRT92
# values of the density, Psat, Gibbs energy
water(c('rho','psat','G'),T=T,P='Psat')
# derivatives of the dielectric constant (Born functions)
water(c('Q','Y','X','U'),T=T)
# now at constant pressure
water(c('Q','Y','X','U'),T=T,P=2000)
## NaCl dissocation logK f(T,P)
# after Shock et al., 1992, Fig. 1
# make note of the warning in the subcrt help page
species <- c('NaCl','Na+','Cl-')
coeffs <- c(-1,1,1)
# start a new plot with the experimental data
thermo.plot.new(xlim=c(0,1000),ylim=c(-5.5,1),
xlab=axis.label("T"),ylab=axis.label("logK"))
expt <- read.csv(system.file("extdata/cpetc/SOJSH.csv",package="CHNOSZ"))
points(expt$T,expt$logK,pch=expt$pch)
T <- list(seq(0,370,25),seq(265,465,25),
seq(285,760,25),seq(395,920,25))
for(i in 5:9) T[[i]] <- seq(400,1000,25)
P <- list("Psat",500,1000,1500,2000,2500,3000,3500,4000)
for(i in 1:length(T)) {
s <- subcrt(species,coeffs,T=T[[i]],P=P[[i]])
lines(s$out$T,s$out$logK)
}
legend("bottomleft",pch=unique(expt$pch),
legend=unique(expt$source))
title(main=paste('NaCl(aq) = Na+ + Cl-\n',
'Psat and 500-4000 bar, after Shock et al., 1992'))
## comparing the computational options
prop <- c('A','G','S','U','H','Cv','Cp','w','epsilon',
'Y','Q','X','rho','Psat')
thermo$opt$water <- 'SUPCRT'
print(water(prop,T=convert(c(25,100,200,300),'K')))
thermo$opt$water <- 'IAPWS'
print(water(c(prop,'N','UBorn'),T=convert(c(25,100,200,300),'K')))
# fixme: things seem to be working except speed of
# sound in our IAPWS calculations
# calculating Q Born function
# after Table 22 of Johnson and Norton, 1991
thermo$opt$water <- 'SUPCRT'
T <- rep(c(375,400,425,450,475),each=5)
P <- rep(c(250,300,350,400,450),5)
w <- water('Q',T=convert(T,'K'),P=P)
# the rest is to make a readable table
w <- as.data.frame(matrix(w[[1]],nrow=5))
colnames(w) <- T[1:5*5]
rownames(w) <- P[1:5]
print(w)
Run the code above in your browser using DataLab