SUBROUTINE lpm_droplet_condensation !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! 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-2014 Leibniz Universitaet Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ------------------ ! ! ! Former revisions: ! ----------------- ! $Id: lpm_droplet_condensation.f90 1347 2014-03-27 13:23:00Z maronga $ ! ! 1346 2014-03-27 13:18:20Z heinze ! Bugfix: REAL constants provided with KIND-attribute especially in call of ! intrinsic function like MAX, MIN, SIGN ! ! 1322 2014-03-20 16:38:49Z raasch ! REAL constants defined as wp-kind ! ! 1320 2014-03-20 08:40:49Z raasch ! ONLY-attribute added to USE-statements, ! kind-parameters added to all INTEGER and REAL declaration statements, ! kinds are defined in new module kinds, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1318 2014-03-17 13:35:16Z raasch ! module interfaces removed ! ! 1092 2013-02-02 11:24:22Z raasch ! unused variables removed ! ! 1071 2012-11-29 16:54:55Z franke ! Ventilation effect for evaporation of large droplets included ! Check for unreasonable results included in calculation of Rosenbrock method ! since physically unlikely results were observed and for the same ! reason the first internal time step in Rosenbrock method should be < 1.0E02 in ! case of evaporation ! Unnecessary calculation of ql_int removed ! Unnecessary calculations in Rosenbrock method (d2rdt2, drdt_m, dt_ros_last) ! removed ! Bugfix: factor in calculation of surface tension changed from 0.00155 to ! 0.000155 ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 849 2012-03-15 10:35:09Z raasch ! initial revision (former part of advec_particles) ! ! ! Description: ! ------------ ! Calculates change in droplet radius by condensation/evaporation, using ! either an analytic formula or by numerically integrating the radius growth ! equation including curvature and solution effects using Rosenbrocks method ! (see Numerical recipes in FORTRAN, 2nd edition, p. 731). ! The analytical formula and growth equation follow those given in ! Rogers and Yau (A short course in cloud physics, 3rd edition, p. 102/103). !------------------------------------------------------------------------------! USE arrays_3d, & ONLY: hyp, pt, q, ql_c, ql_v, zu USE cloud_parameters, & ONLY: bfactor, curvature_solution_effects, diff_coeff_l, & eps_ros, l_d_rv, l_v, rho_l, r_v, thermal_conductivity_l USE constants, & ONLY: pi USE control_parameters, & ONLY: atmos_ocean_sign, dt_3d, dz, message_string, & molecular_viscosity, rho_surface USE cpulog, & ONLY: cpu_log, log_point_s USE grid_variables, & ONLY: dx, ddx, dy, ddy USE lpm_collision_kernels_mod, & ONLY: rclass_lbound, rclass_ubound USE kinds USE particle_attributes, & ONLY: hall_kernel, number_of_particles, offset_ocean_nzt, & offset_ocean_nzt_m1, particles, radius_classes, & use_kernel_tables, wang_kernel IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: internal_timestep_count !: INTEGER(iwp) :: j !: INTEGER(iwp) :: jtry !: INTEGER(iwp) :: k !: INTEGER(iwp) :: n !: INTEGER(iwp) :: ros_count !: INTEGER(iwp), PARAMETER :: maxtry = 40 !: LOGICAL :: repeat !: REAL(wp) :: aa !: REAL(wp) :: afactor !: REAL(wp) :: arg !: REAL(wp) :: bb !: REAL(wp) :: cc !: REAL(wp) :: dd !: REAL(wp) :: ddenom !: REAL(wp) :: delta_r !: REAL(wp) :: drdt !: REAL(wp) :: drdt_ini !: REAL(wp) :: dt_ros !: REAL(wp) :: dt_ros_next !: REAL(wp) :: dt_ros_sum !: REAL(wp) :: dt_ros_sum_ini !: REAL(wp) :: d2rdtdr !: REAL(wp) :: errmax !: REAL(wp) :: err_ros !: REAL(wp) :: g1 !: REAL(wp) :: g2 !: REAL(wp) :: g3 !: REAL(wp) :: g4 !: REAL(wp) :: e_a !: REAL(wp) :: e_s !: REAL(wp) :: gg !: REAL(wp) :: new_r !: REAL(wp) :: p_int !: REAL(wp) :: pt_int !: REAL(wp) :: pt_int_l !: REAL(wp) :: pt_int_u !: REAL(wp) :: q_int !: REAL(wp) :: q_int_l !: REAL(wp) :: q_int_u !: REAL(wp) :: r_ros !: REAL(wp) :: r_ros_ini !: REAL(wp) :: sigma !: REAL(wp) :: t_int !: REAL(wp) :: x !: REAL(wp) :: y !: REAL(wp) :: re_p !: !-- Parameters for Rosenbrock method REAL(wp), PARAMETER :: a21 = 2.0 !: REAL(wp), PARAMETER :: a31 = 48.0/25.0_wp !: REAL(wp), PARAMETER :: a32 = 6.0/25.0_wp !: REAL(wp), PARAMETER :: b1 = 19.0/9.0_wp !: REAL(wp), PARAMETER :: b2 = 0.5 !: REAL(wp), PARAMETER :: b3 = 25.0/108.0_wp !: REAL(wp), PARAMETER :: b4 = 125.0/108.0_wp !: REAL(wp), PARAMETER :: c21 = -8.0 !: REAL(wp), PARAMETER :: c31 = 372.0/25.0_wp !: REAL(wp), PARAMETER :: c32 = 12.0/5.0_wp !: REAL(wp), PARAMETER :: c41 = -112.0/125.0_wp !: REAL(wp), PARAMETER :: c42 = -54.0/125.0_wp !: REAL(wp), PARAMETER :: c43 = -2.0/5.0_wp !: REAL(wp), PARAMETER :: errcon = 0.1296 !: REAL(wp), PARAMETER :: e1 = 17.0/54.0_wp !: REAL(wp), PARAMETER :: e2 = 7.0/36.0_wp !: REAL(wp), PARAMETER :: e3 = 0.0 !: REAL(wp), PARAMETER :: e4 = 125.0/108.0_wp !: REAL(wp), PARAMETER :: gam = 0.5 !: REAL(wp), PARAMETER :: grow = 1.5 !: REAL(wp), PARAMETER :: pgrow = -0.25 !: REAL(wp), PARAMETER :: pshrnk = -1.0/3.0_wp !: REAL(wp), PARAMETER :: shrnk = 0.5 !: CALL cpu_log( log_point_s(42), 'lpm_droplet_condens', 'start' ) DO n = 1, number_of_particles ! !-- Interpolate temperature and humidity. !-- First determine left, south, and bottom index of the arrays. i = particles(n)%x * ddx j = particles(n)%y * ddy k = ( particles(n)%z + 0.5 * dz * atmos_ocean_sign ) / dz & + offset_ocean_nzt ! only exact if equidistant x = particles(n)%x - i * dx y = particles(n)%y - j * dy aa = x**2 + y**2 bb = ( dx - x )**2 + y**2 cc = x**2 + ( dy - y )**2 dd = ( dx - x )**2 + ( dy - y )**2 gg = aa + bb + cc + dd pt_int_l = ( ( gg - aa ) * pt(k,j,i) + ( gg - bb ) * pt(k,j,i+1) & + ( gg - cc ) * pt(k,j+1,i) + ( gg - dd ) * pt(k,j+1,i+1) & ) / ( 3.0 * gg ) pt_int_u = ( ( gg-aa ) * pt(k+1,j,i) + ( gg-bb ) * pt(k+1,j,i+1) & + ( gg-cc ) * pt(k+1,j+1,i) + ( gg-dd ) * pt(k+1,j+1,i+1) & ) / ( 3.0 * gg ) pt_int = pt_int_l + ( particles(n)%z - zu(k) ) / dz * & ( pt_int_u - pt_int_l ) q_int_l = ( ( gg - aa ) * q(k,j,i) + ( gg - bb ) * q(k,j,i+1) & + ( gg - cc ) * q(k,j+1,i) + ( gg - dd ) * q(k,j+1,i+1) & ) / ( 3.0 * gg ) q_int_u = ( ( gg-aa ) * q(k+1,j,i) + ( gg-bb ) * q(k+1,j,i+1) & + ( gg-cc ) * q(k+1,j+1,i) + ( gg-dd ) * q(k+1,j+1,i+1) & ) / ( 3.0 * gg ) q_int = q_int_l + ( particles(n)%z - zu(k) ) / dz * & ( q_int_u - q_int_l ) ! !-- Calculate real temperature and saturation vapor pressure p_int = hyp(k) + ( particles(n)%z - zu(k) ) / dz * ( hyp(k+1)-hyp(k) ) t_int = pt_int * ( p_int / 100000.0 )**0.286 e_s = 611.0 * EXP( l_d_rv * ( 3.6609E-3 - 1.0 / t_int ) ) ! !-- Current vapor pressure e_a = q_int * p_int / ( 0.378 * q_int + 0.622 ) ! !-- Thermal conductivity for water (from Rogers and Yau, Table 7.1), !-- diffusivity for water vapor (after Hall und Pruppacher, 1976) thermal_conductivity_l = 7.94048E-05 * t_int + 0.00227011 diff_coeff_l = 0.211E-4 * ( t_int / 273.15 )**1.94 * & ( 101325.0 / p_int) ! !-- Change in radius by condensation/evaporation IF ( particles(n)%radius >= 4.0E-5 .AND. e_a/e_s < 1.0 ) THEN ! !-- Approximation for large radii, where curvature and solution effects !-- can be neglected but ventilation effect has to be included in case of !-- evaporation. !-- First calculate the droplet's Reynolds number re_p = 2.0 * particles(n)%radius * ABS( particles(n)%speed_z ) / & molecular_viscosity ! !-- Ventilation coefficient after Rogers and Yau, 1989 IF ( re_p > 2.5 ) THEN afactor = 0.78 + 0.28 * SQRT( re_p ) ELSE afactor = 1.0 + 0.09 * re_p ENDIF arg = particles(n)%radius**2 + 2.0 * dt_3d * afactor * & ( e_a / e_s - 1.0 ) / & ( ( l_d_rv / t_int - 1.0 ) * l_v * rho_l / t_int / & thermal_conductivity_l + & rho_l * r_v * t_int / diff_coeff_l / e_s ) new_r = SQRT( arg ) ELSEIF ( particles(n)%radius >= 1.0E-6 .OR. & .NOT. curvature_solution_effects ) THEN ! !-- Approximation for larger radii in case that curvature and solution !-- effects are neglected and ventilation effects does not play a role arg = particles(n)%radius**2 + 2.0 * dt_3d * & ( e_a / e_s - 1.0 ) / & ( ( l_d_rv / t_int - 1.0 ) * l_v * rho_l / t_int / & thermal_conductivity_l + & rho_l * r_v * t_int / diff_coeff_l / e_s ) IF ( arg < 1.0E-16 ) THEN new_r = 1.0E-8 ELSE new_r = SQRT( arg ) ENDIF ENDIF IF ( curvature_solution_effects .AND. & ( ( particles(n)%radius < 1.0E-6 ) .OR. ( new_r < 1.0E-6 ) ) ) & THEN ! !-- Curvature and solutions effects are included in growth equation. !-- Change in Radius is calculated with 4th-order Rosenbrock method !-- for stiff o.d.e's with monitoring local truncation error to adjust !-- stepsize (see Numerical recipes in FORTRAN, 2nd edition, p. 731). !-- For larger radii the simple analytic method (see ELSE) gives !-- almost the same results. ros_count = 0 repeat = .TRUE. ! !-- Carry out the Rosenbrock algorithm. In case of unreasonable results !-- the switch "repeat" will be set true and the algorithm will be carried !-- out again with the internal time step set to its initial (small) value. !-- Unreasonable results may occur if the external conditions, especially the !-- supersaturation, has significantly changed compared to the last PALM !-- timestep. DO WHILE ( repeat ) repeat = .FALSE. ! !-- Surface tension after (Straka, 2009) sigma = 0.0761 - 0.000155 * ( t_int - 273.15 ) r_ros = particles(n)%radius dt_ros_sum = 0.0 ! internal integrated time (s) internal_timestep_count = 0 ddenom = 1.0 / ( rho_l * r_v * t_int / ( e_s * diff_coeff_l ) + & ( l_v / ( r_v * t_int ) - 1.0 ) * & rho_l * l_v / ( thermal_conductivity_l * t_int )& ) afactor = 2.0 * sigma / ( rho_l * r_v * t_int ) ! !-- Take internal time step values from the end of last PALM time step dt_ros_next = particles(n)%rvar1 ! !-- Internal time step should not be > 1.0E-2 in case of evaporation !-- because larger values may lead to secondary solutions which are !-- physically unlikely IF ( dt_ros_next > 1.0E-2 .AND. e_a/e_s < 1.0 ) THEN dt_ros_next = 1.0E-3 ENDIF ! !-- If calculation of Rosenbrock method is repeated due to unreasonalble !-- results during previous try the initial internal time step has to be !-- reduced IF ( ros_count > 1 ) THEN dt_ros_next = dt_ros_next - ( 0.2 * dt_ros_next ) ELSEIF ( ros_count > 5 ) THEN ! !-- Prevent creation of infinite loop message_string = 'ros_count > 5 in Rosenbrock method' CALL message( 'lpm_droplet_condensation', 'PA0018', 2, 2, & 0, 6, 0 ) ENDIF ! !-- Internal time step must not be larger than PALM time step dt_ros = MIN( dt_ros_next, dt_3d ) ! !-- Integrate growth equation in time unless PALM time step is reached DO WHILE ( dt_ros_sum < dt_3d ) internal_timestep_count = internal_timestep_count + 1 ! !-- Derivative at starting value drdt = ddenom / r_ros * ( e_a / e_s - 1.0 - afactor / r_ros + & bfactor / r_ros**3 ) drdt_ini = drdt dt_ros_sum_ini = dt_ros_sum r_ros_ini = r_ros ! !-- Calculate radial derivative of dr/dt d2rdtdr = ddenom * ( ( 1.0 - e_a/e_s ) / r_ros**2 + & 2.0 * afactor / r_ros**3 - & 4.0 * bfactor / r_ros**5 ) ! !-- Adjust stepsize unless required accuracy is reached DO jtry = 1, maxtry+1 IF ( jtry == maxtry+1 ) THEN message_string = 'maxtry > 40 in Rosenbrock method' CALL message( 'lpm_droplet_condensation', 'PA0347', 2, 2, & 0, 6, 0 ) ENDIF aa = 1.0 / ( gam * dt_ros ) - d2rdtdr g1 = drdt_ini / aa r_ros = r_ros_ini + a21 * g1 drdt = ddenom / r_ros * ( e_a / e_s - 1.0 - & afactor / r_ros + & bfactor / r_ros**3 ) g2 = ( drdt + c21 * g1 / dt_ros )& / aa r_ros = r_ros_ini + a31 * g1 + a32 * g2 drdt = ddenom / r_ros * ( e_a / e_s - 1.0 - & afactor / r_ros + & bfactor / r_ros**3 ) g3 = ( drdt + & ( c31 * g1 + c32 * g2 ) / dt_ros ) / aa g4 = ( drdt + & ( c41 * g1 + c42 * g2 + c43 * g3 ) / dt_ros ) / aa r_ros = r_ros_ini + b1 * g1 + b2 * g2 + b3 * g3 + b4 * g4 dt_ros_sum = dt_ros_sum_ini + dt_ros IF ( dt_ros_sum == dt_ros_sum_ini ) THEN message_string = 'zero stepsize in Rosenbrock method' CALL message( 'lpm_droplet_condensation', 'PA0348', 2, 2, & 0, 6, 0 ) ENDIF ! !-- Calculate error err_ros = e1*g1 + e2*g2 + e3*g3 + e4*g4 errmax = 0.0 errmax = MAX( errmax, ABS( err_ros / r_ros_ini ) ) / eps_ros ! !-- Leave loop if accuracy is sufficient, otherwise try again !-- with a reduced stepsize IF ( errmax <= 1.0 ) THEN EXIT ELSE dt_ros = SIGN( MAX( ABS( 0.9 * dt_ros * errmax**pshrnk ), & shrnk * ABS( dt_ros ) ), dt_ros ) ENDIF ENDDO ! loop for stepsize adjustment ! !-- Calculate next internal time step IF ( errmax > errcon ) THEN dt_ros_next = 0.9 * dt_ros * errmax**pgrow ELSE dt_ros_next = grow * dt_ros ENDIF ! !-- Estimated time step is reduced if the PALM time step is exceeded IF ( ( dt_ros_next + dt_ros_sum ) >= dt_3d ) THEN dt_ros = dt_3d - dt_ros_sum ELSE dt_ros = dt_ros_next ENDIF ENDDO ! !-- Store internal time step value for next PALM step particles(n)%rvar1 = dt_ros_next new_r = r_ros ! !-- Radius should not fall below 1E-8 because Rosenbrock method may !-- lead to errors otherwise new_r = MAX( new_r, 1.0E-8_wp ) ! !-- Check if calculated droplet radius change is reasonable since in !-- case of droplet evaporation the Rosenbrock method may lead to !-- secondary solutions which are physically unlikely. !-- Due to the solution effect the droplets may grow for relative !-- humidities below 100%, but change of radius should not be too large. !-- In case of unreasonable droplet growth the Rosenbrock method is !-- recalculated using a smaller initial time step. !-- Limiting values are tested for droplets down to 1.0E-7 IF ( new_r - particles(n)%radius >= 3.0E-7 .AND. & e_a/e_s < 0.97 ) THEN ros_count = ros_count + 1 repeat = .TRUE. ENDIF ENDDO ! Rosenbrock method ENDIF delta_r = new_r - particles(n)%radius ! !-- Sum up the change in volume of liquid water for the respective grid !-- volume (this is needed later in lpm_calc_liquid_water_content for !-- calculating the release of latent heat) i = ( particles(n)%x + 0.5 * dx ) * ddx j = ( particles(n)%y + 0.5 * dy ) * ddy k = particles(n)%z / dz + 1 + offset_ocean_nzt_m1 ! only exact if equidistant ql_c(k,j,i) = ql_c(k,j,i) + particles(n)%weight_factor * & rho_l * 1.33333333 * pi * & ( new_r**3 - particles(n)%radius**3 ) / & ( rho_surface * dx * dy * dz ) IF ( ql_c(k,j,i) > 100.0 ) THEN WRITE( message_string, * ) 'k=',k,' j=',j,' i=',i, & ' ql_c=',ql_c(k,j,i), ' &part(',n,')%wf=', & particles(n)%weight_factor,' delta_r=',delta_r CALL message( 'lpm_droplet_condensation', 'PA0143', 2, 2, -1, 6, 1 ) ENDIF ! !-- Change the droplet radius IF ( ( new_r - particles(n)%radius ) < 0.0 .AND. new_r < 0.0 ) & THEN WRITE( message_string, * ) '#1 k=',k,' j=',j,' i=',i, & ' e_s=',e_s, ' e_a=',e_a,' t_int=',t_int, & ' &delta_r=',delta_r, & ' particle_radius=',particles(n)%radius CALL message( 'lpm_droplet_condensation', 'PA0144', 2, 2, -1, 6, 1 ) ENDIF ! !-- Sum up the total volume of liquid water (needed below for !-- re-calculating the weighting factors) ql_v(k,j,i) = ql_v(k,j,i) + particles(n)%weight_factor * new_r**3 particles(n)%radius = new_r ! !-- Determine radius class of the particle needed for collision IF ( ( hall_kernel .OR. wang_kernel ) .AND. use_kernel_tables ) & THEN particles(n)%class = ( LOG( new_r ) - rclass_lbound ) / & ( rclass_ubound - rclass_lbound ) * & radius_classes particles(n)%class = MIN( particles(n)%class, radius_classes ) particles(n)%class = MAX( particles(n)%class, 1 ) ENDIF ENDDO CALL cpu_log( log_point_s(42), 'lpm_droplet_condens', 'stop' ) END SUBROUTINE lpm_droplet_condensation