forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine_bc_tower.f90
267 lines (174 loc) · 7.92 KB
/
define_bc_tower.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
module define_bc_module
use bl_types
use ml_layout_module
use bc_module
implicit none
type bc_level
! 1st index is the grid number (grid "0" corresponds to the entire problem domain)
! 2nd index is the direction (1=x, 2=y, 3=z)
! 3rd index is the side (1=lo, 2=hi)
! 4th index is the variable (only assuming 1 variable here)
integer, pointer :: phys_bc_level_array(:,:,:) => Null()
integer, pointer :: adv_bc_level_array(:,:,:,:) => Null()
integer, pointer :: ell_bc_level_array(:,:,:,:) => Null()
end type bc_level
type bc_tower
integer :: max_level_built = 0
! an array of bc_levels, one for each level of refinement
type(bc_level), pointer :: bc_tower_array(:) => Null()
! 1st index is the direction (1=x, 2=y, 3=z)
! 2nd index is the side (1=lo, 2=hi)
integer , pointer :: domain_bc(:,:) => Null()
end type bc_tower
private
interface build
module procedure bc_tower_init
module procedure bc_tower_level_build
end interface build
interface destroy
module procedure bc_tower_destroy
end interface destroy
public :: bc_level, bc_tower, bc_tower_init, bc_tower_level_build, bc_tower_destroy, build, destroy
contains
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine bc_tower_init(bct,num_levs,dm,phys_bc_in)
type(bc_tower ), intent( out) :: bct
integer , intent(in ) :: num_levs
integer , intent(in ) :: dm
integer , intent(in ) :: phys_bc_in(:,:)
allocate(bct%bc_tower_array(num_levs))
allocate(bct%domain_bc(dm,2))
bct%domain_bc(:,:) = phys_bc_in(:,:)
end subroutine bc_tower_init
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine bc_tower_level_build(bct,n,la)
type(bc_tower ), intent(inout) :: bct
integer , intent(in ) :: n
type(layout) , intent(in ) :: la
integer :: ngrids,ncomp,dm
ncomp = 1
dm = layout_dim(la)
if (associated(bct%bc_tower_array(n)%phys_bc_level_array)) then
deallocate(bct%bc_tower_array(n)%phys_bc_level_array)
deallocate(bct%bc_tower_array(n)%adv_bc_level_array)
deallocate(bct%bc_tower_array(n)%ell_bc_level_array)
bct%bc_tower_array(n)%phys_bc_level_array => NULL()
bct%bc_tower_array(n)%adv_bc_level_array => NULL()
bct%bc_tower_array(n)%ell_bc_level_array => NULL()
end if
ngrids = layout_nlocal(la)
allocate(bct%bc_tower_array(n)%phys_bc_level_array(0:ngrids,dm,2))
call phys_bc_level_build(bct%bc_tower_array(n)%phys_bc_level_array,la, &
bct%domain_bc)
! Here we allocate 1 component and set the default to be INTERIOR
allocate(bct%bc_tower_array(n)%adv_bc_level_array(0:ngrids,dm,2,ncomp))
call adv_bc_level_build(bct%bc_tower_array(n)%adv_bc_level_array, &
bct%bc_tower_array(n)%phys_bc_level_array)
! Here we allocate 1 component and set the default to be BC_INT
allocate(bct%bc_tower_array(n)%ell_bc_level_array(0:ngrids,dm,2,ncomp))
call ell_bc_level_build(bct%bc_tower_array(n)%ell_bc_level_array, &
bct%bc_tower_array(n)%phys_bc_level_array)
bct%max_level_built = n
end subroutine bc_tower_level_build
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine phys_bc_level_build(phys_bc_level,la_level,domain_bc)
integer , intent(inout) :: phys_bc_level(0:,:,:)
integer , intent(in ) :: domain_bc(:,:)
type(layout), intent(in ) :: la_level
! local
type(box) :: bx,pd
integer :: d,i
pd = layout_get_pd(la_level)
! set to interior everywhere, then overwrite with physical bc's where appropriate
phys_bc_level = INTERIOR
! grid 0 corresponds to the problem domain
do d = 1,layout_dim(la_level)
phys_bc_level(0,d,1) = domain_bc(d,1)
phys_bc_level(0,d,2) = domain_bc(d,2)
end do
! loop over individual grids
do i = 1,layout_nlocal(la_level) ! loop over grids
bx = layout_get_box(la_level,global_index(la_level,i)) ! grab box associated with the grid
do d = 1,layout_dim(la_level) ! loop over directions
! if one side of a grid is a domain boundary, set the
! physical boundary condition
if (lwb(bx,d) == lwb(pd,d)) phys_bc_level(i,d,1) = domain_bc(d,1)
if (upb(bx,d) == upb(pd,d)) phys_bc_level(i,d,2) = domain_bc(d,2)
end do
end do
end subroutine phys_bc_level_build
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine adv_bc_level_build(adv_bc_level,phys_bc_level)
integer , intent(inout) :: adv_bc_level(0:,:,:,:)
integer , intent(in ) :: phys_bc_level(0:,:,:)
integer :: dm
integer :: igrid,d,lohi
adv_bc_level = INTERIOR
dm = size(adv_bc_level,dim=2)
! if the physical boundary conditions is something other than
! INTERIOR or PERIODIC, then overwrite the default value
do igrid=0,size(adv_bc_level,dim=1)-1 ! loop over grids
do d=1,dm ! loop over directions
do lohi=1,2 ! loop over lo/hi side
if (phys_bc_level(igrid,d,lohi) == INLET) then
call bl_error("define_bc_tower.f90: INLET not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == OUTLET) then
adv_bc_level(igrid,d,lohi,1) = FOEXTRAP
else if (phys_bc_level(igrid,d,lohi) == SYMMETRY) then
call bl_error("define_bc_tower.f90: SYMMETRY not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == SLIP_WALL) then
call bl_error("define_bc_tower.f90: SLIP_WALL not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == NO_SLIP_WALL) then
adv_bc_level(igrid,d,lohi,1) = EXT_DIR
end if
end do
end do
end do
end subroutine adv_bc_level_build
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine ell_bc_level_build(ell_bc_level,phys_bc_level)
integer , intent(inout) :: ell_bc_level(0:,:,:,:)
integer , intent(in ) :: phys_bc_level(0:,:,:)
integer :: dm
integer :: igrid,d,lohi
ell_bc_level = BC_INT
dm = size(ell_bc_level,dim=2)
! if the physical boundary conditions is something other than
! INTERIOR, then overwrite the default value
do igrid=0,size(ell_bc_level,dim=1)-1 ! loop over grids
do d=1,dm ! loop over directions
do lohi=1,2 ! loop over lo/hi side
if (phys_bc_level(igrid,d,lohi) == INLET) then
call bl_error("define_bc_tower.f90: INLET not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == OUTLET) then
ell_bc_level(igrid,d,lohi,1) = BC_NEU
else if (phys_bc_level(igrid,d,lohi) == SYMMETRY) then
call bl_error("define_bc_tower.f90: SYMMETRY not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == SLIP_WALL) then
call bl_error("define_bc_tower.f90: SLIP_WALL not supported for this example")
else if (phys_bc_level(igrid,d,lohi) == NO_SLIP_WALL) then
ell_bc_level(igrid,d,lohi,1) = BC_DIR
else if (phys_bc_level(igrid,d,lohi) == PERIODIC) then
ell_bc_level(igrid,d,lohi,1) = BC_PER
end if
end do
end do
end do
end subroutine ell_bc_level_build
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
subroutine bc_tower_destroy(bct)
type(bc_tower), intent(inout) :: bct
integer :: n
do n = 1,bct%max_level_built
deallocate(bct%bc_tower_array(n)%phys_bc_level_array)
deallocate(bct%bc_tower_array(n)%adv_bc_level_array)
deallocate(bct%bc_tower_array(n)%ell_bc_level_array)
bct%bc_tower_array(n)%phys_bc_level_array => NULL()
bct%bc_tower_array(n)%adv_bc_level_array => NULL()
bct%bc_tower_array(n)%ell_bc_level_array => NULL()
end do
deallocate(bct%bc_tower_array)
deallocate(bct%domain_bc)
end subroutine bc_tower_destroy
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
end module define_bc_module