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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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