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

Last change on this file since 1976 was 1976, checked in by maronga, 5 years ago

further modularization of land surface model (2D/3D output and restart data). Bugfix for restart runs without land surface model

  • Property svn:keywords set to Id
File size: 17.1 KB
Line 
1!> @file palm.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21! Added call to radiation_last_actions for binary output of land surface model
22! data
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 1976 2016-07-27 13:28:04Z maronga $
27!
28! 1972 2016-07-26 07:52:02Z maronga
29! Added call to lsm_last_actions for binary output of land surface model data
30!
31! 1960 2016-07-12 16:34:24Z suehring
32! Separate humidity and passive scalar
33!
34! 1834 2016-04-07 14:34:20Z raasch
35! Initial version of purely vertical nesting introduced.
36!
37! 1833 2016-04-07 14:23:03Z raasch
38! required user interface version changed
39!
40! 1808 2016-04-05 19:44:00Z raasch
41! routine local_flush replaced by FORTRAN statement
42!
43! 1783 2016-03-06 18:36:17Z raasch
44! required user interface version changed
45!
46! 1781 2016-03-03 15:12:23Z raasch
47! pmc initialization moved from time_integration to here
48!
49! 1779 2016-03-03 08:01:28Z raasch
50! setting of nest_domain and coupling_char moved to the pmci
51!
52! 1764 2016-02-28 12:45:19Z raasch
53! cpp-statements for nesting removed, communicator settings cleaned up
54!
55! 1762 2016-02-25 12:31:13Z hellstea
56! Introduction of nested domain feature
57!
58! 1747 2016-02-08 12:25:53Z raasch
59! OpenACC-adjustment for new surface layer parameterization
60!
61! 1682 2015-10-07 23:56:08Z knoop
62! Code annotations made doxygen readable
63!
64! 1668 2015-09-23 13:45:36Z raasch
65! warning replaced by abort in case of failed user interface check
66!
67! 1666 2015-09-23 07:31:10Z raasch
68! check for user's interface version added
69!
70! 1482 2014-10-18 12:34:45Z raasch
71! adjustments for using CUDA-aware OpenMPI
72!
73! 1468 2014-09-24 14:06:57Z maronga
74! Adapted for use on up to 6-digit processor cores
75!
76! 1402 2014-05-09 14:25:13Z raasch
77! location messages added
78!
79! 1374 2014-04-25 12:55:07Z raasch
80! bugfix: various modules added
81!
82! 1320 2014-03-20 08:40:49Z raasch
83! ONLY-attribute added to USE-statements,
84! kind-parameters added to all INTEGER and REAL declaration statements,
85! kinds are defined in new module kinds,
86! old module precision_kind is removed,
87! revision history before 2012 removed,
88! comment fields (!:) to be used for variable explanations added to
89! all variable declaration statements
90!
91! 1318 2014-03-17 13:35:16Z raasch
92! module interfaces removed
93!
94! 1241 2013-10-30 11:36:58Z heinze
95! initialization of nuding and large scale forcing from external file
96!
97! 1221 2013-09-10 08:59:13Z raasch
98! +wall_flags_00, rflags_invers, rflags_s_inner in copyin statement
99!
100! 1212 2013-08-15 08:46:27Z raasch
101! +tri in copyin statement
102!
103! 1179 2013-06-14 05:57:58Z raasch
104! ref_state added to copyin-list
105!
106! 1113 2013-03-10 02:48:14Z raasch
107! openACC statements modified
108!
109! 1111 2013-03-08 23:54:10Z raasch
110! openACC statements updated
111!
112! 1092 2013-02-02 11:24:22Z raasch
113! unused variables removed
114!
115! 1036 2012-10-22 13:43:42Z raasch
116! code put under GPL (PALM 3.9)
117!
118! 1015 2012-09-27 09:23:24Z raasch
119! Version number changed from 3.8 to 3.8a.
120! OpenACC statements added + code changes required for GPU optimization
121!
122! 849 2012-03-15 10:35:09Z raasch
123! write_particles renamed lpm_write_restart_file
124!
125! Revision 1.1  1997/07/24 11:23:35  raasch
126! Initial revision
127!
128!
129! Description:
130! ------------
131!> Large-Eddy Simulation (LES) model for the convective boundary layer,
132!> optimized for use on parallel machines (implementation realized using the
133!> Message Passing Interface (MPI)). The model can also be run on vector machines
134!> (less well optimized) and workstations. Versions for the different types of
135!> machines are controlled via cpp-directives.
136!> Model runs are only feasible using the ksh-script mrun.
137!>
138!> @todo create routine last_actions instead of calling lsm_last_actions etc.
139!------------------------------------------------------------------------------!
140 PROGRAM palm
141 
142
143    USE arrays_3d
144
145    USE control_parameters,                                                    &
146        ONLY:  constant_diffusion, coupling_char, coupling_mode,               &
147               do2d_at_begin, do3d_at_begin, humidity, io_blocks, io_group,    &
148               large_scale_forcing, message_string, nest_domain, neutral,      &
149               nudging, passive_scalar, simulated_time, simulated_time_chr,    &
150               user_interface_current_revision,                                &
151               user_interface_required_revision, version, wall_heatflux,       &
152               write_binary
153
154    USE cpulog,                                                                &
155        ONLY:  cpu_log, log_point, cpu_statistics
156
157    USE grid_variables,                                                        &
158        ONLY:  fxm, fxp, fym, fyp, fwxm, fwxp, fwym, fwyp, wall_e_x, wall_e_y, &
159               wall_u, wall_v, wall_w_x, wall_w_y
160
161    USE indices,                                                               &
162        ONLY:  nbgp, ngp_2dh, ngp_2dh_s_inner, nzb_diff_s_inner, nzb_diff_s_outer,   &
163               nzb_diff_u, nzb_diff_v, nzb_s_inner, nzb_s_outer, nzb_u_inner,  &
164               nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner,             &
165               nzb_w_outer, rflags_invers, rflags_s_inner, wall_flags_0,       &
166               wall_flags_00
167
168    USE kinds
169
170    USE land_surface_model_mod,                                                &
171        ONLY:  land_surface, lsm_last_actions
172
173    USE ls_forcing_mod,                                                        &
174        ONLY:  init_ls_forcing
175
176    USE nudge_mod,                                                             &
177        ONLY:  init_nudge
178
179    USE particle_attributes,                                                   &
180        ONLY:  particle_advection
181
182    USE pegrid
183
184    USE pmc_interface,                                                         &
185        ONLY:  cpl_id, nested_run, pmci_child_initialize, pmci_init,           &
186               pmci_modelconfiguration, pmci_parent_initialize
187
188    USE radiation_model_mod,                                                   &
189        ONLY:  radiation, radiation_last_actions
190
191    USE statistics,                                                            &
192        ONLY:  hom, rmask, weight_pres, weight_substep
193
194    USE surface_layer_fluxes_mod,                                              &
195        ONLY:  pt1, qv1, uv_total
196
197#if defined( __openacc )
198    USE OPENACC
199#endif
200
201    IMPLICIT NONE
202
203!
204!-- Local variables
205    CHARACTER(LEN=9)  ::  time_to_string  !<
206    CHARACTER(LEN=10) ::  env_string      !< to store string of environment var
207    INTEGER(iwp)      ::  env_stat        !< to hold status of GET_ENV
208    INTEGER(iwp)      ::  i               !<
209    INTEGER(iwp)      ::  myid_openmpi    !< OpenMPI local rank for CUDA aware MPI
210#if defined( __openacc )
211    REAL(wp), DIMENSION(100) ::  acc_dum     !<
212#endif
213
214    version = 'PALM 4.0'
215    user_interface_required_revision = 'r1819'
216
217#if defined( __parallel )
218!
219!-- MPI initialisation. comm2d is preliminary set, because
220!-- it will be defined in init_pegrid but is used before in cpu_log.
221    CALL MPI_INIT( ierr )
222
223!
224!-- Initialize the coupling for nested-domain runs
225!-- comm_palm is the communicator which includes all PEs (MPI processes)
226!-- available for this (nested) model. If it is not a nested run, comm_palm
227!-- is returned as MPI_COMM_WORLD
228    CALL pmci_init( comm_palm )
229    comm2d = comm_palm
230!
231!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
232!-- of a further communicator splitting in init_coupling, these numbers will
233!-- be changed in init_pegrid).
234    IF ( nested_run )  THEN
235
236       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
237       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
238
239    ELSE
240
241       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
242       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
243!
244!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
245!--    will be splitted in init_coupling)
246       CALL init_coupling
247    ENDIF
248#endif
249
250#if defined( __openacc )
251!
252!-- Get the local MPI rank in case of CUDA aware OpenMPI. Important, if there
253!-- is more than one accelerator board on the node
254    CALL GET_ENVIRONMENT_VARIABLE('OMPI_COMM_WORLD_LOCAL_RANK',                &
255         VALUE=env_string, STATUS=env_stat )
256    READ( env_string, '(I1)' )  myid_openmpi
257    PRINT*, '### local_rank = ', myid_openmpi, '  status=',env_stat
258!
259!-- Get the number of accelerator boards per node and assign the MPI processes
260!-- to these boards
261    PRINT*, '*** ACC_DEVICE_NVIDIA = ', ACC_DEVICE_NVIDIA
262    num_acc_per_node  = ACC_GET_NUM_DEVICES( ACC_DEVICE_NVIDIA )
263    IF ( numprocs == 1  .AND.  num_acc_per_node > 0 )  num_acc_per_node = 1
264    PRINT*, '*** myid = ', myid_openmpi, ' num_acc_per_node = ', num_acc_per_node
265    acc_rank = MOD( myid_openmpi, num_acc_per_node )
266    CALL ACC_SET_DEVICE_NUM ( acc_rank, ACC_DEVICE_NVIDIA )
267!
268!-- Test output (to be removed later)
269    WRITE (*,'(A,I6,A,I3,A,I3,A,I3)') '*** Connect MPI-Task ', myid_openmpi,   &
270                                      ' to CPU ', acc_rank, ' Devices: ',      &
271                                      num_acc_per_node, ' connected to:',      &
272                                      ACC_GET_DEVICE_NUM( ACC_DEVICE_NVIDIA )
273#endif
274
275!
276!-- Ensure that OpenACC first attaches the GPU devices by copying a dummy data
277!-- region
278    !$acc data copyin( acc_dum )
279
280!
281!-- Initialize measuring of the CPU-time remaining to the run
282    CALL local_tremain_ini
283
284!
285!-- Start of total CPU time measuring.
286    CALL cpu_log( log_point(1), 'total', 'start' )
287    CALL cpu_log( log_point(2), 'initialisation', 'start' )
288
289!
290!-- Open a file for debug output
291    WRITE (myid_char,'(''_'',I6.6)')  myid
292    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
293
294!
295!-- Initialize dvrp logging. Also, one PE maybe split from the global
296!-- communicator for doing the dvrp output. In that case, the number of
297!-- PEs available for PALM is reduced by one and communicator comm_palm
298!-- is changed respectively.
299#if defined( __parallel )
300    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
301!
302!-- TEST OUTPUT (TO BE REMOVED)
303    WRITE(9,*) '*** coupling_mode = "', TRIM( coupling_mode ), '"'
304    FLUSH( 9 )
305    IF ( TRIM( coupling_mode ) /= 'uncoupled' )  THEN
306       PRINT*, '*** PE', myid, ' Global target PE:', target_id, &
307               TRIM( coupling_mode )
308    ENDIF
309#endif
310
311    CALL init_dvrp_logging
312
313!
314!-- Read control parameters from NAMELIST files and read environment-variables
315    CALL parin
316
317!
318!-- Check for the user's interface version
319    IF ( user_interface_current_revision /= user_interface_required_revision )  &
320    THEN
321       message_string = 'current user-interface revision "' //                  &
322                        TRIM( user_interface_current_revision ) // '" does ' // &
323                        'not match the required revision ' //                   &
324                        TRIM( user_interface_required_revision )
325        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
326    ENDIF
327
328!
329!-- Determine processor topology and local array indices
330    CALL init_pegrid
331
332!
333!-- Generate grid parameters
334    CALL init_grid
335
336!
337!-- Initialize nudging if required
338    IF ( nudging )  THEN
339       CALL init_nudge
340    ENDIF
341
342!
343!-- Initialize reading of large scale forcing from external file - if required
344    IF ( large_scale_forcing )  THEN
345       CALL init_ls_forcing
346    ENDIF
347
348!
349!-- Check control parameters and deduce further quantities
350    CALL check_parameters
351
352!
353!-- Initialize all necessary variables
354    CALL init_3d_model
355
356!
357!-- Coupling protocol setup for nested-domain runs
358    IF ( nested_run )  THEN
359       CALL pmci_modelconfiguration
360!
361!--    Receive and interpolate initial data on children.
362!--    Child initialization must be made first if the model is both child and
363!--    parent
364       CALL pmci_child_initialize
365!
366!--    Send initial condition data from parent to children
367       CALL pmci_parent_initialize
368!
369!--    Exchange_horiz is needed after the nest initialization
370       IF ( nest_domain )  THEN
371          CALL exchange_horiz( u, nbgp )
372          CALL exchange_horiz( v, nbgp )
373          CALL exchange_horiz( w, nbgp )
374          IF ( .NOT. neutral )  THEN
375             CALL exchange_horiz( pt, nbgp )
376          ENDIF
377          IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
378          IF ( humidity       )  CALL exchange_horiz( q, nbgp )
379          IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
380       ENDIF
381
382    ENDIF
383
384!
385!-- Output of program header
386    IF ( myid == 0 )  CALL header
387
388    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
389
390!
391!-- Set start time in format hh:mm:ss
392    simulated_time_chr = time_to_string( simulated_time )
393
394!
395!-- If required, output of initial arrays
396    IF ( do2d_at_begin )  THEN
397       CALL data_output_2d( 'xy', 0 )
398       CALL data_output_2d( 'xz', 0 )
399       CALL data_output_2d( 'yz', 0 )
400    ENDIF
401
402    IF ( do3d_at_begin )  THEN
403       CALL data_output_3d( 0 )
404    ENDIF
405
406!
407!-- Declare and initialize variables in the accelerator memory with their
408!-- host values
409    !$acc  data copyin( d, diss, e, e_p, kh, km, p, pt, pt_p, q, ql, tend, te_m, tpt_m, tu_m, tv_m, tw_m, u, u_p, v, vpt, v_p, w, w_p )          &
410    !$acc       copyin( tri, tric, dzu, ddzu, ddzw, dd2zu, l_grid, l_wall, ptdf_x, ptdf_y, pt_init, rdf, rdf_sc, ref_state, ug, u_init, vg, v_init, zu, zw )   &
411    !$acc       copyin( hom, ol, pt1, qs, qsws, qswst, qv1, rif_wall, shf, ts, tswst, us, usws, uswst, uv_total, vsws, vswst, z0, z0h )      &
412    !$acc       copyin( fxm, fxp, fym, fyp, fwxm, fwxp, fwym, fwyp, nzb_diff_s_inner, nzb_diff_s_outer, nzb_diff_u )       &
413    !$acc       copyin( nzb_diff_v, nzb_s_inner, nzb_s_outer, nzb_u_inner )    &
414    !$acc       copyin( nzb_u_outer, nzb_v_inner, nzb_v_outer, nzb_w_inner )   &
415    !$acc       copyin( nzb_w_outer, rflags_invers, rflags_s_inner, rmask, wall_heatflux, wall_e_x, wall_e_y, wall_u, wall_v, wall_w_x, wall_w_y, wall_flags_0, wall_flags_00 )  &
416    !$acc       copyin( ngp_2dh, ngp_2dh_s_inner )  &
417    !$acc       copyin( weight_pres, weight_substep )
418!
419!-- Integration of the model equations using timestep-scheme
420    CALL time_integration
421
422!
423!-- If required, write binary data for restart runs
424    IF ( write_binary(1:4) == 'true' )  THEN
425
426       CALL cpu_log( log_point(22), 'write_3d_binary', 'start' )
427
428       CALL location_message( 'writing restart data', .FALSE. )
429
430       CALL check_open( 14 )
431
432       DO  i = 0, io_blocks-1
433          IF ( i == io_group )  THEN
434!
435!--          Write flow field data
436             CALL write_3d_binary
437          ENDIF
438#if defined( __parallel )
439          CALL MPI_BARRIER( comm2d, ierr )
440#endif
441       ENDDO
442
443       CALL location_message( 'finished', .TRUE. )
444
445       CALL cpu_log( log_point(22), 'write_3d_binary', 'stop' )
446
447!
448!--    If required, write particle data
449       IF ( particle_advection )  CALL lpm_write_restart_file
450    ENDIF
451
452!
453!-- If required, repeat output of header including the required CPU-time
454    IF ( myid == 0 )  CALL header
455!
456!-- If required, final land surface and user-defined actions, and
457!-- last actions on the open files and close files. Unit 14 was opened
458!-- in write_3d_binary but it is closed here, to allow writing on this
459!-- unit in routine user_last_actions.
460    CALL cpu_log( log_point(4), 'last actions', 'start' )
461    DO  i = 0, io_blocks-1
462       IF ( i == io_group )  THEN
463          IF ( land_surface )  THEN
464             CALL lsm_last_actions
465          ENDIF
466          IF ( radiation )  THEN
467             CALL radiation_last_actions
468          ENDIF
469          CALL user_last_actions
470          IF ( write_binary(1:4) == 'true' )  CALL close_file( 14 )
471       ENDIF
472#if defined( __parallel )
473       CALL MPI_BARRIER( comm2d, ierr )
474#endif
475    ENDDO
476    CALL close_file( 0 )
477    CALL close_dvrp
478    CALL cpu_log( log_point(4), 'last actions', 'stop' )
479
480#if defined( __mpi2 )
481!
482!-- Test exchange via intercommunicator in case of a MPI-2 coupling
483    IF ( coupling_mode == 'atmosphere_to_ocean' )  THEN
484       i = 12345 + myid
485       CALL MPI_SEND( i, 1, MPI_INTEGER, myid, 11, comm_inter, ierr )
486    ELSEIF ( coupling_mode == 'ocean_to_atmosphere' )  THEN
487       CALL MPI_RECV( i, 1, MPI_INTEGER, myid, 11, comm_inter, status, ierr )
488       PRINT*, '### myid: ', myid, '   received from atmosphere:  i = ', i
489    ENDIF
490#endif
491
492!
493!-- Close the OpenACC dummy data region
494    !$acc end data
495    !$acc end data
496
497!
498!-- Take final CPU-time for CPU-time analysis
499    CALL cpu_log( log_point(1), 'total', 'stop' )
500    CALL cpu_statistics
501
502#if defined( __parallel )
503    CALL MPI_FINALIZE( ierr )
504#endif
505
506 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.