reaction_microbial_aux.F90 coverage: 92.31 %func 91.47 %block
1) module Reaction_Microbial_Aux_module
2)
3) use Reaction_Database_Aux_module
4)
5) use PFLOTRAN_Constants_module
6)
7) implicit none
8)
9) private
10)
11) #include "petsc/finclude/petscsys.h"
12)
13) PetscInt, parameter, public :: INHIBITION_THRESHOLD = 1
14) PetscInt, parameter, public :: INHIBITION_THERMODYNAMIC = 2
15) PetscInt, parameter, public :: INHIBITION_MONOD = 3
16) PetscInt, parameter, public :: INHIBITION_INVERSE_MONOD = 4
17)
18) type, public :: microbial_rxn_type
19) PetscInt :: id
20) PetscInt :: itype
21) character(len=MAXSTRINGLENGTH) :: reaction
22) PetscReal :: rate_constant
23) PetscReal :: activation_energy
24) PetscBool :: print_me
25) type(database_rxn_type), pointer :: dbaserxn
26) type(monod_type), pointer :: monod
27) type(inhibition_type), pointer :: inhibition
28) type(microbial_biomass_type), pointer :: biomass
29) type(microbial_rxn_type), pointer :: next
30) end type microbial_rxn_type
31)
32) type, public :: monod_type
33) PetscInt :: id
34) character(len=MAXWORDLENGTH) :: species_name
35) PetscReal :: half_saturation_constant
36) PetscReal :: threshold_concentration
37) type(monod_type), pointer :: next
38) end type monod_type
39)
40) type, public :: inhibition_type
41) PetscInt :: id
42) PetscInt :: itype
43) character(len=MAXWORDLENGTH) :: species_name
44) PetscReal :: inhibition_constant
45) PetscReal :: inhibition_constant2
46) type(inhibition_type), pointer :: next
47) end type inhibition_type
48)
49) type, public :: microbial_biomass_type
50) PetscInt :: id
51) character(len=MAXWORDLENGTH) :: species_name
52) PetscReal :: yield
53) end type microbial_biomass_type
54)
55) type, public :: microbial_type
56)
57) PetscInt :: nrxn
58)
59) type(microbial_rxn_type), pointer :: microbial_rxn_list
60)
61) ! microbial reactions
62) PetscReal, pointer :: rate_constant(:)
63) PetscReal, pointer :: activation_energy(:)
64) PetscReal, pointer :: stoich(:,:)
65) PetscInt, pointer :: specid(:,:)
66) PetscInt, pointer :: biomassid(:)
67) PetscReal, pointer :: biomass_yield(:)
68) PetscInt, pointer :: monodid(:,:)
69) PetscInt, pointer :: inhibitionid(:,:)
70) PetscInt, pointer :: monod_specid(:)
71) PetscReal, pointer :: monod_K(:)
72) PetscReal, pointer :: monod_Cth(:)
73) PetscInt, pointer :: inhibition_type(:)
74) PetscInt, pointer :: inhibition_specid(:)
75) PetscReal, pointer :: inhibition_C(:)
76) PetscReal, pointer :: inhibition_C2(:)
77)
78) end type microbial_type
79)
80) public :: MicrobialCreate, &
81) MicrobialRxnCreate, &
82) MicrobialMonodCreate, &
83) MicrobialInhibitionCreate, &
84) MicrobialBiomassCreate, &
85) MicrobialGetMonodCount, &
86) MicrobialGetInhibitionCount, &
87) MicrobialGetBiomassCount, &
88) MicrobialRxnDestroy, &
89) MicrobialBiomassDestroy, &
90) MicrobialDestroy
91)
92) contains
93)
94) ! ************************************************************************** !
95)
96) function MicrobialCreate()
97) !
98) ! Allocate and initialize microbial object
99) !
100) ! Author: Glenn Hammond
101) ! Date: 10/30/12
102) !
103)
104) implicit none
105)
106) type(microbial_type), pointer :: MicrobialCreate
107)
108) type(microbial_type), pointer :: microbial
109)
110) allocate(microbial)
111)
112) nullify(microbial%microbial_rxn_list)
113)
114) microbial%nrxn = 0
115)
116) nullify(microbial%rate_constant)
117) nullify(microbial%activation_energy)
118) nullify(microbial%stoich)
119) nullify(microbial%specid)
120) nullify(microbial%biomassid)
121) nullify(microbial%biomass_yield)
122) nullify(microbial%monodid)
123) nullify(microbial%inhibitionid)
124) nullify(microbial%monod_specid)
125) nullify(microbial%monod_K)
126) nullify(microbial%monod_Cth)
127) nullify(microbial%inhibition_type)
128) nullify(microbial%inhibition_specid)
129) nullify(microbial%inhibition_C)
130) nullify(microbial%inhibition_C2)
131)
132) MicrobialCreate => microbial
133)
134) end function MicrobialCreate
135)
136) ! ************************************************************************** !
137)
138) function MicrobialRxnCreate()
139) !
140) ! Allocate and initialize a microbial object
141) !
142) ! Author: Glenn Hammond
143) ! Date: 10/30/12
144) !
145)
146) implicit none
147)
148) type(microbial_rxn_type), pointer :: MicrobialRxnCreate
149)
150) type(microbial_rxn_type), pointer :: microbial_rxn
151)
152) allocate(microbial_rxn)
153) microbial_rxn%id = 0
154) microbial_rxn%itype = 0
155) microbial_rxn%reaction = ''
156) microbial_rxn%rate_constant = 0.d0
157) microbial_rxn%activation_energy = 0.d0
158) microbial_rxn%print_me = PETSC_FALSE
159) nullify(microbial_rxn%biomass)
160) nullify(microbial_rxn%dbaserxn)
161) nullify(microbial_rxn%monod)
162) nullify(microbial_rxn%inhibition)
163) nullify(microbial_rxn%next)
164)
165) MicrobialRxnCreate => microbial_rxn
166)
167) end function MicrobialRxnCreate
168)
169) ! ************************************************************************** !
170)
171) function MicrobialMonodCreate()
172) !
173) ! Allocate and initialize a microbial monod object
174) !
175) ! Author: Glenn Hammond
176) ! Date: 10/30/12
177) !
178)
179) implicit none
180)
181) type(monod_type), pointer :: MicrobialMonodCreate
182)
183) type(monod_type), pointer :: monod
184)
185) allocate(monod)
186) monod%id = 0
187) monod%species_name = ''
188) monod%half_saturation_constant = 0.d0
189) monod%threshold_concentration = 0.d0
190) nullify(monod%next)
191)
192) MicrobialMonodCreate => monod
193)
194) end function MicrobialMonodCreate
195)
196) ! ************************************************************************** !
197)
198) function MicrobialInhibitionCreate()
199) !
200) ! Allocate and initialize a microbial inhibition
201) ! object
202) !
203) ! Author: Glenn Hammond
204) ! Date: 10/30/12
205) !
206)
207) implicit none
208)
209) type(inhibition_type), pointer :: MicrobialInhibitionCreate
210)
211) type(inhibition_type), pointer :: inhibition
212)
213) allocate(inhibition)
214) inhibition%id = 0
215) inhibition%itype = 0
216) inhibition%species_name = ''
217) inhibition%inhibition_constant = UNINITIALIZED_DOUBLE
218) inhibition%inhibition_constant2 = 0.d0
219) nullify(inhibition%next)
220)
221) MicrobialInhibitionCreate => inhibition
222)
223) end function MicrobialInhibitionCreate
224)
225) ! ************************************************************************** !
226)
227) function MicrobialBiomassCreate()
228) !
229) ! Allocate and initialize a microbial biomass object
230) !
231) ! Author: Glenn Hammond
232) ! Date: 01/02/13
233) !
234)
235) implicit none
236)
237) type(microbial_biomass_type), pointer :: MicrobialBiomassCreate
238)
239) type(microbial_biomass_type), pointer :: biomass
240)
241) allocate(biomass)
242) biomass%id = 0
243) biomass%species_name = ''
244) biomass%yield = 0.d0
245)
246) MicrobialBiomassCreate => biomass
247)
248) end function MicrobialBiomassCreate
249)
250) ! ************************************************************************** !
251)
252) function MicrobialGetMonodCount(microbial_rxn)
253) !
254) ! Counts number of monod expressions in
255) ! microbial reaction
256) !
257) ! Author: Glenn Hammond
258) ! Date: 10/30/12
259) !
260)
261) implicit none
262)
263) type(microbial_rxn_type) :: microbial_rxn
264)
265) PetscInt :: MicrobialGetMonodCount
266)
267) type(monod_type), pointer :: cur_monod
268) PetscInt :: icount
269)
270) icount = 0
271) cur_monod => microbial_rxn%monod
272) do
273) if (.not.associated(cur_monod)) exit
274) icount = icount + 1
275) cur_monod => cur_monod%next
276) enddo
277)
278) MicrobialGetMonodCount = icount
279)
280) end function MicrobialGetMonodCount
281)
282) ! ************************************************************************** !
283)
284) function MicrobialGetInhibitionCount(microbial_rxn)
285) !
286) ! Counts number of inhibiton expressions in
287) ! microbial reaction
288) !
289) ! Author: Glenn Hammond
290) ! Date: 10/30/12
291) !
292)
293) implicit none
294)
295) type(microbial_rxn_type) :: microbial_rxn
296)
297) PetscInt :: MicrobialGetInhibitionCount
298)
299) type(inhibition_type), pointer :: cur_inhibition
300) PetscInt :: icount
301)
302) icount = 0
303) cur_inhibition => microbial_rxn%inhibition
304) do
305) if (.not.associated(cur_inhibition)) exit
306) icount = icount + 1
307) cur_inhibition => cur_inhibition%next
308) enddo
309)
310) MicrobialGetInhibitionCount = icount
311)
312) end function MicrobialGetInhibitionCount
313)
314) ! ************************************************************************** !
315)
316) function MicrobialGetBiomassCount(microbial)
317) !
318) ! Returns the number of biomass species
319) !
320) ! Author: Glenn Hammond
321) ! Date: 01/02/13
322) !
323)
324) implicit none
325)
326) PetscInt :: MicrobialGetBiomassCount
327) type(microbial_type) :: microbial
328)
329) type(microbial_rxn_type), pointer :: microbial_rxn
330)
331) MicrobialGetBiomassCount = 0
332) microbial_rxn => microbial%microbial_rxn_list
333) do
334) if (.not.associated(microbial_rxn%biomass)) exit
335) MicrobialGetBiomassCount = MicrobialGetBiomassCount + 1
336) microbial_rxn => microbial_rxn%next
337) enddo
338)
339) end function MicrobialGetBiomassCount
340)
341) ! ************************************************************************** !
342)
343) subroutine MicrobialRxnDestroy(microbial)
344) !
345) ! Deallocates a microbial rxn object
346) !
347) ! Author: Glenn Hammond
348) ! Date: 10/30/12
349) !
350)
351) implicit none
352)
353) type(microbial_rxn_type), pointer :: microbial
354)
355) call DatabaseRxnDestroy(microbial%dbaserxn)
356) call MicrobialMonodDestroy(microbial%monod)
357) call MicrobialInhibitionDestroy(microbial%inhibition)
358) call MicrobialBiomassDestroy(microbial%biomass)
359)
360) deallocate(microbial)
361) nullify(microbial)
362)
363) end subroutine MicrobialRxnDestroy
364)
365) ! ************************************************************************** !
366)
367) recursive subroutine MicrobialMonodDestroy(monod)
368) !
369) ! Deallocates a microbial monod object
370) !
371) ! Author: Glenn Hammond
372) ! Date: 10/30/12
373) !
374)
375) implicit none
376)
377) type(monod_type), pointer :: monod
378)
379) if (.not.associated(monod)) return
380)
381) call MicrobialMonodDestroy(monod%next)
382)
383) deallocate(monod)
384) nullify(monod)
385)
386) end subroutine MicrobialMonodDestroy
387)
388) ! ************************************************************************** !
389)
390) recursive subroutine MicrobialInhibitionDestroy(inhibition)
391) !
392) ! Deallocates a microbial inhibition object
393) !
394) ! Author: Glenn Hammond
395) ! Date: 10/30/12
396) !
397)
398) implicit none
399)
400) type(inhibition_type), pointer :: inhibition
401)
402) if (.not. associated(inhibition)) return
403)
404) call MicrobialInhibitionDestroy(inhibition%next)
405)
406) deallocate(inhibition)
407) nullify(inhibition)
408)
409) end subroutine MicrobialInhibitionDestroy
410)
411) ! ************************************************************************** !
412)
413) subroutine MicrobialBiomassDestroy(biomass)
414) !
415) ! Deallocates a microbial biomass object
416) !
417) ! Author: Glenn Hammond
418) ! Date: 01/02/13
419) !
420)
421) implicit none
422)
423) type(microbial_biomass_type), pointer :: biomass
424)
425) if (.not.associated(biomass)) return
426)
427) deallocate(biomass)
428) nullify(biomass)
429)
430) end subroutine MicrobialBiomassDestroy
431)
432) ! ************************************************************************** !
433)
434) subroutine MicrobialDestroy(microbial)
435) !
436) ! Deallocates a microbial object
437) !
438) ! Author: Glenn Hammond
439) ! Date: 05/29/08
440) !
441)
442) use Utility_module, only: DeallocateArray
443)
444) implicit none
445)
446) type(microbial_type), pointer :: microbial
447)
448) type(microbial_rxn_type), pointer :: cur_microbial, prev_microbial
449)
450) if (.not.associated(microbial)) return
451)
452) ! microbial reactions
453) cur_microbial => microbial%microbial_rxn_list
454) do
455) if (.not.associated(cur_microbial)) exit
456) prev_microbial => cur_microbial
457) cur_microbial => cur_microbial%next
458) call MicrobialRxnDestroy(prev_microbial)
459) enddo
460) nullify(microbial%microbial_rxn_list)
461)
462) call DeallocateArray(microbial%rate_constant)
463) call DeallocateArray(microbial%activation_energy)
464) call DeallocateArray(microbial%stoich)
465) call DeallocateArray(microbial%specid)
466) call DeallocateArray(microbial%biomassid)
467) call DeallocateArray(microbial%biomass_yield)
468) call DeallocateArray(microbial%monodid)
469) call DeallocateArray(microbial%inhibitionid)
470) call DeallocateArray(microbial%monod_specid)
471) call DeallocateArray(microbial%monod_K)
472) call DeallocateArray(microbial%monod_Cth)
473) call DeallocateArray(microbial%inhibition_type)
474) call DeallocateArray(microbial%inhibition_specid)
475) call DeallocateArray(microbial%inhibition_C)
476) call DeallocateArray(microbial%inhibition_C2)
477)
478) deallocate(microbial)
479) nullify(microbial)
480)
481) end subroutine MicrobialDestroy
482)
483) end module Reaction_Microbial_Aux_module