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

Last change on this file since 2296 was 2296, checked in by maronga, 4 years ago

added new spinup mechanism for surface/radiation models

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