MFIX  2016-1
solve_species_eq.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2 ! C
3 ! Subroutine: SOLVE_SPECIES_EQ C
4 ! Purpose: Solve species mass balance equations in matrix equation C
5 ! form Ax=b. The center coefficient (ap) and source vector (b) C
6 ! are negative. The off-diagonal coefficients are positive. C
7 ! C
8 ! Author: M. Syamlal Date: 11-FEB-98 C
9 ! Reviewer: Date: C
10 ! C
11 ! Literature/Document References: C
12 ! C
13 ! Variables referenced: C
14 ! Variables modified: C
15 ! Local variables: C
16 ! C
17 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
18  SUBROUTINE solve_species_eq(IER)
19 
20 ! Modules
21 !---------------------------------------------------------------------//
22  use ambm, only: a_m, b_m, lock_ambm, unlock_ambm
23  use bc, only: bc_x_g, bc_xw_g, bc_hw_x_g, bc_c_x_g
24  use bc, only: bc_x_s, bc_xw_s, bc_hw_x_s, bc_c_x_s
25  use chischeme, only: set_chi, unset_chi
26  use compar, only: ijkstart3, ijkend3, mype, numpes
27  use fldvar, only: ep_g, u_g, v_g, w_g, x_g, x_go, rop_go
28  use fldvar, only: ep_s, u_s, v_s, w_s, x_s, x_so, rop_so
29  use functions, only: fluid_at, zmax
30  use geometry, only: ijkmax2, vol
32  use mflux, only: flux_ge, flux_gse, flux_gn, flux_gsn
33  use mflux, only: flux_se, flux_sse, flux_sn, flux_ssn
34  use mflux, only: flux_gt, flux_gst, flux_st, flux_sst
35  use mpi_utility, only: global_all_sum
36  use param, only: dimension_3, dimension_m
38  use param1, only: zero
39  use physprop, only: nmax, dif_g, dif_s
40  use physprop, only: smax
41  use ps, only: point_source
42  use ps, only: ps_x_g, ps_massflow_g
43  use ps, only: ps_x_s, ps_massflow_s
44  use residual, only: resid, max_resid, ijk_resid
45  use residual, only: num_resid, den_resid
46  use residual, only: resid_x
48  use run, only: chi_scheme
49  use rxns, only: sum_r_g, rox_gc, r_gp
50  use rxns, only: sum_r_s, rox_sc, r_sp
51  use toleranc, only: zero_x_gs
52  use ur_facs, only: ur_fac
54  use usr_src, only: gas_species, solids_species
55  use utilities, only: bound_x
56  IMPLICIT NONE
57 
58 ! Dummy arguments
59 !---------------------------------------------------------------------//
60 ! Error index
61  INTEGER, INTENT(INOUT) :: IER
62 
63 ! Local variables
64 !---------------------------------------------------------------------//
65 ! phase index
66  INTEGER :: M
67 ! species index
68  INTEGER :: LN
69 ! previous time step term
70  DOUBLE PRECISION :: apo
71 ! Indices
72  INTEGER :: IJK
73 ! linear equation solver method and iterations
74  INTEGER :: LEQM, LEQI
75 ! tmp array to pass to set_chi
76  DOUBLE PRECISION :: X_s_temp(dimension_3, dimension_n_s)
77 
78 ! Arrays for storing errors:
79 ! 130 - Gas phase species equation diverged
80 ! 131 - Solids phase species equation diverged
81 ! 13x - Unclassified
82  INTEGER :: Err_l(0:numpes-1) ! local
83  INTEGER :: Err_g(0:numpes-1) ! global
84 
85 ! temporary use of global arrays:
86 ! array1 (locally s_p)
87 ! source lhs: coefficient of dependent variable
88 ! becomes part of a_m matrix; must be positive
89  DOUBLE PRECISION :: S_P(dimension_3)
90 ! array2 (locally s_c)
91 ! source rhs vector: constant part becomes part of b_m vector
92  DOUBLE PRECISION :: S_C(dimension_3)
93 ! array3 (locally eps)
94 ! alias for solids volume fraction
95  DOUBLE PRECISION :: eps(dimension_3)
96 ! array4 (locally vxgama)
97  DOUBLE PRECISION :: vxgama(dimension_3)
98 ! Septadiagonal matrix A_m, vector b_m
99 ! DOUBLE PRECISION A_m(DIMENSION_3, -3:3, 0:DIMENSION_M)
100 ! DOUBLE PRECISION B_m(DIMENSION_3, 0:DIMENSION_M)
101 
102 ! External functions
103 !---------------------------------------------------------------------//
104  DOUBLE PRECISION , EXTERNAL :: Check_conservation
105 !---------------------------------------------------------------------//
106 
107  call lock_ambm ! locks arrys a_m and b_m
108 
109 ! Initialize error flag.
110  err_l = 0
111 
112 ! Fluid phase species mass balance equations
113 ! ---------------------------------------------------------------->>>
114  IF (species_eq(0)) THEN
115  IF(chi_scheme) call set_chi(discretize(7), x_g, nmax(0), &
116  u_g, v_g, w_g)
117 
118 ! looping over species
119  DO ln = 1, nmax(0)
120  CALL init_ab_m (a_m, b_m, ijkmax2, 0)
121 !!$omp parallel do private(IJK, APO)
122  DO ijk = ijkstart3, ijkend3
123  IF (fluid_at(ijk)) THEN
124 ! calculate the source terms to be used in the a matrix and b vector
125  apo = rop_go(ijk)*vol(ijk)*odt
126  s_p(ijk) = apo+&
127  (zmax(sum_r_g(ijk))+rox_gc(ijk,ln))*vol(ijk)
128  s_c(ijk) = apo*x_go(ijk,ln) + &
129  x_g(ijk,ln)*zmax((-sum_r_g(ijk)))*vol(ijk) +&
130  r_gp(ijk,ln)*vol(ijk)
131  ELSE
132  s_p(ijk) = zero
133  s_c(ijk) = zero
134  ENDIF
135  ENDDO
136 
137 ! calculate the convection-diffusion terms
138  IF(.NOT.added_mass) THEN
139  CALL conv_dif_phi (x_g(1,ln), dif_g(1,ln), &
140  discretize(7), u_g, v_g, w_g, &
141  flux_ge, flux_gn, flux_gt, 0, a_m, b_m)
142  ELSE
143  CALL conv_dif_phi (x_g(1,ln), dif_g(1,ln),&
144  discretize(7), u_g, v_g, w_g, &
145  flux_gse, flux_gsn, flux_gst, 0, a_m, b_m)
146  ENDIF
147 
148 ! calculate standard bc
149  CALL bc_phi (x_g(1,ln), bc_x_g(1,ln), bc_xw_g(1,ln), &
150  bc_hw_x_g(1,ln), bc_c_x_g(1,ln), 0, a_m, b_m)
151 
152 ! set the source terms in a and b matrix form
153  CALL source_phi (s_p, s_c, ep_g, x_g(1,ln), 0, a_m, b_m)
154 
155 ! Add point sources.
156  IF(point_source) CALL point_source_phi (x_g(1,ln), &
157  ps_x_g(:,ln), ps_massflow_g, 0, a_m, b_m)
158 
159 ! usr sources
160  IF(call_usr_source(8)) CALL calc_usr_source(gas_species, &
161  a_m, b_m, lm=0, ln=ln)
162 
163  CALL calc_resid_s (x_g(1,ln), a_m, b_m, 0, &
164  num_resid(resid_x+(ln-1),0), &
165  den_resid(resid_x+(ln-1),0), resid(resid_x+(ln-1),0), &
166  max_resid(resid_x+(ln-1),0), ijk_resid(resid_x+(ln-1),0), &
167  zero_x_gs)
168 
169  CALL under_relax_s (x_g(1,ln), a_m, b_m, 0, ur_fac(7))
170 
171  CALL adjust_leq (resid(resid_x+(ln-1),0), leq_it(7), &
172  leq_method(7), leqi, leqm)
173 
174 ! solve the phi equation
175  CALL solve_lin_eq ('X_g', 7, x_g(1,ln), a_m, b_m, 0, &
176  leqi, leqm, leq_sweep(7), leq_tol(7), leq_pc(7), ier)
177 
178 ! Check for linear solver divergence.
179  IF(ier == -2) err_l(mype) = 130
180 
181  CALL bound_x (x_g(1,ln), ijkmax2)
182 
183  ENDDO ! end do loop (ln = 1, nmax(0)
184  IF(chi_scheme) call unset_chi()
185  ENDIF
186 ! end fluid phase species equations
187 ! ----------------------------------------------------------------<<<
188 
189 ! Solids phase species balance equations
190 ! ---------------------------------------------------------------->>>
191  DO m = 1, smax
192  IF (species_eq(m)) THEN
193  IF(chi_scheme) THEN
194  DO ln = 1, nmax(m)
195  DO ijk = ijkstart3, ijkend3
196  x_s_temp(ijk, ln) = x_s(ijk,m,ln)
197  ENDDO
198  ENDDO
199  call set_chi(discretize(7), x_s_temp, nmax(m), &
200  u_s(1,m), v_s(1,m), w_s(1,m))
201  ENDIF ! for chi_scheme
202 
203  DO ln = 1, nmax(m)
204  CALL init_ab_m (a_m, b_m, ijkmax2, m)
205 
206 !!$omp parallel do private(IJK, APO)
207  DO ijk = ijkstart3, ijkend3
208  IF (fluid_at(ijk)) THEN
209  apo = rop_so(ijk,m)*vol(ijk)*odt
210  s_p(ijk) = apo + &
211  (zmax(sum_r_s(ijk,m))+rox_sc(ijk,m,ln))*vol(ijk)
212  s_c(ijk) = apo*x_so(ijk,m,ln) + &
213  x_s(ijk,m,ln)*zmax((-sum_r_s(ijk,m)))*vol(ijk) + &
214  r_sp(ijk,m,ln)*vol(ijk)
215  eps(ijk) = ep_s(ijk,m)
216  ELSE
217  s_p(ijk) = zero
218  s_c(ijk) = zero
219  eps(ijk) = zero
220  ENDIF
221  ENDDO
222 
223  IF(.NOT.added_mass .OR. m /= m_am) THEN
224  CALL conv_dif_phi (x_s(1,m,ln), dif_s(1,m,ln), &
225  discretize(7), u_s(1,m), v_s(1,m), w_s(1,m), &
226  flux_se(1,m), flux_sn(1,m), flux_st(1,m), m, a_m, b_m)
227  ELSE
228  CALL conv_dif_phi (x_s(1,m,ln), dif_s(1,m,ln), &
229  discretize(7), u_s(1,m), v_s(1,m), w_s(1,m), &
230  flux_sse, flux_ssn, flux_sst, m, a_m, b_m)
231  ENDIF
232 
233  CALL bc_phi (x_s(1,m,ln), bc_x_s(1,m,ln), &
234  bc_xw_s(1,m,ln), bc_hw_x_s(1,m,ln), &
235  bc_c_x_s(1,m,ln), m, a_m, b_m)
236 
237  CALL source_phi (s_p, s_c, eps, x_s(1,m,ln), m, a_m, b_m)
238 
239 ! Add point sources.
240  IF(point_source) CALL point_source_phi (x_s(1,m,ln), &
241  ps_x_s(:,m,ln), ps_massflow_s(:,m), m, a_m, b_m)
242 
243 ! usr sources
244  IF(call_usr_source(8)) CALL calc_usr_source(solids_species,&
245  a_m, b_m, lm=m, ln=ln)
246 
247  CALL calc_resid_s (x_s(1,m,ln), a_m, b_m, m, &
248  num_resid(resid_x+(ln-1),m), &
249  den_resid(resid_x+(ln-1),m), resid(resid_x+(ln-1),&
250  m), max_resid(resid_x+(ln-1),m), ijk_resid(resid_x+(ln-1),m), &
251  zero_x_gs)
252 
253  CALL under_relax_s (x_s(1,m,ln), a_m, b_m, m, ur_fac(7))
254 
255 ! call check_ab_m(a_m, b_m, m, .false., ier)
256 ! write(*,*) resid(resid_x+(LN-1), m), &
257 ! max_resid(resid_x+(LN-1), m), &
258 ! ijk_resid(resid_x+(LN-1), m)
259 ! call write_ab_m(a_m, b_m, ijkmax2, m, ier)
260 !
261 ! call test_lin_eq(ijkmax2, ijmax2, imax2, a_m(1,-3,M),&
262 ! 1, DO_K, ier)
263 
264  CALL adjust_leq (resid(resid_x+(ln-1),m), leq_it(7), &
265  leq_method(7), leqi, leqm)
266 
267  CALL solve_lin_eq ('X_s', 7, x_s(1,m,ln), a_m, b_m, m,&
268  leqi, leqm, leq_sweep(7), leq_tol(7), leq_pc(7), ier)
269 
270 ! Check for linear solver divergence.
271  IF(ier == -2) err_l(mype) = 131
272 
273  CALL bound_x (x_s(1,m,ln), ijkmax2)
274 ! call out_array(X_s(1,m,LN), 'X_s')
275 
276  END DO
277 
278  if(chi_scheme) call unset_chi()
279  ENDIF ! check for any species in phase m
280  END DO ! for m = 1, mmax
281 ! end solids phases species equations
282 ! ----------------------------------------------------------------<<<
283 
284  call unlock_ambm
285 
286 ! If the linear solver diverged, species mass fractions may take on
287 ! unphysical values. To prevent them from propogating through the domain
288 ! or causing failure in other routines, force an exit from iterate and
289 ! reduce the time step.
290  CALL global_all_sum(err_l, err_g)
291  ier = maxval(err_g)
292 
293  RETURN
294  END SUBROUTINE solve_species_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
integer ijkend3
Definition: compar_mod.f:80
double precision, dimension(dimension_bc, dim_m, dim_n_s) bc_hw_x_s
Definition: bc_mod.f:365
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(:,:), allocatable flux_st
Definition: mflux_mod.f:24
double precision, dimension(:,:), allocatable dif_g
Definition: physprop_mod.f:110
double precision, dimension(:,:,:), allocatable x_so
Definition: fldvar_mod.f:84
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
double precision, dimension(dimension_bc, dim_n_g) bc_c_x_g
Definition: bc_mod.f:374
integer ijkmax2
Definition: geometry_mod.f:80
subroutine init_ab_m(A_M, B_M, IJKMAX2A, M)
Definition: init_ab_m.f:21
integer dimension_n_g
Definition: param_mod.f:20
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
logical, dimension(0:dim_m) species_eq
Definition: run_mod.f:115
double precision, dimension(dimension_bc, dim_m, dim_n_s) bc_x_s
Definition: bc_mod.f:254
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 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
double precision, dimension(:,:,:), allocatable rox_sc
Definition: rxns_mod.f:33
double precision, dimension(dimension_ps) ps_massflow_g
Definition: ps_mod.f:48
subroutine unset_chi()
double precision, dimension(:,:), allocatable u_s
Definition: fldvar_mod.f:93
integer numpes
Definition: compar_mod.f:24
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 x_s
Definition: fldvar_mod.f:78
double precision, dimension(dimension_bc, dim_m, dim_n_s) bc_c_x_s
Definition: bc_mod.f:377
double precision, dimension(:), allocatable flux_gn
Definition: mflux_mod.f:15
double precision, dimension(:,:), allocatable x_g
Definition: fldvar_mod.f:75
integer m_am
Definition: run_mod.f:94
logical chi_scheme
Definition: run_mod.f:71
subroutine lock_ambm
Definition: ambm_mod.f:38
double precision, dimension(dimension_bc, dim_m, dim_n_s) bc_xw_s
Definition: bc_mod.f:371
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 r_sp
Definition: rxns_mod.f:31
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 dif_s
Definition: physprop_mod.f:116
double precision, dimension(:,:), allocatable rop_so
Definition: fldvar_mod.f:54
Definition: run_mod.f:13
double precision, dimension(dimension_ps, dim_n_g) ps_x_g
Definition: ps_mod.f:59
double precision, dimension(dimension_bc, dim_n_g) bc_xw_g
Definition: bc_mod.f:368
Definition: param_mod.f:2
double precision, dimension(:), allocatable flux_gt
Definition: mflux_mod.f:17
double precision, dimension(:,:), allocatable rox_gc
Definition: rxns_mod.f:26
integer, dimension(:,:), allocatable ijk_resid
Definition: residual_mod.f:46
integer, dimension(0:dim_m) nmax
Definition: physprop_mod.f:119
double precision, dimension(:), allocatable rop_go
Definition: fldvar_mod.f:41
integer mype
Definition: compar_mod.f:24
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
double precision, dimension(:,:), allocatable x_go
Definition: fldvar_mod.f:81
integer ijkstart3
Definition: compar_mod.f:80
subroutine point_source_phi(PHI, PS_PHI, PS_FLOW, M, A_M, B_M)
Definition: source_phi.f:155
double precision, dimension(dimension_ps, dim_m) ps_massflow_s
Definition: ps_mod.f:66
double precision, dimension(:), allocatable u_g
Definition: fldvar_mod.f:87
double precision function ep_s(IJK, xxM)
Definition: fldvar_mod.f:178
double precision, dimension(dimension_bc, dim_n_g) bc_x_g
Definition: bc_mod.f:251
integer, dimension(dim_eqs) discretize
Definition: run_mod.f:67
subroutine bound_x(ARRAY, IJKMAX2)
subroutine set_chi(DISCR, PHI, Nmax, U, V, W)
Definition: chischeme_mod.f:44
double precision, dimension(dimension_ps, dim_m, dim_n_s) ps_x_s
Definition: ps_mod.f:77
Definition: ps_mod.f:22
double precision, parameter zero_x_gs
Definition: toleranc_mod.f:19
integer, dimension(dim_eqs) leq_method
Definition: leqsol_mod.f:14
subroutine solve_species_eq(IER)
integer smax
Definition: physprop_mod.f:22
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
logical point_source
Definition: ps_mod.f:27
integer dimension_n_s
Definition: param_mod.f:21
double precision, dimension(:), allocatable vol
Definition: geometry_mod.f:212
integer, parameter resid_x
Definition: residual_mod.f:20
integer dimension_m
Definition: param_mod.f:18
double precision, dimension(:,:), allocatable flux_sn
Definition: mflux_mod.f:20
double precision, dimension(dimension_bc, dim_n_g) bc_hw_x_g
Definition: bc_mod.f:362
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
double precision, dimension(:,:), allocatable r_gp
Definition: rxns_mod.f:24
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