source: palm/trunk/SOURCE/palm.f90 @ 2501

Last change on this file since 2501 was 2320, checked in by suehring, 7 years ago

large-scale forcing and nudging modularized

  • Property svn:keywords set to Id
File size: 15.7 KB
Line 
1!> @file palm.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
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: palm.f90 2320 2017-07-21 12:47:43Z raasch $
27! Modularize large-scale forcing and nudging
28!
29! 2298 2017-06-29 09:28:18Z raasch
30! type of write_binary changed from CHARACTER to LOGICAL,
31! user interface required revision updated, MPI2 related part removed
32!
33! 2296 2017-06-28 07:53:56Z maronga
34! Added call to new spinup routine
35!
36! 2292 2017-06-20 09:51:42Z schwenkel
37! Implementation of new microphysic scheme: cloud_scheme = 'morrison'
38! includes two more prognostic equations for cloud drop concentration (nc) 
39! and cloud water content (qc).
40!
41! 2261 2017-06-08 14:25:57Z raasch
42! output of run number for mrun to create unified cycle numbers
43!
44! 2233 2017-05-30 18:08:54Z suehring
45!
46! 2232 2017-05-30 17:47:52Z suehring
47! Renamed wall_flags_0 and wall_flags_00 into advc_flags_1 and advc_flags_2,
48! respectively, within copyin statement. Moreover, introduced further flag
49! array wall_flags_0.
50! Remove unused variables from ONLY list.
51!
52! 2178 2017-03-17 11:07:39Z hellstea
53! Calls for pmci_ensure_nest_mass_conservation and pres are added after
54! the nest initialization
55!
56! 2118 2017-01-17 16:38:49Z raasch
57! OpenACC directives and related code removed
58!
59! 2011 2016-09-19 17:29:57Z kanani
60! Flag urban_surface is now defined in module control_parameters.
61!
62! 2007 2016-08-24 15:47:17Z kanani
63! Temporarily added CALL for writing of restart data for urban surface model
64!
65! 2000 2016-08-20 18:09:15Z knoop
66! Forced header and separation lines into 80 columns
67!
68! 1976 2016-07-27 13:28:04Z maronga
69! Added call to radiation_last_actions for binary output of land surface model
70! data
71!
72! 1972 2016-07-26 07:52:02Z maronga
73! Added call to lsm_last_actions for binary output of land surface model data
74!
75! 1960 2016-07-12 16:34:24Z suehring
76! Separate humidity and passive scalar
77!
78! 1834 2016-04-07 14:34:20Z raasch
79! Initial version of purely vertical nesting introduced.
80!
81! 1833 2016-04-07 14:23:03Z raasch
82! required user interface version changed
83!
84! 1808 2016-04-05 19:44:00Z raasch
85! routine local_flush replaced by FORTRAN statement
86!
87! 1783 2016-03-06 18:36:17Z raasch
88! required user interface version changed
89!
90! 1781 2016-03-03 15:12:23Z raasch
91! pmc initialization moved from time_integration to here
92!
93! 1779 2016-03-03 08:01:28Z raasch
94! setting of nest_domain and coupling_char moved to the pmci
95!
96! 1764 2016-02-28 12:45:19Z raasch
97! cpp-statements for nesting removed, communicator settings cleaned up
98!
99! 1762 2016-02-25 12:31:13Z hellstea
100! Introduction of nested domain feature
101!
102! 1747 2016-02-08 12:25:53Z raasch
103! OpenACC-adjustment for new surface layer parameterization
104!
105! 1682 2015-10-07 23:56:08Z knoop
106! Code annotations made doxygen readable
107!
108! 1668 2015-09-23 13:45:36Z raasch
109! warning replaced by abort in case of failed user interface check
110!
111! 1666 2015-09-23 07:31:10Z raasch
112! check for user's interface version added
113!
114! 1482 2014-10-18 12:34:45Z raasch
115! adjustments for using CUDA-aware OpenMPI
116!
117! 1468 2014-09-24 14:06:57Z maronga
118! Adapted for use on up to 6-digit processor cores
119!
120! 1402 2014-05-09 14:25:13Z raasch
121! location messages added
122!
123! 1374 2014-04-25 12:55:07Z raasch
124! bugfix: various modules added
125!
126! 1320 2014-03-20 08:40:49Z raasch
127! ONLY-attribute added to USE-statements,
128! kind-parameters added to all INTEGER and REAL declaration statements,
129! kinds are defined in new module kinds,
130! old module precision_kind is removed,
131! revision history before 2012 removed,
132! comment fields (!:) to be used for variable explanations added to
133! all variable declaration statements
134!
135! 1318 2014-03-17 13:35:16Z raasch
136! module interfaces removed
137!
138! 1241 2013-10-30 11:36:58Z heinze
139! initialization of nuding and large scale forcing from external file
140!
141! 1221 2013-09-10 08:59:13Z raasch
142! +wall_flags_00, rflags_invers, rflags_s_inner in copyin statement
143!
144! 1212 2013-08-15 08:46:27Z raasch
145! +tri in copyin statement
146!
147! 1179 2013-06-14 05:57:58Z raasch
148! ref_state added to copyin-list
149!
150! 1113 2013-03-10 02:48:14Z raasch
151! openACC statements modified
152!
153! 1111 2013-03-08 23:54:10Z raasch
154! openACC statements updated
155!
156! 1092 2013-02-02 11:24:22Z raasch
157! unused variables removed
158!
159! 1036 2012-10-22 13:43:42Z raasch
160! code put under GPL (PALM 3.9)
161!
162! 1015 2012-09-27 09:23:24Z raasch
163! Version number changed from 3.8 to 3.8a.
164! OpenACC statements added + code changes required for GPU optimization
165!
166! 849 2012-03-15 10:35:09Z raasch
167! write_particles renamed lpm_write_restart_file
168!
169! Revision 1.1  1997/07/24 11:23:35  raasch
170! Initial revision
171!
172!
173! Description:
174! ------------
175!> Large-Eddy Simulation (LES) model for the convective boundary layer,
176!> optimized for use on parallel machines (implementation realized using the
177!> Message Passing Interface (MPI)). The model can also be run on vector machines
178!> (less well optimized) and workstations. Versions for the different types of
179!> machines are controlled via cpp-directives.
180!> Model runs are only feasible using the ksh-script mrun.
181!>
182!> @todo create routine last_actions instead of calling lsm_last_actions etc.
183!> @todo eventually move CALL usm_write_restart_data to suitable location
184!------------------------------------------------------------------------------!
185 PROGRAM palm
186 
187
188    USE arrays_3d
189
190    USE control_parameters,                                                    &
191        ONLY:  cloud_physics, constant_diffusion, coupling_char, coupling_mode,&
192               do2d_at_begin, do3d_at_begin, humidity, initializing_actions,   &
193               io_blocks, io_group, land_surface, large_scale_forcing,         &
194               message_string, microphysics_morrison, microphysics_seifert,    &
195               nest_domain, neutral, nudging, passive_scalar, runnr,           &
196               simulated_time, simulated_time_chr, spinup, urban_surface,      &
197               user_interface_current_revision,                                &
198               user_interface_required_revision, version, wall_heatflux,       &
199               write_binary
200
201    USE cpulog,                                                                &
202        ONLY:  cpu_log, log_point, cpu_statistics
203
204    USE indices,                                                               &
205        ONLY:  nbgp
206
207    USE kinds
208
209    USE land_surface_model_mod,                                                &
210        ONLY:  lsm_last_actions
211
212    USE particle_attributes,                                                   &
213        ONLY:  particle_advection
214
215    USE pegrid
216
217    USE pmc_interface,                                                         &
218        ONLY:  cpl_id, nested_run, pmci_child_initialize, pmci_init,           &
219               pmci_modelconfiguration, pmci_parent_initialize,                &
220               pmci_ensure_nest_mass_conservation
221
222    USE radiation_model_mod,                                                   &
223        ONLY:  radiation, radiation_last_actions
224       
225    USE urban_surface_mod,                                                     &
226        ONLY:  usm_write_restart_data       
227
228    IMPLICIT NONE
229
230!
231!-- Local variables
232    CHARACTER(LEN=9)  ::  time_to_string  !<
233    CHARACTER(LEN=10) ::  env_string      !< to store string of environment var
234    INTEGER(iwp)      ::  env_stat        !< to hold status of GET_ENV
235    INTEGER(iwp)      ::  i               !<
236    INTEGER(iwp)      ::  myid_openmpi    !< OpenMPI local rank for CUDA aware MPI
237
238    version = 'PALM 4.0'
239    user_interface_required_revision = 'r2297'
240
241#if defined( __parallel )
242!
243!-- MPI initialisation. comm2d is preliminary set, because
244!-- it will be defined in init_pegrid but is used before in cpu_log.
245    CALL MPI_INIT( ierr )
246
247!
248!-- Initialize the coupling for nested-domain runs
249!-- comm_palm is the communicator which includes all PEs (MPI processes)
250!-- available for this (nested) model. If it is not a nested run, comm_palm
251!-- is returned as MPI_COMM_WORLD
252    CALL pmci_init( comm_palm )
253    comm2d = comm_palm
254!
255!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
256!-- of a further communicator splitting in init_coupling, these numbers will
257!-- be changed in init_pegrid).
258    IF ( nested_run )  THEN
259
260       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
261       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
262
263    ELSE
264
265       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
266       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
267!
268!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
269!--    will be splitted in init_coupling)
270       CALL init_coupling
271    ENDIF
272#endif
273
274!
275!-- Initialize measuring of the CPU-time remaining to the run
276    CALL local_tremain_ini
277
278!
279!-- Start of total CPU time measuring.
280    CALL cpu_log( log_point(1), 'total', 'start' )
281    CALL cpu_log( log_point(2), 'initialisation', 'start' )
282
283!
284!-- Open a file for debug output
285    WRITE (myid_char,'(''_'',I6.6)')  myid
286    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
287
288!
289!-- Initialize dvrp logging. Also, one PE maybe split from the global
290!-- communicator for doing the dvrp output. In that case, the number of
291!-- PEs available for PALM is reduced by one and communicator comm_palm
292!-- is changed respectively.
293#if defined( __parallel )
294    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
295!
296!-- TEST OUTPUT (TO BE REMOVED)
297    WRITE(9,*) '*** coupling_mode = "', TRIM( coupling_mode ), '"'
298    FLUSH( 9 )
299    IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
300       PRINT*, '*** PE', myid, ' Global target PE:', target_id, &
301               TRIM( coupling_mode )
302    ENDIF
303#endif
304
305    CALL init_dvrp_logging
306
307!
308!-- Read control parameters from NAMELIST files and read environment-variables
309    CALL parin
310
311!
312!-- Check for the user's interface version
313    IF ( user_interface_current_revision /= user_interface_required_revision )  &
314    THEN
315       message_string = 'current user-interface revision "' //                  &
316                        TRIM( user_interface_current_revision ) // '" does ' // &
317                        'not match the required revision ' //                   &
318                        TRIM( user_interface_required_revision )
319        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
320    ENDIF
321
322!
323!-- Determine processor topology and local array indices
324    CALL init_pegrid
325
326!
327!-- Generate grid parameters
328    CALL init_grid
329
330!
331!-- Check control parameters and deduce further quantities
332    CALL check_parameters
333
334!
335!-- Initialize all necessary variables
336    CALL init_3d_model
337
338!
339!-- Coupling protocol setup for nested-domain runs
340    IF ( nested_run )  THEN
341       CALL pmci_modelconfiguration
342!
343!--    Receive and interpolate initial data on children.
344!--    Child initialization must be made first if the model is both child and
345!--    parent if necessary
346       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
347          CALL pmci_child_initialize
348!
349!--       Send initial condition data from parent to children
350          CALL pmci_parent_initialize
351!
352!--    Exchange_horiz is needed after the nest initialization
353          IF ( nest_domain )  THEN
354             CALL exchange_horiz( u, nbgp )
355             CALL exchange_horiz( v, nbgp )
356             CALL exchange_horiz( w, nbgp )
357             IF ( .NOT. neutral )  THEN
358                CALL exchange_horiz( pt, nbgp )
359             ENDIF
360             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
361             IF ( humidity )  THEN
362                CALL exchange_horiz( q, nbgp )
363                IF ( cloud_physics  .AND.  microphysics_morrison )  THEN
364                  CALL exchange_horiz( qc, nbgp )
365                  CALL exchange_horiz( nc, nbgp )
366                ENDIF
367                IF ( cloud_physics  .AND.  microphysics_seifert )  THEN
368                   CALL exchange_horiz( qr, nbgp ) 
369                   CALL exchange_horiz( nr, nbgp )
370                ENDIF
371             ENDIF
372             IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
373
374             CALL pmci_ensure_nest_mass_conservation
375             CALL pres
376          ENDIF
377       ENDIF
378
379    ENDIF
380
381!
382!-- Output of program header
383    IF ( myid == 0 )  CALL header
384
385    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
386
387!
388!-- Integration of the non-atmospheric equations (land surface model, urban
389!-- surface model)
390    IF ( spinup )  THEN
391       CALL time_integration_spinup
392    ENDIF
393
394!
395!-- Set start time in format hh:mm:ss
396    simulated_time_chr = time_to_string( simulated_time )
397
398!
399!-- If required, output of initial arrays
400    IF ( do2d_at_begin )  THEN
401       CALL data_output_2d( 'xy', 0 )
402       CALL data_output_2d( 'xz', 0 )
403       CALL data_output_2d( 'yz', 0 )
404    ENDIF
405
406    IF ( do3d_at_begin )  THEN
407       CALL data_output_3d( 0 )
408    ENDIF
409
410!
411!-- Integration of the model equations using timestep-scheme
412    CALL time_integration
413
414!
415!-- If required, write binary data for restart runs
416    IF ( write_binary )  THEN
417
418       CALL cpu_log( log_point(22), 'write_3d_binary', 'start' )
419
420       CALL location_message( 'writing restart data', .FALSE. )
421
422       CALL check_open( 14 )
423
424       DO  i = 0, io_blocks-1
425          IF ( i == io_group )  THEN
426!
427!--          Write flow field data
428             CALL write_3d_binary
429          ENDIF
430#if defined( __parallel )
431          CALL MPI_BARRIER( comm2d, ierr )
432#endif
433       ENDDO
434
435       CALL location_message( 'finished', .TRUE. )
436
437       CALL cpu_log( log_point(22), 'write_3d_binary', 'stop' )
438
439!
440!--    If required, write particle data
441       IF ( particle_advection )  CALL lpm_write_restart_file
442!
443!--    If required, write urban surface data
444       IF (urban_surface)  CALL usm_write_restart_data
445       
446    ENDIF
447
448!
449!-- If required, repeat output of header including the required CPU-time
450    IF ( myid == 0 )  CALL header
451!
452!-- If required, final land surface and user-defined actions, and
453!-- last actions on the open files and close files. Unit 14 was opened
454!-- in write_3d_binary but it is closed here, to allow writing on this
455!-- unit in routine user_last_actions.
456    CALL cpu_log( log_point(4), 'last actions', 'start' )
457    DO  i = 0, io_blocks-1
458       IF ( i == io_group )  THEN
459          IF ( land_surface )  THEN
460             CALL lsm_last_actions
461          ENDIF
462          IF ( radiation )  THEN
463             CALL radiation_last_actions
464          ENDIF
465          CALL user_last_actions
466          IF ( write_binary )  CALL close_file( 14 )
467       ENDIF
468#if defined( __parallel )
469       CALL MPI_BARRIER( comm2d, ierr )
470#endif
471    ENDDO
472    CALL close_file( 0 )
473    CALL close_dvrp
474    CALL cpu_log( log_point(4), 'last actions', 'stop' )
475
476!
477!-- Write run number to file (used by mrun to create unified cycle numbers for
478!-- output files
479    IF ( myid == 0  .AND.  runnr > 0 )  THEN
480       OPEN( 90, FILE='RUN_NUMBER', FORM='FORMATTED' )
481       WRITE( 90, '(I4)' )  runnr
482       CLOSE( 90 )
483    ENDIF
484
485!
486!-- Take final CPU-time for CPU-time analysis
487    CALL cpu_log( log_point(1), 'total', 'stop' )
488    CALL cpu_statistics
489
490#if defined( __parallel )
491    CALL MPI_FINALIZE( ierr )
492#endif
493
494 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.