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

Last change on this file since 4209 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
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 4182 2019-08-22 15:20:23Z suehring $
27! Corrected "Former revisions" section
28!
29! 4039 2019-06-18 10:32:41Z suehring
30! Rename subroutines in module for diagnostic quantities
31!
32! 4017 2019-06-06 12:16:46Z schwenkel
33! new module for calculation and output of diagnostic quantities added
34!
35! 3885 2019-04-11 11:29:34Z kanani
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
40! unused variable removed
41!
42! 3719 2019-02-06 13:10:18Z kanani
43! Included cpu measurement for wall/soil spinup
44!
45! 3703 2019-01-29 16:43:53Z knoop
46! Some interface calls moved to module_interface + cleanup
47!
48! 3648 2019-01-02 16:35:46Z suehring
49! Rename subroutines for surface-data output
50!
51! Revision 1.1  1997/07/24 11:23:35  raasch
52! Initial revision
53!
54!
55! Description:
56! ------------
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
60!------------------------------------------------------------------------------!
61 PROGRAM palm
62 
63
64    USE arrays_3d
65
66    USE bulk_cloud_model_mod,                                                  &
67        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
68
69    USE control_parameters,                                                    &
70        ONLY:  constant_diffusion, child_domain,                               &
71               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
72               initializing_actions, io_blocks, io_group, message_string,      &
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
76
77    USE cpulog,                                                                &
78        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
79
80    USE date_and_time_mod,                                                     &
81        ONLY:  calc_date_and_time, init_date_and_time
82
83    USE diagnostic_output_quantities_mod,                                      &
84        ONLY:  doq_calculate
85
86    USE indices,                                                               &
87        ONLY:  nbgp
88
89    USE kinds
90
91    USE module_interface,                                                      &
92        ONLY:  module_interface_last_actions
93
94    USE multi_agent_system_mod,                                                &
95        ONLY:  agents_active, mas_last_actions
96
97    USE netcdf_data_input_mod,                                                 &
98        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
99               netcdf_data_input_surface_data, netcdf_data_input_topo
100
101    USE pegrid
102
103    USE pmc_particle_interface,                                                &
104        ONLY: pmcp_g_alloc_win
105
106    USE pmc_interface,                                                         &
107        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
108               pmci_modelconfiguration, pmci_parent_initialize
109               
110    USE surface_data_output_mod,                                               &
111        ONLY:  surface_data_output_last_action
112
113    USE write_restart_data_mod,                                                &
114        ONLY:  wrd_global, wrd_local
115
116#if defined( __parallel) && defined( _OPENACC )
117    USE openacc
118#endif
119
120
121    IMPLICIT NONE
122
123!
124!-- Local variables
125    CHARACTER(LEN=9) ::  time_to_string  !<
126    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
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
135
136    version = 'PALM 6.0'
137    user_interface_required_revision = 'r3703'
138
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 )
144
145!
146!-- Initialize the coupling for nested-domain runs
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
150    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
151    CALL pmci_init( comm_palm )
152    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
153    comm2d = comm_palm
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
159
160       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
161       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
162
163    ELSE
164
165       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
166       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
167!
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
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 )
203#endif
204#endif
205
206!
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!
216!-- Open a file for debug output
217    WRITE (myid_char,'(''_'',I6.6)')  myid
218    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
219
220!
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 )
227#endif
228
229!
230!-- Read control parameters from NAMELIST files and read environment-variables
231    CALL parin
232
233!
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 )
241        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
242    ENDIF
243
244!
245!-- Determine processor topology and local array indices
246    CALL init_pegrid
247!
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
257    CALL init_grid
258!
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!
267!-- Check control parameters and deduce further quantities
268    CALL check_parameters
269!
270!-- Initial time for chem_emissions_mod
271    CALL init_date_and_time
272
273    CALL init_3d_model
274
275!
276!-- Coupling protocol setup for nested-domain runs
277    IF ( nested_run )  THEN
278       CALL pmci_modelconfiguration
279!
280!--    Receive and interpolate initial data on children.
281!--    Child initialization must be made first if the model is both child and
282!--    parent if necessary
283       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
284          CALL pmci_child_initialize
285!
286!--       Send initial condition data from parent to children
287          CALL pmci_parent_initialize
288!
289!--       Exchange_horiz is needed after the nest initialization
290          IF ( child_domain )  THEN
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 )
300                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
301                  CALL exchange_horiz( qc, nbgp )
302                  CALL exchange_horiz( nc, nbgp )
303                ENDIF
304                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
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 )
310          ENDIF
311       ENDIF
312
313       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
314    ENDIF
315
316!
317!-- Output of program header
318    IF ( myid == 0 )  CALL header
319
320    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
321
322!
323!-- Integration of the non-atmospheric equations (land surface model, urban
324!-- surface model)
325    IF ( spinup )  THEN
326       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
327       CALL time_integration_spinup
328       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
329    ENDIF
330
331!
332!-- Set start time in format hh:mm:ss
333    simulated_time_chr = time_to_string( time_since_reference_point )
334
335!
336!-- If required, output of initial arrays
337    IF ( do2d_at_begin )  THEN
338       CALL doq_calculate    !TODO, will be called twice
339
340       CALL data_output_2d( 'xy', 0 )
341       CALL data_output_2d( 'xz', 0 )
342       CALL data_output_2d( 'yz', 0 )
343    ENDIF
344
345    IF ( do3d_at_begin )  THEN
346       CALL doq_calculate    !TODO, will be called twice
347
348       CALL data_output_3d( 0 )
349    ENDIF
350
351!
352!-- Integration of the model equations using timestep-scheme
353    CALL time_integration
354
355!
356!-- If required, write binary data for restart runs
357    IF ( write_binary )  THEN
358
359       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
360
361       CALL location_message( 'writing restart data', 'start' )
362
363       DO  i = 0, io_blocks-1
364          IF ( i == io_group )  THEN
365
366!
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
379          ENDIF
380#if defined( __parallel )
381          CALL MPI_BARRIER( comm2d, ierr )
382#endif
383       ENDDO
384
385       CALL location_message( 'writing restart data', 'finished' )
386
387       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
388       
389    ENDIF
390!
391!-- Last actions for surface output, for instantaneous and time-averaged data
392    CALL surface_data_output_last_action( 0 )
393    CALL surface_data_output_last_action( 1 )
394
395!
396!-- If required, repeat output of header including the required CPU-time
397    IF ( myid == 0 )  CALL header
398!
399!-- Perform module specific last actions
400    CALL cpu_log( log_point(4), 'last actions', 'start' )
401
402    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
403
404    CALL module_interface_last_actions
405
406    CALL cpu_log( log_point(4), 'last actions', 'stop' )
407
408!
409!-- Close files
410    CALL close_file( 0 )
411
412!
413!-- Write run number to file (used by palmrun to create unified cycle numbers
414!-- for output files
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!
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.