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

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

Last commit documented

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