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

Last change on this file since 2543 was 2512, checked in by raasch, 6 years ago

upper bounds of cross section and 3d output changed from nx+1,ny+1 to nx,ny; no output if redundant ghost layer data to NetCDF files

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