MFIX  2016-1
solve_scalar_eq.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2 ! C
3 ! Subroutine: SOLVE_SCALAR_EQ C
4 ! Purpose: Solve scalar transport equations C
5 ! C
6 ! C
7 ! Author: M. Syamlal Date: 4-12-99 C
8 ! C
9 ! C
10 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
11  SUBROUTINE solve_scalar_eq(IER)
12 
13 ! Modules
14 !---------------------------------------------------------------------//
15  use ambm, only: a_m, b_m, lock_ambm, unlock_ambm
17  use compar, only: ijkstart3, ijkend3
18  use fldvar, only: rop_g, rop_go, ep_g, u_g, v_g, w_g
19  use fldvar, only: rop_s, rop_so, ep_s, u_s, v_s, w_s
20  use fldvar, only: scalar, scalaro
21  use functions, only: fluid_at, zmax
22  use geometry, only: vol, ijkmax2
24  use mflux, only: flux_ge, flux_gn, flux_gt
25  use mflux, only: flux_se, flux_sn, flux_st
26  use mflux, only: flux_gse, flux_gsn, flux_gst
27  use mflux, only: flux_sse, flux_ssn, flux_sst
28  use param, only: dimension_3
29  use param1, only: zero
30  use residual, only: resid, max_resid, ijk_resid
31  use residual, only: num_resid, den_resid
32  use residual, only: resid_sc
33  use run, only: discretize, added_mass, m_am, odt
34  use rxns, only: sum_r_g, sum_r_s
35  use scalars, only: nscalar, phase4scalar
36  use scalars, only: scalar_c, scalar_p, dif_scalar
37  use toleranc, only: zero_ep_s
38  use ur_facs, only: ur_fac
40  use usr_src, only: usr_scalar
41  IMPLICIT NONE
42 
43 ! Dummy arguments
44 !---------------------------------------------------------------------//
45 ! Error index
46  INTEGER, INTENT(INOUT) :: IER
47 
48 ! Local variables
49 !---------------------------------------------------------------------//
50 ! phase index
51  INTEGER :: M
52 ! species index
53  INTEGER :: NN
54 ! Indices
55  INTEGER :: IJK
56 !
57  DOUBLE PRECISION :: APO
58 !
59 ! linear equation solver method and iterations
60  INTEGER :: LEQM, LEQI
61 ! temporary variables in residual computation
62  DOUBLE PRECISION :: res1, mres1, num_res, den_res
63  INTEGER :: ires1
64 ! source vector: coefficient of dependent variable
65 ! becomes part of a_m matrix; must be positive
66  DOUBLE PRECISION :: S_P(dimension_3)
67 ! source vector: constant part becomes part of b_m vector
68  DOUBLE PRECISION :: S_C(dimension_3)
69 !
70  DOUBLE PRECISION :: EPS(dimension_3)
71 !
72  character(LEN=8) :: Vname
73 !---------------------------------------------------------------------//
74 
75  call lock_ambm
76 
77  resid(resid_sc,0) = zero
78  num_resid(resid_sc,0) = zero
79  den_resid(resid_sc,0) = zero
80  max_resid(resid_sc,0) = zero
81  ijk_resid(resid_sc,0) = 0
82 
83 ! Loop over number of scalar equations
84  DO nn = 1, nscalar
85 
86 ! Setting M to the phase assigned to convecting the indicated scalar
87 ! equation
88  m = phase4scalar(nn)
89  CALL init_ab_m (a_m, b_m, ijkmax2, m)
90 
91 ! Gas phase
92 ! ---------------------------------------------------------------->>>
93  IF(m == 0) THEN
94 
95  DO ijk = ijkstart3, ijkend3
96  IF (fluid_at(ijk)) THEN
97  apo = rop_go(ijk)*vol(ijk)*odt
98  s_p(ijk) = apo + (zmax(sum_r_g(ijk)) + &
99  scalar_p(ijk,nn))*vol(ijk)
100  s_c(ijk) = apo*scalaro(ijk,nn) + &
101  scalar(ijk,nn)*zmax((-sum_r_g(ijk)))*vol(ijk) + &
102  scalar_c(ijk, nn)*vol(ijk)
103  ELSE
104  s_p(ijk) = zero
105  s_c(ijk) = zero
106  ENDIF
107  ENDDO
108 
109  IF(.NOT.added_mass) THEN
110  CALL conv_dif_phi (scalar(1,nn), dif_scalar(1,nn), &
111  discretize(9), u_g, v_g, w_g, &
112  flux_ge, flux_gn, flux_gt, m, a_m, b_m)
113  ELSE
114  CALL conv_dif_phi (scalar(1,nn), dif_scalar(1,nn), &
115  discretize(9), u_g, v_g, w_g, &
116  flux_gse, flux_gsn, flux_gst, m, a_m, b_m)
117  ENDIF
118 
119  CALL bc_phi (scalar(1,nn), bc_scalar(1,nn), &
120  bc_scalarw(1,nn), bc_hw_scalar(1,nn), &
121  bc_c_scalar(1,nn), m, a_m, b_m)
122 
123  CALL source_phi (s_p, s_c, ep_g, scalar(1,nn), m, a_m, b_m)
124 
125 ! calculate any usr source terms
126  IF (call_usr_source(9)) CALL calc_usr_source(usr_scalar,&
127  a_m, b_m, lm=m, ln=nn)
128 
129  CALL calc_resid_s (scalar(1,nn), a_m, b_m, m, num_res, &
130  den_res, res1, mres1, ires1, zero)
131  resid(resid_sc,0) = resid(resid_sc,0)+res1
132  num_resid(resid_sc,0) = num_resid(resid_sc,0)+num_res
133  den_resid(resid_sc,0) = den_resid(resid_sc,0)+den_res
134  if(mres1 .gt. max_resid(resid_sc,0))then
135  max_resid(resid_sc,0) = mres1
136  ijk_resid(resid_sc,0) = ires1
137  endif
138 
139  CALL under_relax_s (scalar(1,nn), a_m, b_m, m, ur_fac(9))
140 
141 ! call check_ab_m(a_m, b_m, m, .false., ier)
142 ! call write_ab_m(a_m, b_m, ijkmax2, m, ier)
143 ! write(*,*) res1, mres1, ires1
144 ! call test_lin_eq(ijkmax2, ijmax2, imax2, a_m(1, -3, 0), 1, &
145 ! DO_K, ier)
146 
147  CALL adjust_leq (res1, leq_it(9), leq_method(9), &
148  leqi, leqm)
149 
150  write(vname, '(A,I2)')'Scalar',nn
151  CALL solve_lin_eq (vname, 9, scalar(1,nn), a_m, b_m, m,&
152  leqi, leqm, leq_sweep(9), leq_tol(9),&
153  leq_pc(9), ier)
154 ! call out_array(Scalar(1, N), Vname)
155 
156 ! Solids phase
157 ! ---------------------------------------------------------------->>>
158  ELSE ! (m/=0) , i.e., solids phase
159 
160  DO ijk = ijkstart3, ijkend3
161  IF (fluid_at(ijk)) THEN
162  apo = rop_so(ijk, m)*vol(ijk)*odt
163  s_p(ijk) = apo + (zmax(sum_r_s(ijk, m)) + &
164  scalar_p(ijk, nn))*vol(ijk)
165  s_c(ijk) = apo*scalaro(ijk,nn) + &
166  scalar(ijk,nn)*zmax((-sum_r_s(ijk, m)))*vol(ijk)+&
167  scalar_c(ijk, nn)*vol(ijk)
168  eps(ijk) = ep_s(ijk, m)
169  ELSE
170  s_p(ijk) = zero
171  s_c(ijk) = zero
172  eps(ijk) = zero
173  ENDIF
174  ENDDO
175 
176  IF(.NOT.added_mass .OR. m /= m_am) THEN
177  CALL conv_dif_phi (scalar(1,nn), dif_scalar(1,nn), &
178  discretize(9), u_s(1,m), v_s(1,m), &
179  w_s(1,m), flux_se(1,m), flux_sn(1,m),&
180  flux_st(1,m), m, a_m, b_m)
181  ELSE ! virtual mass term added for M = M_AM ONLY!!!!
182  CALL conv_dif_phi (scalar(1,nn), dif_scalar(1,nn), &
183  discretize(9), u_s(1,m), v_s(1,m), &
184  w_s(1,m), flux_sse, flux_ssn, flux_sst, &
185  m, a_m, b_m)
186  ENDIF
187 
188  CALL bc_phi (scalar(1,nn), bc_scalar(1,nn), bc_scalarw(1,nn), &
189  bc_hw_scalar(1,nn), bc_c_scalar(1,nn), m, a_m, b_m)
190 
191  CALL source_phi (s_p, s_c, eps, scalar(1,nn), m, a_m, b_m)
192 
193 ! calculate any usr source terms
194  IF (call_usr_source(9)) CALL calc_usr_source(usr_scalar,&
195  a_m, b_m, lm=m, ln=nn)
196 
197 
198  CALL calc_resid_s (scalar(1,nn), a_m, b_m, m, num_res, &
199  den_res, res1, mres1, ires1, zero)
200  resid(resid_sc,0) = resid(resid_sc,0)+res1
201  num_resid(resid_sc,0) = num_resid(resid_sc,0)+num_res
202  den_resid(resid_sc,0) = den_resid(resid_sc,0)+den_res
203  if(mres1 .gt. max_resid(resid_sc,0))then
204  max_resid(resid_sc,0) = mres1
205  ijk_resid(resid_sc,0) = ires1
206  endif
207 
208  CALL under_relax_s (scalar(1,nn), a_m, b_m, m, ur_fac(9))
209 
210 ! call check_ab_m(a_m, b_m, m, .false., ier)
211 ! call write_ab_m(a_m, b_m, ijkmax2, m, ier)
212 ! write(*,*) res1, mres1, ires1
213 ! call test_lin_eq(ijkmax2, ijmax2, imax2, a_m(1, -3, 0), 1, &
214 ! DO_K, ier)
215 
216  CALL adjust_leq (res1, leq_it(9), leq_method(9), &
217  leqi, leqm)
218 
219  write(vname, '(A,I2)')'Scalar',nn
220  CALL solve_lin_eq (vname, 9, scalar(1,nn), a_m, b_m, m, &
221  leqi, leqm, leq_sweep(9), leq_tol(9), &
222  leq_pc(9), ier)
223 ! call out_array(Scalar(1, N), Vname)
224 
225  ENDIF
226  ENDDO
227 
228  call unlock_ambm
229 
230  RETURN
231  END SUBROUTINE solve_scalar_eq
double precision, dimension(:,:,:), allocatable a_m
Definition: ambm_mod.f:27
double precision, dimension(:), allocatable flux_ge
Definition: mflux_mod.f:13
double precision, dimension(:,:), allocatable v_s
Definition: fldvar_mod.f:105
double precision, dimension(dim_eqs) ur_fac
Definition: ur_facs_mod.f:6
double precision, dimension(dimension_bc, dim_scalar) bc_scalarw
Definition: bc_mod.f:396
integer ijkend3
Definition: compar_mod.f:80
double precision, dimension(:), allocatable ep_g
Definition: fldvar_mod.f:15
double precision, dimension(:), allocatable flux_gst
Definition: mflux_mod.f:32
double precision, dimension(dimension_bc, dim_scalar) bc_c_scalar
Definition: bc_mod.f:392
double precision, dimension(:,:), allocatable flux_st
Definition: mflux_mod.f:24
double precision, dimension(:,:), allocatable scalar_c
Definition: scalars_mod.f:14
double precision, dimension(:,:), allocatable scalar_p
Definition: scalars_mod.f:15
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
integer ijkmax2
Definition: geometry_mod.f:80
subroutine init_ab_m(A_M, B_M, IJKMAX2A, M)
Definition: init_ab_m.f:21
subroutine solve_scalar_eq(IER)
logical added_mass
Definition: run_mod.f:91
double precision, dimension(:,:), allocatable w_s
Definition: fldvar_mod.f:117
double precision, dimension(:,:), allocatable den_resid
Definition: residual_mod.f:52
Definition: rxns_mod.f:1
double precision, dimension(:), allocatable flux_ssn
Definition: mflux_mod.f:31
subroutine under_relax_s(VAR, A_M, B_M, M, UR)
Definition: under_relax.f:21
double precision, dimension(:,:), allocatable scalar
Definition: fldvar_mod.f:155
double precision, dimension(:), allocatable sum_r_g
Definition: rxns_mod.f:28
double precision, dimension(:,:), allocatable sum_r_s
Definition: rxns_mod.f:35
subroutine calc_resid_s(VAR, A_M, B_M, M, NUM, DEN, RESID, MAX_RESID, IJK_RESID, TOL)
Definition: calc_resid.f:197
double precision, dimension(:,:), allocatable num_resid
Definition: residual_mod.f:49
Definition: ambm_mod.f:16
character(len=4), dimension(dim_eqs) leq_sweep
Definition: leqsol_mod.f:20
integer, parameter resid_sc
Definition: residual_mod.f:17
double precision, dimension(:,:), allocatable dif_scalar
Definition: scalars_mod.f:18
double precision, dimension(:,:), allocatable u_s
Definition: fldvar_mod.f:93
double precision, dimension(:,:), allocatable scalaro
Definition: fldvar_mod.f:158
double precision, dimension(:), allocatable flux_gse
Definition: mflux_mod.f:28
double precision, dimension(:,:), allocatable max_resid
Definition: residual_mod.f:40
integer, dimension(dim_eqs) leq_it
Definition: leqsol_mod.f:11
double precision, dimension(:), allocatable flux_gn
Definition: mflux_mod.f:15
integer m_am
Definition: run_mod.f:94
double precision, parameter zero_ep_s
Definition: toleranc_mod.f:15
subroutine lock_ambm
Definition: ambm_mod.f:38
double precision, dimension(dimension_bc, dim_scalar) bc_scalar
Definition: bc_mod.f:384
double precision odt
Definition: run_mod.f:54
subroutine bc_phi(VAR, BC_PHIF, BC_PHIW, BC_HW_PHI, BC_C_PHI, M, A_M, B_M)
Definition: bc_phi.f:13
double precision, dimension(:), allocatable v_g
Definition: fldvar_mod.f:99
subroutine adjust_leq(RESID, LEQ_ITL, LEQ_METHODL, LEQI, LEQM)
Definition: adjust_leq.f:21
double precision, dimension(:), allocatable w_g
Definition: fldvar_mod.f:111
double precision, dimension(dim_eqs) leq_tol
Definition: leqsol_mod.f:23
double precision, dimension(:,:), allocatable rop_so
Definition: fldvar_mod.f:54
Definition: run_mod.f:13
Definition: param_mod.f:2
double precision, dimension(:), allocatable flux_gt
Definition: mflux_mod.f:17
integer, dimension(:,:), allocatable ijk_resid
Definition: residual_mod.f:46
double precision, dimension(:), allocatable rop_go
Definition: fldvar_mod.f:41
subroutine conv_dif_phi(PHI, DIF, DISC, UF, VF, WF, Flux_E, Flux_N, Flux_T, M, A_M, B_M)
Definition: conv_dif_phi.f:23
integer ijkstart3
Definition: compar_mod.f:80
double precision, dimension(:), allocatable u_g
Definition: fldvar_mod.f:87
integer nscalar
Definition: scalars_mod.f:7
double precision function ep_s(IJK, xxM)
Definition: fldvar_mod.f:178
integer, dimension(dim_eqs) discretize
Definition: run_mod.f:67
integer, dimension(dim_eqs) leq_method
Definition: leqsol_mod.f:14
double precision, dimension(:,:), allocatable rop_s
Definition: fldvar_mod.f:51
double precision, dimension(:,:), allocatable flux_se
Definition: mflux_mod.f:22
double precision, dimension(:), allocatable flux_gsn
Definition: mflux_mod.f:30
subroutine source_phi(S_P, S_C, EP, PHI, M, A_M, B_M)
Definition: source_phi.f:26
logical, dimension(dim_eqs) call_usr_source
Definition: usr_src_mod.f:7
double precision, dimension(:,:), allocatable resid
Definition: residual_mod.f:37
double precision, dimension(:,:), allocatable b_m
Definition: ambm_mod.f:28
integer, dimension(1:dim_scalar) phase4scalar
Definition: scalars_mod.f:10
double precision, dimension(:), allocatable vol
Definition: geometry_mod.f:212
double precision, dimension(:), allocatable rop_g
Definition: fldvar_mod.f:38
double precision, dimension(:,:), allocatable flux_sn
Definition: mflux_mod.f:20
double precision, dimension(dimension_bc, dim_scalar) bc_hw_scalar
Definition: bc_mod.f:388
double precision, parameter zero
Definition: param1_mod.f:27
subroutine unlock_ambm
Definition: ambm_mod.f:52
double precision, dimension(:), allocatable flux_sst
Definition: mflux_mod.f:33
Definition: bc_mod.f:23
double precision, dimension(:), allocatable flux_sse
Definition: mflux_mod.f:29
subroutine solve_lin_eq(VNAME, Vno, VAR, A_M, B_M, M, ITMAX, METHOD, SWEEP, TOL1, PC, IER)
Definition: solve_lin_eq.f:19
character(len=4), dimension(dim_eqs) leq_pc
Definition: leqsol_mod.f:26