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

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

changes in the course of urban surface model implementation

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