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

Last change on this file since 2939 was 2903, checked in by hellstea, 7 years ago

Nesting-related calls to pmci_ensure_nest_mass_conservation and pres after the nest initialization are removed as they may create unwanted initial perturbation in some cases

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