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

Last change on this file since 4400 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
RevLine 
[4017]1! !> @file palm.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]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!
[4360]17! Copyright 1997-2020 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[1]21! -----------------
[2233]22!
23!
24! Former revisions:
25! -----------------
26! $Id: palm.f90 4400 2020-02-10 20:32:41Z suehring $
[4400]27! Add interface to initialize data output with dom
28!
29! 4360 2020-01-07 11:25:50Z suehring
[4227]30! implement new palm_date_time_mod
31!
32! 4094 2019-07-12 09:24:21Z gronemeier
[4182]33! Corrected "Former revisions" section
34!
35! 4039 2019-06-18 10:32:41Z suehring
[4039]36! Rename subroutines in module for diagnostic quantities
37!
38! 4017 2019-06-06 12:16:46Z schwenkel
[3994]39! new module for calculation and output of diagnostic quantities added
40!
41! 3885 2019-04-11 11:29:34Z kanani
[3885]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
[3761]46! unused variable removed
47!
48! 3719 2019-02-06 13:10:18Z kanani
[3719]49! Included cpu measurement for wall/soil spinup
50!
51! 3703 2019-01-29 16:43:53Z knoop
[3685]52! Some interface calls moved to module_interface + cleanup
53!
54! 3648 2019-01-02 16:35:46Z suehring
[3648]55! Rename subroutines for surface-data output
[3298]56!
[4182]57! Revision 1.1  1997/07/24 11:23:35  raasch
58! Initial revision
59!
60!
[1]61! Description:
62! ------------
[3232]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
[1]66!------------------------------------------------------------------------------!
[1682]67 PROGRAM palm
68 
[1]69
[1374]70    USE arrays_3d
[1]71
[3298]72    USE bulk_cloud_model_mod,                                                  &
73        ONLY: bulk_cloud_model, microphysics_morrison, microphysics_seifert
74
[1320]75    USE control_parameters,                                                    &
[3761]76        ONLY:  constant_diffusion, child_domain,                               &
[3524]77               coupling_char, do2d_at_begin, do3d_at_begin, humidity,          &
78               initializing_actions, io_blocks, io_group, message_string,      &
[3241]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
[1320]82
83    USE cpulog,                                                                &
[2951]84        ONLY:  cpu_log, log_point, log_point_s, cpu_statistics
[1320]85
[3994]86    USE diagnostic_output_quantities_mod,                                      &
[4039]87        ONLY:  doq_calculate
[3994]88
[1374]89    USE indices,                                                               &
[2232]90        ONLY:  nbgp
[1374]91
[3274]92    USE kinds
93
[3687]94    USE module_interface,                                                      &
[4400]95        ONLY:  module_interface_init_output,                                   &
96               module_interface_last_actions
[3687]97
[4400]98
[3235]99    USE multi_agent_system_mod,                                                &
100        ONLY:  agents_active, mas_last_actions
101
[2696]102    USE netcdf_data_input_mod,                                                 &
[3685]103        ONLY:  netcdf_data_input_inquire_file, netcdf_data_input_init,         &
[2696]104               netcdf_data_input_surface_data, netcdf_data_input_topo
105
[1]106    USE pegrid
107
[2894]108    USE pmc_particle_interface,                                                &
109        ONLY: pmcp_g_alloc_win
110
[1762]111    USE pmc_interface,                                                         &
[3241]112        ONLY:  nested_run, pmci_child_initialize, pmci_init,                   &
[3484]113               pmci_modelconfiguration, pmci_parent_initialize
[3494]114               
[3648]115    USE surface_data_output_mod,                                               &
116        ONLY:  surface_data_output_last_action
[1762]117
[2894]118    USE write_restart_data_mod,                                                &
119        ONLY:  wrd_global, wrd_local
[2801]120
[3689]121#if defined( __parallel) && defined( _OPENACC )
122    USE openacc
123#endif
[1747]124
[3689]125
[1]126    IMPLICIT NONE
127
128!
129!-- Local variables
[3241]130    CHARACTER(LEN=9) ::  time_to_string  !<
131    INTEGER(iwp)     ::  i               !< loop counter for blocked I/O
[3689]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
[1]140
[3487]141    version = 'PALM 6.0'
[3703]142    user_interface_required_revision = 'r3703'
[75]143
[1]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 )
[1762]149
150!
151!-- Initialize the coupling for nested-domain runs
[1764]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
[2951]155    CALL cpu_log( log_point_s(70), 'pmci_init', 'start' )
[1762]156    CALL pmci_init( comm_palm )
[2951]157    CALL cpu_log( log_point_s(70), 'pmci_init', 'stop' )
[1762]158    comm2d = comm_palm
[1764]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
[1762]164
[1764]165       CALL MPI_COMM_SIZE( comm_palm, numprocs, ierr )
166       CALL MPI_COMM_RANK( comm_palm, myid, ierr )
[1762]167
[1764]168    ELSE
169
170       CALL MPI_COMM_SIZE( MPI_COMM_WORLD, numprocs, ierr )
171       CALL MPI_COMM_RANK( MPI_COMM_WORLD, myid, ierr )
[1]172!
[1764]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
[3689]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 )
[102]208#endif
[3689]209#endif
[102]210
211!
[1]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!
[206]221!-- Open a file for debug output
[1468]222    WRITE (myid_char,'(''_'',I6.6)')  myid
[206]223    OPEN( 9, FILE='DEBUG'//TRIM( coupling_char )//myid_char, FORM='FORMATTED' )
224
225!
[1]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 )
[102]232#endif
233
234!
[108]235!-- Read control parameters from NAMELIST files and read environment-variables
236    CALL parin
237
238!
[1666]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 )
[1668]246        CALL message( 'palm', 'PA0169', 1, 2, 0, 6, 0 )
[1666]247    ENDIF
248
249!
[108]250!-- Determine processor topology and local array indices
251    CALL init_pegrid
252!
[2696]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
[1]262    CALL init_grid
263!
[2696]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!
[1]272!-- Check control parameters and deduce further quantities
273    CALL check_parameters
[3298]274
[1]275    CALL init_3d_model
276
[4400]277    CALL module_interface_init_output
278
[1]279!
[1762]280!-- Coupling protocol setup for nested-domain runs
[1764]281    IF ( nested_run )  THEN
282       CALL pmci_modelconfiguration
[1781]283!
[1933]284!--    Receive and interpolate initial data on children.
285!--    Child initialization must be made first if the model is both child and
[2177]286!--    parent if necessary
287       IF ( TRIM( initializing_actions ) /= 'read_restart_data' )  THEN
288          CALL pmci_child_initialize
[1781]289!
[2177]290!--       Send initial condition data from parent to children
291          CALL pmci_parent_initialize
[1781]292!
[3232]293!--       Exchange_horiz is needed after the nest initialization
[3182]294          IF ( child_domain )  THEN
[2178]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 )
[3274]304                IF ( bulk_cloud_model  .AND.  microphysics_morrison )  THEN
[2292]305                  CALL exchange_horiz( qc, nbgp )
306                  CALL exchange_horiz( nc, nbgp )
307                ENDIF
[3274]308                IF ( bulk_cloud_model  .AND.  microphysics_seifert )  THEN
[2178]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 )
[1933]314          ENDIF
[1781]315       ENDIF
316
[2801]317       CALL pmcp_g_alloc_win                    ! Must be called after pmci_child_initialize and pmci_parent_initialize
[1764]318    ENDIF
[1762]319
320!
[1]321!-- Output of program header
322    IF ( myid == 0 )  CALL header
323
324    CALL cpu_log( log_point(2), 'initialisation', 'stop' )
325
326!
[2296]327!-- Integration of the non-atmospheric equations (land surface model, urban
328!-- surface model)
329    IF ( spinup )  THEN
[3719]330       CALL cpu_log( log_point(41), 'wall/soil spinup', 'start' )
[2296]331       CALL time_integration_spinup
[3719]332       CALL cpu_log( log_point(41), 'wall/soil spinup', 'stop' )
[2296]333    ENDIF
334
335!
[1]336!-- Set start time in format hh:mm:ss
[2977]337    simulated_time_chr = time_to_string( time_since_reference_point )
[1]338
339!
340!-- If required, output of initial arrays
341    IF ( do2d_at_begin )  THEN
[4039]342       CALL doq_calculate    !TODO, will be called twice
[3994]343
[1]344       CALL data_output_2d( 'xy', 0 )
345       CALL data_output_2d( 'xz', 0 )
346       CALL data_output_2d( 'yz', 0 )
347    ENDIF
[1976]348
[1]349    IF ( do3d_at_begin )  THEN
[4039]350       CALL doq_calculate    !TODO, will be called twice
[3994]351
[1]352       CALL data_output_3d( 0 )
353    ENDIF
354
355!
[495]356!-- Integration of the model equations using timestep-scheme
[1]357    CALL time_integration
358
359!
[495]360!-- If required, write binary data for restart runs
[2298]361    IF ( write_binary )  THEN
[759]362
[2894]363       CALL cpu_log( log_point(22), 'wrd_local', 'start' )
[759]364
[3885]365       CALL location_message( 'writing restart data', 'start' )
[1402]366
[759]367       DO  i = 0, io_blocks-1
368          IF ( i == io_group )  THEN
[2894]369
[1]370!
[2894]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
[759]383          ENDIF
384#if defined( __parallel )
385          CALL MPI_BARRIER( comm2d, ierr )
386#endif
387       ENDDO
388
[3885]389       CALL location_message( 'writing restart data', 'finished' )
[1402]390
[2894]391       CALL cpu_log( log_point(22), 'wrd_local', 'stop' )
[2007]392       
[495]393    ENDIF
[3494]394!
395!-- Last actions for surface output, for instantaneous and time-averaged data
[3648]396    CALL surface_data_output_last_action( 0 )
397    CALL surface_data_output_last_action( 1 )
[1]398
399!
400!-- If required, repeat output of header including the required CPU-time
401    IF ( myid == 0 )  CALL header
402!
[3687]403!-- Perform module specific last actions
[1]404    CALL cpu_log( log_point(4), 'last actions', 'start' )
[3235]405
[3687]406    IF ( myid == 0 .AND. agents_active ) CALL mas_last_actions ! ToDo: move to module_interface
[2894]407
[3687]408    CALL module_interface_last_actions
409
[1]410    CALL cpu_log( log_point(4), 'last actions', 'stop' )
411
412!
[3687]413!-- Close files
414    CALL close_file( 0 )
415
416!
[3232]417!-- Write run number to file (used by palmrun to create unified cycle numbers
418!-- for output files
[2261]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!
[1]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.