source: palm/trunk/SOURCE/lpm_read_restart_file.f90 @ 3046

Last change on this file since 3046 was 3046, checked in by Giersch, 6 years ago

Remaining error messages revised, comments extended

  • Property svn:keywords set to Id
File size: 7.2 KB
Line 
1!> @file lpm_read_restart_file.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! Error messages revised
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_read_restart_file.f90 3046 2018-05-29 08:02:15Z Giersch $
27! Error messages revised, code adjusted according to PALMs coding standard
28!
29! 2718 2018-01-02 08:49:38Z maronga
30! Corrected "Former revisions" section
31!
32! 2696 2017-12-14 17:12:51Z kanani
33! Change in file header (GPL part)
34!
35! 2606 2017-11-10 10:36:31Z schwenkel
36! Changed particle box locations: center of particle box now coincides
37! with scalar grid point of same index.
38! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
39! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
40! lpm_sort -> lpm_sort_timeloop_done
41!
42! 2312 2017-07-14 20:26:51Z hoffmann
43! Extended particle data type.
44!
45! 2305 2017-07-06 11:18:47Z hoffmann
46! Improved calculation of particle IDs.
47!
48! 2265 2017-06-08 16:58:28Z schwenkel
49! Unused variables removed.
50!
51! 2101 2017-01-05 16:42:31Z suehring
52!
53! 2000 2016-08-20 18:09:15Z knoop
54! Forced header and separation lines into 80 columns
55!
56! 1822 2016-04-07 07:49:42Z hoffmann
57! Tails removed. Unused variables removed.
58!
59! 1682 2015-10-07 23:56:08Z knoop
60! Code annotations made doxygen readable
61!
62! 1359 2014-04-11 17:15:14Z hoffmann
63! New particle structure integrated.
64!
65! 1320 2014-03-20 08:40:49Z raasch
66! ONLY-attribute added to USE-statements,
67! comment fields (!:) to be used for variable explanations added to
68! all variable declaration statements
69!
70! 1036 2012-10-22 13:43:42Z raasch
71! code put under GPL (PALM 3.9)
72!
73! 849 2012-03-15 10:35:09Z raasch
74! initial revision (former part of init_particles)
75!
76!
77! Description:
78! ------------
79!> Read particle data from the restart file.
80!------------------------------------------------------------------------------!
81 SUBROUTINE lpm_read_restart_file
82
83
84    USE control_parameters,                                                    &
85        ONLY:  message_string
86
87    USE indices,                                                               &
88        ONLY:  nxl, nxlg, nxr, nxrg, nyn, nyng, nys, nysg, nzb, nzt
89
90    USE kinds
91
92    USE lpm_pack_and_sort_mod,                                                   &
93        ONLY:  lpm_sort_in_subboxes
94
95    USE particle_attributes,                                                   &
96        ONLY:  alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,         &
97               grid_particles, min_nr_particle, number_of_particles,           &
98               number_of_particle_groups, particle_groups, particle_type,      &
99               prt_count, time_prel, time_write_particle_data, zero_particle
100
101    USE pegrid
102
103    IMPLICIT NONE
104
105    CHARACTER (LEN=10) ::  particle_binary_version    !<
106    CHARACTER (LEN=10) ::  version_on_file            !<
107
108    INTEGER(iwp) :: alloc_size !<
109    INTEGER(iwp) :: ip         !<
110    INTEGER(iwp) :: jp         !<
111    INTEGER(iwp) :: kp         !<
112
113    TYPE(particle_type), DIMENSION(:), ALLOCATABLE :: tmp_particles !<
114
115!
116!-- Read particle data from previous model run.
117!-- First open the input unit.
118    IF ( myid_char == '' )  THEN
119       OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN'//myid_char,                  &
120                  FORM='UNFORMATTED' )
121    ELSE
122       OPEN ( 90, FILE='PARTICLE_RESTART_DATA_IN/'//myid_char,                 &
123                  FORM='UNFORMATTED' )
124    ENDIF
125
126!
127!-- First compare the version numbers
128    READ ( 90 )  version_on_file
129    particle_binary_version = '4.0'
130    IF ( TRIM( version_on_file ) /= TRIM( particle_binary_version ) )  THEN
131       message_string = 'version mismatch concerning data from prior ' //      &
132                        'run &version on file = "' //                          &
133                                      TRIM( version_on_file ) //               &
134                        '&version in program = "' //                           &
135                                      TRIM( particle_binary_version ) // '"'
136       CALL message( 'lpm_read_restart_file', 'PA0214', 1, 2, 0, 6, 0 )
137    ENDIF
138
139!
140!-- If less particles are stored on the restart file than prescribed by
141!-- min_nr_particle, the remainder is initialized by zero_particle to avoid
142!-- errors.
143    zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
144                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
145                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
146                                   0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,     &
147                                   0, 0, 0_idp, .FALSE., -1 )
148!
149!-- Read some particle parameters and the size of the particle arrays,
150!-- allocate them and read their contents.
151    READ ( 90 )  bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,                     &
152                 number_of_particle_groups, particle_groups, time_prel,        &
153                 time_write_particle_data
154
155    ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg),                        &
156              grid_particles(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
157
158    READ ( 90 )  prt_count
159
160    DO  ip = nxl, nxr
161       DO  jp = nys, nyn
162          DO  kp = nzb+1, nzt
163
164             number_of_particles = prt_count(kp,jp,ip)
165             IF ( number_of_particles > 0 )  THEN
166                alloc_size = MAX( INT( number_of_particles *                   &
167                             ( 1.0_wp + alloc_factor / 100.0_wp ) ),           &
168                             min_nr_particle )
169             ELSE
170                alloc_size = min_nr_particle
171             ENDIF
172
173             ALLOCATE( grid_particles(kp,jp,ip)%particles(1:alloc_size) )
174
175             IF ( number_of_particles > 0 )  THEN
176                ALLOCATE( tmp_particles(1:number_of_particles) )
177                READ ( 90 )  tmp_particles
178                grid_particles(kp,jp,ip)%particles(1:number_of_particles) = tmp_particles
179                DEALLOCATE( tmp_particles )
180                IF ( number_of_particles < alloc_size )  THEN
181                   grid_particles(kp,jp,ip)%particles(number_of_particles+1:alloc_size) &
182                      = zero_particle
183                ENDIF
184             ELSE
185                grid_particles(kp,jp,ip)%particles(1:alloc_size) = zero_particle
186             ENDIF
187
188          ENDDO
189       ENDDO
190    ENDDO
191
192    CLOSE ( 90 )
193!
194!-- Must be called to sort particles into blocks, which is needed for a fast
195!-- interpolation of the LES fields on the particle position.
196    CALL lpm_sort_in_subboxes
197
198
199 END SUBROUTINE lpm_read_restart_file
Note: See TracBrowser for help on using the repository browser.