MODULE buoyancy_mod !--------------------------------------------------------------------------------! ! 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: buoyancy.f90 1354 2014-04-08 15:22:57Z witha $ ! ! 1353 2014-04-08 15:21:23Z heinze ! REAL constants provided with KIND-attribute ! ! 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, ! revision history before 2012 removed, ! comment fields (!:) to be used for variable explanations added to ! all variable declaration statements ! ! 1257 2013-11-08 15:18:40Z raasch ! vector length (32) removed from openacc clause ! ! 1241 2013-10-30 11:36:58Z heinze ! Generalize calc_mean_profile for wider use: use additional steering ! character loc ! ! 1179 2013-06-14 05:57:58Z raasch ! steering of reference state revised (var_reference and pr removed from ! parameter list), use_reference renamed use_single_reference_value ! ! 1171 2013-05-30 11:27:45Z raasch ! openacc statements added to use_reference-case in accelerator version ! ! 1153 2013-05-10 14:33:08Z raasch ! code adjustments of accelerator version required by PGI 12.3 / CUDA 5.0 ! ! 1128 2013-04-12 06:19:32Z raasch ! loop index bounds in accelerator version replaced by i_left, i_right, j_south, ! j_north ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 1015 2012-09-27 09:23:24Z raasch ! accelerator version (*_acc) added ! ! 1010 2012-09-20 07:59:54Z raasch ! cpp switch __nopointer added for pointer free version ! ! Revision 1.1 1997/08/29 08:56:48 raasch ! Initial revision ! ! ! Description: ! ------------ ! Buoyancy term of the third component of the equation of motion. ! WARNING: humidity is not regarded when using a sloping surface! !------------------------------------------------------------------------------! PRIVATE PUBLIC buoyancy, buoyancy_acc, calc_mean_profile INTERFACE buoyancy MODULE PROCEDURE buoyancy MODULE PROCEDURE buoyancy_ij END INTERFACE buoyancy INTERFACE buoyancy_acc MODULE PROCEDURE buoyancy_acc END INTERFACE buoyancy_acc INTERFACE calc_mean_profile MODULE PROCEDURE calc_mean_profile END INTERFACE calc_mean_profile CONTAINS !------------------------------------------------------------------------------! ! Call for all grid points !------------------------------------------------------------------------------! SUBROUTINE buoyancy( var, wind_component ) USE arrays_3d, & ONLY: pt, pt_slope_ref, ref_state, tend USE control_parameters, & ONLY: atmos_ocean_sign, cos_alpha_surface, g, message_string, & pt_surface, sin_alpha_surface, sloping_surface USE indices, & ONLY: nxl, nxlu, nxr, nyn, nys, nzb_s_inner, nzt USE kinds USE pegrid IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: INTEGER(iwp) :: wind_component !: #if defined( __nopointer ) REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var !: #else REAL(wp), DIMENSION(:,:,:), POINTER :: var #endif IF ( .NOT. sloping_surface ) THEN ! !-- Normal case: horizontal surface DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + atmos_ocean_sign * g * 0.5_wp * & ( & ( var(k,j,i) - ref_state(k) ) / ref_state(k) + & ( var(k+1,j,i) - ref_state(k+1) ) / ref_state(k+1) & ) ENDDO ENDDO ENDDO ELSE ! !-- Buoyancy term for a surface with a slope in x-direction. The equations !-- for both the u and w velocity-component contain proportionate terms. !-- Temperature field at time t=0 serves as environmental temperature. !-- Reference temperature (pt_surface) is the one at the lower left corner !-- of the total domain. IF ( wind_component == 1 ) THEN DO i = nxlu, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * sin_alpha_surface * & 0.5_wp * ( ( pt(k,j,i-1) + pt(k,j,i) ) & - ( pt_slope_ref(k,i-1) + pt_slope_ref(k,i) ) & ) / pt_surface ENDDO ENDDO ENDDO ELSEIF ( wind_component == 3 ) THEN DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * cos_alpha_surface * & 0.5_wp * ( ( pt(k,j,i) + pt(k+1,j,i) ) & - ( pt_slope_ref(k,i) + pt_slope_ref(k+1,i) ) & ) / pt_surface ENDDO ENDDO ENDDO ELSE WRITE( message_string, * ) 'no term for component "', & wind_component,'"' CALL message( 'buoyancy', 'PA0159', 1, 2, 0, 6, 0 ) ENDIF ENDIF END SUBROUTINE buoyancy !------------------------------------------------------------------------------! ! Call for all grid points - accelerator version !------------------------------------------------------------------------------! SUBROUTINE buoyancy_acc( var, wind_component ) USE arrays_3d, & ONLY: pt, pt_slope_ref, ref_state, tend USE control_parameters, & ONLY: atmos_ocean_sign, cos_alpha_surface, g, message_string, & pt_surface, sin_alpha_surface, sloping_surface USE indices, & ONLY: i_left, i_right, j_north, j_south, nxl, nxlu, nxr, nyn, nys, & nzb_s_inner, nzt USE kinds USE pegrid IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: INTEGER(iwp) :: wind_component !: #if defined( __nopointer ) REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var !: #else REAL(wp), DIMENSION(:,:,:), POINTER :: var #endif IF ( .NOT. sloping_surface ) THEN ! !-- Normal case: horizontal surface !$acc kernels present( nzb_s_inner, ref_state, tend, var ) !$acc loop DO i = i_left, i_right DO j = j_south, j_north !$acc loop independent vector DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + atmos_ocean_sign * g * 0.5_wp * & ( & ( var(k,j,i) - ref_state(k) ) / ref_state(k) + & ( var(k+1,j,i) - ref_state(k+1) ) / ref_state(k+1) & ) ENDDO ENDDO ENDDO !$acc end kernels ELSE ! !-- Buoyancy term for a surface with a slope in x-direction. The equations !-- for both the u and w velocity-component contain proportionate terms. !-- Temperature field at time t=0 serves as environmental temperature. !-- Reference temperature (pt_surface) is the one at the lower left corner !-- of the total domain. IF ( wind_component == 1 ) THEN DO i = nxlu, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * sin_alpha_surface * & 0.5_wp * ( ( pt(k,j,i-1) + pt(k,j,i) ) & - ( pt_slope_ref(k,i-1) + pt_slope_ref(k,i) ) & ) / pt_surface ENDDO ENDDO ENDDO ELSEIF ( wind_component == 3 ) THEN DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * cos_alpha_surface * & 0.5_wp * ( ( pt(k,j,i) + pt(k+1,j,i) ) & - ( pt_slope_ref(k,i) + pt_slope_ref(k+1,i) ) & ) / pt_surface ENDDO ENDDO ENDDO ELSE WRITE( message_string, * ) 'no term for component "', & wind_component,'"' CALL message( 'buoyancy', 'PA0159', 1, 2, 0, 6, 0 ) ENDIF ENDIF END SUBROUTINE buoyancy_acc !------------------------------------------------------------------------------! ! Call for grid point i,j ! ATTENTION: PGI-compiler creates SIGFPE if opt>1 is used! Therefore, opt=1 is ! forced by compiler-directive. !------------------------------------------------------------------------------! !pgi$r opt=1 SUBROUTINE buoyancy_ij( i, j, var, wind_component ) USE arrays_3d, & ONLY: pt, pt_slope_ref, ref_state, tend USE control_parameters, & ONLY: atmos_ocean_sign, cos_alpha_surface, g, message_string, & pt_surface, sin_alpha_surface, sloping_surface USE indices, & ONLY: nzb_s_inner, nzt USE kinds USE pegrid IMPLICIT NONE INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: INTEGER(iwp) :: pr !: INTEGER(iwp) :: wind_component !: #if defined( __nopointer ) REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: var !: #else REAL(wp), DIMENSION(:,:,:), POINTER :: var #endif IF ( .NOT. sloping_surface ) THEN ! !-- Normal case: horizontal surface DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + atmos_ocean_sign * g * 0.5_wp * ( & ( var(k,j,i) - ref_state(k) ) / ref_state(k) + & ( var(k+1,j,i) - ref_state(k+1) ) / ref_state(k+1) & ) ENDDO ELSE ! !-- Buoyancy term for a surface with a slope in x-direction. The equations !-- for both the u and w velocity-component contain proportionate terms. !-- Temperature field at time t=0 serves as environmental temperature. !-- Reference temperature (pt_surface) is the one at the lower left corner !-- of the total domain. IF ( wind_component == 1 ) THEN DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * sin_alpha_surface * & 0.5_wp * ( ( pt(k,j,i-1) + pt(k,j,i) ) & - ( pt_slope_ref(k,i-1) + pt_slope_ref(k,i) ) & ) / pt_surface ENDDO ELSEIF ( wind_component == 3 ) THEN DO k = nzb_s_inner(j,i)+1, nzt-1 tend(k,j,i) = tend(k,j,i) + g * cos_alpha_surface * & 0.5_wp * ( ( pt(k,j,i) + pt(k+1,j,i) ) & - ( pt_slope_ref(k,i) + pt_slope_ref(k+1,i) ) & ) / pt_surface ENDDO ELSE WRITE( message_string, * ) 'no term for component "', & wind_component,'"' CALL message( 'buoyancy', 'PA0159', 1, 2, 0, 6, 0 ) ENDIF ENDIF END SUBROUTINE buoyancy_ij SUBROUTINE calc_mean_profile( var, pr, loc ) !------------------------------------------------------------------------------! ! Description: ! ------------ ! Calculate the horizontally averaged vertical temperature profile (pr=4 in case ! of potential temperature, 44 in case of virtual potential temperature, and 64 ! in case of density (ocean runs)). !------------------------------------------------------------------------------! USE arrays_3d, & ONLY: ref_state USE control_parameters, & ONLY: intermediate_timestep_count, message_string USE indices, & ONLY: ngp_2dh_s_inner, nxl, nxr, nyn, nys, nzb, nzb_s_inner, nzt USE kinds USE pegrid USE statistics, & ONLY: flow_statistics_called, hom, sums, sums_l IMPLICIT NONE CHARACTER (LEN=*) :: loc !: INTEGER(iwp) :: i !: INTEGER(iwp) :: j !: INTEGER(iwp) :: k !: INTEGER(iwp) :: pr !: INTEGER(iwp) :: omp_get_thread_num !: INTEGER(iwp) :: tn !: #if defined( __nopointer ) REAL(wp), DIMENSION(:,:,:) :: var !: #else REAL(wp), DIMENSION(:,:,:), POINTER :: var #endif ! !-- Computation of the horizontally averaged profile of variable var, unless !-- already done by the relevant call from flow_statistics. The calculation !-- is done only for the first respective intermediate timestep in order to !-- spare communication time and to produce identical model results with jobs !-- which are calling flow_statistics at different time intervals. IF ( .NOT. flow_statistics_called .AND. & intermediate_timestep_count == 1 ) THEN ! !-- Horizontal average of variable var tn = 0 ! Default thread number in case of one thread !$OMP PARALLEL PRIVATE( i, j, k, tn ) !$ tn = omp_get_thread_num() sums_l(:,pr,tn) = 0.0_wp !$OMP DO DO i = nxl, nxr DO j = nys, nyn DO k = nzb_s_inner(j,i), nzt+1 sums_l(k,pr,tn) = sums_l(k,pr,tn) + var(k,j,i) ENDDO ENDDO ENDDO !$OMP END PARALLEL DO i = 1, threads_per_task-1 sums_l(:,pr,0) = sums_l(:,pr,0) + sums_l(:,pr,i) ENDDO #if defined( __parallel ) IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( sums_l(nzb,pr,0), sums(nzb,pr), nzt+2-nzb, & MPI_REAL, MPI_SUM, comm2d, ierr ) #else sums(:,pr) = sums_l(:,pr,0) #endif hom(:,1,pr,0) = sums(:,pr) / ngp_2dh_s_inner(:,0) ENDIF SELECT CASE ( loc ) CASE ( 'time_int' ) ref_state(:) = hom(:,1,pr,0) ! this is used in the buoyancy term CASE ( 'nudging' ) !nothing to be done CASE DEFAULT message_string = 'unknown location "' // loc // '"' CALL message( 'calc_mean_profile', 'PA0379', 1, 2, 0, 6, 0 ) END SELECT END SUBROUTINE calc_mean_profile END MODULE buoyancy_mod