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

Last change on this file since 4411 was 4400, checked in by suehring, 4 years ago

Revision of the virtual-measurement module: data input from NetCDF file; removed binary output - instead parallel NetCDF output using the new data-output module; variable attributes added; further variables added that can be sampled, file connections added; Functions for coordinate transformation moved to basic_constants_and_equations; netcdf_data_input_mod: unused routines netcdf_data_input_att and netcdf_data_input_var removed; new routines to inquire fill values added; Preprocessing script (palm_cvd) to setup virtual-measurement input files provided; postprocessor combine_virtual_measurements deleted

  • Property svn:keywords set to Id
File size: 14.4 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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4400 2020-02-10 20:32:41Z maronga $
27! Add interface to initialize data output with dom
28!
29! 4360 2020-01-07 11:25:50Z suehring
30! implement new palm_date_time_mod
31!
32! 4094 2019-07-12 09:24:21Z gronemeier
33! Corrected "Former revisions" section
34!
35! 4039 2019-06-18 10:32:41Z suehring
36! Rename subroutines in module for diagnostic quantities
37!
38! 4017 2019-06-06 12:16:46Z schwenkel
39! new module for calculation and output of diagnostic quantities added
40!
41! 3885 2019-04-11 11:29:34Z kanani
42! Changes related to global restructuring of location messages and introduction
43! of additional debug messages
44!
45! 3761 2019-02-25 15:31:42Z raasch
46! unused variable removed
47!
48! 3719 2019-02-06 13:10:18Z kanani
49! Included cpu measurement for wall/soil spinup
50!
51! 3703 2019-01-29 16:43:53Z knoop
52! Some interface calls moved to module_interface + cleanup
53!
54! 3648 2019-01-02 16:35:46Z suehring
55! Rename subroutines for surface-data output
56!
57! Revision 1.1  1997/07/24 11:23:35  raasch
58! Initial revision
59!
60!
61! Description:
62! ------------
63!> Large-Eddy Simulation (LES) model for atmospheric and oceanic boundary-layer
64!> flows
65!> see the PALM homepage https://palm-model.org for further information
66!------------------------------------------------------------------------------!
67 PROGRAM palm
68 
69
70    USE arrays_3d
71
72    USE bulk_cloud_model_mod,                                                  &
73        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
74
75    USE control_parameters,                                                    &
76        ONLY:  constant_diffusion, child_domain,                               &
77               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
78               initializing_actions, io_blocks, io_group, message_string,      &
79               neutral, passive_scalar, runnr, simulated_time_chr, spinup,     &
80               time_since_reference_point, user_interface_current_revision,    &
81               user_interface_required_revision, version, write_binary
82
83    USE cpulog,                                                                &
84        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
85
86    USE diagnostic_output_quantities_mod,                                      &
87        ONLY:  doq_calculate
88
89    USE indices,                                                               &
90        ONLY:  nbgp
91
92    USE kinds
93
94    USE module_interface,                                                      &
95        ONLY:  module_interface_init_output,                                   &
96               module_interface_last_actions
97
98
99    USE multi_agent_system_mod,                                                &
100        ONLY:  agents_active, mas_last_actions
101
102    USE netcdf_data_input_mod,                                                 &
103        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
104               netcdf_data_input_surface_data, netcdf_data_input_topo
105
106    USE pegrid
107
108    USE pmc_particle_interface,                                                &
109        ONLY: pmcp_g_alloc_win
110
111    USE pmc_interface,                                                         &
112        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
113               pmci_modelconfiguration, pmci_parent_initialize
114               
115    USE surface_data_output_mod,                                               &
116        ONLY:  surface_data_output_last_action
117
118    USE write_restart_data_mod,                                                &
119        ONLY:  wrd_global, wrd_local
120
121#if defined( __parallel) && defined( _OPENACC )
122    USE openacc
123#endif
124
125
126    IMPLICIT NONE
127
128!
129!-- Local variables
130    CHARACTER(LEN=9) ::  time_to_string  !<
131    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
132#if defined( __parallel) && defined( _OPENACC )
133    INTEGER(iwp)     :: local_comm       !< local communicator (shared memory)
134    INTEGER(iwp)     :: local_num_procs  !< local number of processes
135    INTEGER(iwp)     :: local_id         !< local id
136    INTEGER(acc_device_kind) :: device_type !< device type for OpenACC
137    INTEGER(iwp)     ::  num_devices     !< number of devices visible to OpenACC
138    INTEGER(iwp)     ::  my_device       !< device used by this process
139#endif
140
141    version = 'PALM 6.0'
142    user_interface_required_revision = 'r3703'
143
144#if defined( __parallel )
145!
146!-- MPI initialisation. comm2d is preliminary set, because
147!-- it will be defined in init_pegrid but is used before in cpu_log.
148    CALL MPI_INIT( ierr )
149
150!
151!-- Initialize the coupling for nested-domain runs
152!-- comm_palm is the communicator which includes all PEs (MPI processes)
153!-- available for this (nested) model. If it is not a nested run, comm_palm
154!-- is returned as MPI_COMM_WORLD
155    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
156    CALL pmci_init( comm_palm )
157    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
158    comm2d = comm_palm
159!
160!-- Get the (preliminary) number of MPI processes and the local PE-id (in case
161!-- of a further communicator splitting in init_coupling, these numbers will
162!-- be changed in init_pegrid).
163    IF ( nested_run )  THEN
164
165       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
166       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
167
168    ELSE
169
170       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
171       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
172!
173!--    Initialize PE topology in case of coupled atmosphere-ocean runs (comm_palm
174!--    will be splitted in init_coupling)
175       CALL init_coupling
176    ENDIF
177
178#ifdef _OPENACC
179!
180!-- Select OpenACC device to use in this process. For this find out how many
181!-- neighbors there are running on the same node and which id this process is.
182    IF ( nested_run )  THEN
183       CALL MPI_COMM_SPLIT_TYPE( comm_palm, MPI_COMM_TYPE_SHARED, 0,           &
184                                 MPI_INFO_NULL, local_comm, ierr )
185    ELSE
186       CALL MPI_COMM_SPLIT_TYPE( MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,      &
187                                 MPI_INFO_NULL, local_comm, ierr )
188    ENDIF
189    CALL MPI_COMM_SIZE( local_comm, local_num_procs, ierr )
190    CALL MPI_COMM_RANK( local_comm, local_id, ierr )
191
192!
193!-- This loop including the barrier is a workaround for PGI compiler versions
194!-- up to and including 18.4. Later releases are able to select their GPUs in
195!-- parallel, without running into spurious errors.
196    DO i = 0, local_num_procs-1
197       CALL MPI_BARRIER( local_comm, ierr )
198
199       IF ( i == local_id )  THEN
200          device_type = acc_get_device_type()
201          num_devices = acc_get_num_devices( device_type )
202          my_device = MOD( local_id, num_devices )
203          CALL acc_set_device_num( my_device, device_type )
204       ENDIF
205    ENDDO
206
207    CALL MPI_COMM_FREE( local_comm, ierr )
208#endif
209#endif
210
211!
212!-- Initialize measuring of the CPU-time remaining to the run
213    CALL local_tremain_ini
214
215!
216!-- Start of total CPU time measuring.
217    CALL cpu_log( log_point(1), 'total', 'start' )
218    CALL cpu_log( log_point(2), 'initialisation', 'start' )
219
220!
221!-- Open a file for debug output
222    WRITE (myid_char,'(''_'',I6.6)')  myid
223    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
224
225!
226!-- Initialize dvrp logging. Also, one PE maybe split from the global
227!-- communicator for doing the dvrp output. In that case, the number of
228!-- PEs available for PALM is reduced by one and communicator comm_palm
229!-- is changed respectively.
230#if defined( __parallel )
231    CALL MPI_COMM_RANK( comm_palm, myid, ierr )
232#endif
233
234!
235!-- Read control parameters from NAMELIST files and read environment-variables
236    CALL parin
237
238!
239!-- Check for the user's interface version
240    IF ( user_interface_current_revision /= user_interface_required_revision )  &
241    THEN
242       message_string = 'current user-interface revision "' //                  &
243                        TRIM( user_interface_current_revision ) // '" does ' // &
244                        'not match the required revision ' //                   &
245                        TRIM( user_interface_required_revision )
246        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
247    ENDIF
248
249!
250!-- Determine processor topology and local array indices
251    CALL init_pegrid
252!
253!-- Check if input file according to input-data standard exists
254    CALL netcdf_data_input_inquire_file
255!
256!-- Read topography input data if required. This is required before the
257!-- numerical grid is finally created in init_grid
258    CALL netcdf_data_input_topo 
259!
260!-- Generate grid parameters, initialize generic topography and further process
261!-- topography information if required
262    CALL init_grid
263!
264!-- Read global attributes if available. 
265    CALL netcdf_data_input_init 
266!
267!-- Read surface classification data, e.g. vegetation and soil types, water
268!-- surfaces, etc., if available. Some of these data is required before
269!-- check parameters is invoked.     
270    CALL netcdf_data_input_surface_data
271!
272!-- Check control parameters and deduce further quantities
273    CALL check_parameters
274
275    CALL init_3d_model
276
277    CALL module_interface_init_output
278
279!
280!-- Coupling protocol setup for nested-domain runs
281    IF ( nested_run )  THEN
282       CALL pmci_modelconfiguration
283!
284!--    Receive and interpolate initial data on children.
285!--    Child initialization must be made first if the model is both child and
286!--    parent if necessary
287       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
288          CALL pmci_child_initialize
289!
290!--       Send initial condition data from parent to children
291          CALL pmci_parent_initialize
292!
293!--       Exchange_horiz is needed after the nest initialization
294          IF ( child_domain )  THEN
295             CALL exchange_horiz( u, nbgp )
296             CALL exchange_horiz( v, nbgp )
297             CALL exchange_horiz( w, nbgp )
298             IF ( .NOT. neutral )  THEN
299                CALL exchange_horiz( pt, nbgp )
300             ENDIF
301             IF ( .NOT. constant_diffusion )  CALL exchange_horiz( e, nbgp )
302             IF ( humidity )  THEN
303                CALL exchange_horiz( q, nbgp )
304                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
305                  CALL exchange_horiz( qc, nbgp )
306                  CALL exchange_horiz( nc, nbgp )
307                ENDIF
308                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
309                   CALL exchange_horiz( qr, nbgp ) 
310                   CALL exchange_horiz( nr, nbgp )
311                ENDIF
312             ENDIF
313             IF ( passive_scalar )  CALL exchange_horiz( s, nbgp )
314          ENDIF
315       ENDIF
316
317       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
318    ENDIF
319
320!
321!-- Output of program header
322    IF ( myid == 0 )  CALL header
323
324    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
325
326!
327!-- Integration of the non-atmospheric equations (land surface model, urban
328!-- surface model)
329    IF ( spinup )  THEN
330       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
331       CALL time_integration_spinup
332       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
333    ENDIF
334
335!
336!-- Set start time in format hh:mm:ss
337    simulated_time_chr = time_to_string( time_since_reference_point )
338
339!
340!-- If required, output of initial arrays
341    IF ( do2d_at_begin )  THEN
342       CALL doq_calculate    !TODO, will be called twice
343
344       CALL data_output_2d( 'xy', 0 )
345       CALL data_output_2d( 'xz', 0 )
346       CALL data_output_2d( 'yz', 0 )
347    ENDIF
348
349    IF ( do3d_at_begin )  THEN
350       CALL doq_calculate    !TODO, will be called twice
351
352       CALL data_output_3d( 0 )
353    ENDIF
354
355!
356!-- Integration of the model equations using timestep-scheme
357    CALL time_integration
358
359!
360!-- If required, write binary data for restart runs
361    IF ( write_binary )  THEN
362
363       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
364
365       CALL location_message( 'writing restart data', 'start' )
366
367       DO  i = 0, io_blocks-1
368          IF ( i == io_group )  THEN
369
370!
371!--          Open binary file
372             CALL check_open( 14 )
373!
374!--          Write control parameters and other global variables for restart.
375             IF ( myid == 0 )  CALL wrd_global
376!
377!--          Write processor specific flow field data for restart runs
378             CALL wrd_local
379!
380!--          Close binary file
381             CALL close_file( 14 )
382
383          ENDIF
384#if defined( __parallel )
385          CALL MPI_BARRIER( comm2d, ierr )
386#endif
387       ENDDO
388
389       CALL location_message( 'writing restart data', 'finished' )
390
391       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
392       
393    ENDIF
394!
395!-- Last actions for surface output, for instantaneous and time-averaged data
396    CALL surface_data_output_last_action( 0 )
397    CALL surface_data_output_last_action( 1 )
398
399!
400!-- If required, repeat output of header including the required CPU-time
401    IF ( myid == 0 )  CALL header
402!
403!-- Perform module specific last actions
404    CALL cpu_log( log_point(4), 'last actions', 'start' )
405
406    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
407
408    CALL module_interface_last_actions
409
410    CALL cpu_log( log_point(4), 'last actions', 'stop' )
411
412!
413!-- Close files
414    CALL close_file( 0 )
415
416!
417!-- Write run number to file (used by palmrun to create unified cycle numbers
418!-- for output files
419    IF ( myid == 0  .AND.  runnr > 0 )  THEN
420       OPEN( 90, FILE='RUN_NUMBER', FORM='FORMATTED' )
421       WRITE( 90, '(I4)' )  runnr
422       CLOSE( 90 )
423    ENDIF
424
425!
426!-- Take final CPU-time for CPU-time analysis
427    CALL cpu_log( log_point(1), 'total', 'stop' )
428    CALL cpu_statistics
429
430#if defined( __parallel )
431    CALL MPI_FINALIZE( ierr )
432#endif
433
434 END PROGRAM palm
Note: See TracBrowser for help on using the repository browser.