!> @file basic_constants_and_equations_mod.f90 !------------------------------------------------------------------------------! ! This file is part of the PALM model system. ! ! PALM is free software: you can redistribute it and/or modify it under the ! terms of the GNU General Public License as published by the Free Software ! Foundation, either version 3 of the License, or (at your option) any later ! version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2019 Leibniz Universitaet Hannover !------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: basic_constants_and_equations_mod.f90 4084 2019-07-10 17:09:11Z gronemeier $ ! Changed precomputed fractions to be variable based ! ! 4055 2019-06-27 09:47:29Z suehring ! Added rgas_univ (universal gas constant) (E.C. Chan) ! ! ! 3655 2019-01-07 16:51:22Z knoop ! OpenACC port for SPEC ! ! 3449 2018-10-29 19:36:56Z suehring ! +degc_to_k ! ! 3361 2018-10-16 20:39:37Z knoop ! New module (introduced with modularization of bulk cloud physics model) ! ! ! ! ! Description: ! ------------ !> This module contains all basic (physical) constants !> and !> functions for the calculation of diagnostic quantities. !------------------------------------------------------------------------------! MODULE basic_constants_and_equations_mod USE kinds IMPLICIT NONE REAL(wp), PARAMETER :: c_p = 1005.0_wp !< heat capacity of dry air (J kg-1 K-1) REAL(wp), PARAMETER :: degc_to_k = 273.15_wp !< temperature (in K) of 0 deg C (K) REAL(wp), PARAMETER :: g = 9.81_wp !< gravitational acceleration (m s-2) REAL(wp), PARAMETER :: kappa = 0.4_wp !< von Karman constant REAL(wp), PARAMETER :: l_m = 0.33E+06_wp !< latent heat of water melting (J kg-1) REAL(wp), PARAMETER :: l_v = 2.5E+06_wp !< latent heat of water vaporization (J kg-1) REAL(wp), PARAMETER :: l_s = l_m + l_v !< latent heat of water sublimation (J kg-1) REAL(wp), PARAMETER :: molecular_weight_of_nacl = 0.05844_wp !< mol. m. NaCl (kg mol-1) REAL(wp), PARAMETER :: molecular_weight_of_c3h4o4 = 0.10406_wp !< mol. m. malonic acid (kg mol-1) REAL(wp), PARAMETER :: molecular_weight_of_nh4no3 = 0.08004_wp !< mol. m. ammonium sulfate (kg mol-1) REAL(wp), PARAMETER :: molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1) REAL(wp), PARAMETER :: pi = 3.141592654_wp !< PI !$ACC DECLARE COPYIN(pi) REAL(wp), PARAMETER :: rgas_univ = 8.31446261815324_wp !< universal gas constant (J K-1 mol-1) REAL(wp), PARAMETER :: rho_l = 1.0E3_wp !< density of water (kg m-3) REAL(wp), PARAMETER :: rho_nacl = 2165.0_wp !< density of NaCl (kg m-3) REAL(wp), PARAMETER :: rho_c3h4o4 = 1600.0_wp !< density of malonic acid (kg m-3) REAL(wp), PARAMETER :: rho_nh4no3 = 1720.0_wp !< density of ammonium sulfate (kg m-3) REAL(wp), PARAMETER :: r_d = 287.0_wp !< sp. gas const. dry air (J kg-1 K-1) REAL(wp), PARAMETER :: r_v = 461.51_wp !< sp. gas const. water vapor (J kg-1 K-1) REAL(wp), PARAMETER :: sigma_sb = 5.67037E-08_wp !< Stefan-Boltzmann constant REAL(wp), PARAMETER :: solar_constant = 1368.0_wp !< solar constant at top of atmosphere REAL(wp), PARAMETER :: vanthoff_nacl = 2.0_wp !< van't Hoff factor for NaCl REAL(wp), PARAMETER :: vanthoff_c3h4o4 = 1.37_wp !< van't Hoff factor for malonic acid REAL(wp), PARAMETER :: vanthoff_nh4no3 = 2.31_wp !< van't Hoff factor for ammonium sulfate REAL(wp), PARAMETER :: p_0 = 100000.0_wp !< standard pressure reference state REAL(wp), PARAMETER :: g_d_cp = g / c_p !< precomputed g / c_p REAL(wp), PARAMETER :: lv_d_cp = l_v / c_p !< precomputed l_v / c_p REAL(wp), PARAMETER :: lv_d_rd = l_v / r_d !< precomputed l_v / r_d REAL(wp), PARAMETER :: rd_d_rv = r_d / r_v !< precomputed r_d / r_v REAL(wp), PARAMETER :: rd_d_cp = r_d / c_p !< precomputed r_d / c_p REAL(wp), PARAMETER :: cp_d_rd = c_p / r_d !< precomputed c_p / r_d REAL(wp) :: molecular_weight_of_solute = molecular_weight_of_nacl !< mol. m. NaCl (kg mol-1) REAL(wp) :: rho_s = rho_nacl !< density of NaCl (kg m-3) REAL(wp) :: vanthoff = vanthoff_nacl !< van't Hoff factor for NaCl SAVE PRIVATE magnus_0d, & magnus_1d, & ideal_gas_law_rho_0d, & ideal_gas_law_rho_1d, & ideal_gas_law_rho_pt_0d, & ideal_gas_law_rho_pt_1d, & exner_function_0d, & exner_function_1d, & exner_function_invers_0d, & exner_function_invers_1d, & barometric_formula_0d, & barometric_formula_1d INTERFACE magnus MODULE PROCEDURE magnus_0d MODULE PROCEDURE magnus_1d END INTERFACE magnus INTERFACE ideal_gas_law_rho MODULE PROCEDURE ideal_gas_law_rho_0d MODULE PROCEDURE ideal_gas_law_rho_1d END INTERFACE ideal_gas_law_rho INTERFACE ideal_gas_law_rho_pt MODULE PROCEDURE ideal_gas_law_rho_pt_0d MODULE PROCEDURE ideal_gas_law_rho_pt_1d END INTERFACE ideal_gas_law_rho_pt INTERFACE exner_function MODULE PROCEDURE exner_function_0d MODULE PROCEDURE exner_function_1d END INTERFACE exner_function INTERFACE exner_function_invers MODULE PROCEDURE exner_function_invers_0d MODULE PROCEDURE exner_function_invers_1d END INTERFACE exner_function_invers INTERFACE barometric_formula MODULE PROCEDURE barometric_formula_0d MODULE PROCEDURE barometric_formula_1d END INTERFACE barometric_formula CONTAINS !------------------------------------------------------------------------------! ! Description: ! ------------ !> This function computes the magnus formula (Press et al., 1992). !> The magnus formula is needed to calculate the saturation vapor pressure !------------------------------------------------------------------------------! FUNCTION magnus_0d( t ) IMPLICIT NONE REAL(wp), INTENT(IN) :: t !< temperature (K) REAL(wp) :: magnus_0d ! !-- Saturation vapor pressure for a specific temperature: magnus_0d = 611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / & ( t - 29.65_wp ) ) END FUNCTION magnus_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> This function computes the magnus formula (Press et al., 1992). !> The magnus formula is needed to calculate the saturation vapor pressure !------------------------------------------------------------------------------! FUNCTION magnus_1d( t ) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) REAL(wp), DIMENSION(size(t)) :: magnus_1d ! !-- Saturation vapor pressure for a specific temperature: magnus_1d = 611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / & ( t - 29.65_wp ) ) END FUNCTION magnus_1d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the ideal gas law for scalar arguments. !------------------------------------------------------------------------------! FUNCTION ideal_gas_law_rho_0d( p, t ) IMPLICIT NONE REAL(wp), INTENT(IN) :: p !< pressure (Pa) REAL(wp), INTENT(IN) :: t !< temperature (K) REAL(wp) :: ideal_gas_law_rho_0d ! !-- compute density according to ideal gas law: ideal_gas_law_rho_0d = p / (r_d * t) END FUNCTION ideal_gas_law_rho_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the ideal gas law for 1-D array arguments. !------------------------------------------------------------------------------! FUNCTION ideal_gas_law_rho_1d( p, t ) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) REAL(wp), DIMENSION(size(p)) :: ideal_gas_law_rho_1d ! !-- compute density according to ideal gas law: ideal_gas_law_rho_1d = p / (r_d * t) END FUNCTION ideal_gas_law_rho_1d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the ideal gas law for scalar arguments. !------------------------------------------------------------------------------! FUNCTION ideal_gas_law_rho_pt_0d( p, t ) IMPLICIT NONE REAL(wp), INTENT(IN) :: p !< pressure (Pa) REAL(wp), INTENT(IN) :: t !< temperature (K) REAL(wp) :: ideal_gas_law_rho_pt_0d ! !-- compute density according to ideal gas law: ideal_gas_law_rho_pt_0d = p / (r_d * (1.0_wp / exner_function_invers(p)) * t) END FUNCTION ideal_gas_law_rho_pt_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the ideal gas law for 1-D array arguments. !------------------------------------------------------------------------------! FUNCTION ideal_gas_law_rho_pt_1d( p, t ) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) REAL(wp), INTENT(IN), DIMENSION(:) :: t !< temperature (K) REAL(wp), DIMENSION(size(p)) :: ideal_gas_law_rho_pt_1d ! !-- compute density according to ideal gas law: ideal_gas_law_rho_pt_1d = p / (r_d * (1.0_wp / exner_function_invers(p)) * t) END FUNCTION ideal_gas_law_rho_pt_1d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the exner function for scalar arguments. !------------------------------------------------------------------------------! FUNCTION exner_function_0d( p ) IMPLICIT NONE REAL(wp), INTENT(IN) :: p !< pressure (Pa) REAL(wp) :: exner_function_0d ! !-- compute exner function: exner_function_0d = ( p / p_0 )**( rd_d_cp ) END FUNCTION exner_function_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the exner function for 1-D array arguments. !------------------------------------------------------------------------------! FUNCTION exner_function_1d( p ) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) REAL(wp), DIMENSION(size(p)) :: exner_function_1d ! !-- compute exner function: exner_function_1d = ( p / p_0 )**( rd_d_cp ) END FUNCTION exner_function_1d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the exner function for scalar arguments. !------------------------------------------------------------------------------! FUNCTION exner_function_invers_0d( p ) IMPLICIT NONE REAL(wp), INTENT(IN) :: p !< pressure (Pa) REAL(wp) :: exner_function_invers_0d ! !-- compute exner function: exner_function_invers_0d = ( p_0 / p )**( rd_d_cp ) END FUNCTION exner_function_invers_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the exner function for 1-D array arguments. !------------------------------------------------------------------------------! FUNCTION exner_function_invers_1d( p ) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: p !< pressure (Pa) REAL(wp), DIMENSION(size(p)) :: exner_function_invers_1d ! !-- compute exner function: exner_function_invers_1d = ( p_0 / p )**( rd_d_cp ) END FUNCTION exner_function_invers_1d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the barometric formula for scalar arguments. !------------------------------------------------------------------------------! FUNCTION barometric_formula_0d( z, t_0, p_0) IMPLICIT NONE REAL(wp), INTENT(IN) :: z !< height (m) REAL(wp), INTENT(IN) :: t_0 !< temperature reference state (K) REAL(wp), INTENT(IN) :: p_0 !< surface pressure (Pa) REAL(wp) :: barometric_formula_0d ! !-- compute barometric formula: barometric_formula_0d = p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd ) END FUNCTION barometric_formula_0d !------------------------------------------------------------------------------! ! Description: ! ------------ !> Compute the barometric formula for 1-D array arguments. !------------------------------------------------------------------------------! FUNCTION barometric_formula_1d( z, t_0, p_0) IMPLICIT NONE REAL(wp), INTENT(IN), DIMENSION(:) :: z !< height (m) REAL(wp), INTENT(IN) :: t_0 !< temperature reference state (K) REAL(wp), INTENT(IN) :: p_0 !< surface pressure (Pa) REAL(wp), DIMENSION(size(z)) :: barometric_formula_1d ! !-- compute barometric formula: barometric_formula_1d = p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd ) END FUNCTION barometric_formula_1d END MODULE basic_constants_and_equations_mod