Last active
March 26, 2021 16:30
-
-
Save yoshida-eth0/f1f0f11a4817ffff3f1822bf28e1558e to your computer and use it in GitHub Desktop.
飽和水蒸気圧と飽和水蒸気量の計算、乾湿差から相対湿度の計算、不快指数の計算
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 飽和水蒸気圧 SWVP: saturation water vapor pressure | |
module Swvp | |
end | |
# 飽和水蒸気圧 Tetensの式 | |
class TetensSwvp | |
include Swvp | |
def calc(temp) | |
6.11 * 10 ** ((7.5 * temp) / (237.3 + temp)) | |
end | |
end | |
# 飽和水蒸気圧 Wagnerの式 | |
class WagnerSwvp | |
include Swvp | |
Pc = 221200 # hPa:臨界圧 | |
Tc = 647.3 # K:臨界温度 | |
A = -7.76451 | |
B = 1.45838 | |
C = -2.7758 | |
D = -1.2303 | |
def calc(temp) | |
x = 1 - (temp + 273.15) / Tc | |
Pc * Math.exp((A * x + B * x**1.5 + C * x**3 + D * x**6) / (1 - x)) | |
end | |
end | |
# 飽和水蒸気圧 Sonntagの式 | |
class SonntagSwvp | |
include Swvp | |
A = -6096.9385 | |
B = 21.2409642 | |
C = 2.711193 * 10**-2 | |
D = 1.673852 * 10**-5 | |
E = 2.433502 | |
def calc(temp) | |
(Math.exp(A * ((temp + 273.15)**-1) + B - C * (temp + 273.15) + D * ((temp + 273.15)**2) + E * Math.log(temp + 273.15))) / 100 | |
end | |
end | |
# 飽和水蒸気量 SWVA: saturation water vapor amount | |
class Swva | |
attr_reader :swvp | |
def initialize(swvp=WagnerSwvp.new) | |
@swvp = swvp | |
end | |
def calc(temp) | |
217.0 * swvp.calc(temp) / (temp + 273.15) | |
end | |
end | |
# 乾湿差 | |
class Psychrometry | |
attr_reader :swvp | |
attr_reader :pressure | |
attr_reader :k | |
def initialize(swvp=WagnerSwvp.new, pressure: 1013, k: 0.000662) | |
@swvp = swvp | |
@pressure = pressure | |
@k = k | |
end | |
# 乾湿差から相対湿度へ変換 | |
def calc(t_wet, t_dry) | |
p_wet = swvp.calc(t_wet) | |
p_dry = swvp.calc(t_dry) | |
p_w = p_wet - pressure * k * (t_dry - t_wet) | |
rh = p_w / p_dry | |
rh | |
end | |
end | |
# 不快指数 | |
class DiscomfortIndex | |
attr_reader :wet | |
attr_reader :dry | |
attr_reader :psychrometry | |
def initialize(wet, dry, psychrometry=Psychrometry.new) | |
@wet = wet | |
@dry = dry | |
@psychrometry = psychrometry | |
end | |
def from_dw | |
0.72 * (dry + wet) + 40.6 | |
end | |
def from_rh | |
rh = psychrometry.calc(wet, dry) | |
0.81 * dry + 0.01 * (rh * 100) * (0.99 * dry - 14.3) + 46.3 | |
end | |
end | |
# 飽和水蒸気圧 | |
temp = 30 | |
puts "飽和水蒸気圧" | |
puts "Tetensの式: #{TetensSwvp.new.calc(temp)} hPa" | |
puts "Wagnerの式: #{WagnerSwvp.new.calc(temp)} hPa" | |
puts "Sonntagの式: #{SonntagSwvp.new.calc(temp)} hPa" | |
puts | |
# 飽和水蒸気量 | |
puts "飽和水蒸気量: #{Swva.new.calc(temp)} g/m^3" | |
puts | |
# 乾湿差から相対湿度 | |
dry = 30.0 | |
wet = 25.0 | |
pressures = { | |
"平穏な地上": 1013, | |
"猛烈な台風": 900, | |
"富士山山頂": 630, | |
} | |
pressures.each {|label, hpa| | |
humidity = Psychrometry.new(pressure: hpa).calc(wet, dry) * 100 | |
puts "相対湿度 #{label}: #{humidity} %rh" | |
} | |
puts | |
# 不快指数 | |
di = DiscomfortIndex.new(wet, dry) | |
puts "DI (from DW): #{di.from_dw}" | |
puts "DI (from RH): #{di.from_rh}" | |
__END__ | |
飽和水蒸気圧 | |
Tetensの式: 42.441629713216905 hPa | |
Wagnerの式: 42.49122382333086 hPa | |
Sonntagの式: 42.46638883838413 hPa | |
飽和水蒸気量: 30.415951079210945 g/m^3 | |
相対湿度 平穏な地上: 66.75729341239447 %rh | |
相対湿度 猛烈な台風: 67.63754577122305 %rh | |
相対湿度 富士山山頂: 69.7408036197515 %rh | |
DI (from DW): 80.2 | |
DI (from RH): 80.88062318550874 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment