#if defined( __ibmy_special ) @PROCESS NOOPTimize #endif SUBROUTINE init_3d_model !------------------------------------------------------------------------------! ! Current revisions: ! ----------------- ! var_ts is replaced by dots_max ! ! ! Former revisions: ! ----------------- ! $Id: init_3d_model.f90 394 2009-09-29 14:34:24Z maronga $ ! ! 388 2009-09-23 09:40:33Z raasch ! Initialization of prho added. ! bugfix: correction of initial volume flow for non-flat topography ! bugfix: zero initialization of arrays within buildings for 'cyclic_fill' ! bugfix: avoid that ngp_2dh_s_inner becomes zero ! initializing_actions='read_data_for_recycling' renamed to 'cyclic_fill', now ! independent of turbulent_inflow ! Output of messages replaced by message handling routine. ! Set the starting level and the vertical smoothing factor used for ! the external pressure gradient ! +conserve_volume_flow_mode: 'default', 'initial_profiles', 'inflow_profile' ! and 'bulk_velocity' ! If the inversion height calculated by the prerun is zero, ! inflow_damping_height must be explicitly specified. ! ! 181 2008-07-30 07:07:47Z raasch ! bugfix: zero assignments to tendency arrays in case of restarts, ! further extensions and modifications in the initialisation of the plant ! canopy model, ! allocation of hom_sum moved to parin, initialization of spectrum_x|y directly ! after allocating theses arrays, ! read data for recycling added as new initialization option, ! dummy allocation for diss ! ! 138 2007-11-28 10:03:58Z letzel ! New counter ngp_2dh_s_inner. ! Allow new case bc_uv_t = 'dirichlet_0' for channel flow. ! Corrected calculation of initial volume flow for 'set_1d-model_profiles' and ! 'set_constant_profiles' in case of buildings in the reference cross-sections. ! ! 108 2007-08-24 15:10:38Z letzel ! Flux initialization in case of coupled runs, +momentum fluxes at top boundary, ! +arrays for phase speed c_u, c_v, c_w, indices for u|v|w_m_l|r changed ! +qswst_remote in case of atmosphere model with humidity coupled to ocean ! Rayleigh damping for ocean, optionally calculate km and kh from initial ! TKE e_init ! ! 97 2007-06-21 08:23:15Z raasch ! Initialization of salinity, call of init_ocean ! ! 87 2007-05-22 15:46:47Z raasch ! var_hom and var_sum renamed pr_palm ! ! 75 2007-03-22 09:54:05Z raasch ! Arrays for radiation boundary conditions are allocated (u_m_l, u_m_r, etc.), ! bugfix for cases with the outflow damping layer extending over more than one ! subdomain, moisture renamed humidity, ! new initializing action "by_user" calls user_init_3d_model, ! precipitation_amount/rate, ts_value are allocated, +module netcdf_control, ! initial velocities at nzb+1 are regarded for volume ! flow control in case they have been set zero before (to avoid small timesteps) ! -uvmean_outflow, uxrp, vynp eliminated ! ! 19 2007-02-23 04:53:48Z raasch ! +handling of top fluxes ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.49 2006/08/22 15:59:07 raasch ! No optimization of this file on the ibmy (Yonsei Univ.) ! ! Revision 1.1 1998/03/09 16:22:22 raasch ! Initial revision ! ! ! Description: ! ------------ ! Allocation of arrays and initialization of the 3D model via ! a) pre-run the 1D model ! or ! b) pre-set constant linear profiles ! or ! c) read values of a previous run !------------------------------------------------------------------------------! USE arrays_3d USE averaging USE cloud_parameters USE constants USE control_parameters USE cpulog USE indices USE interfaces USE model_1d USE netcdf_control USE particle_attributes USE pegrid USE profil_parameter USE random_function_mod USE statistics IMPLICIT NONE INTEGER :: i, ind_array(1), j, k, sr INTEGER, DIMENSION(:), ALLOCATABLE :: ngp_2dh_l, ngp_3d_inner_l INTEGER, DIMENSION(:,:), ALLOCATABLE :: ngp_2dh_outer_l, & ngp_2dh_s_inner_l REAL :: a, b REAL, DIMENSION(1:2) :: volume_flow_area_l, volume_flow_initial_l ! !-- Allocate arrays ALLOCATE( ngp_2dh(0:statistic_regions), ngp_2dh_l(0:statistic_regions), & ngp_3d(0:statistic_regions), & ngp_3d_inner(0:statistic_regions), & ngp_3d_inner_l(0:statistic_regions), & sums_divnew_l(0:statistic_regions), & sums_divold_l(0:statistic_regions) ) ALLOCATE( dp_smooth_factor(nzb:nzt), rdf(nzb+1:nzt) ) ALLOCATE( ngp_2dh_outer(nzb:nzt+1,0:statistic_regions), & ngp_2dh_outer_l(nzb:nzt+1,0:statistic_regions), & ngp_2dh_s_inner(nzb:nzt+1,0:statistic_regions), & ngp_2dh_s_inner_l(nzb:nzt+1,0:statistic_regions), & rmask(nys-1:nyn+1,nxl-1:nxr+1,0:statistic_regions), & sums(nzb:nzt+1,pr_palm+max_pr_user), & sums_l(nzb:nzt+1,pr_palm+max_pr_user,0:threads_per_task-1), & sums_l_l(nzb:nzt+1,0:statistic_regions,0:threads_per_task-1), & sums_up_fraction_l(10,3,0:statistic_regions), & sums_wsts_bc_l(nzb:nzt+1,0:statistic_regions), & ts_value(dots_max,0:statistic_regions) ) ALLOCATE( km_damp_x(nxl-1:nxr+1), km_damp_y(nys-1:nyn+1) ) ALLOCATE( rif_1(nys-1:nyn+1,nxl-1:nxr+1), shf_1(nys-1:nyn+1,nxl-1:nxr+1), & ts(nys-1:nyn+1,nxl-1:nxr+1), tswst_1(nys-1:nyn+1,nxl-1:nxr+1), & us(nys-1:nyn+1,nxl-1:nxr+1), usws_1(nys-1:nyn+1,nxl-1:nxr+1), & uswst_1(nys-1:nyn+1,nxl-1:nxr+1), & vsws_1(nys-1:nyn+1,nxl-1:nxr+1), & vswst_1(nys-1:nyn+1,nxl-1:nxr+1), z0(nys-1:nyn+1,nxl-1:nxr+1) ) IF ( timestep_scheme(1:5) /= 'runge' ) THEN ! !-- Leapfrog scheme needs two timelevels of diffusion quantities ALLOCATE( rif_2(nys-1:nyn+1,nxl-1:nxr+1), & shf_2(nys-1:nyn+1,nxl-1:nxr+1), & tswst_2(nys-1:nyn+1,nxl-1:nxr+1), & usws_2(nys-1:nyn+1,nxl-1:nxr+1), & uswst_2(nys-1:nyn+1,nxl-1:nxr+1), & vswst_2(nys-1:nyn+1,nxl-1:nxr+1), & vsws_2(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ALLOCATE( d(nzb+1:nzta,nys:nyna,nxl:nxra), & e_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & e_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & e_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & kh_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & km_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & p(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & pt_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & pt_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & pt_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & tend(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & u_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & u_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & u_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & v_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & v_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & v_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & w_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & w_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & w_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) IF ( timestep_scheme(1:5) /= 'runge' ) THEN ALLOCATE( kh_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & km_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF IF ( humidity .OR. passive_scalar ) THEN ! !-- 2D-humidity/scalar arrays ALLOCATE ( qs(nys-1:nyn+1,nxl-1:nxr+1), & qsws_1(nys-1:nyn+1,nxl-1:nxr+1), & qswst_1(nys-1:nyn+1,nxl-1:nxr+1) ) IF ( timestep_scheme(1:5) /= 'runge' ) THEN ALLOCATE( qsws_2(nys-1:nyn+1,nxl-1:nxr+1), & qswst_2(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ! !-- 3D-humidity/scalar arrays ALLOCATE( q_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & q_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & q_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ! !-- 3D-arrays needed for humidity only IF ( humidity ) THEN ALLOCATE( vpt_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) IF ( timestep_scheme(1:5) /= 'runge' ) THEN ALLOCATE( vpt_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF IF ( cloud_physics ) THEN ! !-- Liquid water content ALLOCATE ( ql_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ! !-- Precipitation amount and rate (only needed if output is switched) ALLOCATE( precipitation_amount(nys-1:nyn+1,nxl-1:nxr+1), & precipitation_rate(nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF IF ( cloud_droplets ) THEN ! !-- Liquid water content, change in liquid water content, !-- real volume of particles (with weighting), volume of particles ALLOCATE ( ql_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & ql_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & ql_v(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & ql_vp(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ENDIF ENDIF IF ( ocean ) THEN ALLOCATE( saswsb_1(nys-1:nyn+1,nxl-1:nxr+1), & saswst_1(nys-1:nyn+1,nxl-1:nxr+1) ) ALLOCATE( prho_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & rho_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & sa_1(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & sa_2(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & sa_3(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) prho => prho_1 rho => rho_1 ! routines calc_mean_profile and diffusion_e require ! density to be apointer IF ( humidity_remote ) THEN ALLOCATE( qswst_remote(nys-1:nyn+1,nxl-1:nxr+1) ) qswst_remote = 0.0 ENDIF ENDIF ! !-- 3D-array for storing the dissipation, needed for calculating the sgs !-- particle velocities IF ( use_sgs_for_particles ) THEN ALLOCATE ( diss(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ELSE ALLOCATE ( diss(2,2,2) ) ! required because diss is used as a ! formal parameter ENDIF IF ( dt_dosp /= 9999999.9 ) THEN ALLOCATE( spectrum_x( 1:nx/2, 1:10, 1:10 ), & spectrum_y( 1:ny/2, 1:10, 1:10 ) ) spectrum_x = 0.0 spectrum_y = 0.0 ENDIF ! !-- 3D-arrays for the leaf area density and the canopy drag coefficient IF ( plant_canopy ) THEN ALLOCATE ( lad_s(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & lad_u(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & lad_v(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & lad_w(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & cdc(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) IF ( passive_scalar ) THEN ALLOCATE ( sls(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & sec(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF IF ( cthf /= 0.0 ) THEN ALLOCATE ( lai(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1), & canopy_heat_flux(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1) ) ENDIF ENDIF ! !-- 4D-array for storing the Rif-values at vertical walls IF ( topography /= 'flat' ) THEN ALLOCATE( rif_wall(nzb:nzt+1,nys-1:nyn+1,nxl-1:nxr+1,1:4) ) rif_wall = 0.0 ENDIF ! !-- Velocities at nzb+1 needed for volume flow control IF ( conserve_volume_flow ) THEN ALLOCATE( u_nzb_p1_for_vfc(nys:nyn), v_nzb_p1_for_vfc(nxl:nxr) ) u_nzb_p1_for_vfc = 0.0 v_nzb_p1_for_vfc = 0.0 ENDIF ! !-- Arrays to store velocity data from t-dt and the phase speeds which !-- are needed for radiation boundary conditions IF ( outflow_l ) THEN ALLOCATE( u_m_l(nzb:nzt+1,nys-1:nyn+1,1:2), & v_m_l(nzb:nzt+1,nys-1:nyn+1,0:1), & w_m_l(nzb:nzt+1,nys-1:nyn+1,0:1) ) ENDIF IF ( outflow_r ) THEN ALLOCATE( u_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx), & v_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx), & w_m_r(nzb:nzt+1,nys-1:nyn+1,nx-1:nx) ) ENDIF IF ( outflow_l .OR. outflow_r ) THEN ALLOCATE( c_u(nzb:nzt+1,nys-1:nyn+1), c_v(nzb:nzt+1,nys-1:nyn+1), & c_w(nzb:nzt+1,nys-1:nyn+1) ) ENDIF IF ( outflow_s ) THEN ALLOCATE( u_m_s(nzb:nzt+1,0:1,nxl-1:nxr+1), & v_m_s(nzb:nzt+1,1:2,nxl-1:nxr+1), & w_m_s(nzb:nzt+1,0:1,nxl-1:nxr+1) ) ENDIF IF ( outflow_n ) THEN ALLOCATE( u_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1), & v_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1), & w_m_n(nzb:nzt+1,ny-1:ny,nxl-1:nxr+1) ) ENDIF IF ( outflow_s .OR. outflow_n ) THEN ALLOCATE( c_u(nzb:nzt+1,nxl-1:nxr+1), c_v(nzb:nzt+1,nxl-1:nxr+1), & c_w(nzb:nzt+1,nxl-1:nxr+1) ) ENDIF ! !-- Initial assignment of the pointers IF ( timestep_scheme(1:5) /= 'runge' ) THEN rif_m => rif_1; rif => rif_2 shf_m => shf_1; shf => shf_2 tswst_m => tswst_1; tswst => tswst_2 usws_m => usws_1; usws => usws_2 uswst_m => uswst_1; uswst => uswst_2 vsws_m => vsws_1; vsws => vsws_2 vswst_m => vswst_1; vswst => vswst_2 e_m => e_1; e => e_2; e_p => e_3; te_m => e_3 kh_m => kh_1; kh => kh_2 km_m => km_1; km => km_2 pt_m => pt_1; pt => pt_2; pt_p => pt_3; tpt_m => pt_3 u_m => u_1; u => u_2; u_p => u_3; tu_m => u_3 v_m => v_1; v => v_2; v_p => v_3; tv_m => v_3 w_m => w_1; w => w_2; w_p => w_3; tw_m => w_3 IF ( humidity .OR. passive_scalar ) THEN qsws_m => qsws_1; qsws => qsws_2 qswst_m => qswst_1; qswst => qswst_2 q_m => q_1; q => q_2; q_p => q_3; tq_m => q_3 IF ( humidity ) vpt_m => vpt_1; vpt => vpt_2 IF ( cloud_physics ) ql => ql_1 IF ( cloud_droplets ) THEN ql => ql_1 ql_c => ql_2 ENDIF ENDIF ELSE rif => rif_1 shf => shf_1 tswst => tswst_1 usws => usws_1 uswst => uswst_1 vsws => vsws_1 vswst => vswst_1 e => e_1; e_p => e_2; te_m => e_3; e_m => e_3 kh => kh_1 km => km_1 pt => pt_1; pt_p => pt_2; tpt_m => pt_3; pt_m => pt_3 u => u_1; u_p => u_2; tu_m => u_3; u_m => u_3 v => v_1; v_p => v_2; tv_m => v_3; v_m => v_3 w => w_1; w_p => w_2; tw_m => w_3; w_m => w_3 IF ( humidity .OR. passive_scalar ) THEN qsws => qsws_1 qswst => qswst_1 q => q_1; q_p => q_2; tq_m => q_3; q_m => q_3 IF ( humidity ) vpt => vpt_1 IF ( cloud_physics ) ql => ql_1 IF ( cloud_droplets ) THEN ql => ql_1 ql_c => ql_2 ENDIF ENDIF IF ( ocean ) THEN saswsb => saswsb_1 saswst => saswst_1 sa => sa_1; sa_p => sa_2; tsa_m => sa_3 ENDIF ENDIF ! !-- Initialize model variables IF ( TRIM( initializing_actions ) /= 'read_restart_data' .AND. & TRIM( initializing_actions ) /= 'cyclic_fill' ) THEN ! !-- First model run of a possible job queue. !-- Initial profiles of the variables must be computes. IF ( INDEX( initializing_actions, 'set_1d-model_profiles' ) /= 0 ) THEN ! !-- Use solutions of the 1D model as initial profiles, !-- start 1D model CALL init_1d_model ! !-- Transfer initial profiles to the arrays of the 3D model DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 e(:,j,i) = e1d kh(:,j,i) = kh1d km(:,j,i) = km1d pt(:,j,i) = pt_init u(:,j,i) = u1d v(:,j,i) = v1d ENDDO ENDDO IF ( humidity .OR. passive_scalar ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 q(:,j,i) = q_init ENDDO ENDDO ENDIF IF ( .NOT. constant_diffusion ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 e(:,j,i) = e1d ENDDO ENDDO ! !-- Store initial profiles for output purposes etc. hom(:,1,25,:) = SPREAD( l1d, 2, statistic_regions+1 ) IF ( prandtl_layer ) THEN rif = rif1d(nzb+1) ts = 0.0 ! could actually be computed more accurately in the ! 1D model. Update when opportunity arises. us = us1d usws = usws1d vsws = vsws1d ELSE ts = 0.0 ! must be set, because used in rif = 0.0 ! flowste us = 0.0 usws = 0.0 vsws = 0.0 ENDIF ELSE e = 0.0 ! must be set, because used in rif = 0.0 ! flowste ts = 0.0 us = 0.0 usws = 0.0 vsws = 0.0 ENDIF uswst = top_momentumflux_u vswst = top_momentumflux_v ! !-- In every case qs = 0.0 (see also pt) !-- This could actually be computed more accurately in the 1D model. !-- Update when opportunity arises! IF ( humidity .OR. passive_scalar ) qs = 0.0 ! !-- inside buildings set velocities back to zero IF ( topography /= 'flat' ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 u(nzb:nzb_u_inner(j,i),j,i) = 0.0 v(nzb:nzb_v_inner(j,i),j,i) = 0.0 ENDDO ENDDO IF ( conserve_volume_flow ) THEN IF ( nxr == nx ) THEN DO j = nys, nyn DO k = nzb + 1, nzb_u_inner(j,nx) u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + & u1d(k) * dzu(k) ENDDO ENDDO ENDIF IF ( nyn == ny ) THEN DO i = nxl, nxr DO k = nzb + 1, nzb_v_inner(ny,i) v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + & v1d(k) * dzu(k) ENDDO ENDDO ENDIF ENDIF ! !-- WARNING: The extra boundary conditions set after running the !-- ------- 1D model impose an error on the divergence one layer !-- below the topography; need to correct later !-- ATTENTION: Provisional correction for Piacsek & Williams !-- --------- advection scheme: keep u and v zero one layer below !-- the topography. IF ( ibc_uv_b == 0 ) THEN ! !-- Satisfying the Dirichlet condition with an extra layer below !-- the surface where the u and v component change their sign. DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = -u(1,j,i) IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = -v(1,j,i) ENDDO ENDDO ELSE ! !-- Neumann condition DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 IF ( nzb_u_inner(j,i) == 0 ) u(0,j,i) = u(1,j,i) IF ( nzb_v_inner(j,i) == 0 ) v(0,j,i) = v(1,j,i) ENDDO ENDDO ENDIF ENDIF ELSEIF ( INDEX(initializing_actions, 'set_constant_profiles') /= 0 ) & THEN ! !-- Use constructed initial profiles (velocity constant with height, !-- temperature profile with constant gradient) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 pt(:,j,i) = pt_init u(:,j,i) = u_init v(:,j,i) = v_init ENDDO ENDDO ! !-- Set initial horizontal velocities at the lowest computational grid !-- levels to zero in order to avoid too small time steps caused by the !-- diffusion limit in the initial phase of a run (at k=1, dz/2 occurs !-- in the limiting formula!). The original values are stored to be later !-- used for volume flow control. DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 u(nzb:nzb_u_inner(j,i)+1,j,i) = 0.0 v(nzb:nzb_v_inner(j,i)+1,j,i) = 0.0 ENDDO ENDDO IF ( conserve_volume_flow ) THEN IF ( nxr == nx ) THEN DO j = nys, nyn DO k = nzb + 1, nzb_u_inner(j,nx) + 1 u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + & u_init(k) * dzu(k) ENDDO ENDDO ENDIF IF ( nyn == ny ) THEN DO i = nxl, nxr DO k = nzb + 1, nzb_v_inner(ny,i) + 1 v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + & v_init(k) * dzu(k) ENDDO ENDDO ENDIF ENDIF IF ( humidity .OR. passive_scalar ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 q(:,j,i) = q_init ENDDO ENDDO ENDIF IF ( ocean ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 sa(:,j,i) = sa_init ENDDO ENDDO ENDIF IF ( constant_diffusion ) THEN km = km_constant kh = km / prandtl_number e = 0.0 ELSEIF ( e_init > 0.0 ) THEN DO k = nzb+1, nzt km(k,:,:) = 0.1 * l_grid(k) * SQRT( e_init ) ENDDO km(nzb,:,:) = km(nzb+1,:,:) km(nzt+1,:,:) = km(nzt,:,:) kh = km / prandtl_number e = e_init ELSE IF ( .NOT. ocean ) THEN kh = 0.01 ! there must exist an initial diffusion, because km = 0.01 ! otherwise no TKE would be produced by the ! production terms, as long as not yet ! e = (u*/cm)**2 at k=nzb+1 ELSE kh = 0.00001 km = 0.00001 ENDIF e = 0.0 ENDIF rif = 0.0 ts = 0.0 us = 0.0 usws = 0.0 uswst = top_momentumflux_u vsws = 0.0 vswst = top_momentumflux_v IF ( humidity .OR. passive_scalar ) qs = 0.0 ! !-- Compute initial temperature field and other constants used in case !-- of a sloping surface IF ( sloping_surface ) CALL init_slope ELSEIF ( INDEX(initializing_actions, 'by_user') /= 0 ) & THEN ! !-- Initialization will completely be done by the user CALL user_init_3d_model ENDIF ! !-- Apply channel flow boundary condition IF ( TRIM( bc_uv_t ) == 'dirichlet_0' ) THEN u(nzt+1,:,:) = 0.0 v(nzt+1,:,:) = 0.0 !-- For the Dirichlet condition to be correctly applied at the top, set !-- ug and vg to zero there ug(nzt+1) = 0.0 vg(nzt+1) = 0.0 ENDIF ! !-- Calculate virtual potential temperature IF ( humidity ) vpt = pt * ( 1.0 + 0.61 * q ) ! !-- Store initial profiles for output purposes etc. hom(:,1,5,:) = SPREAD( u(:,nys,nxl), 2, statistic_regions+1 ) hom(:,1,6,:) = SPREAD( v(:,nys,nxl), 2, statistic_regions+1 ) IF ( ibc_uv_b == 0 ) THEN hom(nzb,1,5,:) = -hom(nzb+1,1,5,:) ! due to satisfying the Dirichlet hom(nzb,1,6,:) = -hom(nzb+1,1,6,:) ! condition with an extra layer ! below the surface where the u and v component change their sign ENDIF hom(:,1,7,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 ) hom(:,1,23,:) = SPREAD( km(:,nys,nxl), 2, statistic_regions+1 ) hom(:,1,24,:) = SPREAD( kh(:,nys,nxl), 2, statistic_regions+1 ) IF ( ocean ) THEN ! !-- Store initial salinity profile hom(:,1,26,:) = SPREAD( sa(:,nys,nxl), 2, statistic_regions+1 ) ENDIF IF ( humidity ) THEN ! !-- Store initial profile of total water content, virtual potential !-- temperature hom(:,1,26,:) = SPREAD( q(:,nys,nxl), 2, statistic_regions+1 ) hom(:,1,29,:) = SPREAD( vpt(:,nys,nxl), 2, statistic_regions+1 ) IF ( cloud_physics .OR. cloud_droplets ) THEN ! !-- Store initial profile of specific humidity and potential !-- temperature hom(:,1,27,:) = SPREAD( q(:,nys,nxl), 2, statistic_regions+1 ) hom(:,1,28,:) = SPREAD( pt(:,nys,nxl), 2, statistic_regions+1 ) ENDIF ENDIF IF ( passive_scalar ) THEN ! !-- Store initial scalar profile hom(:,1,26,:) = SPREAD( q(:,nys,nxl), 2, statistic_regions+1 ) ENDIF ! !-- Initialize fluxes at bottom surface IF ( use_surface_fluxes ) THEN IF ( constant_heatflux ) THEN ! !-- Heat flux is prescribed IF ( random_heatflux ) THEN CALL disturb_heatflux ELSE shf = surface_heatflux ! !-- Over topography surface_heatflux is replaced by wall_heatflux(0) IF ( TRIM( topography ) /= 'flat' ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 IF ( nzb_s_inner(j,i) /= 0 ) THEN shf(j,i) = wall_heatflux(0) ENDIF ENDDO ENDDO ENDIF ENDIF IF ( ASSOCIATED( shf_m ) ) shf_m = shf ENDIF ! !-- Determine the near-surface water flux IF ( humidity .OR. passive_scalar ) THEN IF ( constant_waterflux ) THEN qsws = surface_waterflux IF ( ASSOCIATED( qsws_m ) ) qsws_m = qsws ENDIF ENDIF ENDIF ! !-- Initialize fluxes at top surface !-- Currently, only the heatflux and salinity flux can be prescribed. !-- The latent flux is zero in this case! IF ( use_top_fluxes ) THEN IF ( constant_top_heatflux ) THEN ! !-- Heat flux is prescribed tswst = top_heatflux IF ( ASSOCIATED( tswst_m ) ) tswst_m = tswst IF ( humidity .OR. passive_scalar ) THEN qswst = 0.0 IF ( ASSOCIATED( qswst_m ) ) qswst_m = qswst ENDIF IF ( ocean ) THEN saswsb = bottom_salinityflux saswst = top_salinityflux ENDIF ENDIF ! !-- Initialization in case of a coupled model run IF ( coupling_mode == 'ocean_to_atmosphere' ) THEN tswst = 0.0 IF ( ASSOCIATED( tswst_m ) ) tswst_m = tswst ENDIF ENDIF ! !-- Initialize Prandtl layer quantities IF ( prandtl_layer ) THEN z0 = roughness_length IF ( .NOT. constant_heatflux ) THEN ! !-- Surface temperature is prescribed. Here the heat flux cannot be !-- simply estimated, because therefore rif, u* and theta* would have !-- to be computed by iteration. This is why the heat flux is assumed !-- to be zero before the first time step. It approaches its correct !-- value in the course of the first few time steps. shf = 0.0 IF ( ASSOCIATED( shf_m ) ) shf_m = 0.0 ENDIF IF ( humidity .OR. passive_scalar ) THEN IF ( .NOT. constant_waterflux ) THEN qsws = 0.0 IF ( ASSOCIATED( qsws_m ) ) qsws_m = 0.0 ENDIF ENDIF ENDIF ! !-- Calculate the initial volume flow at the right and north boundary IF ( conserve_volume_flow ) THEN volume_flow_initial_l = 0.0 volume_flow_area_l = 0.0 IF ( nxr == nx ) THEN DO j = nys, nyn DO k = nzb_2d(j,nx) + 1, nzt volume_flow_initial_l(1) = volume_flow_initial_l(1) + & u(k,j,nx) * dzu(k) volume_flow_area_l(1) = volume_flow_area_l(1) + dzu(k) ENDDO ! !-- Correction if velocity at nzb+1 has been set zero further above volume_flow_initial_l(1) = volume_flow_initial_l(1) + & u_nzb_p1_for_vfc(j) ENDDO ENDIF IF ( nyn == ny ) THEN DO i = nxl, nxr DO k = nzb_2d(ny,i) + 1, nzt volume_flow_initial_l(2) = volume_flow_initial_l(2) + & v(k,ny,i) * dzu(k) volume_flow_area_l(2) = volume_flow_area_l(2) + dzu(k) ENDDO ! !-- Correction if velocity at nzb+1 has been set zero further above volume_flow_initial_l(2) = volume_flow_initial_l(2) + & v_nzb_p1_for_vfc(i) ENDDO ENDIF #if defined( __parallel ) CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),& 2, MPI_REAL, MPI_SUM, comm2d, ierr ) CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), & 2, MPI_REAL, MPI_SUM, comm2d, ierr ) #else volume_flow_initial = volume_flow_initial_l volume_flow_area = volume_flow_area_l #endif ! !-- In case of 'bulk_velocity' mode, volume_flow_initial is overridden !-- and calculated from u|v_bulk instead. IF ( TRIM( conserve_volume_flow_mode ) == 'bulk_velocity' ) THEN volume_flow_initial(1) = u_bulk * volume_flow_area(1) volume_flow_initial(2) = v_bulk * volume_flow_area(2) ENDIF ENDIF ! !-- For the moment, perturbation pressure and vertical velocity are zero p = 0.0; w = 0.0 ! !-- Initialize array sums (must be defined in first call of pres) sums = 0.0 ! !-- Treating cloud physics, liquid water content and precipitation amount !-- are zero at beginning of the simulation IF ( cloud_physics ) THEN ql = 0.0 IF ( precipitation ) precipitation_amount = 0.0 ENDIF ! !-- Impose vortex with vertical axis on the initial velocity profile IF ( INDEX( initializing_actions, 'initialize_vortex' ) /= 0 ) THEN CALL init_rankine ENDIF ! !-- Impose temperature anomaly (advection test only) IF ( INDEX( initializing_actions, 'initialize_ptanom' ) /= 0 ) THEN CALL init_pt_anomaly ENDIF ! !-- If required, change the surface temperature at the start of the 3D run IF ( pt_surface_initial_change /= 0.0 ) THEN pt(nzb,:,:) = pt(nzb,:,:) + pt_surface_initial_change ENDIF ! !-- If required, change the surface humidity/scalar at the start of the 3D !-- run IF ( ( humidity .OR. passive_scalar ) .AND. & q_surface_initial_change /= 0.0 ) THEN q(nzb,:,:) = q(nzb,:,:) + q_surface_initial_change ENDIF ! !-- Initialize the random number generator (from numerical recipes) CALL random_function_ini ! !-- Impose random perturbation on the horizontal velocity field and then !-- remove the divergences from the velocity field IF ( create_disturbances ) THEN CALL disturb_field( nzb_u_inner, tend, u ) CALL disturb_field( nzb_v_inner, tend, v ) n_sor = nsor_ini CALL pres n_sor = nsor ENDIF ! !-- Once again set the perturbation pressure explicitly to zero in order to !-- assure that it does not generate any divergences in the first time step. !-- At t=0 the velocity field is free of divergence (as constructed above). !-- Divergences being created during a time step are not yet known and thus !-- cannot be corrected during the time step yet. p = 0.0 ! !-- Initialize old and new time levels. IF ( timestep_scheme(1:5) /= 'runge' ) THEN e_m = e; pt_m = pt; u_m = u; v_m = v; w_m = w; kh_m = kh; km_m = km ELSE te_m = 0.0; tpt_m = 0.0; tu_m = 0.0; tv_m = 0.0; tw_m = 0.0 ENDIF e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w IF ( humidity .OR. passive_scalar ) THEN IF ( ASSOCIATED( q_m ) ) q_m = q IF ( timestep_scheme(1:5) == 'runge' ) tq_m = 0.0 q_p = q IF ( humidity .AND. ASSOCIATED( vpt_m ) ) vpt_m = vpt ENDIF IF ( ocean ) THEN tsa_m = 0.0 sa_p = sa ENDIF ELSEIF ( TRIM( initializing_actions ) == 'read_restart_data' .OR. & TRIM( initializing_actions ) == 'cyclic_fill' ) & THEN ! !-- When reading data for cyclic fill of 3D prerun data, first read !-- some of the global variables from restart file IF ( TRIM( initializing_actions ) == 'cyclic_fill' ) THEN WRITE (9,*) 'before read_parts_of_var_list' CALL local_flush( 9 ) CALL read_parts_of_var_list WRITE (9,*) 'after read_parts_of_var_list' CALL local_flush( 9 ) CALL close_file( 13 ) ! !-- Initialization of the turbulence recycling method IF ( turbulent_inflow ) THEN ! !-- Store temporally and horizontally averaged vertical profiles to be !-- used as mean inflow profiles ALLOCATE( mean_inflow_profiles(nzb:nzt+1,5) ) mean_inflow_profiles(:,1) = hom_sum(:,1,0) ! u mean_inflow_profiles(:,2) = hom_sum(:,2,0) ! v mean_inflow_profiles(:,4) = hom_sum(:,4,0) ! pt mean_inflow_profiles(:,5) = hom_sum(:,8,0) ! e ! !-- Use these mean profiles for the inflow (provided that Dirichlet !-- conditions are used) IF ( inflow_l ) THEN DO j = nys-1, nyn+1 DO k = nzb, nzt+1 u(k,j,-1) = mean_inflow_profiles(k,1) v(k,j,-1) = mean_inflow_profiles(k,2) w(k,j,-1) = 0.0 pt(k,j,-1) = mean_inflow_profiles(k,4) e(k,j,-1) = mean_inflow_profiles(k,5) ENDDO ENDDO ENDIF ! !-- Calculate the damping factors to be used at the inflow. For a !-- turbulent inflow the turbulent fluctuations have to be limited !-- vertically because otherwise the turbulent inflow layer will grow !-- in time. IF ( inflow_damping_height == 9999999.9 ) THEN ! !-- Default: use the inversion height calculated by the prerun; if !-- this is zero, inflow_damping_height must be explicitly !-- specified. IF ( hom_sum(nzb+6,pr_palm,0) /= 0.0 ) THEN inflow_damping_height = hom_sum(nzb+6,pr_palm,0) ELSE WRITE( message_string, * ) 'inflow_damping_height must be ',& 'explicitly specified because&the inversion height ', & 'calculated by the prerun is zero.' CALL message( 'init_3d_model', 'PA0318', 1, 2, 0, 6, 0 ) ENDIF ENDIF IF ( inflow_damping_width == 9999999.9 ) THEN ! !-- Default for the transition range: one tenth of the undamped !-- layer inflow_damping_width = 0.1 * inflow_damping_height ENDIF ALLOCATE( inflow_damping_factor(nzb:nzt+1) ) DO k = nzb, nzt+1 IF ( zu(k) <= inflow_damping_height ) THEN inflow_damping_factor(k) = 1.0 ELSEIF ( zu(k) <= inflow_damping_height + & inflow_damping_width ) THEN inflow_damping_factor(k) = 1.0 - & ( zu(k) - inflow_damping_height ) / & inflow_damping_width ELSE inflow_damping_factor(k) = 0.0 ENDIF ENDDO ENDIF ENDIF ! !-- Read binary data from restart file WRITE (9,*) 'before read_3d_binary' CALL local_flush( 9 ) CALL read_3d_binary WRITE (9,*) 'after read_3d_binary' CALL local_flush( 9 ) ! !-- Inside buildings set velocities and TKE back to zero IF ( TRIM( initializing_actions ) == 'cyclic_fill' .AND. & topography /= 'flat' ) THEN ! !-- Correction of initial volume flow IF ( conserve_volume_flow ) THEN IF ( nxr == nx ) THEN DO j = nys, nyn DO k = nzb + 1, nzb_u_inner(j,nx) u_nzb_p1_for_vfc(j) = u_nzb_p1_for_vfc(j) + & u(k,j,nx) * dzu(k) ENDDO ENDDO ENDIF IF ( nyn == ny ) THEN DO i = nxl, nxr DO k = nzb + 1, nzb_v_inner(ny,i) v_nzb_p1_for_vfc(i) = v_nzb_p1_for_vfc(i) + & v(k,ny,i) * dzu(k) ENDDO ENDDO ENDIF ENDIF ! !-- Inside buildings set velocities and TKE back to zero. !-- Other scalars (pt, q, s, km, kh, p, sa, ...) are ignored at present, !-- maybe revise later. IF ( timestep_scheme(1:5) == 'runge' ) THEN DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 u (nzb:nzb_u_inner(j,i),j,i) = 0.0 v (nzb:nzb_v_inner(j,i),j,i) = 0.0 w (nzb:nzb_w_inner(j,i),j,i) = 0.0 e (nzb:nzb_w_inner(j,i),j,i) = 0.0 u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0 v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0 w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 tu_m(nzb:nzb_u_inner(j,i),j,i) = 0.0 tv_m(nzb:nzb_v_inner(j,i),j,i) = 0.0 tw_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 te_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 tpt_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 ENDDO ENDDO ELSE DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 u (nzb:nzb_u_inner(j,i),j,i) = 0.0 v (nzb:nzb_v_inner(j,i),j,i) = 0.0 w (nzb:nzb_w_inner(j,i),j,i) = 0.0 e (nzb:nzb_w_inner(j,i),j,i) = 0.0 u_m(nzb:nzb_u_inner(j,i),j,i) = 0.0 v_m(nzb:nzb_v_inner(j,i),j,i) = 0.0 w_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 e_m(nzb:nzb_w_inner(j,i),j,i) = 0.0 u_p(nzb:nzb_u_inner(j,i),j,i) = 0.0 v_p(nzb:nzb_v_inner(j,i),j,i) = 0.0 w_p(nzb:nzb_w_inner(j,i),j,i) = 0.0 e_p(nzb:nzb_w_inner(j,i),j,i) = 0.0 ENDDO ENDDO ENDIF ENDIF ! !-- Calculate the initial volume flow at the right and north boundary IF ( conserve_volume_flow .AND. & TRIM( initializing_actions ) == 'cyclic_fill' ) THEN volume_flow_initial_l = 0.0 volume_flow_area_l = 0.0 IF ( nxr == nx ) THEN DO j = nys, nyn DO k = nzb_2d(j,nx) + 1, nzt volume_flow_initial_l(1) = volume_flow_initial_l(1) + & u(k,j,nx) * dzu(k) volume_flow_area_l(1) = volume_flow_area_l(1) + dzu(k) ENDDO ! !-- Correction if velocity inside buildings has been set to zero !-- further above volume_flow_initial_l(1) = volume_flow_initial_l(1) + & u_nzb_p1_for_vfc(j) ENDDO ENDIF IF ( nyn == ny ) THEN DO i = nxl, nxr DO k = nzb_2d(ny,i) + 1, nzt volume_flow_initial_l(2) = volume_flow_initial_l(2) + & v(k,ny,i) * dzu(k) volume_flow_area_l(2) = volume_flow_area_l(2) + dzu(k) ENDDO ! !-- Correction if velocity inside buildings has been set to zero !-- further above volume_flow_initial_l(2) = volume_flow_initial_l(2) + & v_nzb_p1_for_vfc(i) ENDDO ENDIF #if defined( __parallel ) CALL MPI_ALLREDUCE( volume_flow_initial_l(1), volume_flow_initial(1),& 2, MPI_REAL, MPI_SUM, comm2d, ierr ) CALL MPI_ALLREDUCE( volume_flow_area_l(1), volume_flow_area(1), & 2, MPI_REAL, MPI_SUM, comm2d, ierr ) #else volume_flow_initial = volume_flow_initial_l volume_flow_area = volume_flow_area_l #endif ENDIF ! !-- Calculate initial temperature field and other constants used in case !-- of a sloping surface IF ( sloping_surface ) CALL init_slope ! !-- Initialize new time levels (only done in order to set boundary values !-- including ghost points) e_p = e; pt_p = pt; u_p = u; v_p = v; w_p = w IF ( humidity .OR. passive_scalar ) q_p = q IF ( ocean ) sa_p = sa ! !-- Allthough tendency arrays are set in prognostic_equations, they have !-- have to be predefined here because they are used (but multiplied with 0) !-- there before they are set. IF ( timestep_scheme(1:5) == 'runge' ) THEN te_m = 0.0; tpt_m = 0.0; tu_m = 0.0; tv_m = 0.0; tw_m = 0.0 IF ( humidity .OR. passive_scalar ) tq_m = 0.0 IF ( ocean ) tsa_m = 0.0 ENDIF ELSE ! !-- Actually this part of the programm should not be reached message_string = 'unknown initializing problem' CALL message( 'init_3d_model', 'PA0193', 1, 2, 0, 6, 0 ) ENDIF IF ( TRIM( initializing_actions ) /= 'read_restart_data' ) THEN ! !-- Initialize old timelevels needed for radiation boundary conditions IF ( outflow_l ) THEN u_m_l(:,:,:) = u(:,:,1:2) v_m_l(:,:,:) = v(:,:,0:1) w_m_l(:,:,:) = w(:,:,0:1) ENDIF IF ( outflow_r ) THEN u_m_r(:,:,:) = u(:,:,nx-1:nx) v_m_r(:,:,:) = v(:,:,nx-1:nx) w_m_r(:,:,:) = w(:,:,nx-1:nx) ENDIF IF ( outflow_s ) THEN u_m_s(:,:,:) = u(:,0:1,:) v_m_s(:,:,:) = v(:,1:2,:) w_m_s(:,:,:) = w(:,0:1,:) ENDIF IF ( outflow_n ) THEN u_m_n(:,:,:) = u(:,ny-1:ny,:) v_m_n(:,:,:) = v(:,ny-1:ny,:) w_m_n(:,:,:) = w(:,ny-1:ny,:) ENDIF ENDIF ! !-- Initialization of the leaf area density IF ( plant_canopy ) THEN SELECT CASE ( TRIM( canopy_mode ) ) CASE( 'block' ) DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 lad_s(:,j,i) = lad(:) cdc(:,j,i) = drag_coefficient IF ( passive_scalar ) THEN sls(:,j,i) = leaf_surface_concentration sec(:,j,i) = scalar_exchange_coefficient ENDIF ENDDO ENDDO CASE DEFAULT ! !-- The DEFAULT case is reached either if the parameter !-- canopy mode contains a wrong character string or if the !-- user has coded a special case in the user interface. !-- There, the subroutine user_init_plant_canopy checks !-- which of these two conditions applies. CALL user_init_plant_canopy END SELECT CALL exchange_horiz( lad_s ) CALL exchange_horiz( cdc ) IF ( passive_scalar ) THEN CALL exchange_horiz( sls ) CALL exchange_horiz( sec ) ENDIF ! !-- Sharp boundaries of the plant canopy in horizontal directions !-- In vertical direction the interpolation is retained, as the leaf !-- area density is initialised by prescribing a vertical profile !-- consisting of piecewise linear segments. The upper boundary !-- of the plant canopy is now defined by lad_w(pch_index,:,:) = 0.0. DO i = nxl, nxr DO j = nys, nyn DO k = nzb, nzt+1 IF ( lad_s(k,j,i) > 0.0 ) THEN lad_u(k,j,i) = lad_s(k,j,i) lad_u(k,j,i+1) = lad_s(k,j,i) lad_v(k,j,i) = lad_s(k,j,i) lad_v(k,j+1,i) = lad_s(k,j,i) ENDIF ENDDO DO k = nzb, nzt lad_w(k,j,i) = 0.5 * ( lad_s(k+1,j,i) + lad_s(k,j,i) ) ENDDO ENDDO ENDDO lad_w(pch_index,:,:) = 0.0 lad_w(nzt+1,:,:) = lad_w(nzt,:,:) CALL exchange_horiz( lad_u ) CALL exchange_horiz( lad_v ) CALL exchange_horiz( lad_w ) ! !-- Initialisation of the canopy heat source distribution IF ( cthf /= 0.0 ) THEN ! !-- Piecewise evaluation of the leaf area index by !-- integration of the leaf area density lai(:,:,:) = 0.0 DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = pch_index-1, 0, -1 lai(k,j,i) = lai(k+1,j,i) + & ( 0.5 * ( lad_w(k+1,j,i) + & lad_s(k+1,j,i) ) * & ( zw(k+1) - zu(k+1) ) ) + & ( 0.5 * ( lad_w(k,j,i) + & lad_s(k+1,j,i) ) * & ( zu(k+1) - zw(k) ) ) ENDDO ENDDO ENDDO ! !-- Evaluation of the upward kinematic vertical heat flux within the !-- canopy DO i = nxl-1, nxr+1 DO j = nys-1, nyn+1 DO k = 0, pch_index canopy_heat_flux(k,j,i) = cthf * & exp( -0.6 * lai(k,j,i) ) ENDDO ENDDO ENDDO ! !-- The near surface heat flux is derived from the heat flux !-- distribution within the canopy shf(:,:) = canopy_heat_flux(0,:,:) IF ( ASSOCIATED( shf_m ) ) shf_m = shf ENDIF ENDIF ! !-- If required, initialize dvrp-software IF ( dt_dvrp /= 9999999.9 ) CALL init_dvrp IF ( ocean ) THEN ! !-- Initialize quantities needed for the ocean model CALL init_ocean ELSE ! !-- Initialize quantities for handling cloud physics !-- This routine must be called before init_particles, because !-- otherwise, array pt_d_t, needed in data_output_dvrp (called by !-- init_particles) is not defined. CALL init_cloud_physics ENDIF ! !-- If required, initialize particles IF ( particle_advection ) CALL init_particles ! !-- Initialize quantities for special advections schemes CALL init_advec ! !-- Initialize Rayleigh damping factors rdf = 0.0 IF ( rayleigh_damping_factor /= 0.0 ) THEN IF ( .NOT. ocean ) THEN DO k = nzb+1, nzt IF ( zu(k) >= rayleigh_damping_height ) THEN rdf(k) = rayleigh_damping_factor * & ( SIN( pi * 0.5 * ( zu(k) - rayleigh_damping_height ) & / ( zu(nzt) - rayleigh_damping_height ) )& )**2 ENDIF ENDDO ELSE DO k = nzt, nzb+1, -1 IF ( zu(k) <= rayleigh_damping_height ) THEN rdf(k) = rayleigh_damping_factor * & ( SIN( pi * 0.5 * ( rayleigh_damping_height - zu(k) ) & / ( rayleigh_damping_height - zu(nzb+1)))& )**2 ENDIF ENDDO ENDIF ENDIF ! !-- Initialize the starting level and the vertical smoothing factor used for !-- the external pressure gradient dp_smooth_factor = 1.0 IF ( dp_external ) THEN ! !-- Set the starting level dp_level_ind_b only if it has not been set before !-- (e.g. in init_grid). IF ( dp_level_ind_b == 0 ) THEN ind_array = MINLOC( ABS( dp_level_b - zu ) ) dp_level_ind_b = ind_array(1) - 1 + nzb ! MINLOC uses lower array bound 1 ENDIF IF ( dp_smooth ) THEN dp_smooth_factor(:dp_level_ind_b) = 0.0 DO k = dp_level_ind_b+1, nzt dp_smooth_factor(k) = 0.5 * ( 1.0 + SIN( pi * & ( REAL( k - dp_level_ind_b ) / & REAL( nzt - dp_level_ind_b ) - 0.5 ) ) ) ENDDO ENDIF ENDIF ! !-- Initialize diffusivities used within the outflow damping layer in case of !-- non-cyclic lateral boundaries. A linear increase is assumed over the first !-- half of the width of the damping layer IF ( bc_lr == 'dirichlet/radiation' ) THEN DO i = nxl-1, nxr+1 IF ( i >= nx - outflow_damping_width ) THEN km_damp_x(i) = km_damp_max * MIN( 1.0, & ( i - ( nx - outflow_damping_width ) ) / & REAL( outflow_damping_width/2 ) & ) ELSE km_damp_x(i) = 0.0 ENDIF ENDDO ELSEIF ( bc_lr == 'radiation/dirichlet' ) THEN DO i = nxl-1, nxr+1 IF ( i <= outflow_damping_width ) THEN km_damp_x(i) = km_damp_max * MIN( 1.0, & ( outflow_damping_width - i ) / & REAL( outflow_damping_width/2 ) & ) ELSE km_damp_x(i) = 0.0 ENDIF ENDDO ENDIF IF ( bc_ns == 'dirichlet/radiation' ) THEN DO j = nys-1, nyn+1 IF ( j >= ny - outflow_damping_width ) THEN km_damp_y(j) = km_damp_max * MIN( 1.0, & ( j - ( ny - outflow_damping_width ) ) / & REAL( outflow_damping_width/2 ) & ) ELSE km_damp_y(j) = 0.0 ENDIF ENDDO ELSEIF ( bc_ns == 'radiation/dirichlet' ) THEN DO j = nys-1, nyn+1 IF ( j <= outflow_damping_width ) THEN km_damp_y(j) = km_damp_max * MIN( 1.0, & ( outflow_damping_width - j ) / & REAL( outflow_damping_width/2 ) & ) ELSE km_damp_y(j) = 0.0 ENDIF ENDDO ENDIF ! !-- Initialize local summation arrays for UP flow_statistics. This is necessary !-- because they may not yet have been initialized when they are called from !-- flow_statistics (or - depending on the chosen model run - are never !-- initialized) sums_divnew_l = 0.0 sums_divold_l = 0.0 sums_l_l = 0.0 sums_up_fraction_l = 0.0 sums_wsts_bc_l = 0.0 ! !-- Pre-set masks for regional statistics. Default is the total model domain. rmask = 1.0 ! !-- User-defined initializing actions. Check afterwards, if maximum number !-- of allowed timeseries is not exceeded CALL user_init IF ( dots_num > dots_max ) THEN WRITE( message_string, * ) 'number of time series quantities exceeds', & ' its maximum of dots_max = ', dots_max, & ' &Please increase dots_max in modules.f90.' CALL message( 'init_3d_model', 'PA0194', 1, 2, 0, 6, 0 ) ENDIF ! !-- Input binary data file is not needed anymore. This line must be placed !-- after call of user_init! CALL close_file( 13 ) ! !-- Compute total sum of active mask grid points !-- ngp_2dh: number of grid points of a horizontal cross section through the !-- total domain !-- ngp_3d: number of grid points of the total domain ngp_2dh_outer_l = 0 ngp_2dh_outer = 0 ngp_2dh_s_inner_l = 0 ngp_2dh_s_inner = 0 ngp_2dh_l = 0 ngp_2dh = 0 ngp_3d_inner_l = 0 ngp_3d_inner = 0 ngp_3d = 0 ngp_sums = ( nz + 2 ) * ( pr_palm + max_pr_user ) DO sr = 0, statistic_regions DO i = nxl, nxr DO j = nys, nyn IF ( rmask(j,i,sr) == 1.0 ) THEN ! !-- All xy-grid points ngp_2dh_l(sr) = ngp_2dh_l(sr) + 1 ! !-- xy-grid points above topography DO k = nzb_s_outer(j,i), nz + 1 ngp_2dh_outer_l(k,sr) = ngp_2dh_outer_l(k,sr) + 1 ENDDO DO k = nzb_s_inner(j,i), nz + 1 ngp_2dh_s_inner_l(k,sr) = ngp_2dh_s_inner_l(k,sr) + 1 ENDDO ! !-- All grid points of the total domain above topography ngp_3d_inner_l(sr) = ngp_3d_inner_l(sr) + & ( nz - nzb_s_inner(j,i) + 2 ) ENDIF ENDDO ENDDO ENDDO sr = statistic_regions + 1 #if defined( __parallel ) CALL MPI_ALLREDUCE( ngp_2dh_l(0), ngp_2dh(0), sr, MPI_INTEGER, MPI_SUM, & comm2d, ierr ) CALL MPI_ALLREDUCE( ngp_2dh_outer_l(0,0), ngp_2dh_outer(0,0), (nz+2)*sr, & MPI_INTEGER, MPI_SUM, comm2d, ierr ) CALL MPI_ALLREDUCE( ngp_2dh_s_inner_l(0,0), ngp_2dh_s_inner(0,0), & (nz+2)*sr, MPI_INTEGER, MPI_SUM, comm2d, ierr ) CALL MPI_ALLREDUCE( ngp_3d_inner_l(0), ngp_3d_inner(0), sr, MPI_INTEGER, & MPI_SUM, comm2d, ierr ) #else ngp_2dh = ngp_2dh_l ngp_2dh_outer = ngp_2dh_outer_l ngp_2dh_s_inner = ngp_2dh_s_inner_l ngp_3d_inner = ngp_3d_inner_l #endif ngp_3d = ngp_2dh * ( nz + 2 ) ! !-- Set a lower limit of 1 in order to avoid zero divisions in flow_statistics, !-- buoyancy, etc. A zero value will occur for cases where all grid points of !-- the respective subdomain lie below the surface topography ngp_2dh_outer = MAX( 1, ngp_2dh_outer(:,:) ) ngp_3d_inner = MAX( 1, ngp_3d_inner(:) ) ngp_2dh_s_inner = MAX( 1, ngp_2dh_s_inner(:,:) ) DEALLOCATE( ngp_2dh_l, ngp_2dh_outer_l, ngp_3d_inner_l ) END SUBROUTINE init_3d_model