MFIX  2016-1
usr_src_mod.f
Go to the documentation of this file.
1 ! or put the actual routine calc_usr_source here? move logic variable
2 ! usr_source into run or something...
3  module usr_src
4  use param, only: dim_eqs
5 
6 ! If .TRUE. call user-defined source subroutines
7  LOGICAL :: call_usr_source(dim_eqs)
8 
9  enum, bind(c)
10  enumerator :: pressure_correction, solids_correction
11  enumerator :: gas_continuity, solids_continuity
12  enumerator :: gas_u_mom, solids_u_mom, gas_v_mom, solids_v_mom
13  enumerator :: gas_w_mom, solids_w_mom
14  enumerator :: gas_energy, solids_energy
15  enumerator :: gas_species, solids_species
16  enumerator :: gran_energy
17  enumerator :: usr_scalar, k_epsilon_k, k_epsilon_e
18  enumerator :: blank
19  enumerator :: dummy
20  END enum
21 
22  CONTAINS
23 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
24 ! C
25 ! Subroutine: CALC_USR_SOURCE C
26 ! Purpose: Driver routine to calculate user defined source terms C
27 ! for each of the various equations C
28 ! C
29 ! C
30 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
31  SUBROUTINE calc_usr_source(lEQ_NO, A_M, B_M, lB_MMAX, lM, lN)
32 
33 ! Modules
34 !-----------------------------------------------
35  use compar, only: ijkstart3, ijkend3
36  use fldvar, only: ep_s, ep_g
37  use fun_avg, only: avg_x, avg_y, avg_z
38  use functions, only: fluid_at, wall_at
39  use functions, only: ip_at_e, ip_at_n, ip_at_t
40  use functions, only: sip_at_e, sip_at_n, sip_at_t
41  use functions, only: east_of, north_of, top_of
42  use indices, only: i_of, j_of, k_of
43  use param, only: dimension_3, dimension_m
44  use param1, only: undefined_i, zero
45  use pgcor, only: phase_4_p_g
46  use physprop, only: smax, mmax
47  use pscor, only: phase_4_p_s
48  use run, only: kt_type_enum, ghd_2007
50  use toleranc, only: dil_ep_s
51  use error_manager
52  IMPLICIT NONE
53 ! Dummy arguments
54 !-----------------------------------------------
55 ! Equation number
56 ! Table relating the eq_no set in the mfix.dat to the corresponding
57 ! pde/variable of interest
58 ! 1, PP_g (pressure correction eq)
59 ! 2, EPP (solids correction eq)
60 ! 2, rop_g (gas continuity eq)
61 ! 2, rop_s (solids continuity eq)
62 ! 3, u_g (gas u-momentum eq)
63 ! 3, u_s (solids u-momentum eq)
64 ! 4, v_g (gas v-momentum eq)
65 ! 4, v_s (solids v-momentum eq)
66 ! 5, w_g (gas w-momentum eq)
67 ! 5, w_s (solids w-momentum eq)
68 ! 6, T_g (gas energy eq)
69 ! 6, T_s (solids energy eq)
70 ! 7, x_g (gas species eq)
71 ! 7, x_s (solids species eq)
72 ! 8, theta_m (granular energy eq)
73 ! 9, scalar_eq (scalar eq)
74 ! 9, k_epsilon k (k_epsilon eqs)
75 ! 9, k_epsilon e (k_epsilon_eqs)
76  INTEGER, INTENT(IN) :: lEQ_NO
77 
78 ! Septadiagonal matrix A_m
79  DOUBLE PRECISION, INTENT(INOUT) :: A_m(dimension_3, -3:3, 0:dimension_m)
80 ! Vector b_m
81  DOUBLE PRECISION, INTENT(INOUT) :: B_m(dimension_3, 0:dimension_m)
82 ! Vector b_mmax
83  DOUBLE PRECISION, OPTIONAL, INTENT(INOUT) :: lB_mmax(dimension_3, 0:dimension_m)
84 ! Phase index
85  INTEGER, OPTIONAL, INTENT(IN) :: lM
86 ! Species index OR scalar equation number
87  INTEGER, OPTIONAL, INTENT(IN) :: lN
88 
89 ! Local variables
90 !-----------------------------------------------
91 ! source terms which appear appear in the
92 ! center coefficient (lhs) - part of a_m matrix
93 ! source vector (rhs) - part of b_m vector
94  DOUBLE PRECISION :: sourcelhs, sourcerhs
95 ! indices
96  INTEGER :: IJK, I, J, K, IJKE, IJKN, IJKT
97 ! tmp indices
98  INTEGER :: L, ll, M, N
99 ! volume fractions
100  DOUBLE PRECISION :: EPGA, EPSA, EPtmp
101 !-----------------------------------------------
102 
103 ! set local values for phase index and species or scalar index
104  IF (.NOT.present(lm)) THEN
105  m = undefined_i
106  ELSE
107  m = lm
108  ENDIF
109  IF (.NOT.present(ln)) THEN
110  n = undefined_i
111  ELSE
112  n = ln
113  ENDIF
114 
115  SELECT CASE(leq_no)
116 
117 ! gas pressure correction equation
118  CASE(pressure_correction)
119  DO ijk=ijkstart3,ijkend3
120  IF (fluid_at(ijk)) THEN
121  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
122  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
123  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
124  lb_mmax(ijk,m) = max(abs(lb_mmax(ijk,m)), abs(b_m(ijk,m)))
125  ENDIF
126  ENDDO
127 
128 ! solids correction currently only called when smax==1 and
129 ! mcp/=undefined_i
130  CASE(solids_correction)
131  DO ijk=ijkstart3,ijkend3
132  IF (fluid_at(ijk)) THEN
133  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
134  a_m(ijk,0,0) = a_m(ijk,0,0) - sourcelhs
135  b_m(ijk,0) = b_m(ijk,0) - sourcerhs
136  lb_mmax(ijk,0) = max(abs(lb_mmax(ijk,0)), abs(b_m(ijk,0)))
137  ENDIF
138  ENDDO
139 
140 ! gas continuity
141  CASE(gas_continuity)
142  DO ijk=ijkstart3,ijkend3
143  IF (fluid_at(ijk)) THEN
144 ! .AND. PHASE_4_P_G(IJK)/=M) THEN
145 ! have not included phase_4_p_g logic...which would require unique
146 ! structure here
147  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
148  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
149  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
150  ENDIF
151  ENDDO
152 
153 ! soldis continuity
154  CASE(solids_continuity)
155 ! have not included phase_4_p_g/p_s logic...which would require unique
156 ! structure here
157  DO ijk=ijkstart3,ijkend3
158  IF (fluid_at(ijk)) THEN
159 ! .AND. PHASE_4_P_G(IJK)/=M .AND. PHASE_4_P_S(IJK)/=M) THEN
160  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
161  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
162  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
163  ENDIF
164  ENDDO
165 
166 ! u-momentum equations
167  CASE(gas_u_mom)
168  m=0
169  IF(.NOT.momentum_x_eq(m)) RETURN
170  DO ijk=ijkstart3,ijkend3
171  IF (.NOT.fluid_at(ijk)) cycle
172  i = i_of(ijk)
173  ijke = east_of(ijk)
174  epga = avg_x(ep_g(ijk),ep_g(ijke),i)
175  IF (ip_at_e(ijk) .OR. epga <= dil_ep_s) cycle
176  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
177  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
178  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
179  ENDDO
180 
181 ! u-momentum equations
182  CASE(solids_u_mom)
183  DO l=1,mmax
184  IF (kt_type_enum /= ghd_2007 .OR. &
185  (kt_type_enum == ghd_2007 .AND. l==mmax)) THEN
186  IF(.NOT.momentum_x_eq(l)) RETURN
187  DO ijk=ijkstart3,ijkend3
188  IF (.NOT.fluid_at(ijk)) cycle
189  i = i_of(ijk)
190  ijke = east_of(ijk)
191  eptmp = zero
192  IF (kt_type_enum == ghd_2007) THEN
193  DO ll = 1, smax
194  eptmp = eptmp + avg_x(ep_s(ijk,ll),ep_s(ijke,ll),i)
195  ENDDO
196  epsa = eptmp
197  ELSE
198  epsa = avg_x(ep_s(ijk,l),ep_s(ijke,l),i)
199  ENDIF
200  IF (ip_at_e(ijk) .OR. sip_at_e(ijk) .OR. &
201  epsa <= dil_ep_s) cycle
202  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, l, n)
203  a_m(ijk,0,l) = a_m(ijk,0,l) - sourcelhs
204  b_m(ijk,l) = b_m(ijk,l) - sourcerhs
205  ENDDO ! enddo ijk
206  ENDIF
207  ENDDO ! enddo mmax
208 
209 ! v-momentum equations
210  CASE(gas_v_mom)
211  m=0
212  IF(.NOT.momentum_y_eq(m)) RETURN
213  DO ijk=ijkstart3,ijkend3
214  IF (.NOT.fluid_at(ijk)) cycle
215  j = j_of(ijk)
216  ijkn = north_of(ijk)
217  epga = avg_y(ep_g(ijk),ep_g(ijkn),j)
218  IF (ip_at_n(ijk) .OR. epga <= dil_ep_s) cycle
219  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
220  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
221  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
222  ENDDO
223 
224 ! v-momentum equations
225  CASE(solids_v_mom)
226  DO l=1,mmax
227  IF (kt_type_enum /= ghd_2007 .OR. &
228  (kt_type_enum == ghd_2007 .AND. l==mmax)) THEN
229  IF(.NOT.momentum_y_eq(l)) RETURN
230  DO ijk=ijkstart3,ijkend3
231  IF (.NOT.fluid_at(ijk)) cycle
232  j = j_of(ijk)
233  ijkn = north_of(ijk)
234  eptmp = zero
235  IF (kt_type_enum == ghd_2007) THEN
236  DO ll = 1, smax
237  eptmp = eptmp + avg_y(ep_s(ijk,ll),ep_s(ijkn,ll),j)
238  ENDDO
239  epsa = eptmp
240  ELSE
241  epsa = avg_y(ep_s(ijk,l),ep_s(ijkn,l),j)
242  ENDIF
243  IF (ip_at_n(ijk) .OR. sip_at_n(ijk) .OR. &
244  epsa <= dil_ep_s) cycle
245  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, l, n)
246  a_m(ijk,0,l) = a_m(ijk,0,l) - sourcelhs
247  b_m(ijk,l) = b_m(ijk,l) - sourcerhs
248  ENDDO ! enddo ijk
249  ENDIF
250  ENDDO ! enddo mmax
251 
252 ! w-momentum equations
253  CASE (gas_w_mom)
254  m=0
255  IF(.NOT.momentum_z_eq(m)) RETURN
256  DO ijk=ijkstart3,ijkend3
257  IF (.NOT.fluid_at(ijk)) cycle
258  k = k_of(ijk)
259  ijkt = top_of(ijk)
260  epga = avg_z(ep_g(ijk),ep_g(ijkt),k)
261  IF (ip_at_t(ijk) .OR. epga <= dil_ep_s) cycle
262  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
263  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
264  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
265  ENDDO
266 
267 ! w-momentum equations
268  CASE (solids_w_mom)
269  DO l=1,mmax
270  IF (kt_type_enum /= ghd_2007 .OR. &
271  (kt_type_enum == ghd_2007 .AND. l==mmax)) THEN
272  IF(.NOT.momentum_z_eq(l)) RETURN
273  DO ijk=ijkstart3,ijkend3
274  IF (.NOT.fluid_at(ijk)) cycle
275  k = k_of(ijk)
276  ijkt = top_of(ijk)
277  eptmp = zero
278  IF (kt_type_enum == ghd_2007) THEN
279  DO ll = 1, smax
280  eptmp = eptmp + avg_z(ep_s(ijk,ll),ep_s(ijkt,ll),k)
281  ENDDO
282  epsa = eptmp
283  ELSE
284  epsa = avg_z(ep_s(ijk,l),ep_s(ijkt,l),k)
285  ENDIF
286  IF (ip_at_t(ijk) .OR. sip_at_t(ijk) .OR. &
287  epsa <= dil_ep_s) cycle
288  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, l, n)
289  a_m(ijk,0,l) = a_m(ijk,0,l) - sourcelhs
290  b_m(ijk,l) = b_m(ijk,l) - sourcerhs
291  ENDDO ! enddo ijk
292  ENDIF
293  ENDDO ! enddo mmax
294 
295 
296 ! gas and solids energy equations (6)
297 ! gas and solids species mass fractions (7)
298 ! scalars, k_epsilon k and e (9)
299  CASE (gas_energy, solids_energy, gas_species, solids_species,&
300  usr_scalar, k_epsilon_k, k_epsilon_e )
301  DO ijk = ijkstart3, ijkend3
302  IF (fluid_at(ijk)) THEN
303  IF (m==0) THEN
304  eptmp=ep_g(ijk)
305  ELSE
306  eptmp=ep_s(ijk,m)
307  ENDIF
308  IF (eptmp <= dil_ep_s) cycle
309  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
310  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
311  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
312  ENDIF
313  ENDDO
314 
315 
316  CASE (gran_energy) ! unique due to ghd
317 ! granular temperature
318  DO ijk = ijkstart3, ijkend3
319  IF (fluid_at(ijk)) THEN
320  IF (kt_type_enum == ghd_2007) THEN
321  eptmp = zero
322  DO ll=1,smax
323  eptmp=eptmp+ep_s(ijk,ll)
324  ENDDO
325  ELSE
326  eptmp = ep_s(ijk,m)
327  ENDIF
328  ENDIF
329  IF (eptmp<=dil_ep_s) cycle
330  CALL usr_sources(leq_no, ijk, sourcelhs, sourcerhs, m, n)
331  a_m(ijk,0,m) = a_m(ijk,0,m) - sourcelhs
332  b_m(ijk,m) = b_m(ijk,m) - sourcerhs
333  ENDDO
334 
335 
336 ! error out
337  CASE DEFAULT
338 ! should never hit this
339 ! Initialize the error manager.
340  CALL init_err_msg("CALC_USR_SOURCE")
341  WRITE(err_msg, 1001) ival(leq_no)
342  CALL flush_err_msg(abort=.true.)
343  1001 FORMAT('Error 1101: Unknown Equation= ', a)
344  CALL finl_err_msg
345  END SELECT ! end selection of usr_source equation
346 
347  RETURN
348  END SUBROUTINE calc_usr_source
349 
350  end module usr_src
351 
logical, dimension(0:dim_m) momentum_y_eq
Definition: run_mod.f:77
integer, dimension(:), allocatable i_of
Definition: indices_mod.f:45
integer ijkend3
Definition: compar_mod.f:80
double precision, dimension(:), allocatable ep_g
Definition: fldvar_mod.f:15
subroutine finl_err_msg
Definition: pgcor_mod.f:1
subroutine calc_usr_source(lEQ_NO, A_M, B_M, lB_MMAX, lM, lN)
Definition: usr_src_mod.f:32
integer dimension_3
Definition: param_mod.f:11
logical, dimension(0:dim_m) momentum_x_eq
Definition: run_mod.f:74
integer, parameter dim_eqs
Definition: param_mod.f:97
logical, dimension(0:dim_m) momentum_z_eq
Definition: run_mod.f:80
integer, dimension(:), allocatable phase_4_p_s
Definition: pscor_mod.f:28
subroutine init_err_msg(CALLER)
integer, dimension(:), allocatable k_of
Definition: indices_mod.f:47
integer mmax
Definition: physprop_mod.f:19
integer, dimension(:), allocatable j_of
Definition: indices_mod.f:46
Definition: pscor_mod.f:1
Definition: run_mod.f:13
subroutine usr_sources(lEQ_NO, IJK, sourcelhs, sourcerhs, M, N)
Definition: usr_sources.f:26
Definition: param_mod.f:2
double precision, parameter dil_ep_s
Definition: toleranc_mod.f:24
integer, dimension(:), allocatable phase_4_p_g
Definition: pgcor_mod.f:22
integer ijkstart3
Definition: compar_mod.f:80
integer, parameter undefined_i
Definition: param1_mod.f:19
character(len=line_length), dimension(line_count) err_msg
double precision function ep_s(IJK, xxM)
Definition: fldvar_mod.f:178
integer smax
Definition: physprop_mod.f:22
logical, dimension(dim_eqs) call_usr_source
Definition: usr_src_mod.f:7
integer dimension_m
Definition: param_mod.f:18
double precision, parameter zero
Definition: param1_mod.f:27
subroutine flush_err_msg(DEBUG, HEADER, FOOTER, ABORT, LOG, CALL_TREE)