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-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ------------------ ! ! ! Former revisions: ! ----------------- ! $Id: lpm_droplet_condensation.f90 1037 2012-10-22 14:10:22Z hoffmann $ ! ! 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 USE cloud_parameters USE constants USE control_parameters USE cpulog USE grid_variables USE interfaces USE lpm_collision_kernels_mod USE particle_attributes IMPLICIT NONE INTEGER :: i, internal_timestep_count, j, jtry, k, n INTEGER, PARAMETER :: maxtry = 40 REAL :: aa, afactor, arg, bb, cc, dd, ddenom, delta_r, drdt, drdt_ini, & drdt_m, dt_ros, dt_ros_last, dt_ros_next, dt_ros_sum, & dt_ros_sum_ini, d2rdtdr, d2rdt2, errmax, err_ros, g1, g2, g3, g4, & e_a, e_s, gg, new_r, p_int, pt_int, pt_int_l, pt_int_u, q_int, & q_int_l, q_int_u, ql_int, ql_int_l, ql_int_u, r_ros, r_ros_ini, & sigma, t_int, x, y ! !-- Parameters for Rosenbrock method REAL, PARAMETER :: a21 = 2.0, a31 = 48.0/25.0, a32 = 6.0/25.0, & a2x = 1.0, a3x = 3.0/5.0, b1 = 19.0/9.0, b2 = 0.5, & b3 = 25.0/108.0, b4 = 125.0/108.0, c21 = -8.0, & c31 = 372.0/25.0, c32 = 12.0/5.0, & c41 = -112.0/125.0, c42 = -54.0/125.0, & c43 = -2.0/5.0, c1x = 0.5, c2x= -3.0/2.0, & c3x = 121.0/50.0, c4x = 29.0/250.0, & errcon = 0.1296, e1 = 17.0/54.0, e2 = 7.0/36.0, & e3 = 0.0, e4 = 125.0/108.0, gam = 0.5, grow = 1.5, & pgrow = -0.25, pshrnk = -1.0/3.0, 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 ) ql_int_l = ( ( gg - aa ) * ql(k,j,i) + ( gg - bb ) * ql(k,j,i+1) & + ( gg - cc ) * ql(k,j+1,i) + ( gg - dd ) * ql(k,j+1,i+1) & ) / ( 3.0 * gg ) ql_int_u = ( ( gg-aa ) * ql(k+1,j,i) + ( gg-bb ) * ql(k+1,j,i+1) & + ( gg-cc ) * ql(k+1,j+1,i) + ( gg-dd ) * ql(k+1,j+1,i+1) & ) / ( 3.0 * gg ) ql_int = ql_int_l + ( particles(n)%z - zu(k) ) / dz * & ( ql_int_u - ql_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 >= 1.0E-6 .OR. & .NOT. curvature_solution_effects ) THEN ! !-- Approximation for large radii, where curvature and solution !-- effects can be neglected 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. ! !-- Surface tension after (Straka, 2009) sigma = 0.0761 - 0.00155 * ( 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 ) IF ( particles(n)%rvar3 == -9999999.9 ) THEN ! !-- First particle timestep. Derivative has to be calculated. drdt_m = ddenom / r_ros * ( e_a / e_s - 1.0 - & afactor / r_ros + & bfactor / r_ros**3 ) ELSE ! !-- Take value from last PALM timestep drdt_m = particles(n)%rvar3 ENDIF ! !-- Take internal timestep values from the end of last PALM timestep dt_ros_last = particles(n)%rvar1 dt_ros_next = particles(n)%rvar2 ! !-- Internal timestep must not be larger than PALM timestep dt_ros = MIN( dt_ros_next, dt_3d ) ! !-- Integrate growth equation in time unless PALM timestep 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 time derivative of dr/dt d2rdt2 = ( drdt - drdt_m ) / dt_ros_last ! !-- 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 + dt_ros * c1x * d2rdt2 ) / 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 + dt_ros * c2x * d2rdt2 + 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 + dt_ros * c3x * d2rdt2 + & ( c31 * g1 + c32 * g2 ) / dt_ros ) / aa g4 = ( drdt + dt_ros * c4x * d2rdt2 + & ( 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 timestep IF ( errmax > errcon ) THEN dt_ros_next = 0.9 * dt_ros * errmax**pgrow ELSE dt_ros_next = grow * dt_ros ENDIF ! !-- Estimated timestep is reduced if the PALM time step is exceeded dt_ros_last = dt_ros IF ( ( dt_ros_next + dt_ros_sum ) >= dt_3d ) THEN dt_ros = dt_3d - dt_ros_sum ELSE dt_ros = dt_ros_next ENDIF drdt_m = drdt ENDDO ! !-- Store derivative and internal timestep values for next PALM step particles(n)%rvar1 = dt_ros_last particles(n)%rvar2 = dt_ros_next particles(n)%rvar3 = drdt_m 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 ) 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