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

Last change on this file since 4069 was 4055, checked in by suehring, 5 years ago

chem_emissions_mod: Formatting adjustments; initialization of arrays fixed; univsersal gas constant moved to basic_constants_and_equations_mod.f90

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