-
Notifications
You must be signed in to change notification settings - Fork 68
/
trees_pre_ls.f90
285 lines (213 loc) · 7.92 KB
/
trees_pre_ls.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
!!
!! Copyright (C) 2009-2013 Johns Hopkins University
!!
!! This file is part of lesgo.
!!
!! lesgo is free software: you can redistribute it and/or modify
!! it under the terms of the GNU General Public License as published by
!! the Free Software Foundation, either version 3 of the License, or
!! (at your option) any later version.
!!
!! lesgo is distributed in the hope that it will be useful,
!! but WITHOUT ANY WARRANTY; without even the implied warranty of
!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
!! GNU General Public License for more details.
!!
!! You should have received a copy of the GNU General Public License
!! along with lesgo. If not, see <http://www.gnu.org/licenses/>.
!!
module trees_pre_ls_mod
contains
subroutine trees_pre_ls
use types, only : rprec
use param, only : path
use param, only : nx, ny, nz, BOGUS, nproc
use input_util, only : read_input_conf
use trees_base_ls, only : grid_initialize, pt_of_grid
use trees_setup_ls, only : fill_tree_array, sdistfcn_tree_array
use trees_io_ls, only : draw_tree_array
use trees_global_fmask_ls, only : global_fmask_init, calc_global_fmask_ta
implicit none
!character (*), parameter :: ftrees_conf = path // 'trees.conf'
character (*), parameter :: fdraw_out = path // 'draw_tree_array.dat'
character (*), parameter :: fphi_out = path // 'phi.dat'
character (*), parameter :: fphi_raw_out = path // 'phi.out'
character (*), parameter :: fbrindex_out = path // 'brindex.dat'
character (*), parameter :: fbrindex_raw_out = path // 'brindex.out'
logical, parameter :: do_write_ascii = .false.
logical, parameter :: do_calc_global_fmask = .false.
!--may choose to connect np with nproc in params and
! MPI_split with $MPI
character (*), parameter :: MPI_suffix = '.c'
#ifdef PPMPI
logical, parameter :: MPI_split = .true.
#else
logical, parameter :: MPI_split = .false.
#endif
character (128) :: fphi_out_MPI, fphi_raw_out_MPI
character (128) :: fbrindex_out_MPI, fbrindex_raw_out_MPI
integer :: ip, ipmin, ipmax
integer :: i, j, k, ktot
integer :: lbz, ubz
integer, allocatable :: brindex(:, :, :)
real (rprec), allocatable :: phi(:, :, :)
real (rprec) :: x, y, z
!---------------------------------------------------------------------
! Now load the lesgo case information from lesgo.conf
call read_input_conf()
if (MPI_split) then
! !--prompt user for chunks to process
! write (*, '(1x,a,2(i0,a))') 'Enter starting chunk (', 0, '..', nproc-1, '):'
! read (*, *) ipmin
! write (*, *) 'read ipmin = ', ipmin
! write (*, '(1x,a,2(i0,a))') 'Enter ending chunk (', ipmin, '..', nproc-1, '):'
! read (*, *) ipmax
! write (*, *) 'read ipmax = ', ipmax
ipmin = 0
ipmax = nproc - 1
if ((ipmin < 0) .or. (ipmin > nproc - 1)) then
write (*, *) 'invalid ipmin = ', ipmin
stop
else if ((ipmax < ipmin) .or. (ipmax > nproc - 1)) then
write (*, *) 'invalid ipmax = ', ipmax
stop
end if
else
if (nproc /= 1) then
write (*, *) 'nproc must be 1 for when MPI_split is false'
stop
end if
ipmin = 0
ipmax = nproc - 1
end if
call grid_initialize ()
call fill_tree_array ()
! call draw_tree_array (fdraw_out)
allocate ( phi( nx+2, ny, 0:nz ) )
allocate ( brindex( nx+2, ny, nz ) )
!--nx+2 to be compatible with other stuff
!--0-level added for MPI stuff
do ip = ipmin, ipmax
call sdistfcn_tree_array (ip, (/ nx+2, ny, nz /), phi, brindex)
if (ip == 0) phi(:, :, 0) = BOGUS
write (*, '(1x,a,i0,a,i0)') 'chunk ', ip, ' of ', nproc-1
!write (*, *) 'nproc = ', nproc
!write (*, *) 'trees_pre: size (phi)= ', size (phi, 1), size (phi, 2), &
! size (phi, 3) - 1 !--(-1) since ignore 0-level
!--not sure whether to make phi(nz_global) = BOGUS or not, for now
! it is left as a valid value
if (MPI_split) then
write (fphi_raw_out_MPI, '(a,a,i0)') trim (fphi_raw_out), MPI_suffix, ip
open (1, file=fphi_raw_out_MPI, form='unformatted')
!--note some overlap here for local 0, nz levels (less MPI comms later)
!lbz = ip * (nz - 1) / nproc !--0 level (local)
!ubz = lbz + (nz - 1) / nproc + 1 !--nz level (local)
write (1) phi(:, :, 0:nz) !--each file gets 0:nz_local
close (1)
!
! !--branch index
! write (fbrindex_raw_out_MPI, '(a,a,i0)') trim (fbrindex_raw_out), &
! MPI_suffix, ip
! open (1, file=fbrindex_raw_out_MPI, form='unformatted')
!
! !--overlap is different from above: brindex is only 1:nz_local-1
! !lbz = ip * (nz - 1) / nproc + 1 !--1 level (local)
! !ubz = lbz + (nz - 1) / nproc - 1 !--nz-1 level (local)
!
! write (1) brindex(:, :, 1:nz-1)
!
! close (1)
if (do_write_ascii) then !--ascii-files for checking
!--phi
write (fphi_out_MPI, '(a,a,i0)') trim (fphi_out), MPI_suffix, ip
open (1, file=fphi_out_MPI)
write (1, '(a)') 'variables = "x" "y" "z" "phi"'
write (1, '(3(a,i0))') 'zone, f=point, i=', nx, ', j=', ny, &
', k=', nz + 1
!lbz = ip * (nz - 1) / nproc !--0-level
!ubz = lbz + (nz - 1) / nproc + 1 !--nz-level
do k = 0, nz
ktot = ip * (nz - 1) + k
do j = 1, ny
do i = 1, nx
x = pt_of_grid (i, 1, 1)
y = pt_of_grid (j, 2, 1)
z = pt_of_grid (ktot, 3, 1)
!--when ip == 0, this will write out BOGUS for k = 0
write (1, '(4(1x,es12.5))') x, y, z, phi(i, j, k)
end do
end do
end do
close (1)
!--brindex
write (fbrindex_out_MPI, '(a,a,i0)') trim (fbrindex_out), &
MPI_suffix, ip
open (1, file=fbrindex_out_MPI)
write (1, '(a)') 'variables = "x" "y" "z" "brindex"'
write (1, '(3(a,i0))') 'zone, f=point, i=', nx, ', j=', ny, &
', k=', nz - 1
!lbz = ip * (nz - 1) / nproc + 1 !--1 level
!ubz = lbz + (nz - 1) / nproc - 1 !--nz-1 level
do k = 1, nz-1
ktot = ip * (nz - 1) + k
do j = 1, ny
do i = 1, nx
x = pt_of_grid (i, 1, 1)
y = pt_of_grid (j, 2, 1)
z = pt_of_grid (ktot, 3, 1)
!--when ip == 0, this will write out BOGUS for k = 0
write (1, '(3(es12.5,1x),i0)') x, y, z, brindex(i, j, k)
end do
end do
end do
close (1)
end if
else !--no MPI_split (ip = 1)
open (1, file=fphi_raw_out, form='unformatted')
write (1) phi(:, :, 1:nz) !--all k = 1:nz are valid here
close (1)
open (1, file=fbrindex_raw_out, form='unformatted')
write (1) brindex(:, :, 1:nz)
close (1)
if (do_write_ascii) then
!--ascii-file
open (1, file=fphi_out)
write (1, '(a)') 'variables = "x" "y" "z" "phi"'
write (1, '(3(a,i0))') 'zone, f=point, i=', nx, ', j=', ny, ', k=', nz
do k = 1, nz
do j = 1, ny
do i = 1, nx
x = pt_of_grid (i, 1, 1)
y = pt_of_grid (j, 2, 1)
z = pt_of_grid (k, 3, 1)
write (1, '(4(es12.5,1x))') x, y, z, phi(i, j, k)
end do
end do
end do
close (1)
open (1, file=fbrindex_out)
write (1, '(a)') 'variables = "x" "y" "z" "brindex"'
write (1, '(3(a,i0))') 'zone, f=point, i=', nx, ', j=', ny, ', k=', nz
do k = 1, nz
do j = 1, ny
do i = 1, nx
x = pt_of_grid (i, 1, 1)
y = pt_of_grid (j, 2, 1)
z = pt_of_grid (k, 3, 1)
write (1, '(3(es12.5,1x),i0)') x, y, z, brindex(i, j, k)
end do
end do
end do
close (1)
end if
end if
end do
deallocate ( brindex )
deallocate ( phi )
if (do_calc_global_fmask) then !--global fmask initialization
call global_fmask_init()
call calc_global_fmask_ta ( nproc, MPI_split )
!--this also writes to file, which is why we pass MPI stuff
end if
end subroutine trees_pre_ls
end module trees_pre_ls_mod