# CO methanation example using ArrheniusQRatio and HertzKnudsenNist models.
#
# This input is intended as a larger user-facing example with:
# - NIST-based adsorption models
# - multiple surface intermediates
# - transient simulation across a temperature sweep
# - orders, DRC, TDRC, and Eapp analyses

# Shared kinetic parameters.
let asite = 1e-19
let co_ads = {
  Asite=asite, m=28, S=1,
  A=25.56759, B=6.09613, C=4.054656, D=-2.671301, E=0.131021,
  F=-118.0089, G=227.3665, H=-110.5271,
  Qads=1, Edes=80e3
}
let h2_ads = {
  Asite=asite, m=2, S=1,
  A=33.066178, B=-11.363417, C=11.432816, D=-2.772874, E=-0.158558,
  F=-9.980797, G=172.707974, H=0,
  Qads=1, Edes=60e3
}
let h2o_ads = {
  Asite=asite, m=18, S=1,
  A=30.092, B=6.832514, C=6.793435, D=-2.53448, E=0.082139,
  F=-250.881, G=223.3967, H=-241.8264,
  Qads=1, Edes=40e3
}

# Species in the mechanism.
# `CO` is tagged as the key component so rates and sensitivities are reported
# with respect to the CO-based observable.
components {
  CO   {phase=gas, init=1.0, role=reactant, tags=[key]},
  H2   {phase=gas, init=2.0, role=reactant},
  CH4  {phase=gas, init=0.0, role=product},
  H2O  {phase=gas, init=0.0, role=product},
  CO*  {phase=surface, init=0.0, tags=[tdrc]},
  H*   {phase=surface, init=0.0, tags=[tdrc]},
  O*   {phase=surface, init=0.0, tags=[tdrc]},
  OH*  {phase=surface, init=0.0, tags=[tdrc]},
  H2O* {phase=surface, init=0.0, tags=[tdrc]},
  C*   {phase=surface, init=0.0, tags=[tdrc]},
  CH*  {phase=surface, init=0.0, tags=[tdrc]},
  CH2* {phase=surface, init=0.0, tags=[tdrc]},
  CH3* {phase=surface, init=0.0, tags=[tdrc]},
  *    {phase=surface, init=1.0}
}

# Elementary steps for adsorption, dissociation, hydrogenation, and water formation.
reactions {
  {CO}+{*}=>{CO*} @ HertzKnudsenNist(*co_ads) {tags=[drc]},
  {H2}+2{*}=>2{H*} @ HertzKnudsenNist(*h2_ads) {tags=[drc]},
  {H2O}+{*}=>{H2O*} @ HertzKnudsenNist(*h2o_ads) {tags=[drc]},
  {CO*}+{*}=>{C*}+{O*} @ ArrheniusQRatio(QTSQIS=2.78E-01, QTSQFS=4.43E-01, Eaf=68.4e3, Eab=71.7e3) {tags=[drc]},
  {C*}+{H*}=>{CH*}+{*} @ ArrheniusQRatio(QTSQIS=1.12E+00, QTSQFS=1.45E+00, Eaf=40.8e3, Eab=27.3e3) {tags=[drc]},
  {CH*}+{H*}=>{CH2*}+{*} @ ArrheniusQRatio(QTSQIS=4.18E-01, QTSQFS=1.84E-01, Eaf=67.9e3, Eab=35.0e3) {tags=[drc]},
  {CH2*}+{H*}=>{CH3*}+{*} @ ArrheniusQRatio(QTSQIS=4.22E-01, QTSQFS=7.04E-01, Eaf=64.7e3, Eab=63.5e3) {tags=[drc]},
  {CH3*}+{H*}=>{CH4}+2{*} @ ArrheniusQRatio(QTSQIS=5.52E+00, QTSQFS=2.62E+02, Eaf=115.8e3, Eab=41.0e3) {tags=[drc]},
  {O*}+{H*}=>{OH*}+{*} @ ArrheniusQRatio(QTSQIS=1.01E+00, QTSQFS=8.32E-01, Eaf=89.6e3, Eab=59.0e3) {tags=[drc]},
  {OH*}+{H*}=>{H2O*}+{*} @ ArrheniusQRatio(QTSQIS=5.24E-01, QTSQFS=1.05E-01, Eaf=105.4e3, Eab=42.2e3) {tags=[drc]}
}

# Transient temperature sweep with several sensitivity analyses enabled.
simulation {
  baseline @ transient_solve(
    model=thermal,
    solver={method=cvode_bdf, atol=1e-12, rtol=1e-10, t_end=1e8},
    analyses=[
      {type=orders, enabled=true},
      {type=drc, enabled=true},
      {type=tdrc, enabled=true},
      {type=eapp, enabled=true}
    ],
    conditions=[
      {T=400, t_end=1e8}, {T=425, t_end=5e7}, {T=450, t_end=5e7}, {T=475, t_end=2e7},
      {T=500, t_end=1e7}, {T=525, t_end=8e6}, {T=550, t_end=6e6}, {T=575, t_end=4e6},
      {T=600, t_end=1e7}, {T=625, t_end=8e6}, {T=650, t_end=6e6}, {T=675, t_end=4e6},
      {T=700, t_end=1e6}, {T=725, t_end=8e5}, {T=750, t_end=6e5}, {T=775, t_end=4e5},
      {T=800, t_end=1e5}, {T=825, t_end=1e5}, {T=850, t_end=1e5}, {T=875, t_end=1e5},
      {T=900, t_end=1e5}, {T=925, t_end=1e5}, {T=950, t_end=1e5}, {T=975, t_end=1e5},
      {T=1000, t_end=1e5}
    ]
  )
}

# Write a full set of user-friendly outputs.
output {
  formats=[excel, tabdelim, hdf5],
  folder="results"
}
