source: palm/trunk/SOURCE/ls_forcing.f90 @ 1353

Last change on this file since 1353 was 1353, checked in by heinze, 10 years ago

REAL constants provided with KIND-attribute

  • Property svn:keywords set to Id
File size: 11.8 KB
Line 
1 MODULE ls_forcing_mod
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22! REAL constants provided with KIND-attribute
23!
24! Former revisions:
25! -----------------
26! $Id: ls_forcing.f90 1353 2014-04-08 15:21:23Z heinze $
27!
28! 1320 2014-03-20 08:40:49Z raasch
29! ONLY-attribute added to USE-statements,
30! kind-parameters added to all INTEGER and REAL declaration statements,
31! kinds are defined in new module kinds,
32! comment fields (!:) to be used for variable explanations added to
33! all variable declaration statements
34!
35! 1318 2014-03-17 13:35:16Z raasch
36! module interfaces removed
37!
38! 1299 2014-03-06 13:15:21Z heinze
39! Ensure a zero large scale vertical velocity at the surface
40! Bugfix: typo in case of boundary condition in if-clause
41!
42! 1276 2014-01-15 13:40:41Z heinze
43! Use LSF_DATA also in case of Dirichlet bottom boundary condition for scalars
44!
45! 1249 2013-11-06 10:45:47Z heinze
46! remove call of user module
47! reformatting
48!
49! 1241 2013-10-30 11:36:58Z heinze
50! Initial revision
51!
52! Description:
53! ------------
54! Calculates large scale forcings (geostrophic wind and subsidence velocity) as
55! well as surfaces fluxes dependent on time given in an external file (LSF_DATA).
56! Code is based in parts on DALES and UCLA-LES.
57!--------------------------------------------------------------------------------!
58
59    PRIVATE
60    PUBLIC init_ls_forcing, ls_forcing_surf, ls_forcing_vert 
61    SAVE
62
63
64 CONTAINS
65
66    SUBROUTINE init_ls_forcing
67
68       USE arrays_3d,                                                          &
69           ONLY:  p_surf, pt_surf, q_surf, qsws_surf, shf_surf, time_surf,     &
70                  time_vert, ug_vert, vg_vert, wsubs_vert, zu
71
72       USE control_parameters,                                                 &
73           ONLY:  end_time, lsf_surf, lsf_vert, message_string, nlsf
74
75       USE indices,                                                            &
76           ONLY:  nzb, nzt
77
78       USE kinds
79
80
81       IMPLICIT NONE
82
83       CHARACTER(100) ::  chmess              !:
84       CHARACTER(1)   ::  hash                !:
85
86       INTEGER(iwp) ::  ierrn                 !:
87       INTEGER(iwp) ::  finput = 90           !:
88       INTEGER(iwp) ::  k                     !:
89       INTEGER(iwp) ::  t                     !:
90
91       REAL(wp) ::  fac                       !:
92       REAL(wp) ::  highheight                !:
93       REAL(wp) ::  highug_vert               !:
94       REAL(wp) ::  highvg_vert               !:
95       REAL(wp) ::  highwsubs_vert            !:
96       REAL(wp) ::  lowheight                 !:
97       REAL(wp) ::  lowug_vert                !:
98       REAL(wp) ::  lowvg_vert                !:
99       REAL(wp) ::  lowwsubs_vert             !:
100       REAL(wp) ::  r_dummy                   !:
101
102       ALLOCATE( p_surf(0:nlsf), pt_surf(0:nlsf), q_surf(0:nlsf),         &
103                 qsws_surf(0:nlsf), shf_surf(0:nlsf), time_vert(0:nlsf),  &
104                 time_surf(0:nlsf), ug_vert(nzb:nzt+1,0:nlsf),            &
105                 vg_vert(nzb:nzt+1,0:nlsf), wsubs_vert(nzb:nzt+1,0:nlsf) )
106
107       p_surf     = 0.0_wp;  pt_surf  = 0.0_wp;  q_surf    = 0.0_wp
108       qsws_surf  = 0.0_wp;  shf_surf = 0.0_wp;  time_vert = 0.0_wp
109       time_surf  = 0.0_wp;  ug_vert  = 0.0_wp;  vg_vert   = 0.0_wp
110       wsubs_vert = 0.0_wp
111
112
113       OPEN ( finput, FILE='LSF_DATA', STATUS='OLD', &
114              FORM='FORMATTED', IOSTAT=ierrn )
115
116       IF ( ierrn /= 0 )  THEN
117          message_string = 'file LSF_DATA does not exist'
118          CALL message( 'ls_forcing', 'PA0368', 1, 2, 0, 6, 0 )
119       ENDIF
120
121       ierrn = 0
122!
123!--    First three lines of LSF_DATA contain header
124       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
125       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
126       READ ( finput, FMT='(a100)', IOSTAT=ierrn ) chmess
127
128       IF ( ierrn /= 0 )  THEN
129          message_string = 'errors in file LSF_DATA'
130          CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
131       ENDIF
132
133!
134!--    Surface values are read in
135       t     = 0
136       ierrn = 0
137
138       DO WHILE ( time_surf(t) < end_time )
139          t = t + 1
140          READ ( finput, *, IOSTAT = ierrn ) time_surf(t), shf_surf(t), &
141                                             qsws_surf(t), pt_surf(t),  &
142                                             q_surf(t), p_surf(t)
143
144          IF ( ierrn < 0 )  THEN
145            WRITE ( message_string, * ) 'No time dependent surface variables ',&
146                              'in&LSF_DATA for end of run found'
147
148             CALL message( 'ls_forcing', 'PA0370', 1, 2, 0, 6, 0 )
149          ENDIF
150       ENDDO
151
152
153       IF ( time_surf(1) > end_time )  THEN
154          WRITE ( message_string, * ) 'No time dependent surface variables in ',&
155                                     '&LSF_DATA for end of run found - ',  &
156                                     'lsf_surf is set to FALSE'
157          CALL message( 'ls_forcing', 'PA0371', 0, 0, 0, 6, 0 )
158          lsf_surf = .FALSE.
159       ENDIF
160
161!
162!--    Go to the end of the list with surface variables
163       DO WHILE ( ierrn == 0 )
164          READ ( finput, *, IOSTAT = ierrn ) r_dummy
165       ENDDO
166
167!
168!--    Profiles of ug, vg and w_subs are read in (large scale forcing)
169
170       t = 0
171       DO WHILE ( time_vert(t) < end_time )
172          t = t + 1
173          hash = "#"
174          ierrn = 1 ! not zero
175!
176!--       Search for the next line consisting of "# time",
177!--       from there onwards the profiles will be read
178          DO WHILE ( .NOT. ( hash == "#" .AND. ierrn == 0 ) ) 
179             READ ( finput, *, IOSTAT=ierrn ) hash, time_vert(t)
180             IF ( ierrn < 0 )  THEN
181                WRITE( message_string, * ) 'No time dependent vertical profiles',&
182                                 ' in&LSF_DATA for end of run found'
183                CALL message( 'ls_forcing', 'PA0372', 1, 2, 0, 6, 0 )
184             ENDIF
185          ENDDO
186
187          IF ( t == 1 .AND. time_vert(t) > end_time ) EXIT
188
189          READ ( finput, *, IOSTAT=ierrn ) lowheight, lowug_vert, lowvg_vert, &
190                                           lowwsubs_vert
191          IF ( ierrn /= 0 )  THEN
192             message_string = 'errors in file LSF_DATA'
193             CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
194          ENDIF
195
196          READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, highvg_vert, &
197                                           highwsubs_vert
198     
199          IF ( ierrn /= 0 )  THEN
200             message_string = 'errors in file LSF_DATA'
201             CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
202          ENDIF
203
204
205          DO  k = nzb, nzt+1
206             IF ( highheight < zu(k) )  THEN
207                lowheight     = highheight
208                lowug_vert    = highug_vert
209                lowvg_vert    = highvg_vert
210                lowwsubs_vert = highwsubs_vert
211
212                ierrn = 0
213                READ ( finput, *, IOSTAT=ierrn ) highheight, highug_vert, &
214                                                 highvg_vert, highwsubs_vert
215
216                IF ( ierrn /= 0 )  THEN
217                   message_string = 'errors in file LSF_DATA'
218                   CALL message( 'ls_forcing', 'PA0369', 1, 2, 0, 6, 0 )
219                ENDIF
220
221             ENDIF
222
223!
224!--          Interpolation of prescribed profiles in space
225             fac = (highheight-zu(k))/(highheight - lowheight)
226
227             ug_vert(k,t)    = fac*lowug_vert    + (1-fac)*highug_vert
228             vg_vert(k,t)    = fac*lowvg_vert    + (1-fac)*highvg_vert
229             wsubs_vert(k,t) = fac*lowwsubs_vert + (1-fac)*highwsubs_vert
230
231          ENDDO
232
233       ENDDO 
234
235!
236!--    Large scale vertical velocity has to be zero at the surface
237       wsubs_vert(nzb,:) = 0.0_wp
238 
239       IF ( time_vert(1) > end_time )  THEN
240          WRITE ( message_string, * ) 'Time dependent large scale profile ',&
241                             'forcing from&LSF_DATA sets in after end of ' ,&
242                             'simulation - lsf_vert is set to FALSE'
243          CALL message( 'ls_forcing', 'PA0373', 0, 0, 0, 6, 0 )
244          lsf_vert = .FALSE.
245       ENDIF
246
247       CLOSE( finput )
248
249
250    END SUBROUTINE init_ls_forcing 
251
252
253    SUBROUTINE ls_forcing_surf ( time )
254
255       USE arrays_3d,                                                          &
256           ONLY:  p_surf, pt_surf, q_surf, qsws, qsws_surf, shf, shf_surf,     &
257                  time_surf, time_vert, ug, ug_vert, vg, vg_vert
258
259       USE control_parameters,                                                 &
260           ONLY:  bc_q_b, ibc_pt_b, ibc_q_b, pt_surface, q_surface,            &
261                  surface_pressure
262
263       USE kinds
264
265
266       IMPLICIT NONE
267
268       INTEGER(iwp) ::  t                     !:
269
270       REAL(wp)             :: fac            !:
271       REAL(wp), INTENT(in) :: time           !:
272
273!
274!--    Interpolation in time of LSF_DATA at the surface
275       t = 1
276       DO WHILE ( time > time_surf(t) )
277          t = t + 1
278       ENDDO
279       IF ( time /= time_surf(t) )  THEN
280         t = t - 1
281       ENDIF
282
283       fac = ( time -time_surf(t) ) / ( time_surf(t+1) - time_surf(t) )
284
285       IF ( ibc_pt_b == 0 )  THEN
286!
287!--       In case of Dirichlet boundary condition shf must not
288!--       be set - it is calculated via MOST in prandtl_fluxes
289          pt_surface = pt_surf(t) + fac * ( pt_surf(t+1) - pt_surf(t) )
290
291       ELSEIF ( ibc_pt_b == 1 )  THEN
292!
293!--       In case of Neumann boundary condition pt_surface is needed for
294!--       calculation of reference density
295          shf        = shf_surf(t) + fac * ( shf_surf(t+1) - shf_surf(t) )
296          pt_surface = pt_surf(t) + fac * ( pt_surf(t+1) - pt_surf(t) )
297
298       ENDIF
299
300       IF ( ibc_q_b == 0 )  THEN
301!
302!--       In case of Dirichlet boundary condition qsws must not
303!--       be set - it is calculated via MOST in prandtl_fluxes
304          q_surface = q_surf(t) + fac * ( q_surf(t+1) - q_surf(t) )
305
306       ELSEIF ( ibc_q_b == 1 )  THEN
307
308          qsws = qsws_surf(t) + fac * ( qsws_surf(t+1) - qsws_surf(t) )
309
310       ENDIF
311
312       surface_pressure = p_surf(t) + fac * ( p_surf(t+1) - p_surf(t) )
313
314    END SUBROUTINE ls_forcing_surf 
315
316
317    SUBROUTINE ls_forcing_vert ( time )
318
319       USE arrays_3d,                                                          &
320           ONLY:  time_vert, ug, ug_vert, vg, vg_vert, w_subs, wsubs_vert
321
322       USE control_parameters,                                                 &
323           ONLY:  large_scale_subsidence
324
325       USE kinds
326
327
328       IMPLICIT NONE
329
330       INTEGER(iwp) ::  t                     !:
331
332       REAL(wp)             ::  fac           !:
333       REAL(wp), INTENT(in) ::  time          !:
334
335!
336!--    Interpolation in time of LSF_DATA for ug, vg and w_subs
337       t = 1
338       DO WHILE ( time > time_vert(t) )
339          t = t + 1
340       ENDDO
341       IF ( time /= time_vert(t) )  THEN
342         t = t - 1
343       ENDIF
344
345       fac = ( time-time_vert(t) ) / ( time_vert(t+1)-time_vert(t) )
346
347       ug     = ug_vert(:,t) + fac * ( ug_vert(:,t+1) - ug_vert(:,t) )
348       vg     = vg_vert(:,t) + fac * ( vg_vert(:,t+1) - vg_vert(:,t) )
349
350       IF ( large_scale_subsidence )  THEN
351          w_subs = wsubs_vert(:,t) + fac * ( wsubs_vert(:,t+1) - wsubs_vert(:,t) )
352       ENDIF
353
354    END SUBROUTINE ls_forcing_vert
355
356
357 END MODULE ls_forcing_mod
Note: See TracBrowser for help on using the repository browser.