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

Last change on this file since 4380 was 4360, checked in by suehring, 5 years ago

Bugfix in output of time-averaged plant-canopy quanities; Output of plant-canopy data only where tall canopy is defined; land-surface model: fix wrong location strings; tests: update urban test case; all source code files: copyright update

  • Property svn:keywords set to Id
File size: 14.2 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 4360 2020-01-07 11:25:50Z monakurppa $
[4227]27! implement new palm_date_time_mod
28!
29! 4094 2019-07-12 09:24:21Z gronemeier
[4182]30! Corrected "Former revisions" section
31!
32! 4039 2019-06-18 10:32:41Z suehring
[4039]33! Rename subroutines in module for diagnostic quantities
34!
35! 4017 2019-06-06 12:16:46Z schwenkel
[3994]36! new module for calculation and output of diagnostic quantities added
37!
38! 3885 2019-04-11 11:29:34Z kanani
[3885]39! Changes related to global restructuring of location messages and introduction
40! of additional debug messages
41!
42! 3761 2019-02-25 15:31:42Z raasch
[3761]43! unused variable removed
44!
45! 3719 2019-02-06 13:10:18Z kanani
[3719]46! Included cpu measurement for wall/soil spinup
47!
48! 3703 2019-01-29 16:43:53Z knoop
[3685]49! Some interface calls moved to module_interface + cleanup
50!
51! 3648 2019-01-02 16:35:46Z suehring
[3648]52! Rename subroutines for surface-data output
[3298]53!
[4182]54! Revision 1.1  1997/07/24 11:23:35  raasch
55! Initial revision
56!
57!
[1]58! Description:
59! ------------
[3232]60!> Large-Eddy Simulation (LES) model for atmospheric and oceanic boundary-layer
61!> flows
62!> see the PALM homepage https://palm-model.org for further information
[1]63!------------------------------------------------------------------------------!
[1682]64 PROGRAM palm
65 
[1]66
[1374]67    USE arrays_3d
[1]68
[3298]69    USE bulk_cloud_model_mod,                                                  &
70        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
71
[1320]72    USE control_parameters,                                                    &
[3761]73        ONLY:  constant_diffusion, child_domain,                               &
[3524]74               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
75               initializing_actions, io_blocks, io_group, message_string,      &
[3241]76               neutral, passive_scalar, runnr, simulated_time_chr, spinup,     &
77               time_since_reference_point, user_interface_current_revision,    &
78               user_interface_required_revision, version, write_binary
[1320]79
80    USE cpulog,                                                                &
[2951]81        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
[1320]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
[3298]269
[1]270    CALL init_3d_model
271
272!
[1762]273!-- Coupling protocol setup for nested-domain runs
[1764]274    IF ( nested_run )  THEN
275       CALL pmci_modelconfiguration
[1781]276!
[1933]277!--    Receive and interpolate initial data on children.
278!--    Child initialization must be made first if the model is both child and
[2177]279!--    parent if necessary
280       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
281          CALL pmci_child_initialize
[1781]282!
[2177]283!--       Send initial condition data from parent to children
284          CALL pmci_parent_initialize
[1781]285!
[3232]286!--       Exchange_horiz is needed after the nest initialization
[3182]287          IF ( child_domain )  THEN
[2178]288             CALL exchange_horiz( u, nbgp )
289             CALL exchange_horiz( v, nbgp )
290             CALL exchange_horiz( w, nbgp )
291             IF ( .NOT. neutral )  THEN
292                CALL exchange_horiz( pt, nbgp )
293             ENDIF
294             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
295             IF ( humidity )  THEN
296                CALL exchange_horiz( q, nbgp )
[3274]297                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
[2292]298                  CALL exchange_horiz( qc, nbgp )
299                  CALL exchange_horiz( nc, nbgp )
300                ENDIF
[3274]301                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
[2178]302                   CALL exchange_horiz( qr, nbgp ) 
303                   CALL exchange_horiz( nr, nbgp )
304                ENDIF
305             ENDIF
306             IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
[1933]307          ENDIF
[1781]308       ENDIF
309
[2801]310       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
[1764]311    ENDIF
[1762]312
313!
[1]314!-- Output of program header
315    IF ( myid == 0 )  CALL header
316
317    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
318
319!
[2296]320!-- Integration of the non-atmospheric equations (land surface model, urban
321!-- surface model)
322    IF ( spinup )  THEN
[3719]323       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
[2296]324       CALL time_integration_spinup
[3719]325       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
[2296]326    ENDIF
327
328!
[1]329!-- Set start time in format hh:mm:ss
[2977]330    simulated_time_chr = time_to_string( time_since_reference_point )
[1]331
332!
333!-- If required, output of initial arrays
334    IF ( do2d_at_begin )  THEN
[4039]335       CALL doq_calculate    !TODO, will be called twice
[3994]336
[1]337       CALL data_output_2d( 'xy', 0 )
338       CALL data_output_2d( 'xz', 0 )
339       CALL data_output_2d( 'yz', 0 )
340    ENDIF
[1976]341
[1]342    IF ( do3d_at_begin )  THEN
[4039]343       CALL doq_calculate    !TODO, will be called twice
[3994]344
[1]345       CALL data_output_3d( 0 )
346    ENDIF
347
348!
[495]349!-- Integration of the model equations using timestep-scheme
[1]350    CALL time_integration
351
352!
[495]353!-- If required, write binary data for restart runs
[2298]354    IF ( write_binary )  THEN
[759]355
[2894]356       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
[759]357
[3885]358       CALL location_message( 'writing restart data', 'start' )
[1402]359
[759]360       DO  i = 0, io_blocks-1
361          IF ( i == io_group )  THEN
[2894]362
[1]363!
[2894]364!--          Open binary file
365             CALL check_open( 14 )
366!
367!--          Write control parameters and other global variables for restart.
368             IF ( myid == 0 )  CALL wrd_global
369!
370!--          Write processor specific flow field data for restart runs
371             CALL wrd_local
372!
373!--          Close binary file
374             CALL close_file( 14 )
375
[759]376          ENDIF
377#if defined( __parallel )
378          CALL MPI_BARRIER( comm2d, ierr )
379#endif
380       ENDDO
381
[3885]382       CALL location_message( 'writing restart data', 'finished' )
[1402]383
[2894]384       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
[2007]385       
[495]386    ENDIF
[3494]387!
388!-- Last actions for surface output, for instantaneous and time-averaged data
[3648]389    CALL surface_data_output_last_action( 0 )
390    CALL surface_data_output_last_action( 1 )
[1]391
392!
393!-- If required, repeat output of header including the required CPU-time
394    IF ( myid == 0 )  CALL header
395!
[3687]396!-- Perform module specific last actions
[1]397    CALL cpu_log( log_point(4), 'last actions', 'start' )
[3235]398
[3687]399    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
[2894]400
[3687]401    CALL module_interface_last_actions
402
[1]403    CALL cpu_log( log_point(4), 'last actions', 'stop' )
404
405!
[3687]406!-- Close files
407    CALL close_file( 0 )
408
409!
[3232]410!-- Write run number to file (used by palmrun to create unified cycle numbers
411!-- for output files
[2261]412    IF ( myid == 0  .AND.  runnr > 0 )  THEN
413       OPEN( 90, FILE='RUN_NUMBER', FORM='FORMATTED' )
414       WRITE( 90, '(I4)' )  runnr
415       CLOSE( 90 )
416    ENDIF
417
418!
[1]419!-- Take final CPU-time for CPU-time analysis
420    CALL cpu_log( log_point(1), 'total', 'stop' )
421    CALL cpu_statistics
422
423#if defined( __parallel )
424    CALL MPI_FINALIZE( ierr )
425#endif
426
427 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.