MFC
Exascale flow solver
Loading...
Searching...
No Matches
m_boundary_conditions.fpp.f90
Go to the documentation of this file.
1# 1 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
2!>
3!! @file
4!! @brief Contains module m_boundary_conditions
5
6!> @brief Applies spatially varying boundary condition patches along domain edges and faces
8
11#ifdef MFC_MPI
12 use mpi
13#endif
16
17 implicit none
18
21 real(wp) :: radius
23 private; public :: s_apply_boundary_patches
24
25contains
26 !> Apply a line-segment boundary condition patch along a domain edge in 2D.
27 impure subroutine s_line_segment_bc(patch_id, bc_type)
28
29 type(integer_field), dimension(1:num_dims,1:2), intent(inout) :: bc_type
30 integer, intent(in) :: patch_id
31 integer :: j
32
33 ! Patch is a line segment along y on the x-boundary face
34
35 if (patch_bc(patch_id)%dir == 1) then
36 y_centroid = patch_bc(patch_id)%centroid(2)
37 length_y = patch_bc(patch_id)%length(2)
38
39 y_boundary%beg = y_centroid - 0.5_wp*length_y
40 y_boundary%end = y_centroid + 0.5_wp*length_y
41
42 ! Apply patch if x boundary is a domain boundary
43# 43 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
44 if (patch_bc(patch_id)%loc == -1 .and. bc_x%beg < 0) then
45# 44 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
46 do j = 0, n
47 if (y_cc(j) > y_boundary%beg .and. y_cc(j) < y_boundary%end) then
48 bc_type(1, 1)%sf(0, j, 0) = patch_bc(patch_id)%type
49# 47 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
50 end if
51 end do
52 end if
53# 43 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
54 if (patch_bc(patch_id)%loc == 1 .and. bc_x%end < 0) then
55# 44 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
56 do j = 0, n
57 if (y_cc(j) > y_boundary%beg .and. y_cc(j) < y_boundary%end) then
58 bc_type(1, 2)%sf(0, j, 0) = patch_bc(patch_id)%type
59# 47 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
60 end if
61 end do
62 end if
63# 51 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
64 end if
65
66 ! Patch is a line segment along x on the y-boundary face
67 if (patch_bc(patch_id)%dir == 2) then
68 x_centroid = patch_bc(patch_id)%centroid(1)
69 length_x = patch_bc(patch_id)%length(1)
70
71 x_boundary%beg = x_centroid - 0.5_wp*length_x
72 x_boundary%end = x_centroid + 0.5_wp*length_x
73
74 ! Apply patch if y boundary is a domain boundary
75# 63 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
76 if (patch_bc(patch_id)%loc == -1 .and. bc_y%beg < 0) then
77# 64 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
78 do j = 0, m
79 if (x_cc(j) > x_boundary%beg .and. x_cc(j) < x_boundary%end) then
80 bc_type(2, 1)%sf(j, 0, 0) = patch_bc(patch_id)%type
81# 67 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
82 end if
83 end do
84 end if
85# 63 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
86 if (patch_bc(patch_id)%loc == 1 .and. bc_y%end < 0) then
87# 64 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
88 do j = 0, m
89 if (x_cc(j) > x_boundary%beg .and. x_cc(j) < x_boundary%end) then
90 bc_type(2, 2)%sf(j, 0, 0) = patch_bc(patch_id)%type
91# 67 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
92 end if
93 end do
94 end if
95# 71 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
96 end if
97
98 end subroutine s_line_segment_bc
99
100 !> Apply a circular boundary condition patch on a domain face in 3D.
101 impure subroutine s_circle_bc(patch_id, bc_type)
102
103 type(integer_field), dimension(1:num_dims,1:2), intent(inout) :: bc_type
104 integer, intent(in) :: patch_id
105 integer :: j, k
106
107 if (patch_bc(patch_id)%dir == 1) then
108 y_centroid = patch_bc(patch_id)%centroid(2)
109 z_centroid = patch_bc(patch_id)%centroid(3)
110 radius = patch_bc(patch_id)%radius
111 ! Patch is a circle at x_beg and x_beg is a domain boundary
112# 88 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
113 if (patch_bc(patch_id)%loc == -1 .and. bc_x%beg < 0) then
114# 89 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
115 do k = 0, p
116 do j = 0, n
117 if ((z_cc(k) - z_centroid)**2._wp + (y_cc(j) - y_centroid)**2._wp <= radius**2._wp) then
118 bc_type(1, 1)%sf(0, j, k) = patch_bc(patch_id)%type
119# 93 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
120 end if
121 end do
122 end do
123 end if
124# 88 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
125 if (patch_bc(patch_id)%loc == 1 .and. bc_x%end < 0) then
126# 89 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
127 do k = 0, p
128 do j = 0, n
129 if ((z_cc(k) - z_centroid)**2._wp + (y_cc(j) - y_centroid)**2._wp <= radius**2._wp) then
130 bc_type(1, 2)%sf(0, j, k) = patch_bc(patch_id)%type
131# 93 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
132 end if
133 end do
134 end do
135 end if
136# 98 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
137 end if
138 if (patch_bc(patch_id)%dir == 2) then
139 x_centroid = patch_bc(patch_id)%centroid(1)
140 z_centroid = patch_bc(patch_id)%centroid(3)
141 radius = patch_bc(patch_id)%radius
142 ! Patch is a circle at y_beg and y_beg is a domain boundary
143# 105 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
144 if (patch_bc(patch_id)%loc == -1 .and. bc_y%beg < 0) then
145# 106 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
146 do k = 0, p
147 do j = 0, m
148 if ((z_cc(k) - z_centroid)**2._wp + (x_cc(j) - x_centroid)**2._wp <= radius**2._wp) then
149 bc_type(2, 1)%sf(j, 0, k) = patch_bc(patch_id)%type
150# 110 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
151 end if
152 end do
153 end do
154 end if
155# 105 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
156 if (patch_bc(patch_id)%loc == 1 .and. bc_y%end < 0) then
157# 106 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
158 do k = 0, p
159 do j = 0, m
160 if ((z_cc(k) - z_centroid)**2._wp + (x_cc(j) - x_centroid)**2._wp <= radius**2._wp) then
161 bc_type(2, 2)%sf(j, 0, k) = patch_bc(patch_id)%type
162# 110 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
163 end if
164 end do
165 end do
166 end if
167# 115 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
168 end if
169 if (patch_bc(patch_id)%dir == 3) then
170 x_centroid = patch_bc(patch_id)%centroid(1)
171 y_centroid = patch_bc(patch_id)%centroid(2)
172 radius = patch_bc(patch_id)%radius
173# 121 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
174 if (patch_bc(patch_id)%loc == -1 .and. bc_z%beg < 0) then
175# 122 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
176 do k = 0, n
177 do j = 0, m
178 if ((y_cc(k) - y_centroid)**2._wp + (x_cc(j) - x_centroid)**2._wp <= radius**2._wp) then
179 bc_type(3, 1)%sf(j, k, 0) = patch_bc(patch_id)%type
180# 126 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
181 end if
182 end do
183 end do
184 end if
185# 121 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
186 if (patch_bc(patch_id)%loc == 1 .and. bc_z%end < 0) then
187# 122 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
188 do k = 0, n
189 do j = 0, m
190 if ((y_cc(k) - y_centroid)**2._wp + (x_cc(j) - x_centroid)**2._wp <= radius**2._wp) then
191 bc_type(3, 2)%sf(j, k, 0) = patch_bc(patch_id)%type
192# 126 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
193 end if
194 end do
195 end do
196 end if
197# 131 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
198 end if
199
200 end subroutine s_circle_bc
201
202 !> Apply a rectangular boundary condition patch on a domain face in 3D.
203 impure subroutine s_rectangle_bc(patch_id, bc_type)
204
205 type(integer_field), dimension(1:num_dims,1:2), intent(inout) :: bc_type
206 integer, intent(in) :: patch_id
207 integer :: j, k
208
209 if (patch_bc(patch_id)%dir == 1) then
210 y_centroid = patch_bc(patch_id)%centroid(2)
211 z_centroid = patch_bc(patch_id)%centroid(3)
212 length_y = patch_bc(patch_id)%length(2)
213 length_z = patch_bc(patch_id)%length(3)
214
215 y_boundary%beg = y_centroid - 0.5_wp*length_y
216 y_boundary%end = y_centroid + 0.5_wp*length_y
217
218 z_boundary%beg = z_centroid - 0.5_wp*length_z
219 z_boundary%end = z_centroid + 0.5_wp*length_z
220 ! Patch is a rectangle on the x-boundary face
221# 155 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
222 if (patch_bc(patch_id)%loc == -1 .and. bc_x%beg < 0) then
223# 156 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
224 do k = 0, p
225 do j = 0, n
226 if (y_boundary%beg <= y_cc(j) .and. y_boundary%end >= y_cc(j) .and. z_boundary%beg <= z_cc(k) &
227 & .and. z_boundary%end >= z_cc(k)) then
228 bc_type(1, 1)%sf(0, j, k) = patch_bc(patch_id)%type
229# 161 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
230 end if
231 end do
232 end do
233 end if
234# 155 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
235 if (patch_bc(patch_id)%loc == 1 .and. bc_x%end < 0) then
236# 156 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
237 do k = 0, p
238 do j = 0, n
239 if (y_boundary%beg <= y_cc(j) .and. y_boundary%end >= y_cc(j) .and. z_boundary%beg <= z_cc(k) &
240 & .and. z_boundary%end >= z_cc(k)) then
241 bc_type(1, 2)%sf(0, j, k) = patch_bc(patch_id)%type
242# 161 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
243 end if
244 end do
245 end do
246 end if
247# 166 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
248 end if
249 if (patch_bc(patch_id)%dir == 2) then
250 x_centroid = patch_bc(patch_id)%centroid(1)
251 z_centroid = patch_bc(patch_id)%centroid(3)
252 length_x = patch_bc(patch_id)%length(1)
253 length_z = patch_bc(patch_id)%length(3)
254
255 x_boundary%beg = x_centroid - 0.5_wp*length_x
256 x_boundary%end = x_centroid + 0.5_wp*length_x
257
258 z_boundary%beg = z_centroid - 0.5_wp*length_z
259 z_boundary%end = z_centroid + 0.5_wp*length_z
260 ! Patch is a rectangle on the y-boundary face
261# 180 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
262 if (patch_bc(patch_id)%loc == -1 .and. bc_y%beg < 0) then
263# 181 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
264 do k = 0, p
265 do j = 0, m
266 if (x_boundary%beg <= x_cc(j) .and. x_boundary%end >= x_cc(j) .and. z_boundary%beg <= z_cc(k) &
267 & .and. z_boundary%end >= z_cc(k)) then
268 bc_type(2, 1)%sf(j, 0, k) = patch_bc(patch_id)%type
269# 186 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
270 end if
271 end do
272 end do
273 end if
274# 180 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
275 if (patch_bc(patch_id)%loc == 1 .and. bc_y%end < 0) then
276# 181 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
277 do k = 0, p
278 do j = 0, m
279 if (x_boundary%beg <= x_cc(j) .and. x_boundary%end >= x_cc(j) .and. z_boundary%beg <= z_cc(k) &
280 & .and. z_boundary%end >= z_cc(k)) then
281 bc_type(2, 2)%sf(j, 0, k) = patch_bc(patch_id)%type
282# 186 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
283 end if
284 end do
285 end do
286 end if
287# 191 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
288 end if
289 if (patch_bc(patch_id)%dir == 3) then
290 x_centroid = patch_bc(patch_id)%centroid(1)
291 y_centroid = patch_bc(patch_id)%centroid(2)
292 length_x = patch_bc(patch_id)%length(1)
293 length_y = patch_bc(patch_id)%length(2)
294
295 x_boundary%beg = x_centroid - 0.5_wp*length_x
296 x_boundary%end = x_centroid + 0.5_wp*length_x
297
298 y_boundary%beg = y_centroid - 0.5_wp*length_y
299 y_boundary%end = y_centroid + 0.5_wp*length_y
300# 204 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
301 if (patch_bc(patch_id)%loc == -1 .and. bc_z%beg < 0) then
302# 205 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
303 do k = 0, n
304 do j = 0, m
305 if (x_boundary%beg <= x_cc(j) .and. x_boundary%end >= x_cc(j) .and. y_boundary%beg <= y_cc(k) &
306 & .and. y_boundary%end >= y_cc(k)) then
307 bc_type(3, 1)%sf(j, k, 0) = patch_bc(patch_id)%type
308# 210 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
309 end if
310 end do
311 end do
312 end if
313# 204 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
314 if (patch_bc(patch_id)%loc == 1 .and. bc_z%end < 0) then
315# 205 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
316 do k = 0, n
317 do j = 0, m
318 if (x_boundary%beg <= x_cc(j) .and. x_boundary%end >= x_cc(j) .and. y_boundary%beg <= y_cc(k) &
319 & .and. y_boundary%end >= y_cc(k)) then
320 bc_type(3, 2)%sf(j, k, 0) = patch_bc(patch_id)%type
321# 210 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
322 end if
323 end do
324 end do
325 end if
326# 215 "/home/runner/work/MFC/MFC/src/pre_process/m_boundary_conditions.fpp"
327 end if
328
329 end subroutine s_rectangle_bc
330
331 !> Iterate over all boundary condition patches and dispatch them by geometry type.
332 impure subroutine s_apply_boundary_patches(q_prim_vf, bc_type)
333
334 type(scalar_field), dimension(sys_size) :: q_prim_vf
335 type(integer_field), dimension(1:num_dims,1:2) :: bc_type
336 integer :: i
337
338 !> Apply 2D patches to 3D domain
339
340 if (p > 0) then
341 do i = 1, num_bc_patches
342 if (proc_rank == 0) then
343 print *, 'Processing boundary condition patch', i
344 end if
345
346 if (patch_bc(i)%geometry == 2) then
347 call s_circle_bc(i, bc_type)
348 else if (patch_bc(i)%geometry == 3) then
349 call s_rectangle_bc(i, bc_type)
350 end if
351 end do
352 !> Apply 1D patches to 2D domain
353 else if (n > 0) then
354 do i = 1, num_bc_patches
355 if (proc_rank == 0) then
356 print *, 'Processing boundary condition patch', i
357 end if
358
359 if (patch_bc(i)%geometry == 1) then
360 call s_line_segment_bc(i, bc_type)
361 end if
362 end do
363 end if
364
365 end subroutine s_apply_boundary_patches
366
367end module m_boundary_conditions
integer, intent(in) k
integer, intent(in) j
Applies spatially varying boundary condition patches along domain edges and faces.
impure subroutine, public s_apply_boundary_patches(q_prim_vf, bc_type)
Iterate over all boundary condition patches and dispatch them by geometry type.
impure subroutine s_circle_bc(patch_id, bc_type)
Apply a circular boundary condition patch on a domain face in 3D.
impure subroutine s_line_segment_bc(patch_id, bc_type)
Apply a line-segment boundary condition patch along a domain edge in 2D.
impure subroutine s_rectangle_bc(patch_id, bc_type)
Apply a rectangular boundary condition patch on a domain face in 3D.
Platform-specific file and directory operations: create, delete, inquire, getcwd, and basename.
Rank-staggered file access delays to prevent I/O contention on parallel file systems.
Shared derived types for field data, patch geometry, bubble dynamics, and MPI I/O structures.
Defines global parameters for the computational domain, simulation algorithm, and initial conditions.
type(int_bounds_info) bc_z
Boundary conditions in the x-, y- and z-coordinate directions.
real(wp), dimension(:), allocatable y_cc
integer proc_rank
Rank of the local processor Number of cells in the x-, y- and z-coordinate directions.
type(int_bounds_info) bc_y
real(wp), dimension(:), allocatable x_cc
Locations of cell-centers (cc) in x-, y- and z-directions, respectively.
type(int_bounds_info) bc_x
real(wp), dimension(:), allocatable z_cc
Derived type adding beginning (beg) and end bounds info as attributes.
Derived type annexing an integer scalar field (SF).
Derived type annexing a scalar field (SF).