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

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