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

Last change on this file since 2011 was 2011, checked in by kanani, 5 years ago

changes related to steering and formating of urban surface model

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