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

Last change on this file since 2292 was 2292, checked in by schwenkel, 7 years ago

implementation of new bulk microphysics scheme

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