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

Last change on this file since 3649 was 3560, checked in by raasch, 6 years ago

bugfix to guarantee correct particle releases in case that the release interval is smaller than the model timestep

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