[3274] | 1 | !> @file basic_constants_and_equations_mod.f90 |
---|
| 2 | !------------------------------------------------------------------------------! |
---|
| 3 | ! This file is part of the PALM model system. |
---|
| 4 | ! |
---|
| 5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 6 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 8 | ! version. |
---|
| 9 | ! |
---|
| 10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 13 | ! |
---|
| 14 | ! You should have received a copy of the GNU General Public License along with |
---|
| 15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 16 | ! |
---|
[3655] | 17 | ! Copyright 1997-2019 Leibniz Universitaet Hannover |
---|
[3274] | 18 | !------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
| 20 | ! Current revisions: |
---|
| 21 | ! ----------------- |
---|
| 22 | ! |
---|
| 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: basic_constants_and_equations_mod.f90 4088 2019-07-11 13:57:56Z suehring $ |
---|
[4088] | 27 | ! Comment of barometric formula improved, function for ideal gas law revised |
---|
| 28 | ! |
---|
| 29 | ! 4084 2019-07-10 17:09:11Z knoop |
---|
[4084] | 30 | ! Changed precomputed fractions to be variable based |
---|
| 31 | ! |
---|
| 32 | ! 4055 2019-06-27 09:47:29Z suehring |
---|
[4055] | 33 | ! Added rgas_univ (universal gas constant) (E.C. Chan) |
---|
| 34 | ! |
---|
| 35 | ! |
---|
| 36 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3634] | 37 | ! OpenACC port for SPEC |
---|
| 38 | ! |
---|
| 39 | ! 3449 2018-10-29 19:36:56Z suehring |
---|
[3449] | 40 | ! +degc_to_k |
---|
| 41 | ! |
---|
| 42 | ! 3361 2018-10-16 20:39:37Z knoop |
---|
[3274] | 43 | ! New module (introduced with modularization of bulk cloud physics model) |
---|
| 44 | ! |
---|
| 45 | ! |
---|
| 46 | ! |
---|
| 47 | ! |
---|
| 48 | ! Description: |
---|
| 49 | ! ------------ |
---|
| 50 | !> This module contains all basic (physical) constants |
---|
| 51 | !> and |
---|
| 52 | !> functions for the calculation of diagnostic quantities. |
---|
| 53 | !------------------------------------------------------------------------------! |
---|
| 54 | MODULE basic_constants_and_equations_mod |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | USE kinds |
---|
| 58 | |
---|
| 59 | IMPLICIT NONE |
---|
| 60 | |
---|
| 61 | REAL(wp), PARAMETER :: c_p = 1005.0_wp !< heat capacity of dry air (J kg-1 K-1) |
---|
[3449] | 62 | REAL(wp), PARAMETER :: degc_to_k = 273.15_wp !< temperature (in K) of 0 deg C (K) |
---|
[3274] | 63 | REAL(wp), PARAMETER :: g = 9.81_wp !< gravitational acceleration (m s-2) |
---|
| 64 | REAL(wp), PARAMETER :: kappa = 0.4_wp !< von Karman constant |
---|
| 65 | REAL(wp), PARAMETER :: l_m = 0.33E+06_wp !< latent heat of water melting (J kg-1) |
---|
| 66 | REAL(wp), PARAMETER :: l_v = 2.5E+06_wp !< latent heat of water vaporization (J kg-1) |
---|
| 67 | REAL(wp), PARAMETER :: l_s = l_m + l_v !< latent heat of water sublimation (J kg-1) |
---|
| 68 | REAL(wp), PARAMETER :: molecular_weight_of_nacl = 0.05844_wp !< mol. m. NaCl (kg mol-1) |
---|
| 69 | REAL(wp), PARAMETER :: molecular_weight_of_c3h4o4 = 0.10406_wp !< mol. m. malonic acid (kg mol-1) |
---|
| 70 | REAL(wp), PARAMETER :: molecular_weight_of_nh4no3 = 0.08004_wp !< mol. m. ammonium sulfate (kg mol-1) |
---|
| 71 | REAL(wp), PARAMETER :: molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1) |
---|
[3449] | 72 | REAL(wp), PARAMETER :: pi = 3.141592654_wp !< PI |
---|
[3634] | 73 | !$ACC DECLARE COPYIN(pi) |
---|
[4055] | 74 | REAL(wp), PARAMETER :: rgas_univ = 8.31446261815324_wp !< universal gas constant (J K-1 mol-1) |
---|
[3274] | 75 | REAL(wp), PARAMETER :: rho_l = 1.0E3_wp !< density of water (kg m-3) |
---|
| 76 | REAL(wp), PARAMETER :: rho_nacl = 2165.0_wp !< density of NaCl (kg m-3) |
---|
| 77 | REAL(wp), PARAMETER :: rho_c3h4o4 = 1600.0_wp !< density of malonic acid (kg m-3) |
---|
| 78 | REAL(wp), PARAMETER :: rho_nh4no3 = 1720.0_wp !< density of ammonium sulfate (kg m-3) |
---|
| 79 | REAL(wp), PARAMETER :: r_d = 287.0_wp !< sp. gas const. dry air (J kg-1 K-1) |
---|
| 80 | REAL(wp), PARAMETER :: r_v = 461.51_wp !< sp. gas const. water vapor (J kg-1 K-1) |
---|
[3449] | 81 | REAL(wp), PARAMETER :: sigma_sb = 5.67037E-08_wp !< Stefan-Boltzmann constant |
---|
[3274] | 82 | REAL(wp), PARAMETER :: solar_constant = 1368.0_wp !< solar constant at top of atmosphere |
---|
| 83 | REAL(wp), PARAMETER :: vanthoff_nacl = 2.0_wp !< van't Hoff factor for NaCl |
---|
| 84 | REAL(wp), PARAMETER :: vanthoff_c3h4o4 = 1.37_wp !< van't Hoff factor for malonic acid |
---|
| 85 | REAL(wp), PARAMETER :: vanthoff_nh4no3 = 2.31_wp !< van't Hoff factor for ammonium sulfate |
---|
| 86 | |
---|
| 87 | REAL(wp), PARAMETER :: p_0 = 100000.0_wp !< standard pressure reference state |
---|
| 88 | |
---|
| 89 | REAL(wp), PARAMETER :: g_d_cp = g / c_p !< precomputed g / c_p |
---|
| 90 | REAL(wp), PARAMETER :: lv_d_cp = l_v / c_p !< precomputed l_v / c_p |
---|
| 91 | REAL(wp), PARAMETER :: lv_d_rd = l_v / r_d !< precomputed l_v / r_d |
---|
[4084] | 92 | REAL(wp), PARAMETER :: rd_d_rv = r_d / r_v !< precomputed r_d / r_v |
---|
| 93 | REAL(wp), PARAMETER :: rd_d_cp = r_d / c_p !< precomputed r_d / c_p |
---|
| 94 | REAL(wp), PARAMETER :: cp_d_rd = c_p / r_d !< precomputed c_p / r_d |
---|
[3274] | 95 | |
---|
| 96 | REAL(wp) :: molecular_weight_of_solute = molecular_weight_of_nacl !< mol. m. NaCl (kg mol-1) |
---|
| 97 | REAL(wp) :: rho_s = rho_nacl !< density of NaCl (kg m-3) |
---|
| 98 | REAL(wp) :: vanthoff = vanthoff_nacl !< van't Hoff factor for NaCl |
---|
| 99 | |
---|
| 100 | |
---|
| 101 | SAVE |
---|
| 102 | |
---|
| 103 | PRIVATE magnus_0d, & |
---|
| 104 | magnus_1d, & |
---|
| 105 | ideal_gas_law_rho_0d, & |
---|
| 106 | ideal_gas_law_rho_1d, & |
---|
| 107 | ideal_gas_law_rho_pt_0d, & |
---|
| 108 | ideal_gas_law_rho_pt_1d, & |
---|
| 109 | exner_function_0d, & |
---|
| 110 | exner_function_1d, & |
---|
| 111 | exner_function_invers_0d, & |
---|
| 112 | exner_function_invers_1d, & |
---|
| 113 | barometric_formula_0d, & |
---|
| 114 | barometric_formula_1d |
---|
| 115 | |
---|
| 116 | INTERFACE magnus |
---|
| 117 | MODULE PROCEDURE magnus_0d |
---|
| 118 | MODULE PROCEDURE magnus_1d |
---|
| 119 | END INTERFACE magnus |
---|
| 120 | |
---|
| 121 | INTERFACE ideal_gas_law_rho |
---|
| 122 | MODULE PROCEDURE ideal_gas_law_rho_0d |
---|
| 123 | MODULE PROCEDURE ideal_gas_law_rho_1d |
---|
| 124 | END INTERFACE ideal_gas_law_rho |
---|
| 125 | |
---|
| 126 | INTERFACE ideal_gas_law_rho_pt |
---|
| 127 | MODULE PROCEDURE ideal_gas_law_rho_pt_0d |
---|
| 128 | MODULE PROCEDURE ideal_gas_law_rho_pt_1d |
---|
| 129 | END INTERFACE ideal_gas_law_rho_pt |
---|
| 130 | |
---|
| 131 | INTERFACE exner_function |
---|
| 132 | MODULE PROCEDURE exner_function_0d |
---|
| 133 | MODULE PROCEDURE exner_function_1d |
---|
| 134 | END INTERFACE exner_function |
---|
| 135 | |
---|
| 136 | INTERFACE exner_function_invers |
---|
| 137 | MODULE PROCEDURE exner_function_invers_0d |
---|
| 138 | MODULE PROCEDURE exner_function_invers_1d |
---|
| 139 | END INTERFACE exner_function_invers |
---|
| 140 | |
---|
| 141 | INTERFACE barometric_formula |
---|
| 142 | MODULE PROCEDURE barometric_formula_0d |
---|
| 143 | MODULE PROCEDURE barometric_formula_1d |
---|
| 144 | END INTERFACE barometric_formula |
---|
| 145 | |
---|
| 146 | CONTAINS |
---|
| 147 | |
---|
| 148 | !------------------------------------------------------------------------------! |
---|
| 149 | ! Description: |
---|
| 150 | ! ------------ |
---|
| 151 | !> This function computes the magnus formula (Press et al., 1992). |
---|
| 152 | !> The magnus formula is needed to calculate the saturation vapor pressure |
---|
| 153 | !------------------------------------------------------------------------------! |
---|
| 154 | FUNCTION magnus_0d( t ) |
---|
| 155 | |
---|
| 156 | IMPLICIT NONE |
---|
| 157 | |
---|
| 158 | REAL(wp), INTENT(IN) :: t !< temperature (K) |
---|
| 159 | |
---|
| 160 | REAL(wp) :: magnus_0d |
---|
| 161 | ! |
---|
| 162 | !-- Saturation vapor pressure for a specific temperature: |
---|
[3449] | 163 | magnus_0d = 611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / & |
---|
[3274] | 164 | ( t - 29.65_wp ) ) |
---|
| 165 | |
---|
| 166 | END FUNCTION magnus_0d |
---|
| 167 | |
---|
| 168 | !------------------------------------------------------------------------------! |
---|
| 169 | ! Description: |
---|
| 170 | ! ------------ |
---|
| 171 | !> This function computes the magnus formula (Press et al., 1992). |
---|
| 172 | !> The magnus formula is needed to calculate the saturation vapor pressure |
---|
| 173 | !------------------------------------------------------------------------------! |
---|
| 174 | FUNCTION magnus_1d( t ) |
---|
| 175 | |
---|
| 176 | IMPLICIT NONE |
---|
| 177 | |
---|
| 178 | REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) |
---|
| 179 | |
---|
| 180 | REAL(wp), DIMENSION(size(t)) :: magnus_1d |
---|
| 181 | ! |
---|
| 182 | !-- Saturation vapor pressure for a specific temperature: |
---|
[3449] | 183 | magnus_1d = 611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / & |
---|
[3274] | 184 | ( t - 29.65_wp ) ) |
---|
| 185 | |
---|
| 186 | END FUNCTION magnus_1d |
---|
| 187 | |
---|
| 188 | !------------------------------------------------------------------------------! |
---|
| 189 | ! Description: |
---|
| 190 | ! ------------ |
---|
| 191 | !> Compute the ideal gas law for scalar arguments. |
---|
| 192 | !------------------------------------------------------------------------------! |
---|
| 193 | FUNCTION ideal_gas_law_rho_0d( p, t ) |
---|
| 194 | |
---|
| 195 | IMPLICIT NONE |
---|
| 196 | |
---|
| 197 | REAL(wp), INTENT(IN) :: p !< pressure (Pa) |
---|
| 198 | REAL(wp), INTENT(IN) :: t !< temperature (K) |
---|
| 199 | |
---|
| 200 | REAL(wp) :: ideal_gas_law_rho_0d |
---|
| 201 | ! |
---|
| 202 | !-- compute density according to ideal gas law: |
---|
| 203 | ideal_gas_law_rho_0d = p / (r_d * t) |
---|
| 204 | |
---|
| 205 | END FUNCTION ideal_gas_law_rho_0d |
---|
| 206 | |
---|
| 207 | !------------------------------------------------------------------------------! |
---|
| 208 | ! Description: |
---|
| 209 | ! ------------ |
---|
| 210 | !> Compute the ideal gas law for 1-D array arguments. |
---|
| 211 | !------------------------------------------------------------------------------! |
---|
| 212 | FUNCTION ideal_gas_law_rho_1d( p, t ) |
---|
| 213 | |
---|
| 214 | IMPLICIT NONE |
---|
| 215 | |
---|
| 216 | REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) |
---|
| 217 | REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) |
---|
| 218 | |
---|
| 219 | REAL(wp), DIMENSION(size(p)) :: ideal_gas_law_rho_1d |
---|
| 220 | ! |
---|
| 221 | !-- compute density according to ideal gas law: |
---|
| 222 | ideal_gas_law_rho_1d = p / (r_d * t) |
---|
| 223 | |
---|
| 224 | END FUNCTION ideal_gas_law_rho_1d |
---|
| 225 | |
---|
| 226 | !------------------------------------------------------------------------------! |
---|
| 227 | ! Description: |
---|
| 228 | ! ------------ |
---|
| 229 | !> Compute the ideal gas law for scalar arguments. |
---|
| 230 | !------------------------------------------------------------------------------! |
---|
| 231 | FUNCTION ideal_gas_law_rho_pt_0d( p, t ) |
---|
| 232 | |
---|
| 233 | IMPLICIT NONE |
---|
| 234 | |
---|
| 235 | REAL(wp), INTENT(IN) :: p !< pressure (Pa) |
---|
| 236 | REAL(wp), INTENT(IN) :: t !< temperature (K) |
---|
| 237 | |
---|
| 238 | REAL(wp) :: ideal_gas_law_rho_pt_0d |
---|
| 239 | ! |
---|
| 240 | !-- compute density according to ideal gas law: |
---|
[4088] | 241 | ideal_gas_law_rho_pt_0d = p / (r_d * exner_function(p) * t) |
---|
[3274] | 242 | |
---|
| 243 | END FUNCTION ideal_gas_law_rho_pt_0d |
---|
| 244 | |
---|
| 245 | !------------------------------------------------------------------------------! |
---|
| 246 | ! Description: |
---|
| 247 | ! ------------ |
---|
| 248 | !> Compute the ideal gas law for 1-D array arguments. |
---|
| 249 | !------------------------------------------------------------------------------! |
---|
| 250 | FUNCTION ideal_gas_law_rho_pt_1d( p, t ) |
---|
| 251 | |
---|
| 252 | IMPLICIT NONE |
---|
| 253 | |
---|
| 254 | REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) |
---|
| 255 | REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) |
---|
| 256 | |
---|
| 257 | REAL(wp), DIMENSION(size(p)) :: ideal_gas_law_rho_pt_1d |
---|
| 258 | ! |
---|
| 259 | !-- compute density according to ideal gas law: |
---|
[4088] | 260 | ideal_gas_law_rho_pt_1d = p / (r_d * exner_function(p) * t) |
---|
[3274] | 261 | |
---|
| 262 | END FUNCTION ideal_gas_law_rho_pt_1d |
---|
| 263 | |
---|
| 264 | !------------------------------------------------------------------------------! |
---|
| 265 | ! Description: |
---|
| 266 | ! ------------ |
---|
| 267 | !> Compute the exner function for scalar arguments. |
---|
| 268 | !------------------------------------------------------------------------------! |
---|
| 269 | FUNCTION exner_function_0d( p ) |
---|
| 270 | |
---|
| 271 | IMPLICIT NONE |
---|
| 272 | |
---|
| 273 | REAL(wp), INTENT(IN) :: p !< pressure (Pa) |
---|
| 274 | |
---|
| 275 | REAL(wp) :: exner_function_0d |
---|
| 276 | ! |
---|
| 277 | !-- compute exner function: |
---|
| 278 | exner_function_0d = ( p / p_0 )**( rd_d_cp ) |
---|
| 279 | |
---|
| 280 | END FUNCTION exner_function_0d |
---|
| 281 | |
---|
| 282 | !------------------------------------------------------------------------------! |
---|
| 283 | ! Description: |
---|
| 284 | ! ------------ |
---|
| 285 | !> Compute the exner function for 1-D array arguments. |
---|
| 286 | !------------------------------------------------------------------------------! |
---|
| 287 | FUNCTION exner_function_1d( p ) |
---|
| 288 | |
---|
| 289 | IMPLICIT NONE |
---|
| 290 | |
---|
| 291 | REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) |
---|
| 292 | |
---|
| 293 | REAL(wp), DIMENSION(size(p)) :: exner_function_1d |
---|
| 294 | ! |
---|
| 295 | !-- compute exner function: |
---|
| 296 | exner_function_1d = ( p / p_0 )**( rd_d_cp ) |
---|
| 297 | |
---|
| 298 | END FUNCTION exner_function_1d |
---|
| 299 | |
---|
| 300 | !------------------------------------------------------------------------------! |
---|
| 301 | ! Description: |
---|
| 302 | ! ------------ |
---|
| 303 | !> Compute the exner function for scalar arguments. |
---|
| 304 | !------------------------------------------------------------------------------! |
---|
| 305 | FUNCTION exner_function_invers_0d( p ) |
---|
| 306 | |
---|
| 307 | IMPLICIT NONE |
---|
| 308 | |
---|
| 309 | REAL(wp), INTENT(IN) :: p !< pressure (Pa) |
---|
| 310 | |
---|
| 311 | REAL(wp) :: exner_function_invers_0d |
---|
| 312 | ! |
---|
| 313 | !-- compute exner function: |
---|
| 314 | exner_function_invers_0d = ( p_0 / p )**( rd_d_cp ) |
---|
| 315 | |
---|
| 316 | END FUNCTION exner_function_invers_0d |
---|
| 317 | |
---|
| 318 | !------------------------------------------------------------------------------! |
---|
| 319 | ! Description: |
---|
| 320 | ! ------------ |
---|
| 321 | !> Compute the exner function for 1-D array arguments. |
---|
| 322 | !------------------------------------------------------------------------------! |
---|
| 323 | FUNCTION exner_function_invers_1d( p ) |
---|
| 324 | |
---|
| 325 | IMPLICIT NONE |
---|
| 326 | |
---|
| 327 | REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) |
---|
| 328 | |
---|
| 329 | REAL(wp), DIMENSION(size(p)) :: exner_function_invers_1d |
---|
| 330 | ! |
---|
| 331 | !-- compute exner function: |
---|
| 332 | exner_function_invers_1d = ( p_0 / p )**( rd_d_cp ) |
---|
| 333 | |
---|
| 334 | END FUNCTION exner_function_invers_1d |
---|
| 335 | |
---|
| 336 | !------------------------------------------------------------------------------! |
---|
| 337 | ! Description: |
---|
| 338 | ! ------------ |
---|
[4088] | 339 | !> Compute the barometric formula for scalar arguments. The calculation is |
---|
| 340 | !> based on the assumption of a polytropic atmosphere and neutral |
---|
| 341 | !> stratification, where the temperature lapse rate is g/cp. |
---|
[3274] | 342 | !------------------------------------------------------------------------------! |
---|
| 343 | FUNCTION barometric_formula_0d( z, t_0, p_0) |
---|
| 344 | |
---|
| 345 | IMPLICIT NONE |
---|
| 346 | |
---|
| 347 | REAL(wp), INTENT(IN) :: z !< height (m) |
---|
| 348 | REAL(wp), INTENT(IN) :: t_0 !< temperature reference state (K) |
---|
| 349 | REAL(wp), INTENT(IN) :: p_0 !< surface pressure (Pa) |
---|
| 350 | |
---|
| 351 | REAL(wp) :: barometric_formula_0d |
---|
| 352 | ! |
---|
| 353 | !-- compute barometric formula: |
---|
| 354 | barometric_formula_0d = p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd ) |
---|
| 355 | |
---|
| 356 | END FUNCTION barometric_formula_0d |
---|
| 357 | |
---|
| 358 | !------------------------------------------------------------------------------! |
---|
| 359 | ! Description: |
---|
| 360 | ! ------------ |
---|
[4088] | 361 | !> Compute the barometric formula for 1-D array arguments. The calculation is |
---|
| 362 | !> based on the assumption of a polytropic atmosphere and neutral |
---|
| 363 | !> stratification, where the temperature lapse rate is g/cp. |
---|
[3274] | 364 | !------------------------------------------------------------------------------! |
---|
| 365 | FUNCTION barometric_formula_1d( z, t_0, p_0) |
---|
| 366 | |
---|
| 367 | IMPLICIT NONE |
---|
| 368 | |
---|
| 369 | REAL(wp), INTENT(IN), DIMENSION(:) :: z !< height (m) |
---|
| 370 | REAL(wp), INTENT(IN) :: t_0 !< temperature reference state (K) |
---|
| 371 | REAL(wp), INTENT(IN) :: p_0 !< surface pressure (Pa) |
---|
| 372 | |
---|
| 373 | REAL(wp), DIMENSION(size(z)) :: barometric_formula_1d |
---|
| 374 | ! |
---|
| 375 | !-- compute barometric formula: |
---|
| 376 | barometric_formula_1d = p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd ) |
---|
| 377 | |
---|
| 378 | END FUNCTION barometric_formula_1d |
---|
| 379 | |
---|
| 380 | END MODULE basic_constants_and_equations_mod |
---|