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

Last change on this file since 1319 was 1319, checked in by raasch, 10 years ago

last commit documented

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