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

Last change on this file since 4227 was 4227, checked in by gronemeier, 5 years ago

implement new palm_date_time_mod; replaced namelist parameters time_utc_init and day_of_year_init by origin_date_time

  • Property svn:keywords set to Id
File size: 14.2 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 4227 2019-09-10 18:04:34Z gronemeier $
27! implement new palm_date_time_mod
28!
29! 4094 2019-07-12 09:24:21Z gronemeier
30! Corrected "Former revisions" section
31!
32! 4039 2019-06-18 10:32:41Z suehring
33! Rename subroutines in module for diagnostic quantities
34!
35! 4017 2019-06-06 12:16:46Z schwenkel
36! new module for calculation and output of diagnostic quantities added
37!
38! 3885 2019-04-11 11:29:34Z kanani
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
43! unused variable removed
44!
45! 3719 2019-02-06 13:10:18Z kanani
46! Included cpu measurement for wall/soil spinup
47!
48! 3703 2019-01-29 16:43:53Z knoop
49! Some interface calls moved to module_interface + cleanup
50!
51! 3648 2019-01-02 16:35:46Z suehring
52! Rename subroutines for surface-data output
53!
54! Revision 1.1  1997/07/24 11:23:35  raasch
55! Initial revision
56!
57!
58! Description:
59! ------------
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
63!------------------------------------------------------------------------------!
64 PROGRAM palm
65 
66
67    USE arrays_3d
68
69    USE bulk_cloud_model_mod,                                                  &
70        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
71
72    USE control_parameters,                                                    &
73        ONLY:  constant_diffusion, child_domain,                               &
74               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
75               initializing_actions, io_blocks, io_group, message_string,      &
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
79
80    USE cpulog,                                                                &
81        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
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    CALL init_3d_model
271
272!
273!-- Coupling protocol setup for nested-domain runs
274    IF ( nested_run )  THEN
275       CALL pmci_modelconfiguration
276!
277!--    Receive and interpolate initial data on children.
278!--    Child initialization must be made first if the model is both child and
279!--    parent if necessary
280       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
281          CALL pmci_child_initialize
282!
283!--       Send initial condition data from parent to children
284          CALL pmci_parent_initialize
285!
286!--       Exchange_horiz is needed after the nest initialization
287          IF ( child_domain )  THEN
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 )
297                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
298                  CALL exchange_horiz( qc, nbgp )
299                  CALL exchange_horiz( nc, nbgp )
300                ENDIF
301                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
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 )
307          ENDIF
308       ENDIF
309
310       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
311    ENDIF
312
313!
314!-- Output of program header
315    IF ( myid == 0 )  CALL header
316
317    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
318
319!
320!-- Integration of the non-atmospheric equations (land surface model, urban
321!-- surface model)
322    IF ( spinup )  THEN
323       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
324       CALL time_integration_spinup
325       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
326    ENDIF
327
328!
329!-- Set start time in format hh:mm:ss
330    simulated_time_chr = time_to_string( time_since_reference_point )
331
332!
333!-- If required, output of initial arrays
334    IF ( do2d_at_begin )  THEN
335       CALL doq_calculate    !TODO, will be called twice
336
337       CALL data_output_2d( 'xy', 0 )
338       CALL data_output_2d( 'xz', 0 )
339       CALL data_output_2d( 'yz', 0 )
340    ENDIF
341
342    IF ( do3d_at_begin )  THEN
343       CALL doq_calculate    !TODO, will be called twice
344
345       CALL data_output_3d( 0 )
346    ENDIF
347
348!
349!-- Integration of the model equations using timestep-scheme
350    CALL time_integration
351
352!
353!-- If required, write binary data for restart runs
354    IF ( write_binary )  THEN
355
356       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
357
358       CALL location_message( 'writing restart data', 'start' )
359
360       DO  i = 0, io_blocks-1
361          IF ( i == io_group )  THEN
362
363!
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
376          ENDIF
377#if defined( __parallel )
378          CALL MPI_BARRIER( comm2d, ierr )
379#endif
380       ENDDO
381
382       CALL location_message( 'writing restart data', 'finished' )
383
384       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
385       
386    ENDIF
387!
388!-- Last actions for surface output, for instantaneous and time-averaged data
389    CALL surface_data_output_last_action( 0 )
390    CALL surface_data_output_last_action( 1 )
391
392!
393!-- If required, repeat output of header including the required CPU-time
394    IF ( myid == 0 )  CALL header
395!
396!-- Perform module specific last actions
397    CALL cpu_log( log_point(4), 'last actions', 'start' )
398
399    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
400
401    CALL module_interface_last_actions
402
403    CALL cpu_log( log_point(4), 'last actions', 'stop' )
404
405!
406!-- Close files
407    CALL close_file( 0 )
408
409!
410!-- Write run number to file (used by palmrun to create unified cycle numbers
411!-- for output files
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!
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.