MFIX  2016-1
stiff_chem_rrates.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2 ! C
3 ! Subroutine: STIFF_CHEM_RRATES(IER) C
4 ! C
5 ! Purpose: Calculate reaction rates for various reactions in cell ijk C
6 ! using information from the data file C
7 ! C
8 ! Author: J. Musser Date: 12-Feb-13 C
9 ! Reviewer: Date: dd-mmm-yy C
10 ! C
11 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
12  SUBROUTINE stiff_chem_rrates(lNEQ, lTime, Y, YDOT)
13 
14 ! External Module Procedures:
15 !---------------------------------------------------------------------//
16  use stiff_chem_maps, only: mapodetomfix
17 
18 ! Global Parameters:
19 !---------------------------------------------------------------------//
20 ! Maximum number of solids phases
21  use param, only: dimension_m
22 ! Maximum number of gas species
23  use param, only: dimension_n_g
24 ! Maximum number of solid species
25  use param, only: dimension_n_s
26 
27  use param1, only: zero
28 
29 ! Global Variables:
30 !---------------------------------------------------------------------//
31 ! Number of solids phases
32  use physprop, only: mmax
33 ! Number of species
34  use physprop, only: nmax
35 
36 ! Gas Phase
37 !--------------------------------------------//
38 !Temperature
39  use fldvar, only: t_g
40 ! Species Mass Fractions
41  use fldvar, only: x_g
42 ! Gas Phase apparent density
43  use fldvar, only: rop_g
44 ! Gas phase specific heat
45  use physprop, only: c_pg
46 
47 ! Solids Phases
48 !--------------------------------------------//
49 ! Temperatures
50  use fldvar, only: t_s
51 ! Species mass fractions
52  use fldvar, only: x_s
53 ! Apparent densities
54  use fldvar, only: rop_s
55 ! Specific heats
56  use physprop, only: c_ps
57 
58  use rxns, only: reaction
59  use rxns, only: no_of_rxns
60 
61  use run, only: units
62 
63  use stiff_chem, only: ode_dimn_all
64  use stiff_chem, only: neq_dimn
65 
66  implicit none
67 
68 ! Passed Variables: Dummy argument format required by ODEPACK.
69 !---------------------------------------------------------------------//
70 ! (1) Number of ODEs to be solve
71 ! (2) Fluid cell index
72  INTEGER, intent(in) :: lNEQ(neq_dimn)
73 ! Independent variable (not used)
74  DOUBLE PRECISION, intent(in) :: lTime
75 ! Array of dependent variable initial values.
76  DOUBLE PRECISION, dimension(ODE_DIMN_all), intent(in) :: Y
77 ! Rate of change of dependent variables.
78  DOUBLE PRECISION, dimension(ODE_DIMN_all), intent(out) :: YDOT
79 
80 ! Local Variables:
81 !---------------------------------------------------------------------//
82  INTEGER :: IJK ! Fluid Cell Index
83  INTEGER :: H ! Reaction loop counter
84  INTEGER :: L, M ! Global Phase index loop counters
85  INTEGER :: N ! Global species index
86  INTEGER :: lN ! Local reaction speices index/loop counter
87  INTEGER :: mXfr ! Global phase index for mass transfer
88  INTEGER :: Node ! Variable index
89 
90 ! User-defined reaction rates returned from USR_RATES
91  DOUBLE PRECISION :: RATES(no_of_rxns)
92 ! Rate of formation (+) or consumption (-) of a species (GENERIC).
93  DOUBLE PRECISION :: lRate
94 ! Rate of formation (+) or consumption (-) of each gas phase species.
95 ! > Accumulative over all reactions.
96  DOUBLE PRECISION :: lRg(dimension_n_g)
97 ! Rate of formation (+) or consumption (-) of each gas phase species.
98 ! > Single reaction.
99  DOUBLE PRECISION :: rRg(dimension_n_g)
100 ! Heat of reaction assigned to gas phase for a reaction.
101  DOUBLE PRECISION :: rHORg
102 ! Cummulative heat of reaction assigned to gas phase.
103  DOUBLE PRECISION :: lHORg
104 ! Rate of formation (+) or consumption (-) of each solids phase species.
105 ! > Accumulative over all reactions.
106  DOUBLE PRECISION :: lRs(dimension_m, dimension_n_s)
107 ! Rate of formation (+) or consumption (-) of each solids phase species.
108 ! > Single reaction.
109  DOUBLE PRECISION :: rRs(dimension_m, dimension_n_s)
110 ! Heat of reaction assigned to the solids phase for a reaction.
111  DOUBLE PRECISION :: rHORs(dimension_m)
112 ! Cummulative heat of reaction assigned to the solids phase.
113  DOUBLE PRECISION :: lHORs(dimension_m)
114 ! Rate of interphase enthalpy transfer due to mass transfer.
115  DOUBLE PRECISION :: RxH(0:dimension_m, 0:dimension_m)
116 
117 ! Net rate of change of gas phase material.
118  DOUBLE PRECISION :: sumlRg
119 ! Net rate of change of solids phase material.
120  DOUBLE PRECISION :: sumlRs(dimension_m)
121 
122 ! Reaction limiters.
123  DOUBLE PRECISION, parameter :: speciesLimiter = 1.0d-7
124 
125 ! External Function for comparing two numbers.
126  LOGICAL, external :: COMPARE
127  DOUBLE PRECISION, external :: CALC_H
128 
129 ! UDF for Reaction Rates:
130  external usr_rates
131 
132 ! Initialize variables:
133  ijk = lneq(2)
134  rates = zero
135  ydot = zero
136 
137  lrg = zero; lhorg = zero
138  lrs = zero; lhors = zero
139 
140 ! Map the current ODE independent variables to MFIX variables.
141  CALL mapodetomfix(neq_dimn, lneq, ode_dimn_all, y)
142 
143 ! Calculate user defined reaction rates.
144  CALL usr_rates(ijk, rates)
145 
146 ! Loop over reactions.
147  rxn_lp: DO h = 1, no_of_rxns
148 
149 ! Skip empty reactions
150  IF(reaction(h)%nSpecies == 0) cycle rxn_lp
151 
152 ! Initialize local loop arrays
153  rrg = zero; rhorg = zero
154  rrs = zero; rhors = zero
155  rxh = zero
156 
157 ! Calculate the rate of formation/consumption for each species.
158 !---------------------------------------------------------------------//
159  DO ln = 1, reaction(h)%nSpecies
160 ! Global phase index.
161  m = reaction(h)%Species(ln)%pMap
162 ! Global species index.
163  n = reaction(h)%Species(ln)%sMap
164 ! Index for interphase mass transfer. For a gas/solid reaction, the
165 ! index is stored with the gas phase. For solid/solid mass transfer
166 ! the index is stored with the source phase.
167  mxfr = reaction(h)%Species(ln)%mXfr
168  lrate = rates(h) * reaction(h)%Species(ln)%MWxStoich
169 ! Gas Phase:
170  IF(m == 0) THEN
171 ! Consumption of gas phase species.
172  IF(lrate < zero) THEN
173 ! Check that there is a sufficient amount of reactant.
174  IF(x_g(ijk,n) > specieslimiter) THEN
175  rrg(n) = rrg(n) + lrate
176 ! Enthalpy transfer associated with mass transfer. (gas/solid)
177  IF(m /= mxfr) rxh(m,mxfr) = rxh(m,mxfr) + &
178  lrate * calc_h(t_g(ijk),0,n)
179  ELSE
180 ! There is an insignificant amount of reactant. Skip this reaction.
181  cycle rxn_lp
182  ENDIF
183  ELSE
184 ! Formation of gas phase species.
185  rrg(n) = rrg(n) + lrate
186 ! Enthalpy transfer associated with mass transfer. (gas/solid)
187  IF(m /= mxfr) rxh(m,mxfr) = rxh(m,mxfr) + &
188  lrate * calc_h(t_s(ijk,mxfr),0,n)
189  ENDIF
190 ! Solids Phase M:
191  ELSE
192 ! Consumption of solids phase species.
193  IF(lrate < zero) THEN
194  IF(x_s(ijk,m,n) > specieslimiter) THEN
195  rrs(m,n) = rrs(m,n) + lrate
196 ! Enthalpy transfer associated with mass transfer. (solid/solid) This
197 ! is only calculated from the source (reactant) material.
198  IF(m /= mxfr) THEN
199  IF(m < mxfr) THEN
200  rxh(m,mxfr) = rxh(m,mxfr) + &
201  lrate * calc_h(t_s(ijk,m),m,n) * &
202  reaction(h)%Species(ln)%xXfr
203  ELSE
204  rxh(mxfr,m) = rxh(mxfr,m) - &
205  lrate * calc_h(t_s(ijk,m),m,n) * &
206  reaction(h)%Species(ln)%xXfr
207  ENDIF
208  ENDIF
209  ELSE
210 ! There is an insignificant amount of reactant. Skip this reaction.
211  cycle rxn_lp
212  ENDIF
213  ELSE
214 ! Formation of solids phase species.
215  rrs(m,n) = rrs(m,n) + lrate
216  ENDIF
217  ENDIF
218  ENDDO ! Loop of species
219 
220 ! Copy the single reaction rates of formation/consumption to the total
221 ! (accumulative) rates of formation/consumption arrays. This ensures
222 ! that any reactions without sufficient reactants are not included.
223  lrg = lrg + rrg
224  lrs = lrs + rrs
225 
226 ! Calculate and store the heat of reaction.
227 !---------------------------------------------------------------------//
228 ! Automated heat of reaction calculations
229  IF(reaction(h)%Calc_DH) THEN
230 ! Loop over reaction species.
231  DO ln = 1, reaction(h)%nSpecies
232 ! Global phase index.
233  m = reaction(h)%Species(ln)%pMap
234 ! Global species index.
235  n = reaction(h)%Species(ln)%sMap
236 ! Rate of formation/consumption for speices N
237  lrate = rates(h) * reaction(h)%Species(ln)%MWxStoich
238 ! Gas phase enthalpy chnage from energy equation derivation.
239  IF(m == 0) THEN
240  rhorg = rhorg + lrate * calc_h(t_g(ijk),0,n)
241 ! Solid phase enthalpy change from energy equation derivation.
242  ELSE
243  rhors(m) = rhors(m) + lrate * calc_h(t_s(ijk,m),m,n)
244  ENDIF
245  ENDDO
246 
247 ! Complete the skew-symettric for enthalpy transfer with mass transfer
248  DO m=1, mmax
249  DO l=0, m-1
250  rxh(m,l) = - rxh(l,m)
251  ENDDO
252  ENDDO
253 ! Apply enthalpy transfer associated with mass transfer to get the
254 ! complete heat of reaction of heat phse for Reaction H.
255  DO l=0, mmax
256  DO m = 0, mmax
257  IF(l == m) cycle
258  IF(l == 0) THEN
259  rhorg = rhorg - rxh(l,m)
260  ELSE
261  rhors(l) = rhors(l) - rxh(l,m)
262  ENDIF
263  ENDDO
264  ENDDO
265 
266 ! Convert the heat of reaction to the appropriate units (if SI), and
267 ! store in the global array.
268  IF(units == 'SI') THEN
269  lhorg = lhorg + 4.183925d3*rhorg
270  DO m=1,mmax
271  lhors(m) = lhors(m) + 4.183925d3*rhors(m)
272  ENDDO
273  ELSE
274  lhorg = lhorg + rhorg
275  DO m=1,mmax
276  lhors(m) = lhors(m) + rhors(m)
277  ENDDO
278  ENDIF
279  ELSE
280 ! User-defined heat of reaction.
281  lhorg = lhorg + reaction(h)%HoR(0) * rates(h)
282  DO m=1, mmax
283  lhors(m) = lhors(m) + reaction(h)%HoR(m) * rates(h)
284  ENDDO
285  ENDIF
286 
287  ENDDO rxn_lp ! Loop over reactions.
288 
289 
290 
291 
292 ! Calculate and store the heat of reaction.
293 !---------------------------------------------------------------------//
294 
295 ! Calculate the net change for the gas phase.
296  sumlrg = sum(lrg)
297 
298 ! Calculate the net change for solids phases.
299  sumlrs = 0.0d0
300  DO m=1, mmax
301  IF(lneq(2+m) == 1) sumlrs(m) = sum(lrs(m,:))
302  ENDDO
303 
304 
305 ! Calculate and store the heat of reaction.
306 !---------------------------------------------------------------------//
307 ! Initialize counter.
308  node = 1
309 
310 ! Density: ROP_g
311  ydot(node) = sumlrg
312  node = node + 1
313 
314 ! Temperature: T_g
315  ydot(node) = -lhorg/(rop_g(ijk)*c_pg(ijk))
316  node = node + 1
317 
318 ! Species mass fractions: X_g
319  DO n=1,nmax(0)
320  ydot(node) = (lrg(n) - x_g(ijk,n)*sumlrg)/(rop_g(ijk))
321  node = node + 1
322  ENDDO
323 
324 
325 ! Temperature: T_s
326  DO m = 1, mmax
327  IF(rop_s(ijk,m) > 1.0d-8) THEN
328  ydot(node) = -lhors(m)/(rop_s(ijk,m)*c_ps(ijk,m))
329  ELSE
330  ydot(node) = 0.0d0
331  ENDIF
332  node = node + 1
333  ENDDO
334 
335 
336  DO m = 1, mmax
337  IF(lneq(2+m) == 1) THEN
338 ! Solids bulk density: ROP_s
339  ydot(node) = sumlrs(m)
340  node = node + 1
341 ! Species Mass Fraction: X_s
342  DO n=1, nmax(m)
343  ydot(node) = (lrs(m,n) - x_s(ijk,m,n)*sumlrs(m)) / &
344  rop_s(ijk,m)
345  node = node + 1
346  ENDDO
347  ENDIF
348  ENDDO
349 
350  RETURN
351  END SUBROUTINE stiff_chem_rrates
double precision, dimension(:,:), allocatable c_ps
Definition: physprop_mod.f:86
integer neq_dimn
integer dimension_n_g
Definition: param_mod.f:20
Definition: rxns_mod.f:1
double precision, dimension(:), allocatable t_g
Definition: fldvar_mod.f:63
subroutine, public mapodetomfix(lnD, lNEQ, loD, lVars)
subroutine usr_rates(IJK, RATES)
Definition: usr_rates.f:37
integer mmax
Definition: physprop_mod.f:19
double precision, dimension(:,:,:), allocatable x_s
Definition: fldvar_mod.f:78
double precision, dimension(:,:), allocatable t_s
Definition: fldvar_mod.f:66
double precision, dimension(:,:), allocatable x_g
Definition: fldvar_mod.f:75
integer no_of_rxns
Definition: rxns_mod.f:41
Definition: run_mod.f:13
Definition: param_mod.f:2
character(len=16) units
Definition: run_mod.f:30
integer, dimension(0:dim_m) nmax
Definition: physprop_mod.f:119
subroutine stiff_chem_rrates(lNEQ, lTime, Y, YDOT)
double precision, dimension(:,:), allocatable rop_s
Definition: fldvar_mod.f:51
integer ode_dimn_all
integer dimension_n_s
Definition: param_mod.f:21
integer dimension_m
Definition: param_mod.f:18
double precision, dimension(:), allocatable rop_g
Definition: fldvar_mod.f:38
double precision, parameter zero
Definition: param1_mod.f:27
double precision, dimension(:), allocatable c_pg
Definition: physprop_mod.f:80