-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_field.f90
245 lines (226 loc) · 14.8 KB
/
build_field.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
!Crown Copyright 2014 AWE.
!
! This file is part of TeaLeaf.
!
! TeaLeaf 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.
!
! TeaLeaf 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
! TeaLeaf. If not, see http://www.gnu.org/licenses/.
!> @brief Allocates the data for each mesh chunk
!> @author David Beckingsale, Wayne Gaudin
!> @details The data fields for the mesh chunk are allocated based on the mesh
!> size.
SUBROUTINE build_field(chunk,x_cells,y_cells,z_cells)
USE tea_module
IMPLICIT NONE
INTEGER :: chunk,x_cells,y_cells,z_cells,j,k,l
chunks(chunk)%field%x_min=1
chunks(chunk)%field%y_min=1
chunks(chunk)%field%z_min=1
chunks(chunk)%field%x_max=x_cells
chunks(chunk)%field%y_max=y_cells
chunks(chunk)%field%z_max=z_cells
ALLOCATE(chunks(chunk)%field%density (chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%energy0 (chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%energy1 (chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%u(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%u0(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_p(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_r(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_rstore(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_rtemp(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_utemp(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_Mi(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_w(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_z(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_Kx(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_Ky(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_Kz(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%vector_sd(chunks(chunk)%field%x_min-halo_exchange_depth:chunks(chunk)%field%x_max+halo_exchange_depth, &
chunks(chunk)%field%y_min-halo_exchange_depth:chunks(chunk)%field%y_max+halo_exchange_depth, &
chunks(chunk)%field%z_min-halo_exchange_depth:chunks(chunk)%field%z_max+halo_exchange_depth))
ALLOCATE(chunks(chunk)%field%tri_bfp(chunks(chunk)%field%x_min:chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min:chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min:chunks(chunk)%field%z_max))
ALLOCATE(chunks(chunk)%field%tri_cp(chunks(chunk)%field%x_min:chunks(chunk)%field%x_max, &
chunks(chunk)%field%y_min:chunks(chunk)%field%y_max, &
chunks(chunk)%field%z_min:chunks(chunk)%field%z_max))
ALLOCATE(chunks(chunk)%field%cellx (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+2))
ALLOCATE(chunks(chunk)%field%celly (chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+2))
ALLOCATE(chunks(chunk)%field%cellz (chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+2))
ALLOCATE(chunks(chunk)%field%vertexx (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+3))
ALLOCATE(chunks(chunk)%field%vertexy (chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+3))
ALLOCATE(chunks(chunk)%field%vertexz (chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+3))
ALLOCATE(chunks(chunk)%field%celldx (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+2))
ALLOCATE(chunks(chunk)%field%celldy (chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+2))
ALLOCATE(chunks(chunk)%field%celldz (chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+2))
ALLOCATE(chunks(chunk)%field%vertexdx(chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+3))
ALLOCATE(chunks(chunk)%field%vertexdy(chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+3))
ALLOCATE(chunks(chunk)%field%vertexdz(chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+3))
ALLOCATE(chunks(chunk)%field%volume (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+2, &
chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+2, &
chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+2))
ALLOCATE(chunks(chunk)%field%xarea (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+3, &
chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+2, &
chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+2))
ALLOCATE(chunks(chunk)%field%yarea (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+2, &
chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+3, &
chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+2))
ALLOCATE(chunks(chunk)%field%zarea (chunks(chunk)%field%x_min-2:chunks(chunk)%field%x_max+2, &
chunks(chunk)%field%y_min-2:chunks(chunk)%field%y_max+2, &
chunks(chunk)%field%z_min-2:chunks(chunk)%field%z_max+3))
! Zeroing isn't strictly neccessary but it ensures physical pages
! are allocated. This prevents first touch overheads in the main code
! cycle which can skew timings in the first step
! Explicit loop limits ensures correct NUMA access, which array syntax does
! not
!$OMP PARALLEL
!$OMP DO
DO l=chunks(chunk)%field%z_min-halo_exchange_depth,chunks(chunk)%field%z_max+halo_exchange_depth
DO k=chunks(chunk)%field%y_min-halo_exchange_depth,chunks(chunk)%field%y_max+halo_exchange_depth
DO j=chunks(chunk)%field%x_min-halo_exchange_depth,chunks(chunk)%field%x_max+halo_exchange_depth
chunks(chunk)%field%density(j,k,l)=0.0
chunks(chunk)%field%energy0(j,k,l)=0.0
chunks(chunk)%field%energy1(j,k,l)=0.0
chunks(chunk)%field%u(j,k,l)=0.0
chunks(chunk)%field%u0(j,k,l)=0.0
chunks(chunk)%field%vector_r(j,k,l)=0.0
chunks(chunk)%field%vector_rstore(j,k,l)=0.0
chunks(chunk)%field%vector_rtemp(j,k,l)=0.0
chunks(chunk)%field%vector_utemp(j,k,l)=0.0
chunks(chunk)%field%vector_Mi(j,k,l)=0.0
chunks(chunk)%field%vector_w(j,k,l)=0.0
chunks(chunk)%field%vector_z(j,k,l)=0.0
chunks(chunk)%field%vector_Kx(j,k,l)=0.0
chunks(chunk)%field%vector_Ky(j,k,l)=0.0
chunks(chunk)%field%vector_p(j,k,l)=0.0
chunks(chunk)%field%vector_sd(j,k,l)=0.0
chunks(chunk)%field%vector_Kz(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP ENDDO
!$OMP DO
DO l=chunks(chunk)%field%z_min,chunks(chunk)%field%z_max
DO k=chunks(chunk)%field%y_min,chunks(chunk)%field%y_max
DO j=chunks(chunk)%field%x_min,chunks(chunk)%field%x_max
chunks(chunk)%field%tri_cp(j,k,l)=0.0
chunks(chunk)%field%tri_bfp(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP ENDDO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+2
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+2
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+2
chunks(chunk)%field%volume(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP ENDDO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+2
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+2
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+3
chunks(chunk)%field%xarea(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+2
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+3
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+2
chunks(chunk)%field%yarea(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+3
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+2
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+2
chunks(chunk)%field%zarea(j,k,l)=0.0
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP DO
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+2
chunks(chunk)%field%cellx(j)=0.0
chunks(chunk)%field%celldx(j)=0.0
ENDDO
!$OMP END DO
!$OMP DO
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+2
chunks(chunk)%field%celly(k)=0.0
chunks(chunk)%field%celldy(k)=0.0
ENDDO
!$OMP END DO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+2
chunks(chunk)%field%cellz(l)=0.0
chunks(chunk)%field%celldz(l)=0.0
ENDDO
!$OMP END DO
!$OMP DO
DO j=chunks(chunk)%field%x_min-2,chunks(chunk)%field%x_max+3
chunks(chunk)%field%vertexx(j)=0.0
chunks(chunk)%field%vertexdx(j)=0.0
ENDDO
!$OMP END DO
!$OMP DO
DO k=chunks(chunk)%field%y_min-2,chunks(chunk)%field%y_max+3
chunks(chunk)%field%vertexy(k)=0.0
chunks(chunk)%field%vertexdy(k)=0.0
ENDDO
!$OMP END DO
!$OMP DO
DO l=chunks(chunk)%field%z_min-2,chunks(chunk)%field%z_max+3
chunks(chunk)%field%vertexz(l)=0.0
chunks(chunk)%field%vertexdz(l)=0.0
ENDDO
!$OMP END DO
!$OMP END PARALLEL
END SUBROUTINE build_field