source: palm/trunk/SOURCE/basic_constants_and_equations_mod.f90 @ 4598

Last change on this file since 4598 was 4509, checked in by raasch, 4 years ago

files re-formatted to follow the PALM coding standard

  • Property svn:keywords set to Id
File size: 25.2 KB
RevLine 
[3274]1!> @file basic_constants_and_equations_mod.f90
[4509]2!--------------------------------------------------------------------------------------------------!
[3274]3! This file is part of the PALM model system.
4!
[4509]5! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General
6! Public License as published by the Free Software Foundation, either version 3 of the License, or
7! (at your option) any later version.
[3274]8!
[4509]9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11! Public License for more details.
[3274]12!
[4509]13! You should have received a copy of the GNU General Public License along with PALM. If not, see
14! <http://www.gnu.org/licenses/>.
[3274]15!
[4360]16! Copyright 1997-2020 Leibniz Universitaet Hannover
[4509]17!--------------------------------------------------------------------------------------------------!
[3274]18!
19! Current revisions:
20! -----------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: basic_constants_and_equations_mod.f90 4509 2020-04-26 15:57:55Z suehring $
[4509]26! file re-formatted to follow the PALM coding standard
27!
28! 4502 2020-04-17 16:14:16Z schwenkel
[4502]29! Implementation of ice microphysics
[4509]30!
[4502]31! 4400 2020-02-10 20:32:41Z suehring
[4509]32! Move routine to transform coordinates from netcdf_interface_mod to
[4400]33! basic_constants_and_equations_mod
[4509]34!
[4400]35! 4360 2020-01-07 11:25:50Z suehring
[4182]36! Corrected "Former revisions" section
[4509]37!
[4182]38! 4088 2019-07-11 13:57:56Z Giersch
[4509]39! Comment of barometric formula improved, function for ideal gas law revised
40!
[4088]41! 4084 2019-07-10 17:09:11Z knoop
[4084]42! Changed precomputed fractions to be variable based
[4509]43!
[4084]44! 4055 2019-06-27 09:47:29Z suehring
[4055]45! Added rgas_univ (universal gas constant) (E.C. Chan)
[4509]46!
47!
[4055]48! 3655 2019-01-07 16:51:22Z knoop
[3634]49! OpenACC port for SPEC
[4182]50! 3361 2018-10-16 20:39:37Z knoop
51! New module (introduced with modularization of bulk cloud physics model)
52!
[3274]53!
[4182]54!
[4509]55!
[3274]56! Description:
57! ------------
[4509]58!> This module contains all basic (physical) constants and functions for the calculation of
59!> diagnostic quantities.
60!-                    -----------------------------------------------------------------------------!
[3274]61 MODULE basic_constants_and_equations_mod
62
63
64    USE kinds
65
66    IMPLICIT NONE
67
[4509]68
[3274]69    REAL(wp), PARAMETER ::  c_p = 1005.0_wp                           !< heat capacity of dry air (J kg-1 K-1)
[3449]70    REAL(wp), PARAMETER ::  degc_to_k = 273.15_wp                     !< temperature (in K) of 0 deg C (K)
[3274]71    REAL(wp), PARAMETER ::  g = 9.81_wp                               !< gravitational acceleration (m s-2)
72    REAL(wp), PARAMETER ::  kappa = 0.4_wp                            !< von Karman constant
73    REAL(wp), PARAMETER ::  l_m = 0.33E+06_wp                         !< latent heat of water melting (J kg-1)
74    REAL(wp), PARAMETER ::  l_v = 2.5E+06_wp                          !< latent heat of water vaporization (J kg-1)
75    REAL(wp), PARAMETER ::  l_s = l_m + l_v                           !< latent heat of water sublimation (J kg-1)
76    REAL(wp), PARAMETER ::  molecular_weight_of_nacl = 0.05844_wp     !< mol. m. NaCl (kg mol-1)
77    REAL(wp), PARAMETER ::  molecular_weight_of_c3h4o4 = 0.10406_wp   !< mol. m. malonic acid (kg mol-1)
78    REAL(wp), PARAMETER ::  molecular_weight_of_nh4no3 = 0.08004_wp   !< mol. m. ammonium sulfate (kg mol-1)
79    REAL(wp), PARAMETER ::  molecular_weight_of_water = 0.01801528_wp !< mol. m. H2O (kg mol-1)
[3449]80    REAL(wp), PARAMETER ::  pi = 3.141592654_wp                       !< PI
[3634]81    !$ACC DECLARE COPYIN(pi)
[4055]82    REAL(wp), PARAMETER ::  rgas_univ = 8.31446261815324_wp           !< universal gas constant (J K-1 mol-1)
[3274]83    REAL(wp), PARAMETER ::  rho_l = 1.0E3_wp                          !< density of water (kg m-3)
84    REAL(wp), PARAMETER ::  rho_nacl = 2165.0_wp                      !< density of NaCl (kg m-3)
85    REAL(wp), PARAMETER ::  rho_c3h4o4 = 1600.0_wp                    !< density of malonic acid (kg m-3)
86    REAL(wp), PARAMETER ::  rho_nh4no3 = 1720.0_wp                    !< density of ammonium sulfate (kg m-3)
87    REAL(wp), PARAMETER ::  r_d = 287.0_wp                            !< sp. gas const. dry air (J kg-1 K-1)
88    REAL(wp), PARAMETER ::  r_v = 461.51_wp                           !< sp. gas const. water vapor (J kg-1 K-1)
[3449]89    REAL(wp), PARAMETER ::  sigma_sb = 5.67037E-08_wp                 !< Stefan-Boltzmann constant
[3274]90    REAL(wp), PARAMETER ::  solar_constant = 1368.0_wp                !< solar constant at top of atmosphere
91    REAL(wp), PARAMETER ::  vanthoff_nacl = 2.0_wp                    !< van't Hoff factor for NaCl
92    REAL(wp), PARAMETER ::  vanthoff_c3h4o4 = 1.37_wp                 !< van't Hoff factor for malonic acid
93    REAL(wp), PARAMETER ::  vanthoff_nh4no3 = 2.31_wp                 !< van't Hoff factor for ammonium sulfate
94
95    REAL(wp), PARAMETER ::  p_0 = 100000.0_wp                         !< standard pressure reference state
96
[4509]97    REAL(wp), PARAMETER ::  cp_d_rd = c_p / r_d   !< precomputed c_p / r_d
[3274]98    REAL(wp), PARAMETER ::  g_d_cp  = g   / c_p   !< precomputed g / c_p
99    REAL(wp), PARAMETER ::  lv_d_cp = l_v / c_p   !< precomputed l_v / c_p
[4502]100    REAL(wp), PARAMETER ::  ls_d_cp = l_s / c_p   !< precomputed l_s / c_p
[3274]101    REAL(wp), PARAMETER ::  lv_d_rd = l_v / r_d   !< precomputed l_v / r_d
[4084]102    REAL(wp), PARAMETER ::  rd_d_rv = r_d / r_v   !< precomputed r_d / r_v
103    REAL(wp), PARAMETER ::  rd_d_cp = r_d / c_p   !< precomputed r_d / c_p
[3274]104
105    REAL(wp) ::  molecular_weight_of_solute = molecular_weight_of_nacl  !< mol. m. NaCl (kg mol-1)
106    REAL(wp) ::  rho_s = rho_nacl                                       !< density of NaCl (kg m-3)
107    REAL(wp) ::  vanthoff = vanthoff_nacl                               !< van't Hoff factor for NaCl
108
109    SAVE
110
[4509]111    PRIVATE magnus_0d,                                                                             &
112            magnus_1d,                                                                             &
113            magnus_tl_0d,                                                                          &
114            magnus_tl_1d,                                                                          &
115            magnus_0d_ice,                                                                         &
116            magnus_1d_ice,                                                                         &
117            ideal_gas_law_rho_0d,                                                                  &
118            ideal_gas_law_rho_1d,                                                                  &
119            ideal_gas_law_rho_pt_0d,                                                               &
120            ideal_gas_law_rho_pt_1d,                                                               &
121            exner_function_0d,                                                                     &
122            exner_function_1d,                                                                     &
123            exner_function_invers_0d,                                                              &
124            exner_function_invers_1d,                                                              &
125            barometric_formula_0d,                                                                 &
[3274]126            barometric_formula_1d
127
[4400]128
129    INTERFACE convert_utm_to_geographic
130       MODULE PROCEDURE convert_utm_to_geographic
131    END INTERFACE convert_utm_to_geographic
132
[3274]133    INTERFACE magnus
134       MODULE PROCEDURE magnus_0d
135       MODULE PROCEDURE magnus_1d
136    END INTERFACE magnus
137
[4502]138    INTERFACE magnus_tl
139       MODULE PROCEDURE magnus_tl_0d
140       MODULE PROCEDURE magnus_tl_1d
141    END INTERFACE magnus_tl
142
143    INTERFACE magnus_ice
144       MODULE PROCEDURE magnus_0d_ice
145       MODULE PROCEDURE magnus_1d_ice
146    END INTERFACE magnus_ice
147
[3274]148    INTERFACE ideal_gas_law_rho
149       MODULE PROCEDURE ideal_gas_law_rho_0d
150       MODULE PROCEDURE ideal_gas_law_rho_1d
151    END INTERFACE ideal_gas_law_rho
152
153    INTERFACE ideal_gas_law_rho_pt
154       MODULE PROCEDURE ideal_gas_law_rho_pt_0d
155       MODULE PROCEDURE ideal_gas_law_rho_pt_1d
156    END INTERFACE ideal_gas_law_rho_pt
157
158    INTERFACE exner_function
159       MODULE PROCEDURE exner_function_0d
160       MODULE PROCEDURE exner_function_1d
161    END INTERFACE exner_function
162
163    INTERFACE exner_function_invers
164       MODULE PROCEDURE exner_function_invers_0d
165       MODULE PROCEDURE exner_function_invers_1d
166    END INTERFACE exner_function_invers
167
168    INTERFACE barometric_formula
169       MODULE PROCEDURE barometric_formula_0d
170       MODULE PROCEDURE barometric_formula_1d
171    END INTERFACE barometric_formula
[4400]172!
173!-- Public routines
174    PUBLIC convert_utm_to_geographic
[3274]175
176 CONTAINS
177
[4400]178
[4509]179!--------------------------------------------------------------------------------------------------!
[3274]180! Description:
181! ------------
[4509]182!> Convert UTM coordinates into geographic latitude and longitude. Conversion is based on the work
183!> of KrÃŒger (1912) DOI: 10.2312/GFZ.b103-krueger28 and Karney (2013) DOI: 10.1007/s00190-012-0578-z
[4400]184!> Based on a JavaScript of the geodesy function library written by chrisveness
185!> https://github.com/chrisveness/geodesy
[4509]186!--------------------------------------------------------------------------------------------------!
187 SUBROUTINE convert_utm_to_geographic( crs, eutm, nutm, lon, lat )
[4400]188
[4509]189    INTEGER(iwp) ::  j   !< loop index
[4400]190
[4509]191    REAL(wp), INTENT(in)  ::  eutm !< easting (UTM)
192    REAL(wp), INTENT(out) ::  lat  !< geographic latitude in degree
193    REAL(wp), INTENT(out) ::  lon  !< geographic longitude in degree
194    REAL(wp), INTENT(in)  ::  nutm !< northing (UTM)
[4400]195
[4509]196    REAL(wp) ::  a           !< 2*pi*a is the circumference of a meridian
197    REAL(wp) ::  cos_eta_s   !< cos(eta_s)
198    REAL(wp) ::  delta_i     !<
199    REAL(wp) ::  delta_tau_i !<
200    REAL(wp) ::  e           !< eccentricity
201    REAL(wp) ::  eta         !<
202    REAL(wp) ::  eta_s       !<
203    REAL(wp) ::  n           !< 3rd flattening
204    REAL(wp) ::  n2          !< n^2
205    REAL(wp) ::  n3          !< n^3
206    REAL(wp) ::  n4          !< n^4
207    REAL(wp) ::  n5          !< n^5
208    REAL(wp) ::  n6          !< n^6
209    REAL(wp) ::  nu          !<
210    REAL(wp) ::  nu_s        !<
211    REAL(wp) ::  sin_eta_s   !< sin(eta_s)
212    REAL(wp) ::  sinh_nu_s   !< sinush(nu_s)
213    REAL(wp) ::  tau_i       !<
214    REAL(wp) ::  tau_i_s     !<
215    REAL(wp) ::  tau_s       !<
216    REAL(wp) ::  x           !< adjusted easting
217    REAL(wp) ::  y           !< adjusted northing
[4400]218
[4509]219    REAL(wp), DIMENSION(6) ::  beta !< 6th order KrÃŒger expressions
[4400]220
[4509]221    REAL(wp), DIMENSION(8), INTENT(in) ::  crs !< coordinate reference system, consists of
222                                               !< (/semi_major_axis,
223                                               !<   inverse_flattening,
224                                               !<   longitude_of_prime_meridian,
225                                               !<   longitude_of_central_meridian,
226                                               !<   scale_factor_at_central_meridian,
227                                               !<   latitude_of_projection_origin,
228                                               !<   false_easting,
229                                               !<   false_northing /)
[4400]230
[4509]231    x = eutm - crs(7)  ! remove false easting
232    y = nutm - crs(8)  ! remove false northing
[4400]233!
[4509]234!-- From Karney 2011 Eq 15-22, 36:
235    e = SQRT( 1.0_wp / crs(2) * ( 2.0_wp - 1.0_wp / crs(2) ) )
236    n = 1.0_wp / crs(2) / ( 2.0_wp - 1.0_wp / crs(2) )
237    n2 = n * n
238    n3 = n * n2
239    n4 = n * n3
240    n5 = n * n4
241    n6 = n * n5
[4400]242
[4509]243    a = crs(1) / ( 1.0_wp + n ) * ( 1.0_wp + 0.25_wp * n2 + 0.015625_wp * n4 + 3.90625E-3_wp * n6 )
[4400]244
[4509]245    nu  = x / ( crs(5) * a )
246    eta = y / ( crs(5) * a )
[4400]247
[4509]248!-- According to KrÃŒger (1912), eq. 26*
249    beta(1) =          0.5_wp                  * n                                                 &
250              -        2.0_wp /         3.0_wp * n2                                                &
251              +       37.0_wp /        96.0_wp * n3                                                &
252              -        1.0_wp /       360.0_wp * n4                                                &
253              -       81.0_wp /       512.0_wp * n5                                                &
254              +    96199.0_wp /    604800.0_wp * n6
[4400]255
[4509]256    beta(2) =          1.0_wp /        48.0_wp * n2                                                &
257              +        1.0_wp /        15.0_wp * n3                                                &
258              -      437.0_wp /      1440.0_wp * n4                                                &
259              +       46.0_wp /       105.0_wp * n5                                                &
260              -  1118711.0_wp /   3870720.0_wp * n6
[4400]261
[4509]262    beta(3) =         17.0_wp /       480.0_wp * n3                                                &
263              -       37.0_wp /       840.0_wp * n4                                                &
264              -      209.0_wp /      4480.0_wp * n5                                                &
265              +     5569.0_wp /     90720.0_wp * n6
[4400]266
[4509]267    beta(4) =       4397.0_wp /    161280.0_wp * n4                                                &
268              -       11.0_wp /       504.0_wp * n5                                                &
269              -   830251.0_wp /   7257600.0_wp * n6
[4400]270
[4509]271    beta(5) =       4583.0_wp /    161280.0_wp * n5                                                &
272              -   108847.0_wp /   3991680.0_wp * n6
[4400]273
[4509]274    beta(6) =   20648693.0_wp / 638668800.0_wp * n6
[4400]275
[4509]276    eta_s = eta
277    nu_s  = nu
278    DO  j = 1, 6
279      eta_s = eta_s - beta(j) * SIN(2.0_wp * j * eta) * COSH(2.0_wp * j * nu)
280      nu_s  = nu_s  - beta(j) * COS(2.0_wp * j * eta) * SINH(2.0_wp * j * nu)
281    ENDDO
[4400]282
[4509]283    sinh_nu_s = SINH( nu_s )
284    sin_eta_s = SIN( eta_s )
285    cos_eta_s = COS( eta_s )
[4400]286
[4509]287    tau_s = sin_eta_s / SQRT( sinh_nu_s**2 + cos_eta_s**2 )
[4400]288
[4509]289    tau_i = tau_s
290    delta_tau_i = 1.0_wp
[4400]291
[4509]292    DO WHILE ( ABS( delta_tau_i ) > 1.0E-12_wp )
[4400]293
[4509]294      delta_i = SINH( e * ATANH( e * tau_i / SQRT( 1.0_wp + tau_i**2 ) ) )
[4400]295
[4509]296      tau_i_s = tau_i   * SQRT( 1.0_wp + delta_i**2 ) - delta_i * SQRT( 1.0_wp + tau_i**2 )
[4400]297
[4509]298      delta_tau_i = ( tau_s - tau_i_s ) / SQRT( 1.0_wp + tau_i_s**2 )                              &
299                    * ( 1.0_wp + ( 1.0_wp - e**2 ) * tau_i**2 )                                    &
300                    / ( ( 1.0_wp - e**2 ) * SQRT( 1.0_wp + tau_i**2 ) )
[4400]301
[4509]302      tau_i = tau_i + delta_tau_i
[4400]303
[4509]304    ENDDO
[4400]305
[4509]306    lat = ATAN( tau_i ) / pi * 180.0_wp
307    lon = ATAN2( sinh_nu_s, cos_eta_s ) / pi * 180.0_wp + crs(4)
[4400]308
[4509]309 END SUBROUTINE convert_utm_to_geographic
[4400]310
[4509]311!--------------------------------------------------------------------------------------------------!
[4400]312! Description:
313! ------------
[3274]314!> This function computes the magnus formula (Press et al., 1992).
[4509]315!> The magnus formula is needed to calculate the saturation vapor pressure.
316!--------------------------------------------------------------------------------------------------!
317 FUNCTION magnus_0d( t )
[3274]318
[4509]319    IMPLICIT NONE
[3274]320
[4509]321    REAL(wp), INTENT(IN) ::  t  !< temperature (K)
[3274]322
[4509]323    REAL(wp) ::  magnus_0d
324
[3274]325!
[4509]326!-- Saturation vapor pressure for a specific temperature:
327    magnus_0d =  611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / ( t - 29.65_wp  ) )
[3274]328
[4509]329 END FUNCTION magnus_0d
[3274]330
[4509]331!--------------------------------------------------------------------------------------------------!
[3274]332! Description:
333! ------------
334!> This function computes the magnus formula (Press et al., 1992).
[4509]335!> The magnus formula is needed to calculate the saturation vapor pressure.
336!--------------------------------------------------------------------------------------------------!
337 FUNCTION magnus_1d( t )
[3274]338
[4509]339    IMPLICIT NONE
[3274]340
[4509]341    REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
[3274]342
[4509]343    REAL(wp), DIMENSION(size(t)) ::  magnus_1d
344
[3274]345!
[4509]346!-- Saturation vapor pressure for a specific temperature:
347    magnus_1d =  611.2_wp * EXP( 17.62_wp * ( t - degc_to_k ) / ( t - 29.65_wp  ) )
[3274]348
[4509]349 END FUNCTION magnus_1d
[3274]350
[4509]351!--------------------------------------------------------------------------------------------------!
[3274]352! Description:
353! ------------
[4509]354!> This function computes the magnus formula (Press et al., 1992) using the (ice-) liquid water
355!> potential temperature.
356!> The magnus formula is needed to calculate the saturation vapor pressure over a plane liquid water
357!> surface.
358!--------------------------------------------------------------------------------------------------!
359 FUNCTION magnus_tl_0d( t_l )
[4502]360
[4509]361    IMPLICIT NONE
[4502]362
[4509]363    REAL(wp), INTENT(IN) ::  t_l  !< liquid water temperature (K)
[4502]364
[4509]365    REAL(wp) ::  magnus_tl_0d
366
[4502]367!
[4509]368!-- Saturation vapor pressure for a specific temperature:
369    magnus_tl_0d =  610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) / ( t_l - 35.86_wp  ) )
[4502]370
[4509]371 END FUNCTION magnus_tl_0d
[4502]372
[4509]373!--------------------------------------------------------------------------------------------------!
[4502]374! Description:
375! ------------
[4509]376!> This function computes the magnus formula (Press et al., 1992) using the (ice-) liquid water
377!> potential temperature.
378!> The magnus formula is needed to calculate the saturation vapor pressure over a plane liquid water
379!> surface.
380!--------------------------------------------------------------------------------------------------!
381 FUNCTION magnus_tl_1d( t_l )
[4502]382
[4509]383    IMPLICIT NONE
[4502]384
[4509]385    REAL(wp), INTENT(IN), DIMENSION(:) ::  t_l  !< liquid water temperature (K)
[4502]386
[4509]387    REAL(wp), DIMENSION(size(t_l)) ::  magnus_tl_1d
[4502]388!
[4509]389!-- Saturation vapor pressure for a specific temperature:
390    magnus_tl_1d =  610.78_wp * EXP( 17.269_wp * ( t_l - 273.16_wp ) / ( t_l - 35.86_wp  ) )
[4502]391
[4509]392 END FUNCTION magnus_tl_1d
[4502]393
[4509]394!--------------------------------------------------------------------------------------------------!
[4502]395! Description:
396! ------------
397!> This function computes the magnus formula (Press et al., 1992).
[4509]398!> The magnus formula is needed to calculate the saturation vapor pressure over a plane ice surface.
399!--------------------------------------------------------------------------------------------------!
400 FUNCTION magnus_0d_ice( t )
[4502]401
[4509]402    IMPLICIT NONE
[4502]403
[4509]404    REAL(wp), INTENT(IN) ::  t  !< temperature (K)
[4502]405
[4509]406    REAL(wp) ::  magnus_0d_ice
407
[4502]408!
409!--    Saturation vapor pressure for a specific temperature:
[4509]410    magnus_0d_ice =  611.2_wp * EXP( 22.46_wp * ( t - degc_to_k ) / ( t - 0.53_wp  ) )
[4502]411
[4509]412 END FUNCTION magnus_0d_ice
[4502]413
[4509]414!--------------------------------------------------------------------------------------------------!
[4502]415! Description:
416! ------------
417!> This function computes the magnus formula (Press et al., 1992).
[4509]418!> The magnus formula is needed to calculate the saturation vapor pressure over a plane ice surface.
419!--------------------------------------------------------------------------------------------------!
420 FUNCTION magnus_1d_ice( t )
[4502]421
[4509]422    IMPLICIT NONE
[4502]423
[4509]424    REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
[4502]425
[4509]426    REAL(wp), DIMENSION(size(t)) ::  magnus_1d_ice
427
[4502]428!
[4509]429!-- Saturation vapor pressure for a specific temperature:
430    magnus_1d_ice =  611.2_wp * EXP( 22.46_wp * ( t - degc_to_k ) / ( t - 0.53_wp  ) )
[4502]431
[4509]432 END FUNCTION magnus_1d_ice
[4502]433
[4509]434!--------------------------------------------------------------------------------------------------!
[4502]435! Description:
436! ------------
[3274]437!> Compute the ideal gas law for scalar arguments.
[4509]438!--------------------------------------------------------------------------------------------------!
439 FUNCTION ideal_gas_law_rho_0d( p, t )
[3274]440
[4509]441    IMPLICIT NONE
[3274]442
[4509]443    REAL(wp), INTENT(IN) ::  p  !< pressure (Pa)
444    REAL(wp), INTENT(IN) ::  t  !< temperature (K)
[3274]445
[4509]446    REAL(wp) ::  ideal_gas_law_rho_0d
447
[3274]448!
[4509]449!-- Compute density according to ideal gas law:
450    ideal_gas_law_rho_0d = p / (r_d * t)
[3274]451
[4509]452 END FUNCTION ideal_gas_law_rho_0d
[3274]453
[4509]454!--------------------------------------------------------------------------------------------------!
[3274]455! Description:
456! ------------
457!> Compute the ideal gas law for 1-D array arguments.
[4509]458!--------------------------------------------------------------------------------------------------!
459 FUNCTION ideal_gas_law_rho_1d( p, t )
[3274]460
[4509]461    IMPLICIT NONE
[3274]462
[4509]463    REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
464    REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
[3274]465
[4509]466    REAL(wp), DIMENSION(size(p)) ::  ideal_gas_law_rho_1d
467
[3274]468!
[4509]469!-- Compute density according to ideal gas law:
470    ideal_gas_law_rho_1d = p / (r_d * t)
[3274]471
[4509]472 END FUNCTION ideal_gas_law_rho_1d
[3274]473
[4509]474!--------------------------------------------------------------------------------------------------!
[3274]475! Description:
476! ------------
477!> Compute the ideal gas law for scalar arguments.
[4509]478!--------------------------------------------------------------------------------------------------!
479 FUNCTION ideal_gas_law_rho_pt_0d( p, t )
[3274]480
[4509]481    IMPLICIT NONE
[3274]482
[4509]483    REAL(wp), INTENT(IN) ::  p  !< pressure (Pa)
484    REAL(wp), INTENT(IN) ::  t  !< temperature (K)
[3274]485
[4509]486    REAL(wp) ::  ideal_gas_law_rho_pt_0d
487
[3274]488!
[4509]489!-- Compute density according to ideal gas law:
490    ideal_gas_law_rho_pt_0d = p / (r_d * exner_function(p) * t)
[3274]491
[4509]492 END FUNCTION ideal_gas_law_rho_pt_0d
[3274]493
[4509]494!--------------------------------------------------------------------------------------------------!
[3274]495! Description:
496! ------------
497!> Compute the ideal gas law for 1-D array arguments.
[4509]498!--------------------------------------------------------------------------------------------------!
499 FUNCTION ideal_gas_law_rho_pt_1d( p, t )
[3274]500
[4509]501    IMPLICIT NONE
[3274]502
[4509]503    REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
504    REAL(wp), INTENT(IN), DIMENSION(:) ::  t  !< temperature (K)
[3274]505
[4509]506    REAL(wp), DIMENSION(size(p)) ::  ideal_gas_law_rho_pt_1d
507
[3274]508!
[4509]509!-- Compute density according to ideal gas law:
510    ideal_gas_law_rho_pt_1d = p / (r_d * exner_function(p) * t)
[3274]511
[4509]512 END FUNCTION ideal_gas_law_rho_pt_1d
[3274]513
[4509]514!--------------------------------------------------------------------------------------------------!
[3274]515! Description:
516! ------------
517!> Compute the exner function for scalar arguments.
[4509]518!--------------------------------------------------------------------------------------------------!
519 FUNCTION exner_function_0d( p )
[3274]520
[4509]521    IMPLICIT NONE
[3274]522
[4509]523    REAL(wp), INTENT(IN) ::  p    !< pressure (Pa)
[3274]524
[4509]525    REAL(wp) ::  exner_function_0d
526
[3274]527!
[4509]528!-- Compute exner function:
529    exner_function_0d = ( p / p_0 )**( rd_d_cp )
[3274]530
[4509]531 END FUNCTION exner_function_0d
[3274]532
[4509]533!--------------------------------------------------------------------------------------------------!
[3274]534! Description:
535! ------------
536!> Compute the exner function for 1-D array arguments.
[4509]537!--------------------------------------------------------------------------------------------------!
538 FUNCTION exner_function_1d( p )
[3274]539
[4509]540    IMPLICIT NONE
[3274]541
[4509]542    REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
[3274]543
[4509]544    REAL(wp), DIMENSION(size(p)) ::  exner_function_1d
545
[3274]546!
[4509]547!-- Compute exner function:
548    exner_function_1d = ( p / p_0 )**( rd_d_cp )
[3274]549
[4509]550 END FUNCTION exner_function_1d
[3274]551
[4509]552!--------------------------------------------------------------------------------------------------!
[3274]553! Description:
554! ------------
555!> Compute the exner function for scalar arguments.
[4509]556!--------------------------------------------------------------------------------------------------!
557 FUNCTION exner_function_invers_0d( p )
[3274]558
[4509]559    IMPLICIT NONE
[3274]560
[4509]561    REAL(wp), INTENT(IN) ::  p    !< pressure (Pa)
[3274]562
[4509]563    REAL(wp) ::  exner_function_invers_0d
564
[3274]565!
[4509]566!-- Compute exner function:
567    exner_function_invers_0d = ( p_0 / p )**( rd_d_cp )
[3274]568
[4509]569 END FUNCTION exner_function_invers_0d
[3274]570
[4509]571!--------------------------------------------------------------------------------------------------!
[3274]572! Description:
573! ------------
574!> Compute the exner function for 1-D array arguments.
[4509]575!--------------------------------------------------------------------------------------------------!
576 FUNCTION exner_function_invers_1d( p )
[3274]577
[4509]578    IMPLICIT NONE
[3274]579
[4509]580    REAL(wp), INTENT(IN), DIMENSION(:) ::  p  !< pressure (Pa)
[3274]581
[4509]582    REAL(wp), DIMENSION(size(p)) ::  exner_function_invers_1d
583
[3274]584!
[4509]585!-- Compute exner function:
586    exner_function_invers_1d = ( p_0 / p )**( rd_d_cp )
[3274]587
[4509]588 END FUNCTION exner_function_invers_1d
[3274]589
[4509]590!--------------------------------------------------------------------------------------------------!
[3274]591! Description:
592! ------------
[4509]593!> Compute the barometric formula for scalar arguments. The calculation is based on the assumption
594!> of a polytropic atmosphere and neutral stratification, where the temperature lapse rate is g/cp.
595!--------------------------------------------------------------------------------------------------!
596 FUNCTION barometric_formula_0d( z, t_0, p_0)
[3274]597
[4509]598    IMPLICIT NONE
[3274]599
[4509]600    REAL(wp), INTENT(IN) ::  z    !< height (m)
601    REAL(wp), INTENT(IN) ::  t_0  !< temperature reference state (K)
602    REAL(wp), INTENT(IN) ::  p_0  !< surface pressure (Pa)
[3274]603
[4509]604    REAL(wp) ::  barometric_formula_0d
605
[3274]606!
[4509]607!-- Compute barometric formula:
608    barometric_formula_0d =  p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd )
[3274]609
[4509]610 END FUNCTION barometric_formula_0d
[3274]611
[4509]612!--------------------------------------------------------------------------------------------------!
[3274]613! Description:
614! ------------
[4509]615!> Compute the barometric formula for 1-D array arguments. The calculation is based on the
616!> assumption of a polytropic atmosphere and neutral stratification, where the temperature lapse
617!> rate is g/cp.
618!--------------------------------------------------------------------------------------------------!
619 FUNCTION barometric_formula_1d( z, t_0, p_0)
[3274]620
[4509]621    IMPLICIT NONE
[3274]622
[4509]623    REAL(wp), INTENT(IN), DIMENSION(:) ::  z  !< height (m)
624    REAL(wp), INTENT(IN) ::  t_0              !< temperature reference state (K)
625    REAL(wp), INTENT(IN) ::  p_0              !< surface pressure (Pa)
[3274]626
[4509]627    REAL(wp), DIMENSION(size(z)) ::  barometric_formula_1d
628
[3274]629!
[4509]630!-- Compute barometric formula:
631    barometric_formula_1d =  p_0 * ( (t_0 - g_d_cp * z) / t_0 )**( cp_d_rd )
[3274]632
[4509]633 END FUNCTION barometric_formula_1d
[3274]634
635 END MODULE basic_constants_and_equations_mod
Note: See TracBrowser for help on using the repository browser.