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

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

bugfix: cpp-directives for serial mode added

  • Property svn:keywords set to Id
File size: 15.1 KB
RevLine 
[4017]1! !> @file palm.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]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.
[1036]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!
[4360]17! Copyright 1997-2020 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1]21! -----------------
[2233]22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4444 2020-03-05 15:59:50Z raasch $
[4444]27! bugfix: cpp-directives for serial mode added
28!
29! 4414 2020-02-19 20:16:04Z suehring
[4414]30! Call to module_interface_init_numerics
31!
32! 4400 2020-02-10 20:32:41Z suehring
[4400]33! Add interface to initialize data output with dom
34!
35! 4360 2020-01-07 11:25:50Z suehring
[4227]36! implement new palm_date_time_mod
37!
38! 4094 2019-07-12 09:24:21Z gronemeier
[4182]39! Corrected "Former revisions" section
40!
41! 4039 2019-06-18 10:32:41Z suehring
[4039]42! Rename subroutines in module for diagnostic quantities
43!
44! 4017 2019-06-06 12:16:46Z schwenkel
[3994]45! new module for calculation and output of diagnostic quantities added
46!
47! 3885 2019-04-11 11:29:34Z kanani
[3885]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
[3761]52! unused variable removed
53!
54! 3719 2019-02-06 13:10:18Z kanani
[3719]55! Included cpu measurement for wall/soil spinup
56!
57! 3703 2019-01-29 16:43:53Z knoop
[3685]58! Some interface calls moved to module_interface + cleanup
59!
60! 3648 2019-01-02 16:35:46Z suehring
[3648]61! Rename subroutines for surface-data output
[3298]62!
[4182]63! Revision 1.1  1997/07/24 11:23:35  raasch
64! Initial revision
65!
66!
[1]67! Description:
68! ------------
[3232]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
[1]72!------------------------------------------------------------------------------!
[1682]73 PROGRAM palm
74 
[1]75
[1374]76    USE arrays_3d
[1]77
[4444]78#if defined( __parallel )
[3298]79    USE bulk_cloud_model_mod,                                                  &
80        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
[4444]81#endif
[3298]82
[1320]83    USE control_parameters,                                                    &
[4444]84        ONLY:  coupling_char, do2d_at_begin, do3d_at_begin, io_blocks,         &
85               io_group, message_string, runnr, simulated_time_chr, spinup,    &
[3241]86               time_since_reference_point, user_interface_current_revision,    &
87               user_interface_required_revision, version, write_binary
[1320]88
[4444]89#if defined( __parallel )
90    USE control_parameters,                                                    &
91        ONLY:  child_domain, constant_diffusion, humidity,                     &
92               initializing_actions, neutral, passive_scalar
93#endif
94
[1320]95    USE cpulog,                                                                &
[4444]96        ONLY:  cpu_log, log_point, cpu_statistics
[1320]97
[4444]98#if defined( __parallel )
99    USE cpulog,                                                                &
100        ONLY:  log_point_s
101#endif
102
[3994]103    USE diagnostic_output_quantities_mod,                                      &
[4039]104        ONLY:  doq_calculate
[3994]105
[4444]106#if defined( __parallel )
[1374]107    USE indices,                                                               &
[2232]108        ONLY:  nbgp
[4444]109#endif
[1374]110
[3274]111    USE kinds
112
[3687]113    USE module_interface,                                                      &
[4414]114        ONLY:  module_interface_init_numerics,                                 &
115               module_interface_init_output,                                   &
[4400]116               module_interface_last_actions
[3687]117
[4400]118
[3235]119    USE multi_agent_system_mod,                                                &
120        ONLY:  agents_active, mas_last_actions
121
[2696]122    USE netcdf_data_input_mod,                                                 &
[3685]123        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
[2696]124               netcdf_data_input_surface_data, netcdf_data_input_topo
125
[1]126    USE pegrid
127
[4444]128#if defined( __parallel )
[2894]129    USE pmc_particle_interface,                                                &
130        ONLY: pmcp_g_alloc_win
131
[1762]132    USE pmc_interface,                                                         &
[3241]133        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
[3484]134               pmci_modelconfiguration, pmci_parent_initialize
[4444]135#endif
[4414]136
[3648]137    USE surface_data_output_mod,                                               &
138        ONLY:  surface_data_output_last_action
[1762]139
[2894]140    USE write_restart_data_mod,                                                &
141        ONLY:  wrd_global, wrd_local
[2801]142
[4444]143#if defined( __parallel )  &&  defined( _OPENACC )
[3689]144    USE openacc
145#endif
[1747]146
[3689]147
[1]148    IMPLICIT NONE
149
150!
151!-- Local variables
[3241]152    CHARACTER(LEN=9) ::  time_to_string  !<
153    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
[3689]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
[1]162
[3487]163    version = 'PALM 6.0'
[3703]164    user_interface_required_revision = 'r3703'
[75]165
[1]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 )
[1762]171
172!
173!-- Initialize the coupling for nested-domain runs
[1764]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
[2951]177    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
[1762]178    CALL pmci_init( comm_palm )
[2951]179    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
[1762]180    comm2d = comm_palm
[1764]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
[1762]186
[1764]187       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
188       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
[1762]189
[1764]190    ELSE
191
192       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
193       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
[1]194!
[1764]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
[3689]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 )
[102]230#endif
[3689]231#endif
[102]232
233!
[1]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!
[206]243!-- Open a file for debug output
[1468]244    WRITE (myid_char,'(''_'',I6.6)')  myid
[206]245    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
246
247!
[1]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 )
[102]254#endif
255
256!
[108]257!-- Read control parameters from NAMELIST files and read environment-variables
258    CALL parin
259
260!
[1666]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 )
[1668]268        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
[1666]269    ENDIF
270
271!
[108]272!-- Determine processor topology and local array indices
273    CALL init_pegrid
274!
[2696]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
[1]284    CALL init_grid
285!
[4414]286!-- Initialize boundary conditions and numerics such as the multigrid solver or
287!-- the advection routine
288    CALL module_interface_init_numerics
289!
[2696]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!
[1]298!-- Check control parameters and deduce further quantities
299    CALL check_parameters
[3298]300
[1]301    CALL init_3d_model
302
[4400]303    CALL module_interface_init_output
304
[4444]305#if defined( __parallel )
[1]306!
[1762]307!-- Coupling protocol setup for nested-domain runs
[1764]308    IF ( nested_run )  THEN
309       CALL pmci_modelconfiguration
[1781]310!
[1933]311!--    Receive and interpolate initial data on children.
312!--    Child initialization must be made first if the model is both child and
[2177]313!--    parent if necessary
314       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
315          CALL pmci_child_initialize
[1781]316!
[2177]317!--       Send initial condition data from parent to children
318          CALL pmci_parent_initialize
[1781]319!
[3232]320!--       Exchange_horiz is needed after the nest initialization
[3182]321          IF ( child_domain )  THEN
[2178]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 )
[3274]331                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
[2292]332                  CALL exchange_horiz( qc, nbgp )
333                  CALL exchange_horiz( nc, nbgp )
334                ENDIF
[3274]335                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
[2178]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 )
[1933]341          ENDIF
[1781]342       ENDIF
343
[2801]344       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
[1764]345    ENDIF
[4444]346#endif
[1762]347
348!
[1]349!-- Output of program header
350    IF ( myid == 0 )  CALL header
351
352    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
353
354!
[2296]355!-- Integration of the non-atmospheric equations (land surface model, urban
356!-- surface model)
357    IF ( spinup )  THEN
[3719]358       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
[2296]359       CALL time_integration_spinup
[3719]360       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
[2296]361    ENDIF
362
363!
[1]364!-- Set start time in format hh:mm:ss
[2977]365    simulated_time_chr = time_to_string( time_since_reference_point )
[1]366
367!
368!-- If required, output of initial arrays
369    IF ( do2d_at_begin )  THEN
[4039]370       CALL doq_calculate    !TODO, will be called twice
[3994]371
[1]372       CALL data_output_2d( 'xy', 0 )
373       CALL data_output_2d( 'xz', 0 )
374       CALL data_output_2d( 'yz', 0 )
375    ENDIF
[1976]376
[1]377    IF ( do3d_at_begin )  THEN
[4039]378       CALL doq_calculate    !TODO, will be called twice
[3994]379
[1]380       CALL data_output_3d( 0 )
381    ENDIF
382
383!
[495]384!-- Integration of the model equations using timestep-scheme
[1]385    CALL time_integration
386
387!
[495]388!-- If required, write binary data for restart runs
[2298]389    IF ( write_binary )  THEN
[759]390
[2894]391       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
[759]392
[3885]393       CALL location_message( 'writing restart data', 'start' )
[1402]394
[759]395       DO  i = 0, io_blocks-1
396          IF ( i == io_group )  THEN
[2894]397
[1]398!
[2894]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
[759]411          ENDIF
412#if defined( __parallel )
413          CALL MPI_BARRIER( comm2d, ierr )
414#endif
415       ENDDO
416
[3885]417       CALL location_message( 'writing restart data', 'finished' )
[1402]418
[2894]419       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
[2007]420       
[495]421    ENDIF
[3494]422!
423!-- Last actions for surface output, for instantaneous and time-averaged data
[3648]424    CALL surface_data_output_last_action( 0 )
425    CALL surface_data_output_last_action( 1 )
[1]426
427!
428!-- If required, repeat output of header including the required CPU-time
429    IF ( myid == 0 )  CALL header
430!
[3687]431!-- Perform module specific last actions
[1]432    CALL cpu_log( log_point(4), 'last actions', 'start' )
[3235]433
[3687]434    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
[2894]435
[3687]436    CALL module_interface_last_actions
437
[1]438    CALL cpu_log( log_point(4), 'last actions', 'stop' )
439
440!
[3687]441!-- Close files
442    CALL close_file( 0 )
443
444!
[3232]445!-- Write run number to file (used by palmrun to create unified cycle numbers
446!-- for output files
[2261]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!
[1]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.