-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcase_division.f90
379 lines (350 loc) · 17.2 KB
/
case_division.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
module case_division
use precision, only: dp
use input, only: level_py, partition
use array, only: pyramid_grid, cartesian_grid
implicit none
contains
subroutine pyramid_case
implicit none
integer :: i,j,k,n
real(kind=dp) :: i1,i2,i3,i4
real(kind=dp) :: j1,j2,j3,j4
integer :: partition_i, partition_j
integer :: a1,a2,a3
integer :: b1,b2,b3
real(kind=dp) :: ha1,ha2
real(kind=dp) :: hb1,hb2
! Find out how Cartedian coordinate line partition the pyramid cell
do k = 1,level_py
do i = 1,partition(k)
do j = 1,partition(k)
partition_i = 0
partition_j = 0
n = real(partition(k))
! x = i1 is the line at the bottom left of pyramidal cell
i1 = real(i-1)*real(k-1)/n
! x = i2 is the line at the top left of pyramidal cell
i2 = real(i-1)*real(k)/n
! x = i3 is the line at the bottom right of pyramidal cell
i3 = real(i)*real(k-1)/n
! x = i4 is the line at the top right of pyramidal cell
i4 = real(i)*real(k)/n
! y = j1 is the line at the bottom down of pyramidal cell
j1 = real(j-1)*real(k-1)/n
! y = j2 is the line at the top down of pyramidal cell
j2 = real(j-1)*real(k)/n
! y = j3 is the line at the bottom up of pyramidal cell
j3 = real(j)*real(k-1)/n
! y = j4 is the line at the top up of pyramidal cell
j4 = real(j)*real(k)/n
if (int(i4)-int(i1).eq.0) then
partition_i = 1
a1 = int(i1) + 1
elseif (int(i4)-int(i1).eq.1 .and. i4-int(i4).le.0.00000001) then
partition_i = 1
a1 = int(i4)
elseif (int(i4)-int(i1).eq.1 .and. i4-int(i4).gt.0.00000001) then
partition_i = 2
a1 = int(i4)
a2 = int(i4) + 1
!come back to this later
!if (i2.le.i3) then
if (i1.le.a1 .and. a1.le.i2) then
ha1 = real(a1)/real(i-1)
elseif (i3.le.a1 .and. a1.le.i4) then
ha1 = real(a1)/real(i)
endif
! else
!if (i3.lt.a1 .and. a1.lt.i2) write(*,*) 'ewsfewgferg'
!if (a1.lt.i3 .and. i3.lt.i2) write(*,*) 'yyyyrtret43654654'
!if (i3.lt.i2 .and. i2.lt.a1) write(*,*) 'ooooooooooooooooo'
! end
elseif (int(i4)-int(i1).eq.2 .and. i4-int(i4).le.0.00000001) then
partition_i = 2
a1 = int(i1) + 1
a2 = int(i4)
if (i1.le.a1 .and. a1.le.i2) then
ha1 = real(a1)/real(i-1)
elseif (i3.le.a1 .and. a1.le.i4) then
ha1 = real(a1)/real(i)
endif
elseif (int(i4)-int(i1).eq.2 .and. i4-int(i4).gt.0.00000001) then
partition_i = 3
a1 = int(i1) + 1
a2 = int(i4)
a3 = int(i4) + 1
ha1 = real(a1)/real(i-1)
ha2 = real(a2)/real(i)
endif
if (int(j4)-int(j1).eq.0) then
partition_j = 1
b1 = int(j1) + 1
elseif (int(j4)-int(j1).eq.1 .and. j4-int(j4).le.0.00000001) then
partition_j = 1
b1 = int(j4)
elseif (int(j4)-int(j1).eq.1 .and. j4-int(j4).gt.0.00000001) then
partition_j = 2
b1 = int(j4)
b2 = int(j4) + 1
if (j1.le.b1 .and. b1.le.j2) then
hb1 = real(b1)/real(j-1)
elseif (j3.le.b1 .and. b1.le.j4) then
hb1 = real(b1)/real(j)
endif
elseif (int(j4)-int(j1).eq.2 .and. j4-int(j4).le.0.00000001) then
partition_j = 2
b1 = int(j1) + 1
b2 = int(j4)
if (j1.le.b1 .and. b1.le.j2) then
hb1 = real(b1)/real(j-1)
elseif (j3.le.b1 .and. b1.le.j4) then
hb1 = real(b1)/real(j)
endif
elseif (int(j4)-int(j1).eq.2 .and. j4-int(j4).gt.0.00000001) then
partition_j = 3
b1 = int(j1) + 1
b2 = int(j4)
b3 = int(j4) + 1
hb1 = real(b1)/real(j-1)
hb2 = real(b2)/real(j)
endif
! There are 42 different partition cases
if (partition_i.eq.1 .and. partition_j.eq.1) then
pyramid_grid(k)%case(i,j) = 1
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a1,b1:b1))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (partition_i.eq.2 .and. partition_j.eq.1) then
if (i1.le.a1 .and. a1.le.i2) then
pyramid_grid(k)%case(i,j) = 2
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b1))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i2.le.a1 .and. a1.le.i3) then
pyramid_grid(k)%case(i,j) = 3
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b1))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i3.le.a1 .and. a1.le.i4) then
pyramid_grid(k)%case(i,j) = 4
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b1))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (partition_i.eq.1 .and. partition_j.eq.2) then
if (j1.le.b1 .and. b1.le.j2) then
pyramid_grid(k)%case(i,j) = 5
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a1,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (j2.le.b1 .and. b1.le.j3) then
pyramid_grid(k)%case(i,j) = 6
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a1,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (j3.le.b1 .and. b1.le.j4) then
pyramid_grid(k)%case(i,j) = 7
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a1,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (partition_i.eq.2 .and. partition_j.eq.2) then
if (j1.le.b1 .and. b1.le.j2) then
if (i1.le.a1 .and. a1.le.i2) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 8
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.lt.hb1) then
pyramid_grid(k)%case(i,j) = 9
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (i2.le.a1 .and. a1.le.i3) then
pyramid_grid(k)%case(i,j) = 10
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i3.le.a1 .and. a1.le.i4) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 11
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.lt.hb1) then
pyramid_grid(k)%case(i,j) = 12
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
endif
elseif (j2.le.b1 .and. b1.le.j3) then
if (i1.le.a1 .and. a1.le.i2) then
pyramid_grid(k)%case(i,j) = 13
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i2.le.a1 .and. a1.le.i3) then
pyramid_grid(k)%case(i,j) = 14
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i3.le.a1 .and. a1.le.i4) then
pyramid_grid(k)%case(i,j) = 15
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (j3.le.b1 .and. b1.le.j4) then
if (i1.le.a1 .and. a1.le.i2) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 16
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.lt.hb1) then
pyramid_grid(k)%case(i,j) = 17
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (i2.le.a1 .and. a1.le.i3) then
pyramid_grid(k)%case(i,j) = 18
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i3.le.a1 .and. a1.le.i4) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 19
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.lt.hb1) then
pyramid_grid(k)%case(i,j) = 20
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
endif
endif
elseif (partition_i.eq.3 .and. partition_j.eq.1) then
pyramid_grid(k)%case(i,j) = 21
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b1))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (partition_i.eq.1 .and. partition_j.eq.3) then
pyramid_grid(k)%case(i,j) = 22
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a1,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (partition_i.eq.3 .and. partition_j.eq.2) then
if (j1.le.b1 .and. b1.le.j2) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 23
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha2.ge.hb1 .and. hb1.gt.ha1) then
pyramid_grid(k)%case(i,j) = 24
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb1.gt.ha2) then
pyramid_grid(k)%case(i,j) = 25
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
!write(*,*) 'i1',i1,'i2',i2,'i3',i3,'i4',i4,'a1',a1
endif
elseif (j2.le.b1 .and. b1.le.j3) then
pyramid_grid(k)%case(i,j) = 26
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (j3.le.b1 .and. b1.le.j4) then
if (ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 27
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha2.ge.hb1 .and. hb1.gt.ha1) then
pyramid_grid(k)%case(i,j) = 28
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb1.gt.ha2) then
pyramid_grid(k)%case(i,j) = 29
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b2))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
endif
elseif (partition_i.eq.2 .and. partition_j.eq.3) then
if (i1.le.a1 .and. a1.le.i2) then
if (hb1.ge.ha1) then
pyramid_grid(k)%case(i,j) = 30
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb2.ge.ha1 .and. ha1.gt.hb1) then
pyramid_grid(k)%case(i,j) = 31
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.gt.hb2) then
pyramid_grid(k)%case(i,j) = 32
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
elseif (i2.le.a1 .and. a1.le.i3) then
pyramid_grid(k)%case(i,j) = 33
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (i3.le.a1 .and. a1.le.i4) then
if (hb1.ge.ha1) then
pyramid_grid(k)%case(i,j) = 34
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb2.ge.ha1 .and. ha1.gt.hb1) then
pyramid_grid(k)%case(i,j) = 35
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha1.gt.hb2) then
pyramid_grid(k)%case(i,j) = 36
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a2,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
endif
elseif (partition_i.eq.3 .and. partition_j.eq.3) then
if (ha1.ge.hb2) then
pyramid_grid(k)%case(i,j) = 37
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha2.ge.hb2 .and. hb2.gt.ha1 .and. ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 38
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb2.gt.ha2 .and. ha1.ge.hb1) then
pyramid_grid(k)%case(i,j) = 39
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb2.gt.ha2 .and. ha2.ge.hb1 .and. hb1.gt.ha1) then
pyramid_grid(k)%case(i,j) = 40
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (ha2.ge.hb2 .and. hb1.gt.ha1) then
pyramid_grid(k)%case(i,j) = 41
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
elseif (hb1.gt.ha2) then
pyramid_grid(k)%case(i,j) = 42
allocate(pyramid_grid(k)%transform(i,j)%transform_volume(a1:a3,b1:b3))
pyramid_grid(k)%transform(i,j)%transform_volume = 0.0
endif
endif
end do
end do
end do
end subroutine pyramid_case
subroutine cartesian_case
implicit none
integer :: x,y,z,n
integer :: min_i, max_i
integer :: min_j, max_j
!z=1 is treated separatedly
allocate(cartesian_grid(1)%transform(1,1)%transform_volume(1,1))
cartesian_grid(1)%transform(1,1)%transform_volume(1,1) = 0.0
do z = 2,level_py
n = real(partition(z))
do x = 1,z
do y = 1,z
min_i = int(n*real(x-1)/real(z))+1
if (n*real(x)/real(z-1).gt.int(n*real(x)/real(z-1))) then
max_i = int(n*real(x)/real(z-1)+1.0)
elseif (n*real(x)/real(z-1).eq.int(n*real(x)/real(z-1))) then
max_i = int(n*real(x)/real(z-1))
endif
min_j = int(n*real(y-1)/real(z))+1
if (n*real(y)/real(z-1).gt.int(n*real(y)/real(z-1))) then
max_j = int(n*real(y)/real(z-1)+1.0)
elseif (n*real(y)/real(z-1).eq.int(n*real(y)/real(z-1))) then
max_j = int(n*real(y)/real(z-1))
endif
allocate(cartesian_grid(z)%transform(x,y)%transform_volume(min_i:max_i,min_j:max_j))
cartesian_grid(z)%transform(x,y)%transform_volume = 0.0
enddo
enddo
enddo
end subroutine cartesian_case
end module case_division