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

Last change on this file since 2298 was 2298, checked in by raasch, 4 years ago

write_binary is of type LOGICAL now, MPI2-related code removed, obsolete variables removed, sendrecv_in_background related parts removed, missing variable descriptions added

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