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

Last change on this file since 4455 was 4444, checked in by raasch, 5 years ago

bugfix: cpp-directives for serial mode added

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