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

Last change on this file since 4418 was 4414, checked in by suehring, 4 years ago

Remove deprecated topography arrays; Move basic initialization of numerics into an extra module interface

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