Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Created September 28, 2023 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenomoto/abd1d49f10ba64c9f8efe5389bdd106c to your computer and use it in GitHub Desktop.
Save tenomoto/abd1d49f10ba64c9f8efe5389bdd106c to your computer and use it in GitHub Desktop.
Carnot cycle and satuation vapour pressure
eps <- 0.622
calc.es <- function(T) {
# WMO, JMA
exp(19.482-4303.4/(T-29.65))*100
}
pref <- 1e5
Rv <- 461 # J/K/kg
gm <- 7/5
t <- 288
dt <- 1
es <- calc.es(t)
des <- 100
esg <- ((es - des)/es)^(1/gm)
dal <- Rv * t / es - 1.e-3
alA <- Rv * (t - dt) / (es - des)
alB <- esg * alA
alC <- alB + dal
alD <- alC / esg
nal <- 11
alAB <- seq(alA, alB, length.out=nal)
esAB <- es * (alB / alAB)^gm
alCD <- seq(alC, alD, length.out=nal)
esCD <- es * (alC / alCD)^gm
pdf("carnot-es.pdf", width=10, height=8)
#plot(1, type="n", xlim=c(alA, alD), ylim=c(esAB[1], esCD[1]),
plot(1, type="n", xlim=c(60, 180), ylim=c(1580, 1700),
main = "Carnot cycle for mixture of liquid water and vapour",
xlab="specific volume m^3", ylab="saturated vapour pressure Pa",
cex.main=1.5, cex.axis=1.5, cex.lab=1.5, frame=FALSE)
lines(alAB, esAB, lwd=3)
arrows(alAB[nal-1], esAB[nal-1], alAB[nal], esAB[nal], code=2, angle=15, lwd=3)
lines(alCD, esCD, lwd=3)
arrows(alCD[nal-1], esCD[nal-1], alCD[nal], esCD[nal], code=2, angle=15, lwd=3)
arrows(alD, es-des, alA, es-des, code=2, angle=15, lwd=3)
arrows(alB, es, alC, es, code=2, angle=15, lwd=3)
dev.off()
pdf("carnot.pdf", width=10, height=10)
n <- 101
t1 <- 273
t2 <- 300
r <- 287
gm <- 7 / 5
pref <- 1e5 # NB. scale p with pref
alpha <- seq(0.7, 1.3, length.out=n)
a1.ref <- r * t1 / pref
a2.ref <- r * t2 / pref
isotherm1 <- a1.ref / alpha
isotherm2 <- a2.ref / alpha
adiabat1 <- a1.ref / alpha^gm
adiabat2 <- a2.ref / alpha^gm
plot(alpha, isotherm1, type="l", axes=FALSE,
xlim=c(0.6, 1.4), ylim=c(0.5, 1.5), xlab="", ylab="", lwd=3, col="black")
lines(alpha, isotherm2, lwd=3, col="black")
lines(alpha, adiabat1, lwd=3, col="gray")
lines(alpha, adiabat2, lwd=3, col="grey")
a.intsec <- c(1, (t1/t2)^(1/(gm-1)), 1, (t2/t1)^(1/(gm-1)))
p.intsec <- c(a1.ref, a2.ref/a.intsec[2], a2.ref, a1.ref/a.intsec[4])
points(a.intsec, p.intsec, pch=20)
text(a.intsec, p.intsec, c("A", "B", "C", "D"), pos=c(1, 1, 3, 3), cex=2.0)
axis(side=1, cex.axis=2.0)
axis(side=2, cex.axis=2.0)
dev.off()
eps <- 0.622
calc.es <- function(T) {
# WMO, JMA
exp(19.482-4303.4/(T-29.65))*100
}
n <- 101
t <- seq(-50, 40, length.out=n)
t0 <- 273.15
tk <- t + t0
es <- calc.es(tk)
pdf("es.pdf", width=12, height=10)
par(mar = c(4, 5, 2, 0))
plot(t, es, type = "l", lwd = 3, ylim = c(0, 8000),
main = "saturation vapour pressure",
xlab = "temperature C", ylab = "saturation vapour pressure Pa",
cex.main = 2, cex.lab = 2, cex.axis = 2, frame = FALSE)
for (tc in seq(0, 40, 20)) {
es.tc <- calc.es(tc+t0)
segments(tc, -300, tc, es.tc)
segments(-60, es.tc, tc, es.tc)
text(-50, es.tc, round(es.tc), pos = 3, cex = 2)
}
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment