MFIX  2016-1
read_database.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2 ! C
3 ! Module name: read_database(Ier) C
4 ! Purpose: read thermochemical database C
5 ! C
6 ! Author: M. Syamlal Date: 21-OCT-05 C
7 ! C
8 ! Modification 1: J. Musser Date: 02-May-11 C
9 ! Purpose: Provided support for DEM access to database. C
10 ! C
11 ! Modification 2: J. Musser Date: 02-Oct-12 C
12 ! Purpose: Calls to READ_DATABASE were moved to check_gas_phase and C
13 ! check_solids_common_all during input data integrity checks for the C
14 ! gas and solids phases. C
15 ! Rather than looping through all species for each phase, the model C
16 ! (TFM/DEM), phase index, species index, species name, and molecular C
17 ! weight are passed as dummy arguments so that only information for C
18 ! referenced species (lName) is obtained. C
19 ! C
20 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
21  SUBROUTINE read_database(lM, lN, lName, lMW)
22 
23  USE param
24  USE param1
25  USE physprop
26  USE constant
27  USE compar
28  USE rxns
29  USE funits
30  USE discretelement
31  USE des_rxns
33  use run, only: reinitializing
34  use error_manager
35 
36  IMPLICIT NONE
37 
38 ! Phase and species indices
39  INTEGER, INTENT(IN) :: lM, lN
40 ! Species name from data file.
41  CHARACTER(len=*), INTENT(IN) :: lName
42 ! Species molecular weight from the data file (if any)
43  DOUBLE PRECISION, INTENT(INOUT) :: lMW
44 
45 ! Molecular weight read from database.
46  DOUBLE PRECISION dbMW
47 
48 ! Error message returned from Read_Therm and sent to calling routine
49  INTEGER IER
50 ! File unit of databases searched
51  INTEGER FUNIT
52 ! Loop counter for checking all three locations for data
53  INTEGER FILE
54 ! Input/Output error status ( 0 is no error)
55  INTEGER IOS
56 
57 ! Identifies if an error was detected.
58  LOGICAL ErrorFlag
59 
60 ! Tcom +/- SMALL_NUMBER: This is done so that the specific heat
61 ! polynomial can be evaluated at Tcom with the high and low
62 ! coefficients.
63  DOUBLE PRECISION :: xTc
64 
65 ! Various integrations of the specific heat polynomials:
66  DOUBLE PRECISION :: ICpoR_TrL ! 0.0 --> Tref using Alow
67  DOUBLE PRECISION :: ICpoR_TcL ! 0.0 --> Tcom using Alow
68  DOUBLE PRECISION :: ICpoR_TcH ! 0.0 --> Tcom using Ahigh
69 
70  LOGICAL :: testCp = .false.
71 ! Database being searched.
72  CHARACTER(len=256) :: DB
73 
74 #ifdef BURCAT_THR
75  therm = burcat_thr
76 #endif
77 
78  CALL init_err_msg('READ_DATABASE')
79 
80 ! Initialize the file unit to be used.
81  funit = unit_dat ! .dat file unit
82 ! Read data from mfix.dat or from BURCAT.THR in run directory or
83 ! mfix directory.
84  file = 0
85  db_lp: DO
86  file = file + 1
87 ! Check for thermochemical data in the mfix.dat file.
88  IF(file == 1) THEN
89  OPEN(convert='BIG_ENDIAN',unit=funit, file='mfix.dat', status='OLD', iostat= ios)
90  IF(ios /= 0) cycle db_lp
91  db=''; WRITE(db,1000) 'mfix.dat'
92 ! Read thermochemical data from the BURCAT.THR database in the local
93 ! run directory.
94  ELSEIF(file == 2) THEN
95  OPEN(convert='BIG_ENDIAN',unit=funit,file=trim(therm), status='OLD', iostat= ios)
96  IF(ios /= 0) cycle db_lp
97  db=''; WRITE(db,1000) trim(therm)
98  ELSE
99  EXIT db_lp
100  ENDIF
101 
102  rewind(unit=funit)
103 
104 ! Initialize the error flag
105  ier = 0
106 
107  CALL read_therm(funit, lname, thigh(lm,ln), tlow(lm,ln), &
108  tcom(lm,ln), dbmw, ahigh(:,lm,ln), alow(:,lm,ln), &
109  hfrefor(lm,ln), ier)
110 
111  IF(ier == 0) THEN
112 ! If the user did not supply a value for the gas phase molecular weight
113 ! in the mfix.dat file, use the value from the database.
114  IF(lmw == undefined) lmw = dbmw
115 ! There are a number of species with Tlow as 300, for which the
116 ! following calculation will produce an error because T_ref = 298. So
117 ! slightly extend validity of the correlation.
118  IF(abs(tlow(lm,ln)-t_ref)<=2.0d0 .AND. &
119  tlow(lm,ln) > t_ref) tlow(lm,ln) = t_ref
120 
121 ! Initialize the reference integrals.
122  icpor_l(lm,ln) = zero
123  icpor_h(lm,ln) = zero
124 
125 ! Calculate the integral of specific heat from zero to Tref using the
126 ! Alow coefficients.
127  icpor_trl = calc_icpor(t_ref, lm, ln, ier)
128 ! Calculate the integral of specific heat from zero to Tcom using the
129 ! Alow coefficients.
130  xtc = tcom(lm,ln)-small_number
131  icpor_tcl = calc_icpor(xtc, lm, ln, ier)
132 ! Calculate the integral of specific heat from zero to Tcom using the
133 ! Ahigh coefficients.
134  xtc = tcom(lm,ln)+small_number
135  icpor_tch = calc_icpor(xtc, lm, ln, ier)
136 ! Store the integrals in global variables.
137  icpor_l(lm,ln) = icpor_trl
138  icpor_h(lm,ln) = icpor_tch - (icpor_tcl - icpor_trl)
139  ENDIF
140 
141  errorflag = .true.
142  IF(ier == 0) THEN
143  IF(.NOT.reinitializing)THEN
144  WRITE(err_msg,1001) trim(adjustl(db)), 'Found!'
145  CALL flush_err_msg(header=.false., footer=.false.)
146  ENDIF
147  if(testcp) CALL writecp(lm, ln, lname, lmw)
148  errorflag = .false.
149  EXIT db_lp
150  ELSEIF(.NOT.reinitializing) THEN
151  WRITE(err_msg,1001) trim(adjustl(db)), 'Not found.'
152  CALL flush_err_msg(header=.false., footer=.false.)
153  ENDIF
154 
155  ENDDO db_lp
156 
157 ! Error message control.
158 !-----------------------------------------------------------------------
159 ! Write remaining error message if needed.
160  IF(errorflag) THEN
161  CALL flush_err_msg(header=.false.)
162  WRITE(err_msg,1010) trim(lname), trim(therm)
163  CALL flush_err_msg(abort=.true.)
164  ENDIF
165 
166  CALL finl_err_msg
167 
168  RETURN
169 
170 
171 ! Messages
172 !-----------------------------------------------------------------------
173  1000 FORMAT('Checking ',a)
174  1001 FORMAT(8x,a,1x,' :: ',a)
175 
176 ! Error Flags
177 !-----------------------------------------------------------------------
178  1010 FORMAT('Message 1010: Species "',a,'" was not matched to any ', &
179  'entry in the',/'thermochemical databases.',2/,'SUGGESTION: ',&
180  'Search the database for the exact species name. The ',/ &
181  'species names are case sensitive and should match the names',&
182  ' in',/'BURCAT.THR exactly excluding trailing blanks and ', &
183  'tabs. Also verify',/'that the data section in the mfix.dat ',&
184  'file (if any) is below a line',/'that starts with THERMO ', &
185  'DATA.',2/'Database location:', /a)
186 
187  END SUBROUTINE read_database
188 
189 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
190 ! C
191 ! Module name: READ_DATABASE0(IER) C
192 ! Purpose: Provides legacy support for rrates files. C
193 ! C
194 ! Author: J. Musser Date: 02-Oct-12 C
195 ! C
196 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
197  SUBROUTINE read_database0()
199  USE compar
200  USE constant
201  USE des_rxns
202  USE discretelement
203  USE exit, only: mfix_exit
204  USE funits
205  USE param
206  USE param1
207  USE physprop
208  USE rxns
209 
210  IMPLICIT NONE
211 
212 ! Loop indices for mass phase and species
213  INTEGER M, NN
214 ! Loop counter for continuum and discrete species
215  INTEGER Nsp, DES_Nsp
216 
217 ! Return to the calling routine if the database has already been called.
218  IF(database_read)RETURN
219 
220 ! Set the flag identifying that the database has been read.
221  database_read = .true.
222 
223 ! Initialize counters
224  nsp = 0
225  des_nsp = 0
226 
227 ! Read species data for the gas phase.
228 !-----------------------------------------------------------------------
229  DO nn = 1, nmax(0)
230  nsp = nsp + 1
231 ! If a species name was not specified in mfix.dat, flag error and exit.
232  IF(species_name(nsp) == undefined_c) THEN
233  WRITE(*,1010) nn ! screen
234  IF(dmp_log) WRITE(unit_log,1010) nn ! log file
235  CALL mfix_exit(mype)
236  ENDIF
237 ! Read the database.
238  CALL read_database(0, nn, species_name(nsp), mw_g(nn))
239  ENDDO
240 
241 ! Read species data for the continuum solids phases.
242 !-----------------------------------------------------------------------
243 ! Skip reading the database for the continuum solids phase if the
244 ! simulation is only employing discrete solids.
245  IF(.NOT.discrete_element .OR. des_continuum_hybrid)THEN
246  DO m = 1, mmax
247  DO nn = 1, nmax(m)
248  nsp = nsp + 1
249 ! If a species name was not specified in mfix.dat, flag error and exit.
250  IF(species_name(nsp) == undefined_c)THEN
251  WRITE(*,1011)'continuum', m, nn ! screen
252  IF(dmp_log) WRITE(unit_log,1011)'continuum', m, nn
253  CALL mfix_exit(mype)
254  ENDIF
255  CALL read_database(m, nn, species_name(nsp), mw_s(m,nn))
256  ENDDO ! N=1, NMAX(M)
257  ENDDO ! M=1, MMAX
258  ENDIF
259 
260  RETURN
261 
262 ! Error Messages
263 !-----------------------------------------------------------------------
264  1010 FORMAT(/1x,70('*')/, ' From: READ_DATABASE0',/, ' Message: ', &
265  'No SPECIES_NAME provided for gas phase species ',i3,'.',/' ',&
266  'Check mfix.dat.',/1x,70('*')/)
267  1011 FORMAT(/1x,70('*')/, ' From: READ_DATABASE0',/, ' Message: ', &
268  'No SPECIES_NAME provided for ',a,' solids phase ',i2,', ',/ &
269  ' species ',i3,'.',/' Check mfix.dat.',/1x,70('*')/)
270 
271  END SUBROUTINE read_database0
272 
273 
274 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
275 ! C
276 ! Module name: read_database(Ier) C
277 ! Purpose: read thermochemical database C
278 ! C
279 ! Author: M. Syamlal Date: 21-OCT-05 C
280 ! C
281 ! Modification 1: J. Musser Date: 02-May-11 C
282 ! Purpose: Provided support for DEM access to database. C
283 ! C
284 ! Modification 2: J. Musser Date: 02-Oct-12 C
285 ! Purpose: Calls to READ_DATABASE were moved to CHECK_DATA_04/05 C
286 ! duing input data integrity checks for the gas and solids phases. C
287 ! Rather than looping through all species for each phase, the model C
288 ! (TFM/DEM), phase index, species index, species name, and molecular C
289 ! weight are passed as dummy arguments so that only infomration for C
290 ! referenced species (lName) is obtained. C C
291 ! C
292 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
293  SUBROUTINE writecp(lM, lN, lName, lMW)
295  use param1
296  USE physprop
297  USE compar
299 
300 ! Universal gas constant in cal/mol.K
301  use constant, only: rgas => gas_const_cal
302 
303  IMPLICIT NONE
304 
305 ! Phase and species indices
306  INTEGER, INTENT(IN) :: lM, lN
307 ! Species name from data file.
308  CHARACTER(len=*), INTENT(IN) :: lName
309 ! Species molecular weight from the data file (if any)
310  DOUBLE PRECISION, INTENT(in) :: lMW
311 
312  INTEGER :: IER1, IER2, lc
313 
314  DOUBLE PRECISION :: T
315  DOUBLE PRECISION :: lCP, lICP
316 
317  write(*,"(2/,3x,'Specific Heat report for ',A)")trim(lname)
318 
319  write(*,"(/12x,'Low',9x,'High')")
320  write(*,"(6x,'T',3x,g12.5,2x,g12.5)") tlow(lm,ln), thigh(lm,ln)
321  DO lc=1,5
322  write(*,"(4x,'A(',I1,')',2(2x,g12.5))") lc, &
323  alow(lc,lm,ln), ahigh(lc,lm,ln)
324  ENDDO
325  write(*,"('')")
326  write(*,"(5x,'Tcom: ',g12.5)")tcom(lm,ln)
327  write(*,"('')")
328 
329  write(*,"(5x,'Temperature',8x,'Cp',11x,'ICp')")
330 
331  t = tcom(lm,ln) - 100.0
332  DO WHILE(t <= tcom(lm,ln) - small_number)
333 
334  ier1 = 0
335  ier2 = 0
336 
337  write(*,"(7x,g12.5)",advance="NO") t
338  lcp = calc_cpor(t, lm, ln) * rgas / lmw
339  licp = calc_icpor(t, lm, ln, ier2) * rgas / lmw
340  write(*,"(2(3x,g12.5))",advance="NO")lcp, licp
341 
342  IF(ier1 /= 0) write(*,"(3x,'Cp Error!')",advance="NO")
343  IF(ier2 /= 0) write(*,"(3x,'ICp Error!')",advance="NO")
344  write(*,"('')")
345 
346  t = t + 5.0
347  ENDDO
348 
349 
350  t = tcom(lm,ln) + small_number
351  DO WHILE(t <= tcom(lm,ln) + 100.0)
352 
353  ier1 = 0
354  ier2 = 0
355 
356  write(*,"(7x,g12.5)",advance="NO") t
357  lcp = calc_cpor(t, lm, ln) * rgas / lmw
358  licp = calc_icpor(t, lm, ln, ier2) * rgas / lmw
359  write(*,"(2(3x,g12.5))",advance="NO")lcp, licp
360 
361  IF(ier1 /= 0) write(*,"(3x,'Cp Error!')",advance="NO")
362  IF(ier2 /= 0) write(*,"(3x,'ICp Error!')",advance="NO")
363  write(*,"('')")
364 
365  t = t + 5.0
366  ENDDO
367 
368  write(*,"('')")
369  END SUBROUTINE writecp
logical dmp_log
Definition: funits_mod.f:6
double precision, dimension(0:dim_m, dim_n) icpor_l
Definition: physprop_mod.f:148
subroutine finl_err_msg
double precision, dimension(0:dim_m, dim_n) thigh
Definition: physprop_mod.f:140
double precision function calc_icpor(T, M, N, IER)
Definition: rxns_mod.f:1
double precision, dimension(0:dim_m, dim_n) tcom
Definition: physprop_mod.f:142
subroutine writecp(lM, lN, lName, lMW)
double precision, parameter undefined
Definition: param1_mod.f:18
double precision, dimension(dim_n_g) mw_g
Definition: physprop_mod.f:124
subroutine read_therm(funit, Sp, Thigh, Tlow, Tcom, MW, Ahigh, Alow, Hf298oR, IER)
double precision, dimension(0:dim_m, dim_n) hfrefor
Definition: physprop_mod.f:145
subroutine init_err_msg(CALLER)
double precision, dimension(7, 0:dim_m, dim_n) alow
Definition: physprop_mod.f:136
subroutine mfix_exit(myID, normal_termination)
Definition: exit.f:5
integer mmax
Definition: physprop_mod.f:19
double precision, parameter small_number
Definition: param1_mod.f:24
Definition: exit.f:2
pure double precision function calc_cpor(T, M, N)
subroutine read_database0()
integer, parameter unit_log
Definition: funits_mod.f:21
Definition: run_mod.f:13
Definition: param_mod.f:2
logical database_read
Definition: physprop_mod.f:133
integer, dimension(0:dim_m) nmax
Definition: physprop_mod.f:119
double precision, dimension(7, 0:dim_m, dim_n) ahigh
Definition: physprop_mod.f:137
logical reinitializing
Definition: run_mod.f:208
integer mype
Definition: compar_mod.f:24
character(len=142) therm
double precision, dimension(dim_m, dim_n_s) mw_s
Definition: physprop_mod.f:127
character(len=line_length), dimension(line_count) err_msg
subroutine read_database(lM, lN, lName, lMW)
Definition: read_database.f:22
character(len=18), dimension(dim_n_all) species_name
Definition: rxns_mod.f:44
double precision, parameter t_ref
Definition: physprop_mod.f:77
double precision, dimension(0:dim_m, dim_n) tlow
Definition: physprop_mod.f:141
integer, parameter unit_dat
Definition: funits_mod.f:15
double precision, parameter gas_const_cal
Definition: constant_mod.f:155
double precision, dimension(0:dim_m, dim_n) icpor_h
Definition: physprop_mod.f:149
double precision, parameter zero
Definition: param1_mod.f:27
subroutine flush_err_msg(DEBUG, HEADER, FOOTER, ABORT, LOG, CALL_TREE)
pure double precision function calc_icpor0(T, A, REF_ICpoR)
character, parameter undefined_c
Definition: param1_mod.f:20