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

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

bugfix for restart data format query

  • Property svn:keywords set to Id
File size: 16.2 KB
Line 
1! !> @file palm.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4535 2020-05-15 12:07:23Z raasch $
27! bugfix for restart data format query
28!
29! 4496 2020-04-15 08:37:26Z raasch
30! bugfix: coupling character added to restart output filename
31!
32! 4495 2020-04-13 20:11:20Z raasch
33! restart data handling with MPI-IO added
34!
35! 4457 2020-03-11 14:20:43Z raasch
36! use statement for exchange horiz added
37!
38! 4444 2020-03-05 15:59:50Z raasch
39! bugfix: cpp-directives for serial mode added
40!
41! 4414 2020-02-19 20:16:04Z suehring
42! Call to module_interface_init_numerics
43!
44! 4400 2020-02-10 20:32:41Z suehring
45! Add interface to initialize data output with dom
46!
47! 4360 2020-01-07 11:25:50Z suehring
48! implement new palm_date_time_mod
49!
50! 4094 2019-07-12 09:24:21Z gronemeier
51! Corrected "Former revisions" section
52!
53! 4039 2019-06-18 10:32:41Z suehring
54! Rename subroutines in module for diagnostic quantities
55!
56! 4017 2019-06-06 12:16:46Z schwenkel
57! new module for calculation and output of diagnostic quantities added
58!
59! 3885 2019-04-11 11:29:34Z kanani
60! Changes related to global restructuring of location messages and introduction
61! of additional debug messages
62!
63! 3761 2019-02-25 15:31:42Z raasch
64! unused variable removed
65!
66! 3719 2019-02-06 13:10:18Z kanani
67! Included cpu measurement for wall/soil spinup
68!
69! 3703 2019-01-29 16:43:53Z knoop
70! Some interface calls moved to module_interface + cleanup
71!
72! 3648 2019-01-02 16:35:46Z suehring
73! Rename subroutines for surface-data output
74!
75! Revision 1.1  1997/07/24 11:23:35  raasch
76! Initial revision
77!
78!
79! Description:
80! ------------
81!> Large-Eddy Simulation (LES) model for atmospheric and oceanic boundary-layer
82!> flows
83!> see the PALM homepage https://palm-model.org for further information
84!------------------------------------------------------------------------------!
85 PROGRAM palm
86 
87
88    USE arrays_3d
89
90#if defined( __parallel )
91    USE bulk_cloud_model_mod,                                                  &
92        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
93#endif
94
95    USE control_parameters,                                                    &
96        ONLY:  coupling_char, do2d_at_begin, do3d_at_begin, io_blocks,         &
97               io_group, message_string, restart_data_format_output, runnr, simulated_time_chr, spinup,   &
98               time_since_reference_point, user_interface_current_revision,    &
99               user_interface_required_revision, version, write_binary
100
101#if defined( __parallel )
102    USE control_parameters,                                                    &
103        ONLY:  child_domain, constant_diffusion, humidity,                     &
104               initializing_actions, neutral, passive_scalar
105#endif
106
107    USE cpulog,                                                                &
108        ONLY:  cpu_log, log_point, cpu_statistics
109
110#if defined( __parallel )
111    USE cpulog,                                                                &
112        ONLY:  log_point_s
113#endif
114
115    USE diagnostic_output_quantities_mod,                                      &
116        ONLY:  doq_calculate
117
118#if defined( __parallel )
119    USE exchange_horiz_mod,                                                    &
120        ONLY:  exchange_horiz
121
122    USE indices,                                                               &
123        ONLY:  nbgp
124#endif
125
126    USE kinds
127
128    USE module_interface,                                                      &
129        ONLY:  module_interface_init_numerics,                                 &
130               module_interface_init_output,                                   &
131               module_interface_last_actions
132
133
134    USE multi_agent_system_mod,                                                &
135        ONLY:  agents_active, mas_last_actions
136
137    USE netcdf_data_input_mod,                                                 &
138        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
139               netcdf_data_input_surface_data, netcdf_data_input_topo
140
141    USE pegrid
142
143#if defined( __parallel )
144    USE pmc_particle_interface,                                                &
145        ONLY: pmcp_g_alloc_win
146
147    USE pmc_interface,                                                         &
148        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
149               pmci_modelconfiguration, pmci_parent_initialize
150#endif
151
152    USE restart_data_mpi_io_mod,                                               &
153        ONLY:  rd_mpi_io_close, rd_mpi_io_open
154
155    USE surface_data_output_mod,                                               &
156        ONLY:  surface_data_output_last_action
157
158    USE write_restart_data_mod,                                                &
159        ONLY:  wrd_global, wrd_local
160
161#if defined( __parallel )  &&  defined( _OPENACC )
162    USE openacc
163#endif
164
165
166    IMPLICIT NONE
167
168!
169!-- Local variables
170    CHARACTER(LEN=9) ::  time_to_string  !<
171    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
172#if defined( __parallel) && defined( _OPENACC )
173    INTEGER(iwp)     :: local_comm       !< local communicator (shared memory)
174    INTEGER(iwp)     :: local_num_procs  !< local number of processes
175    INTEGER(iwp)     :: local_id         !< local id
176    INTEGER(acc_device_kind) :: device_type !< device type for OpenACC
177    INTEGER(iwp)     ::  num_devices     !< number of devices visible to OpenACC
178    INTEGER(iwp)     ::  my_device       !< device used by this process
179#endif
180
181    version = 'PALM 6.0'
182    user_interface_required_revision = 'r4495'
183
184#if defined( __parallel )
185!
186!-- MPI initialisation. comm2d is preliminary set, because
187!-- it will be defined in init_pegrid but is used before in cpu_log.
188    CALL MPI_INIT( ierr )
189
190!
191!-- Initialize the coupling for nested-domain runs
192!-- comm_palm is the communicator which includes all PEs (MPI processes)
193!-- available for this (nested) model. If it is not a nested run, comm_palm
194!-- is returned as MPI_COMM_WORLD
195    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
196    CALL pmci_init( comm_palm )
197    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
198    comm2d = comm_palm
199!
200!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
201!-- of a further communicator splitting in init_coupling, these numbers will
202!-- be changed in init_pegrid).
203    IF ( nested_run )  THEN
204
205       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
206       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
207
208    ELSE
209
210       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
211       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
212!
213!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
214!--    will be splitted in init_coupling)
215       CALL init_coupling
216    ENDIF
217
218#ifdef _OPENACC
219!
220!-- Select OpenACC device to use in this process. For this find out how many
221!-- neighbors there are running on the same node and which id this process is.
222    IF ( nested_run )  THEN
223       CALL MPI_COMM_SPLIT_TYPE( comm_palm, MPI_COMM_TYPE_SHARED, 0,           &
224                                 MPI_INFO_NULL, local_comm, ierr )
225    ELSE
226       CALL MPI_COMM_SPLIT_TYPE( MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,      &
227                                 MPI_INFO_NULL, local_comm, ierr )
228    ENDIF
229    CALL MPI_COMM_SIZE( local_comm, local_num_procs, ierr )
230    CALL MPI_COMM_RANK( local_comm, local_id, ierr )
231
232!
233!-- This loop including the barrier is a workaround for PGI compiler versions
234!-- up to and including 18.4. Later releases are able to select their GPUs in
235!-- parallel, without running into spurious errors.
236    DO i = 0, local_num_procs-1
237       CALL MPI_BARRIER( local_comm, ierr )
238
239       IF ( i == local_id )  THEN
240          device_type = acc_get_device_type()
241          num_devices = acc_get_num_devices( device_type )
242          my_device = MOD( local_id, num_devices )
243          CALL acc_set_device_num( my_device, device_type )
244       ENDIF
245    ENDDO
246
247    CALL MPI_COMM_FREE( local_comm, ierr )
248#endif
249#endif
250
251!
252!-- Initialize measuring of the CPU-time remaining to the run
253    CALL local_tremain_ini
254
255!
256!-- Start of total CPU time measuring.
257    CALL cpu_log( log_point(1), 'total', 'start' )
258    CALL cpu_log( log_point(2), 'initialisation', 'start' )
259
260!
261!-- Open a file for debug output
262    WRITE (myid_char,'(''_'',I6.6)')  myid
263    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
264
265!
266!-- Initialize dvrp logging. Also, one PE maybe split from the global
267!-- communicator for doing the dvrp output. In that case, the number of
268!-- PEs available for PALM is reduced by one and communicator comm_palm
269!-- is changed respectively.
270#if defined( __parallel )
271    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
272#endif
273
274!
275!-- Read control parameters from NAMELIST files and read environment-variables
276    CALL parin
277
278!
279!-- Check for the user's interface version
280    IF ( user_interface_current_revision /= user_interface_required_revision )  &
281    THEN
282       message_string = 'current user-interface revision "' //                  &
283                        TRIM( user_interface_current_revision ) // '" does ' // &
284                        'not match the required revision ' //                   &
285                        TRIM( user_interface_required_revision )
286        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
287    ENDIF
288
289!
290!-- Determine processor topology and local array indices
291    CALL init_pegrid
292!
293!-- Check if input file according to input-data standard exists
294    CALL netcdf_data_input_inquire_file
295!
296!-- Read topography input data if required. This is required before the
297!-- numerical grid is finally created in init_grid
298    CALL netcdf_data_input_topo 
299!
300!-- Generate grid parameters, initialize generic topography and further process
301!-- topography information if required
302    CALL init_grid
303!
304!-- Initialize boundary conditions and numerics such as the multigrid solver or
305!-- the advection routine
306    CALL module_interface_init_numerics
307!
308!-- Read global attributes if available. 
309    CALL netcdf_data_input_init 
310!
311!-- Read surface classification data, e.g. vegetation and soil types, water
312!-- surfaces, etc., if available. Some of these data is required before
313!-- check parameters is invoked.     
314    CALL netcdf_data_input_surface_data
315!
316!-- Check control parameters and deduce further quantities
317    CALL check_parameters
318
319    CALL init_3d_model
320
321    CALL module_interface_init_output
322
323#if defined( __parallel )
324!
325!-- Coupling protocol setup for nested-domain runs
326    IF ( nested_run )  THEN
327       CALL pmci_modelconfiguration
328!
329!--    Receive and interpolate initial data on children.
330!--    Child initialization must be made first if the model is both child and
331!--    parent if necessary
332       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
333          CALL pmci_child_initialize
334!
335!--       Send initial condition data from parent to children
336          CALL pmci_parent_initialize
337!
338!--       Exchange_horiz is needed after the nest initialization
339          IF ( child_domain )  THEN
340             CALL exchange_horiz( u, nbgp )
341             CALL exchange_horiz( v, nbgp )
342             CALL exchange_horiz( w, nbgp )
343             IF ( .NOT. neutral )  THEN
344                CALL exchange_horiz( pt, nbgp )
345             ENDIF
346             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
347             IF ( humidity )  THEN
348                CALL exchange_horiz( q, nbgp )
349                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
350                  CALL exchange_horiz( qc, nbgp )
351                  CALL exchange_horiz( nc, nbgp )
352                ENDIF
353                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
354                   CALL exchange_horiz( qr, nbgp ) 
355                   CALL exchange_horiz( nr, nbgp )
356                ENDIF
357             ENDIF
358             IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
359          ENDIF
360       ENDIF
361
362       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
363    ENDIF
364#endif
365
366!
367!-- Output of program header
368    IF ( myid == 0 )  CALL header
369
370    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
371
372!
373!-- Integration of the non-atmospheric equations (land surface model, urban
374!-- surface model)
375    IF ( spinup )  THEN
376       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
377       CALL time_integration_spinup
378       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
379    ENDIF
380
381!
382!-- Set start time in format hh:mm:ss
383    simulated_time_chr = time_to_string( time_since_reference_point )
384
385!
386!-- If required, output of initial arrays
387    IF ( do2d_at_begin )  THEN
388       CALL doq_calculate    !TODO, will be called twice
389
390       CALL data_output_2d( 'xy', 0 )
391       CALL data_output_2d( 'xz', 0 )
392       CALL data_output_2d( 'yz', 0 )
393    ENDIF
394
395    IF ( do3d_at_begin )  THEN
396       CALL doq_calculate    !TODO, will be called twice
397
398       CALL data_output_3d( 0 )
399    ENDIF
400
401!
402!-- Integration of the model equations using timestep-scheme
403    CALL time_integration
404
405!
406!-- If required, write binary data for restart runs
407    IF ( write_binary )  THEN
408
409       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
410
411       CALL location_message( 'writing restart data', 'start' )
412
413       IF ( TRIM( restart_data_format_output ) == 'fortran_binary' )  THEN
414
415          DO  i = 0, io_blocks-1
416             IF ( i == io_group )  THEN
417
418!
419!--             Open binary file
420                CALL check_open( 14 )
421!
422!--             Write control parameters and other global variables for restart.
423                IF ( myid == 0 )  CALL wrd_global
424!
425!--             Write processor specific flow field data for restart runs
426                CALL wrd_local
427!
428!--             Close binary file
429                CALL close_file( 14 )
430
431             ENDIF
432#if defined( __parallel )
433             CALL MPI_BARRIER( comm2d, ierr )
434#endif
435          ENDDO
436
437       ELSEIF ( restart_data_format_output(1:3) == 'mpi' )  THEN
438!
439!--       Open MPI-IO restart file
440          CALL rd_mpi_io_open( 'write', 'BINOUT' // TRIM( coupling_char ) )
441!
442!--       Write control parameters and other global variables for restart.
443          CALL wrd_global
444!
445!--       Write processor specific flow field data for restart runs
446          CALL wrd_local
447!
448!--       Close restart File
449          CALL rd_mpi_io_close
450
451       ENDIF
452
453       CALL location_message( 'writing restart data', 'finished' )
454
455       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
456       
457    ENDIF
458!
459!-- Last actions for surface output, for instantaneous and time-averaged data
460    CALL surface_data_output_last_action( 0 )
461    CALL surface_data_output_last_action( 1 )
462
463!
464!-- If required, repeat output of header including the required CPU-time
465    IF ( myid == 0 )  CALL header
466!
467!-- Perform module specific last actions
468    CALL cpu_log( log_point(4), 'last actions', 'start' )
469
470    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
471
472    CALL module_interface_last_actions
473
474    CALL cpu_log( log_point(4), 'last actions', 'stop' )
475
476!
477!-- Close files
478    CALL close_file( 0 )
479
480!
481!-- Write run number to file (used by palmrun to create unified cycle numbers
482!-- for output files
483    IF ( myid == 0  .AND.  runnr > 0 )  THEN
484       OPEN( 90, FILE='RUN_NUMBER', FORM='FORMATTED' )
485       WRITE( 90, '(I4)' )  runnr
486       CLOSE( 90 )
487    ENDIF
488
489!
490!-- Take final CPU-time for CPU-time analysis
491    CALL cpu_log( log_point(1), 'total', 'stop' )
492    CALL cpu_statistics
493
494#if defined( __parallel )
495    CALL MPI_FINALIZE( ierr )
496#endif
497
498 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.