source: palm/trunk/SOURCE/calc_mean_profile.f90 @ 2696

Last change on this file since 2696 was 2696, checked in by kanani, 3 years ago

Merge of branch palm4u into trunk

  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1!> @file calc_mean_profile.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2017 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: calc_mean_profile.f90 2696 2017-12-14 17:12:51Z kanani $
27! Enable usage also during initialization, required for initialization of
28! radiation and land-surface model (MS)
29!
30! 2233 2017-05-30 18:08:54Z suehring
31!
32! 2232 2017-05-30 17:47:52Z suehring
33! Adjustments to new topography concept
34!
35! 2000 2016-08-20 18:09:15Z knoop
36! Forced header and separation lines into 80 columns
37!
38! 1873 2016-04-18 14:50:06Z maronga
39! Module renamed (removed _mod)
40!
41!
42! 1850 2016-04-08 13:29:27Z maronga
43! Module renamed
44!
45!
46! 1738 2015-12-18 13:56:05Z raasch
47! bugfix: if a layer is completely filled with topography, no mean is calculated
48!
49! 1682 2015-10-07 23:56:08Z knoop
50! Code annotations made doxygen readable
51!
52! 1365 2014-04-22 15:03:56Z boeske
53! Initial revision
54!
55! Description:
56! ------------
57!> Calculate the horizontally averaged vertical temperature profile (pr=4 in case
58!> of potential temperature, 44 in case of virtual potential temperature, and 64
59!> in case of density (ocean runs)).
60!------------------------------------------------------------------------------!
61 MODULE calc_mean_profile_mod
62 
63
64    PRIVATE
65    PUBLIC calc_mean_profile
66
67    INTERFACE calc_mean_profile
68       MODULE PROCEDURE calc_mean_profile
69    END INTERFACE calc_mean_profile
70
71 CONTAINS
72
73!------------------------------------------------------------------------------!
74! Description:
75! ------------
76!> @todo Missing subroutine description.
77!------------------------------------------------------------------------------!
78    SUBROUTINE calc_mean_profile( var, pr )
79
80       USE control_parameters,                                                 &
81           ONLY:  intermediate_timestep_count, message_string
82
83       USE indices,                                                            &
84           ONLY:  ngp_2dh_s_inner, nxl, nxr, nyn, nys, nzb, nzb, nzt,          &
85                  wall_flags_0
86
87       USE kinds
88
89       USE pegrid
90
91       USE statistics,                                                         &
92           ONLY:  flow_statistics_called, hom, sums, sums_l
93
94
95       IMPLICIT NONE
96       
97       INTEGER(iwp) ::  i                  !<
98       INTEGER(iwp) ::  j                  !<
99       INTEGER(iwp) ::  k                  !<
100       INTEGER(iwp) ::  pr                 !<
101       INTEGER(iwp) ::  omp_get_thread_num !<
102       INTEGER(iwp) ::  tn                 !<
103       
104#if defined( __nopointer )
105       REAL(wp), DIMENSION(:,:,:) ::  var  !<
106#else
107       REAL(wp), DIMENSION(:,:,:), POINTER ::  var
108#endif
109
110!
111!--    Computation of the horizontally averaged profile of variable var, unless
112!--    already done by the relevant call from flow_statistics. The calculation
113!--    is done only for the first respective intermediate timestep in order to
114!--    spare communication time and to produce identical model results with jobs
115!--    which are calling flow_statistics at different time intervals. At
116!--    initialization, intermediate_timestep_count = 0 is considered as well.
117
118       IF ( .NOT. flow_statistics_called  .AND.                                &
119            intermediate_timestep_count <= 1 )  THEN
120
121!
122!--       Horizontal average of variable var
123          tn           =   0  ! Default thread number in case of one thread
124          !$OMP PARALLEL PRIVATE( i, j, k, tn )
125!$        tn = omp_get_thread_num()
126          sums_l(:,pr,tn) = 0.0_wp
127          !$OMP DO
128          DO  i = nxl, nxr
129             DO  j =  nys, nyn
130                DO  k = nzb, nzt+1
131                   sums_l(k,pr,tn) = sums_l(k,pr,tn) + var(k,j,i)              &
132                                     * MERGE( 1.0_wp, 0.0_wp,                  &
133                                              BTEST( wall_flags_0(k,j,i), 22 ) )
134                ENDDO
135             ENDDO
136          ENDDO
137          !$OMP END PARALLEL
138
139          DO  i = 1, threads_per_task-1
140             sums_l(:,pr,0) = sums_l(:,pr,0) + sums_l(:,pr,i)
141          ENDDO
142
143#if defined( __parallel )
144
145          IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
146          CALL MPI_ALLREDUCE( sums_l(nzb,pr,0), sums(nzb,pr), nzt+2-nzb,       &
147                              MPI_REAL, MPI_SUM, comm2d, ierr )
148
149#else
150
151          sums(:,pr) = sums_l(:,pr,0)
152
153#endif
154
155          DO  k = nzb, nzt+1
156             IF ( ngp_2dh_s_inner(k,0) /= 0 )  THEN
157                hom(k,1,pr,0) = sums(k,pr) / ngp_2dh_s_inner(k,0)
158             ENDIF
159          ENDDO
160
161       ENDIF
162
163
164    END SUBROUTINE calc_mean_profile
165
166 END MODULE calc_mean_profile_mod
Note: See TracBrowser for help on using the repository browser.