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