# Reference example: `where (...)` bindings and spread arguments.
#
# This file demonstrates a few MKX language features that are not obvious from
# the simpler examples: reusable objects, local scoped bindings, and multiple
# simulation entries in the same input file.

# Shared parameter objects that are reused with `*name` spread syntax.
let arr_common = {Vf:1e13, Vb:1e13}
let hk_common = {Asite=1e-20, S=1}

# Species definition.
components {
  A  {phase=gas, init=1.0, role=reactant},
  B  {phase=gas, init=1.0, role=reactant},
  C  {phase=gas, init=0.0, role=product, tags=[key]},
  A* {phase=surface, init=0.0, tags=["tdrc"]},
  B* {phase=surface, init=0.0, tags=["tdrc"]},
  C* {phase=surface, init=0.0, tags=["tdrc"]},
  *  {phase=surface, init=1.0, tags=["emptysite", "tdrc"]},
}

# Reaction network.
# The third step uses a local `where (...)` binding for `shift`.
reactions {
  {A}+{*}=>{A*} @ HertzKnudsenDefault(*hk_common, m=1, theta=1.0, sigma=1, Edes=90e3) {tags=[drc]},
  {B}+{*}=>{B*} @ HertzKnudsenDefault(*hk_common, m=1, theta=1.0, sigma=1, Edes=90e3) {tags=[drc]},
  {A*}+{B*}=>{C*}+{*} @ ArrheniusDefault(*arr_common, Eaf=50e3 + shift, Eab=55e3) where (shift = -5e3) {tags=[drc]},
}

# Two simulations are defined in one file:
# - `baseline` enables analyses
# - `short_run` reuses a local configuration object
simulation {
  baseline @ transient_solve(
    model = thermal,
    solver = {method = cvode_bdf, atol = 1e-12, rtol = 1e-10, t_end = 1e6},
    analyses = [
      {type = reaction_orders, enabled = true},
      {type = drc, enabled = true},
      {type = tdrc, enabled = true},
      {type = selectivity, enabled = true, name = "c-selectivity", key = "A", dsc = true, targets = [
        {coeff = 1, species = "C"}
      ]},
    ],
    conditions = [{T = 600}, {T = 650}, {T = 700}, {T = 750}, {T = 800}]
  ),
  short_run @ transient_solve(*cfg_short, conditions=[{T = 750, t_end = 1e5}, {T = 800, t_end = 1e5}]) where (
    cfg_short = {model = thermal, solver = {method = cvode_bdf, atol = 1e-12, rtol = 1e-10, t_end = 1e5}}
  ),
}

# Output location shared by both simulations.
output {
  formats = [tabdelim, hdf5],
  folder = "results_with_where"
}
