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

Last change on this file since 4484 was 4457, checked in by raasch, 5 years ago

ghost point exchange modularized, bugfix for wrong 2d-exchange

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