MFIX  2016-1
set_icbc_flags.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
2 ! !
3 ! Subroutine: SET_ICBC_FLAG !
4 ! Author: J.Musser Date: 01-Mar-14 !
5 ! !
6 ! Purpose: Provided a detailed error message when the sum of volume !
7 ! !
8 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
9  SUBROUTINE set_icbc_flag
10 
11 
12  CALL init_icbc_flag
13 
14  CALL set_ic_flags
15 
17 
19 
20 ! Verify that ICBC flags are set for all fluid cells.
21  CALL check_icbc_flag
22 
23  END SUBROUTINE set_icbc_flag
24 
25 
26 
27 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
28 ! !
29 ! Subroutine: INIT_ICBC_FLAG !
30 ! Author: J.Musser Date: 01-Mar-14 !
31 ! !
32 ! Purpose: Provided a detailed error message when the sum of volume !
33 ! !
34 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
35  SUBROUTINE init_icbc_flag
36 
37  use param1, only: zero
38  use run, only: run_type
39 
40  use mpi_utility
41  use functions
42 
43  implicit none
44  INTEGER :: I, J, K, IJK
45 
46 ! Initialize the icbc_flag array.
47  DO k = kstart3, kend3
48  DO j = jstart3, jend3
49  DO i = istart3, iend3
50 
51  ijk = funijk(i,j,k)
52 
53 ! Initialize the ICBC Flag
54  icbc_flag(ijk) = merge(' ', '.--', run_type == 'NEW')
55 
56 ! If at domain boundaries then set default values (wall or, if
57 ! specified, cyclic)
58  IF (do_k) THEN
59  IF(k==kmin3 .OR. k==kmin2 .OR. k==kmax2 .OR. k==kmax3)THEN
60  IF (cyclic_z_pd) THEN
61  icbc_flag(ijk) = 'C--'
62  ELSEIF (cyclic_z) THEN
63  icbc_flag(ijk) = 'c--'
64  ELSE
65  icbc_flag(ijk) = 'W--'
66  ENDIF
67  ENDIF
68  ENDIF
69 
70  IF(do_j)THEN
71  IF(j==jmin3 .OR. j==jmin2 .OR. j==jmax2 .OR. j==jmax3)THEN
72  IF (cyclic_y_pd) THEN
73  icbc_flag(ijk) = 'C--'
74  ELSEIF (cyclic_y) THEN
75  icbc_flag(ijk) = 'c--'
76  ELSE
77  icbc_flag(ijk) = 'W--'
78  ENDIF
79  ENDIF
80  ENDIF
81 
82  IF(do_i)THEN
83  IF(i==imin3 .OR. i==imin2 .OR. i==imax2 .OR. i==imax3)THEN
84  IF (cyclic_x_pd) THEN
85  icbc_flag(ijk) = 'C--'
86  ELSEIF (cyclic_x) THEN
87  icbc_flag(ijk) = 'c--'
88  ELSE
89  icbc_flag(ijk) = 'W--'
90  ENDIF
91  ENDIF
92  IF (i==1 .AND. cylindrical .AND. xmin==zero) &
93  icbc_flag(ijk) = 'S--'
94  ENDIF
95 ! corner cells are wall cells
96  IF ((i==imin3 .OR. i==imin2 .OR. i==imax2 .OR. i==imax3) .AND. &
97  (j==jmin3 .OR. j==jmin2 .OR. j==jmax2 .OR. j==jmin3) .AND. &
98  (k==kmin3 .OR. k==kmin2 .OR. k==kmax2 .OR. k==kmax3)) THEN
99  IF (icbc_flag(ijk) /= 'S--') icbc_flag(ijk) = 'W--'
100  ENDIF
101 
102  ENDDO ! end do loop (i=istart3, iend3)
103  ENDDO ! end do loop (j=jstart3, jend3)
104  ENDDO ! end do loop (k=kstart3, kend3)
105 
106  RETURN
107 
108  END SUBROUTINE init_icbc_flag
109 
110 
111 
112 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
113 ! !
114 ! Subroutine: CHECK_ICBC_FLAG !
115 ! Author: P. Nicoletti Date: 10-DEC-91 !
116 ! !
117 ! Purpose: Verify that data was not given for undefined BC regions. !
118 ! Note that the error message may be incomplete
119 ! !
120 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
121  SUBROUTINE check_icbc_flag
123 
124  use run, only: run_type
125 
126  use mpi_utility
127  use sendrecv
128 
129  use error_manager
130  use functions
131 
132  IMPLICIT NONE
133 
134  LOGICAL :: ERROR = .false.
135 
136  INTEGER :: I, J ,K, IER
137 
138  IF(run_type(1:3) /= 'NEW') RETURN
139 
140 
141 
142  CALL init_err_msg("CHECK_ICBC_FLAG")
143 
144 ! First check for any errors.
145  DO k = kstart2, kend2
146  DO j = jstart2, jend2
147  DO i = istart2, iend2
148  IF(icbc_flag(funijk(i,j,k)) == ' ') error = .true.
149  ENDDO
150  ENDDO
151  ENDDO
152 
153 ! Sync up the error flag across all processes.
154  CALL global_all_or(error)
155 
156 ! If an error is detected, have each rank open a log file and write
157 ! it's own message. Otherwise, we need to send all the data back to
158 ! PE_IO and that's too much work!
159  IF(error) THEN
160 
161  CALL open_pe_log(ier)
162 
163  WRITE(err_msg, 1100) trim(ival(mype))
164  CALL flush_err_msg(footer=.false.)
165 
166  DO k = kstart2, kend2
167  DO j = jstart2, jend2
168  DO i = istart2, iend2
169  IF(icbc_flag(funijk(i,j,k)) == ' ') THEN
170  WRITE(err_msg,1101) i, j, k
171  CALL flush_err_msg(header=.false., footer=.false.)
172  ENDIF
173 
174  ENDDO
175  ENDDO
176  ENDDO
177 
178  WRITE(err_msg, 1102)
179  CALL flush_err_msg(header=.false., abort=.true.)
180 
181  ELSE
182 ! If no erros, sync up the ghost cell layers.
183  CALL send_recv(icbc_flag,2)
184  ENDIF
185 
186 ! Clean up and return.
187  CALL finl_err_msg
188 
189  RETURN
190 
191  1100 FORMAT('Error 1100 (PE ',a,') : No initial or boundary ', &
192  'condtions specified in','the following cells:',/ &
193  ' I J K')
194 
195  1101 FORMAT(i5,3x,i5,3x,i5)
196 
197  1102 FORMAT('Please correct the mfix.dat file.')
198 
199  END SUBROUTINE check_icbc_flag
200 
201 
202 
203 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
204 ! !
205 ! Subroutine: SET_IC_FLAGS !
206 ! Author: P. Nicoletti Date: 10-DEC-91 !
207 ! !
208 ! Purpose: Set the IC portions of the ICBC_Flag array. !
209 ! !
210 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
211  SUBROUTINE set_ic_flags
213  use ic, only: ic_defined
214  use ic, only: ic_type
215 
216  use ic, only: ic_i_w, ic_i_e
217  use ic, only: ic_j_s, ic_j_n
218  use ic, only: ic_k_b, ic_k_t
219 
220  use param, only: dimension_ic
221 
222  use sendrecv
223  use mpi_utility
224  use error_manager
225  use functions
226 
227  IMPLICIT NONE
228 
229 !-----------------------------------------------
230 ! Local variables
231 !-----------------------------------------------
232  INTEGER :: ICV
233  INTEGER :: I, J, K, IJK
234 
235  CALL init_err_msg("SET_IC_FLAGS")
236 
237 
238  ic_lp: DO icv=1, dimension_ic
239 
240  IF(.NOT.ic_defined(icv)) cycle ic_lp
241 
242 ! Skip checks for PATCH restarts.
243  IF (ic_type(icv) == 'PATCH') cycle ic_lp
244 
245 ! Set ICBC flag
246  DO k = ic_k_b(icv), ic_k_t(icv)
247  DO j = ic_j_s(icv), ic_j_n(icv)
248  DO i = ic_i_w(icv), ic_i_e(icv)
249  IF(.NOT.is_on_mype_plus2layers(i,j,k)) cycle
250  IF(dead_cell_at(i,j,k)) cycle
251  ijk = funijk(i,j,k)
252  WRITE(icbc_flag(ijk)(1:3),"('.',I2.2)") mod(icv,100)
253  ENDDO
254  ENDDO
255  ENDDO
256 
257 
258  ENDDO ic_lp
259 
260 ! Update the ICBC flag on ghost cells.
261  CALL send_recv(icbc_flag, 2)
262 
263 
264 ! Clean up and return.
265  CALL finl_err_msg
266 
267  RETURN
268 
269  END SUBROUTINE set_ic_flags
270 
271 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
272 ! !
273 ! Subroutine: SET_BC_FLAGS_WALL !
274 ! Author: P. Nicoletti Date: 10-DEC-91 !
275 ! !
276 ! Purpose: Find and validate i, j, k locations for walls BC's !
277 ! !
278 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
279  SUBROUTINE set_bc_flags_wall
281  USE param
282  USE param1
283  USE geometry
284  USE fldvar
285  USE physprop
286  USE bc
287  USE indices
288  USE funits
289  USE compar
290  USE sendrecv
291  USE functions
292 
293  use error_manager
294 
295  IMPLICIT NONE
296 
297 !-----------------------------------------------
298 ! Local variables
299 !-----------------------------------------------
300 ! loop/variable indices
301  INTEGER :: I , J , K , IJK
302 ! loop index
303  INTEGER :: BCV
304 
305 !-----------------------------------------------
306 
307  CALL init_err_msg("SET_BC_FLAGS_WALL")
308 
309 ! Set the wall flags.
310  DO bcv=1, dimension_bc
311  IF(.NOT.bc_defined(bcv)) cycle
312 
313  IF(bc_type_enum(bcv)==free_slip_wall .OR. &
314  bc_type_enum(bcv)==no_slip_wall .OR. &
315  bc_type_enum(bcv)==par_slip_wall) THEN
316 
317  DO k = bc_k_b(bcv), bc_k_t(bcv)
318  DO j = bc_j_s(bcv), bc_j_n(bcv)
319  DO i = bc_i_w(bcv), bc_i_e(bcv)
320 
321  IF(.NOT.is_on_mype_plus2layers(i,j,k)) cycle
322  IF(dead_cell_at(i,j,k)) cycle
323 
324  ijk = funijk(i,j,k)
325 
326  SELECT CASE (bc_type_enum(bcv))
327  CASE(free_slip_wall); icbc_flag(ijk)(1:1) = 'S'
328  CASE(no_slip_wall); icbc_flag(ijk)(1:1) = 'W'
329  CASE(par_slip_wall); icbc_flag(ijk)(1:1) = 's'
330  END SELECT
331  WRITE (icbc_flag(ijk)(2:3),"(I2.2)") mod(bcv,100)
332  ENDDO
333  ENDDO
334  ENDDO
335 
336  ENDIF
337  ENDDO
338 
339  CALL send_recv(icbc_flag,2)
340 
341  CALL finl_err_msg
342 
343  RETURN
344  END SUBROUTINE set_bc_flags_wall
345 
346 
347 
348 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
349 ! !
350 ! Subroutine: SET_BC_FLAGS_FLOW !
351 ! Author: P. Nicoletti Date: 10-DEC-91 !
352 ! !
353 ! Purpose: Find and validate i, j, k locations for flow BC's. Also !
354 ! set value of bc_plane for flow BC's. !
355 ! !
356 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
357  SUBROUTINE set_bc_flags_flow
359  USE param
360  USE param1
361  USE geometry
362  USE fldvar
363  USE physprop
364  USE bc
365  USE indices
366  USE funits
367  USE compar
368  USE sendrecv
369 
370  use mpi_utility
371  use sendrecv
372  use functions
373 
374  use error_manager
375 
376  IMPLICIT NONE
377 
378 ! loop/variable indices
379  INTEGER :: BCV, I, J, K, IJK
380 
381  INTEGER :: IER
382 
383 ! error indicator
384  LOGICAL :: ERROR
385 ! surface indictors
386  LOGICAL :: X_CONSTANT, Y_CONSTANT, Z_CONSTANT
387 
388  CALL init_err_msg("SET_BC_FLAGS_FLOW")
389 
390 
391 ! FIND THE FLOW SURFACES
392  error = .false.
393 
394  DO bcv = 1, dimension_bc
395 
396  IF(.NOT.bc_defined(bcv)) cycle
397 
398  IF(bc_type_enum(bcv)==mass_inflow .OR. &
399  bc_type_enum(bcv)==mass_outflow .OR. &
400  bc_type_enum(bcv)==p_inflow .OR. &
401  bc_type_enum(bcv)==p_outflow .OR. &
402  bc_type_enum(bcv)==outflow) THEN
403 
404  x_constant = (bc_x_w(bcv) == bc_x_e(bcv))
405  y_constant = (bc_y_s(bcv) == bc_y_n(bcv))
406  z_constant = (bc_z_b(bcv) == bc_z_t(bcv))
407 
408  IF(x_constant .AND. bc_x_w(bcv)/=undefined) &
409  CALL mod_bc_i(bcv)
410 
411  IF(y_constant .AND. bc_y_s(bcv)/=undefined) &
412  CALL mod_bc_j(bcv)
413 
414  IF(z_constant .AND. bc_z_b(bcv)/=undefined) &
415  CALL mod_bc_k(bcv)
416 
417 ! Extend the boundaries for cyclic implementation
418  IF(bc_i_w(bcv) == 2 .AND. bc_i_e(bcv) == (imax2 - 1) .AND. &
419  cyclic_x .AND. nodesi > 1) THEN
420  bc_i_w(bcv) = 1
421  bc_i_e(bcv) = imax2
422  ENDIF
423  IF(bc_j_s(bcv) == 2 .AND. bc_j_n(bcv) == (jmax2 - 1) .AND. &
424  cyclic_y .AND. nodesj > 1) THEN
425  bc_j_s(bcv) = 1
426  bc_j_n(bcv) = jmax2
427  ENDIF
428  IF(bc_k_b(bcv) == 2 .AND. bc_k_t(bcv) == (kmax2 - 1) .AND. &
429  cyclic_z .AND. nodesk > 1) THEN
430  bc_k_b(bcv) = 1
431  bc_k_t(bcv) = kmax2
432  ENDIF
433 
434 ! Set add the BC to the ICBC_FLAG. If a "non-wall" BC is found, then flag
435 ! this as an error. The next triple-loop will take care of reporting the
436 ! error.
437  error = .false.
438  DO k = bc_k_b(bcv), bc_k_t(bcv)
439  DO j = bc_j_s(bcv), bc_j_n(bcv)
440  DO i = bc_i_w(bcv), bc_i_e(bcv)
441 
442  IF(.NOT.is_on_mype_plus2layers(i,j,k)) cycle
443  IF(dead_cell_at(i,j,k)) cycle
444 
445  ijk = funijk(i,j,k)
446 
447 ! Verify that the FLOW BC is overwriting a wall.
448  IF(wall_icbc_flag(ijk)) THEN
449 
450  SELECT CASE (bc_type_enum(bcv))
451  CASE (p_outflow); icbc_flag(ijk)(1:1) = 'P'
452  CASE (mass_inflow); icbc_flag(ijk)(1:1) = 'I'
453  CASE (mass_outflow); icbc_flag(ijk)(1:1) = 'O'
454  CASE (outflow); icbc_flag(ijk)(1:1) = 'o'
455  CASE (p_inflow); icbc_flag(ijk)(1:1) = 'p'
456  END SELECT
457 
458  WRITE(icbc_flag(ijk)(2:3),"(I2.2)") mod(bcv,100)
459 
460  ELSE
461  error = .true.
462  ENDIF
463 
464  ENDDO
465  ENDDO
466  ENDDO
467 
468 ! Sync the error flag over all ranks.
469  CALL global_all_or(error)
470 
471 ! Report errors and exit.
472  IF(error)THEN
473 
474  CALL open_pe_log(ier)
475 
476  WRITE(err_msg, 1200) bcv
477  CALL flush_err_msg(footer=.false.)
478 
479  1200 FORMAT('Error 1200: Boundary condition ',i3,' overlaps with ',&
480  'another BC.',2/7x,'I',7x,'J',7x,'K',3x,'ICBC')
481 
482  DO k = bc_k_b(bcv), bc_k_t(bcv)
483  DO j = bc_j_s(bcv), bc_j_n(bcv)
484  DO i = bc_i_w(bcv), bc_i_e(bcv)
485 
486  IF(.NOT.is_on_mype_plus2layers(i,j,k)) cycle
487  IF(dead_cell_at(i,j,k)) cycle
488 
489  ijk = funijk(i,j,k)
490 
491 ! Verify that the FLOW BC is overwriting a wall.
492  IF(.NOT.wall_icbc_flag(ijk)) THEN
493  WRITE(err_msg, 1201) i,j,k, icbc_flag(ijk)
494  CALL flush_err_msg(header=.false., footer=.false.)
495  ENDIF
496 
497  1201 FORMAT(1x,3(2x,i6),3x,a3)
498 
499  ENDDO
500  ENDDO
501  ENDDO
502 
503  WRITE(err_msg,"('Please correct the mfix.dat file.')")
504  CALL flush_err_msg(header=.false., abort=.true.)
505 
506  ENDIF ! IF(ERROR)
507  ENDIF ! IF(not a wall BC)
508  ENDDO ! BC Loop
509 
510 ! Sync the ICBC flag across ghost layers
511  CALL send_recv(icbc_flag,2)
512 
513  CALL finl_err_msg
514 
515  RETURN
516  END SUBROUTINE set_bc_flags_flow
integer, dimension(dimension_bc) bc_k_b
Definition: bc_mod.f:70
double precision, dimension(dimension_bc) bc_y_n
Definition: bc_mod.f:42
integer, parameter dimension_ic
Definition: param_mod.f:59
integer imax2
Definition: geometry_mod.f:61
subroutine finl_err_msg
integer, dimension(dimension_ic) ic_j_s
Definition: ic_mod.f:47
subroutine mod_bc_i(BCV)
Definition: mod_bc_i.f:11
integer, dimension(dimension_bc) bc_i_w
Definition: bc_mod.f:54
integer, dimension(dimension_bc) bc_j_n
Definition: bc_mod.f:66
integer, dimension(dimension_ic) ic_j_n
Definition: ic_mod.f:50
logical, dimension(dimension_ic) ic_defined
Definition: ic_mod.f:107
integer, parameter dimension_bc
Definition: param_mod.f:61
logical cyclic_z
Definition: geometry_mod.f:153
integer, dimension(dimension_bc) bc_type_enum
Definition: bc_mod.f:146
double precision, dimension(dimension_bc) bc_x_e
Definition: bc_mod.f:34
double precision, parameter undefined
Definition: param1_mod.f:18
character(len=16), dimension(dimension_ic) ic_type
Definition: ic_mod.f:59
character(len=3), dimension(:), pointer icbc_flag
Definition: geometry_mod.f:111
double precision, dimension(dimension_bc) bc_y_s
Definition: bc_mod.f:38
subroutine init_err_msg(CALLER)
Definition: ic_mod.f:9
subroutine check_icbc_flag
integer, dimension(dimension_ic) ic_i_w
Definition: ic_mod.f:41
integer, dimension(dimension_bc) bc_k_t
Definition: bc_mod.f:74
logical, dimension(:,:,:), allocatable dead_cell_at
Definition: compar_mod.f:127
subroutine mod_bc_j(BCV)
Definition: mod_bc_j.f:10
integer jmax2
Definition: geometry_mod.f:63
integer, dimension(dimension_ic) ic_i_e
Definition: ic_mod.f:44
subroutine set_bc_flags_wall
integer, dimension(dimension_ic) ic_k_b
Definition: ic_mod.f:53
integer, dimension(dimension_bc) bc_j_s
Definition: bc_mod.f:62
logical cyclic_y
Definition: geometry_mod.f:151
subroutine set_icbc_flag
character(len=16) run_type
Definition: run_mod.f:33
logical, dimension(dimension_bc) bc_defined
Definition: bc_mod.f:207
integer kmax2
Definition: geometry_mod.f:65
subroutine mod_bc_k(BCV)
Definition: mod_bc_k.f:10
Definition: run_mod.f:13
logical cyclic_x
Definition: geometry_mod.f:149
integer, dimension(dimension_ic) ic_k_t
Definition: ic_mod.f:56
Definition: param_mod.f:2
subroutine init_icbc_flag
double precision, dimension(dimension_bc) bc_z_b
Definition: bc_mod.f:46
integer nodesj
Definition: compar_mod.f:37
character(len=line_length), dimension(line_count) err_msg
integer nodesk
Definition: compar_mod.f:37
double precision, dimension(dimension_bc) bc_z_t
Definition: bc_mod.f:50
integer nodesi
Definition: compar_mod.f:37
subroutine set_bc_flags_flow
subroutine open_pe_log(IER)
Definition: open_files.f:270
integer, dimension(dimension_bc) bc_i_e
Definition: bc_mod.f:58
double precision, dimension(:), allocatable x
Definition: geometry_mod.f:129
double precision, parameter zero
Definition: param1_mod.f:27
subroutine flush_err_msg(DEBUG, HEADER, FOOTER, ABORT, LOG, CALL_TREE)
Definition: bc_mod.f:23
double precision, dimension(dimension_bc) bc_x_w
Definition: bc_mod.f:30
subroutine set_ic_flags