[1873] | 1 | !> @file calc_mean_profile.f90 |
---|
[4542] | 2 | !--------------------------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1365] | 4 | ! |
---|
[4542] | 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms of the GNU General |
---|
| 6 | ! Public License as published by the Free Software Foundation, either version 3 of the License, or |
---|
| 7 | ! (at your option) any later version. |
---|
[1365] | 8 | ! |
---|
[4542] | 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the |
---|
| 10 | ! implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
---|
| 11 | ! Public License for more details. |
---|
[1365] | 12 | ! |
---|
[4542] | 13 | ! You should have received a copy of the GNU General Public License along with PALM. If not, see |
---|
| 14 | ! <http://www.gnu.org/licenses/>. |
---|
[1365] | 15 | ! |
---|
[4542] | 16 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[4542] | 18 | !--------------------------------------------------------------------------------------------------! |
---|
[1365] | 19 | ! |
---|
| 20 | ! Current revisions: |
---|
| 21 | ! ----------------- |
---|
[4743] | 22 | ! Bugfix for last commit |
---|
[4741] | 23 | ! |
---|
[1365] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: calc_mean_profile.f90 4743 2020-10-14 16:40:58Z pavelkrc $ |
---|
[4741] | 27 | ! Add option to force calculation of horizontal mean profiles independent on data output |
---|
| 28 | ! |
---|
| 29 | ! 4542 2020-05-19 15:45:12Z raasch |
---|
[4542] | 30 | ! file re-formatted to follow the PALM coding standard |
---|
| 31 | ! |
---|
| 32 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4346] | 33 | ! Introduction of wall_flags_total_0, which currently sets bits based on static |
---|
| 34 | ! topography information used in wall_flags_static_0 |
---|
[4542] | 35 | ! |
---|
[4346] | 36 | ! 4329 2019-12-10 15:46:36Z motisi |
---|
[4329] | 37 | ! Renamed wall_flags_0 to wall_flags_static_0 |
---|
[4542] | 38 | ! |
---|
[4329] | 39 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
[4182] | 40 | ! Corrected "Former revisions" section |
---|
[4542] | 41 | ! |
---|
[4182] | 42 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3636] | 43 | ! nopointer option removed |
---|
[4542] | 44 | ! |
---|
[4182] | 45 | ! 1365 2014-04-22 15:03:56Z boeske |
---|
| 46 | ! Initial revision |
---|
[1365] | 47 | ! |
---|
| 48 | ! Description: |
---|
| 49 | ! ------------ |
---|
[1682] | 50 | !> Calculate the horizontally averaged vertical temperature profile (pr=4 in case |
---|
| 51 | !> of potential temperature, 44 in case of virtual potential temperature, and 64 |
---|
| 52 | !> in case of density (ocean runs)). |
---|
[1365] | 53 | !------------------------------------------------------------------------------! |
---|
[1682] | 54 | MODULE calc_mean_profile_mod |
---|
[1365] | 55 | |
---|
[4542] | 56 | |
---|
[1365] | 57 | PRIVATE |
---|
| 58 | PUBLIC calc_mean_profile |
---|
| 59 | |
---|
| 60 | INTERFACE calc_mean_profile |
---|
| 61 | MODULE PROCEDURE calc_mean_profile |
---|
| 62 | END INTERFACE calc_mean_profile |
---|
| 63 | |
---|
| 64 | CONTAINS |
---|
| 65 | |
---|
[4542] | 66 | !--------------------------------------------------------------------------------------------------! |
---|
[1682] | 67 | ! Description: |
---|
| 68 | ! ------------ |
---|
| 69 | !> @todo Missing subroutine description. |
---|
[4542] | 70 | !--------------------------------------------------------------------------------------------------! |
---|
[4741] | 71 | SUBROUTINE calc_mean_profile( var, pr, force_calc ) |
---|
[1365] | 72 | |
---|
[4542] | 73 | USE control_parameters, & |
---|
[3241] | 74 | ONLY: intermediate_timestep_count |
---|
[1365] | 75 | |
---|
[4542] | 76 | USE indices, & |
---|
| 77 | ONLY: ngp_2dh_s_inner, nxl, nxr, nyn, nys, nzb, nzb, nzt, wall_flags_total_0 |
---|
[1365] | 78 | |
---|
| 79 | USE kinds |
---|
| 80 | |
---|
| 81 | USE pegrid |
---|
| 82 | |
---|
[4542] | 83 | USE statistics, & |
---|
[1365] | 84 | ONLY: flow_statistics_called, hom, sums, sums_l |
---|
| 85 | |
---|
| 86 | |
---|
| 87 | IMPLICIT NONE |
---|
[4542] | 88 | |
---|
[4741] | 89 | LOGICAL, OPTIONAL :: force_calc !< passed flag used to force calculation of mean profiles independend on data output |
---|
| 90 | LOGICAL :: force_calc_l = .FALSE. !< control flag |
---|
| 91 | |
---|
[1682] | 92 | INTEGER(iwp) :: i !< |
---|
| 93 | INTEGER(iwp) :: j !< |
---|
| 94 | INTEGER(iwp) :: k !< |
---|
[4542] | 95 | INTEGER(iwp) :: pr !< |
---|
[3241] | 96 | !$ INTEGER(iwp) :: omp_get_thread_num !< |
---|
[1682] | 97 | INTEGER(iwp) :: tn !< |
---|
[4542] | 98 | |
---|
[1365] | 99 | REAL(wp), DIMENSION(:,:,:), POINTER :: var |
---|
| 100 | |
---|
| 101 | ! |
---|
[4542] | 102 | !-- Computation of the horizontally averaged profile of variable var, unless already done by the |
---|
| 103 | !-- relevant call from flow_statistics. The calculation is done only for the first respective |
---|
| 104 | !-- intermediate timestep in order to spare communication time and to produce identical model |
---|
| 105 | !-- results with jobs which are calling flow_statistics at different time intervals. At |
---|
[2696] | 106 | !-- initialization, intermediate_timestep_count = 0 is considered as well. |
---|
[4741] | 107 | !-- Note, calc_mean_profile is also called from the radiation. Especially during the spinup when |
---|
| 108 | !-- no data output is called, the values in hom do not necessarily reflect horizontal mean. |
---|
| 109 | !-- The same is also for nested simulations during the spinup, where hom is initialized on a |
---|
| 110 | !-- ealier point in time than the initialization via the parent domain takes place, meaning |
---|
| 111 | !-- that hom does not necessarily reflect the horizontal mean during the spinup, too. |
---|
| 112 | !-- In order to force the computation of horizontal mean profiles independent on data output, |
---|
| 113 | !-- i.e. independent on flow_statistics, add a special control flag. |
---|
| 114 | IF ( PRESENT( force_calc ) ) THEN |
---|
[4743] | 115 | force_calc_l = force_calc |
---|
| 116 | ELSE |
---|
| 117 | force_calc_l = .FALSE. |
---|
[4741] | 118 | ENDIF |
---|
[2696] | 119 | |
---|
[4741] | 120 | IF ( ( .NOT. flow_statistics_called .AND. intermediate_timestep_count <= 1 ) .OR. & |
---|
| 121 | force_calc_l ) THEN |
---|
[1365] | 122 | |
---|
| 123 | ! |
---|
| 124 | !-- Horizontal average of variable var |
---|
| 125 | tn = 0 ! Default thread number in case of one thread |
---|
| 126 | !$OMP PARALLEL PRIVATE( i, j, k, tn ) |
---|
| 127 | !$ tn = omp_get_thread_num() |
---|
| 128 | sums_l(:,pr,tn) = 0.0_wp |
---|
| 129 | !$OMP DO |
---|
| 130 | DO i = nxl, nxr |
---|
| 131 | DO j = nys, nyn |
---|
[2232] | 132 | DO k = nzb, nzt+1 |
---|
[4542] | 133 | sums_l(k,pr,tn) = sums_l(k,pr,tn) + var(k,j,i) * MERGE( 1.0_wp, 0.0_wp, & |
---|
| 134 | BTEST( wall_flags_total_0(k,j,i), 22 ) ) |
---|
[1365] | 135 | ENDDO |
---|
| 136 | ENDDO |
---|
| 137 | ENDDO |
---|
| 138 | !$OMP END PARALLEL |
---|
| 139 | |
---|
| 140 | DO i = 1, threads_per_task-1 |
---|
| 141 | sums_l(:,pr,0) = sums_l(:,pr,0) + sums_l(:,pr,i) |
---|
| 142 | ENDDO |
---|
| 143 | |
---|
| 144 | #if defined( __parallel ) |
---|
| 145 | |
---|
| 146 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[4542] | 147 | CALL MPI_ALLREDUCE( sums_l(nzb,pr,0), sums(nzb,pr), nzt+2-nzb, MPI_REAL, MPI_SUM, comm2d,& |
---|
| 148 | ierr ) |
---|
[1365] | 149 | |
---|
| 150 | #else |
---|
| 151 | |
---|
| 152 | sums(:,pr) = sums_l(:,pr,0) |
---|
| 153 | |
---|
| 154 | #endif |
---|
| 155 | |
---|
[1738] | 156 | DO k = nzb, nzt+1 |
---|
| 157 | IF ( ngp_2dh_s_inner(k,0) /= 0 ) THEN |
---|
| 158 | hom(k,1,pr,0) = sums(k,pr) / ngp_2dh_s_inner(k,0) |
---|
| 159 | ENDIF |
---|
| 160 | ENDDO |
---|
[1365] | 161 | |
---|
| 162 | ENDIF |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | END SUBROUTINE calc_mean_profile |
---|
| 166 | |
---|
[1738] | 167 | END MODULE calc_mean_profile_mod |
---|