Skip to content

Commit

Permalink
[Fortran] Enable creating surfaces from YAML
Browse files Browse the repository at this point in the history
Add an example of importing an interface phase / kinetics to the
F90 demo program
  • Loading branch information
speth authored and bryanwweber committed May 25, 2022
1 parent 0867fe8 commit fca204f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
36 changes: 35 additions & 1 deletion samples/f90/demo.f90
Expand Up @@ -16,9 +16,11 @@ program main
implicit none

! objects representing phases of matter have type 'phase_t'
type(phase_t) gas
type(phase_t) :: gas, surf
type(interface_t) iface
integer nsp, nrxns
double precision :: t, p
character*1000 err_buf

write(*,*)
write(*,*) '******** Fortran 90 Test Program ********'
Expand All @@ -41,6 +43,14 @@ program main

call demo(gas, nsp, nrxns)

! Demo of importing a phase with surface kinetics
gas = importPhase('ptcombust.yaml', 'gas')
iface = importInterface('ptcombust.yaml', 'Pt_surf', gas)
surf = iface%surf
call setState_TPX(gas, t, p, 'H2:0.1, O2:0.65, H2O:0.2, CO:0.05')
call setState_TPX(surf, t, p, 'O(S):0.01, PT(S): 0.8, CO(S): 0.19')
call demo_surf(surf, nSpecies(surf), nReactions(surf))

end program main


Expand Down Expand Up @@ -137,3 +147,27 @@ subroutine demo(gas, MAXSP, MAXRXNS)
return

end subroutine demo

subroutine demo_surf(surf, nsp, nrxn)
use cantera
implicit none

type(phase_t) surf
integer :: nsp, nrxn, i
character*40 equation
double precision :: kf(nrxn), ropnet(nrxn)

write(*,*)
write(*,*) '******** Interface Kinetics Test ********'
write(*,*)

call getFwdRatesOfProgress(surf, kf)
call getNetRatesOfProgress(surf, ropnet)

write(*,*) 'Equation k_fwd Net rate'
do i = 1, nrxn
call getReactionString(surf, i, equation)
write(*,60) equation, kf(i), ropnet(i)
60 format(' ',a40, e14.5, e14.5)
end do
end subroutine demo_surf
7 changes: 5 additions & 2 deletions src/fortran/cantera_funcs.f90
Expand Up @@ -41,13 +41,16 @@ type(interface_t) function ctfunc_importInterface(src, id, gas, bulk, loglevel)
implicit none
character*(*), intent(in) :: src
character*(*), intent(in), optional :: id
type(phase_t) gas, bulk, surf
type(phase_t) gas, surf
type(phase_t), intent(in), optional :: bulk
integer, intent(in), optional :: loglevel

type(interface_t) self

self%surf = ctthermo_newFromFile(src, id)
self%bulk = bulk
if (present(bulk)) then
self%bulk = bulk
end if
self%gas = gas
call ctkin_newFromFile(self%surf, src, id, gas, bulk)

Expand Down
28 changes: 28 additions & 0 deletions test_problems/fortran/f90_demo_blessed.txt
Expand Up @@ -78,3 +78,31 @@ Thermal conductivity: 0.16396 W/m/K
H2O2 77993. J/kmol-K 0.32003E+08 J/kmol -43.168 -
AR 20786. J/kmol-K 0.52023E+08 J/kmol -21.976 -
N2 36896. J/kmol-K 0.85374E+08 J/kmol -28.119 -

******** Interface Kinetics Test ********

Equation k_fwd Net rate
H2 + 2 PT(S) => 2 H(S) 0.33111E-01 0.33111E-01
2 H(S) => H2 + 2 PT(S) 0.00000E+00 0.00000E+00
H + PT(S) => H(S) 0.00000E+00 0.00000E+00
O2 + 2 PT(S) => 2 O(S) 0.15290E-01 0.15290E-01
O2 + 2 PT(S) => 2 O(S) 0.20585E-01 0.20585E-01
2 O(S) => O2 + 2 PT(S) 0.14336E-07 0.14336E-07
O + PT(S) => O(S) 0.00000E+00 0.00000E+00
H2O + PT(S) => H2O(S) 0.35283E+00 0.35283E+00
H2O(S) => H2O + PT(S) 0.00000E+00 0.00000E+00
OH + PT(S) => OH(S) 0.00000E+00 0.00000E+00
OH(S) => OH + PT(S) 0.00000E+00 0.00000E+00
H(S) + O(S) <=> OH(S) + PT(S) 0.00000E+00 0.00000E+00
H(S) + OH(S) <=> H2O(S) + PT(S) 0.00000E+00 0.00000E+00
2 OH(S) <=> H2O(S) + O(S) 0.00000E+00 0.00000E+00
CO + PT(S) => CO(S) 0.12687E+00 0.12687E+00
CO(S) => CO + PT(S) 0.17276E+00 0.17276E+00
CO2(S) => CO2 + PT(S) 0.00000E+00 0.00000E+00
CO(S) + O(S) => CO2(S) + PT(S) 0.13165E-01 0.13165E-01
CH4 + 2 PT(S) => CH3(S) + H(S) 0.00000E+00 0.00000E+00
CH3(S) + PT(S) => CH2(S)s + H(S) 0.00000E+00 0.00000E+00
CH2(S)s + PT(S) => CH(S) + H(S) 0.00000E+00 0.00000E+00
CH(S) + PT(S) => C(S) + H(S) 0.00000E+00 0.00000E+00
C(S) + O(S) => CO(S) + PT(S) 0.00000E+00 0.00000E+00
CO(S) + PT(S) => C(S) + O(S) 0.10366E-06 0.10366E-06

0 comments on commit fca204f

Please sign in to comment.