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
Line 
1! !> @file palm.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
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.
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!
17! Copyright 1997-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4180 2019-08-21 14:37:54Z scharf $
27! Rename subroutines in module for diagnostic quantities
28!
29! 4017 2019-06-06 12:16:46Z schwenkel
30! new module for calculation and output of diagnostic quantities added
31!
32! 3885 2019-04-11 11:29:34Z kanani
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
37! unused variable removed
38!
39! 3719 2019-02-06 13:10:18Z kanani
40! Included cpu measurement for wall/soil spinup
41!
42! 3703 2019-01-29 16:43:53Z knoop
43! Some interface calls moved to module_interface + cleanup
44!
45! 3648 2019-01-02 16:35:46Z suehring
46! Rename subroutines for surface-data output
47!
48!
49! Description:
50! ------------
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
54!------------------------------------------------------------------------------!
55 PROGRAM palm
56 
57
58    USE arrays_3d
59
60    USE bulk_cloud_model_mod,                                                  &
61        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
62
63    USE control_parameters,                                                    &
64        ONLY:  constant_diffusion, child_domain,                               &
65               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
66               initializing_actions, io_blocks, io_group, message_string,      &
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
70
71    USE cpulog,                                                                &
72        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
73
74    USE date_and_time_mod,                                                     &
75        ONLY:  calc_date_and_time, init_date_and_time
76
77    USE diagnostic_output_quantities_mod,                                      &
78        ONLY:  doq_calculate
79
80    USE indices,                                                               &
81        ONLY:  nbgp
82
83    USE kinds
84
85    USE module_interface,                                                      &
86        ONLY:  module_interface_last_actions
87
88    USE multi_agent_system_mod,                                                &
89        ONLY:  agents_active, mas_last_actions
90
91    USE netcdf_data_input_mod,                                                 &
92        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
93               netcdf_data_input_surface_data, netcdf_data_input_topo
94
95    USE pegrid
96
97    USE pmc_particle_interface,                                                &
98        ONLY: pmcp_g_alloc_win
99
100    USE pmc_interface,                                                         &
101        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
102               pmci_modelconfiguration, pmci_parent_initialize
103               
104    USE surface_data_output_mod,                                               &
105        ONLY:  surface_data_output_last_action
106
107    USE write_restart_data_mod,                                                &
108        ONLY:  wrd_global, wrd_local
109
110#if defined( __parallel) && defined( _OPENACC )
111    USE openacc
112#endif
113
114
115    IMPLICIT NONE
116
117!
118!-- Local variables
119    CHARACTER(LEN=9) ::  time_to_string  !<
120    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
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
129
130    version = 'PALM 6.0'
131    user_interface_required_revision = 'r3703'
132
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 )
138
139!
140!-- Initialize the coupling for nested-domain runs
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
144    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
145    CALL pmci_init( comm_palm )
146    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
147    comm2d = comm_palm
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
153
154       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
155       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
156
157    ELSE
158
159       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
160       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
161!
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
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 )
197#endif
198#endif
199
200!
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!
210!-- Open a file for debug output
211    WRITE (myid_char,'(''_'',I6.6)')  myid
212    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
213
214!
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 )
221#endif
222
223!
224!-- Read control parameters from NAMELIST files and read environment-variables
225    CALL parin
226
227!
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 )
235        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
236    ENDIF
237
238!
239!-- Determine processor topology and local array indices
240    CALL init_pegrid
241!
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
251    CALL init_grid
252!
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!
261!-- Check control parameters and deduce further quantities
262    CALL check_parameters
263!
264!-- Initial time for chem_emissions_mod
265    CALL init_date_and_time
266
267    CALL init_3d_model
268
269!
270!-- Coupling protocol setup for nested-domain runs
271    IF ( nested_run )  THEN
272       CALL pmci_modelconfiguration
273!
274!--    Receive and interpolate initial data on children.
275!--    Child initialization must be made first if the model is both child and
276!--    parent if necessary
277       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
278          CALL pmci_child_initialize
279!
280!--       Send initial condition data from parent to children
281          CALL pmci_parent_initialize
282!
283!--       Exchange_horiz is needed after the nest initialization
284          IF ( child_domain )  THEN
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 )
294                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
295                  CALL exchange_horiz( qc, nbgp )
296                  CALL exchange_horiz( nc, nbgp )
297                ENDIF
298                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
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 )
304          ENDIF
305       ENDIF
306
307       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
308    ENDIF
309
310!
311!-- Output of program header
312    IF ( myid == 0 )  CALL header
313
314    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
315
316!
317!-- Integration of the non-atmospheric equations (land surface model, urban
318!-- surface model)
319    IF ( spinup )  THEN
320       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
321       CALL time_integration_spinup
322       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
323    ENDIF
324
325!
326!-- Set start time in format hh:mm:ss
327    simulated_time_chr = time_to_string( time_since_reference_point )
328
329!
330!-- If required, output of initial arrays
331    IF ( do2d_at_begin )  THEN
332       CALL doq_calculate    !TODO, will be called twice
333
334       CALL data_output_2d( 'xy', 0 )
335       CALL data_output_2d( 'xz', 0 )
336       CALL data_output_2d( 'yz', 0 )
337    ENDIF
338
339    IF ( do3d_at_begin )  THEN
340       CALL doq_calculate    !TODO, will be called twice
341
342       CALL data_output_3d( 0 )
343    ENDIF
344
345!
346!-- Integration of the model equations using timestep-scheme
347    CALL time_integration
348
349!
350!-- If required, write binary data for restart runs
351    IF ( write_binary )  THEN
352
353       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
354
355       CALL location_message( 'writing restart data', 'start' )
356
357       DO  i = 0, io_blocks-1
358          IF ( i == io_group )  THEN
359
360!
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
373          ENDIF
374#if defined( __parallel )
375          CALL MPI_BARRIER( comm2d, ierr )
376#endif
377       ENDDO
378
379       CALL location_message( 'writing restart data', 'finished' )
380
381       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
382       
383    ENDIF
384!
385!-- Last actions for surface output, for instantaneous and time-averaged data
386    CALL surface_data_output_last_action( 0 )
387    CALL surface_data_output_last_action( 1 )
388
389!
390!-- If required, repeat output of header including the required CPU-time
391    IF ( myid == 0 )  CALL header
392!
393!-- Perform module specific last actions
394    CALL cpu_log( log_point(4), 'last actions', 'start' )
395
396    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
397
398    CALL module_interface_last_actions
399
400    CALL cpu_log( log_point(4), 'last actions', 'stop' )
401
402!
403!-- Close files
404    CALL close_file( 0 )
405
406!
407!-- Write run number to file (used by palmrun to create unified cycle numbers
408!-- for output files
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!
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.