Hello,
I am interested in a chemical model given by:
using ModelingToolkit
using OrdinaryDiffEq
@parameters k1 k2 k3 k4 k5 k6 k7 k8 k9 k10 k11 M
@variables t O1D(t) O(t) O3(t) O2(t) NO(t) NO2(t) σ(t) r1(t) r2(t) r3(t) r4(t) r5(t) r6(t) r7(t) r8(t) r9(t) r10(t) r11(t)
D = Differential(t)
# Introduce forcing term
# Tr = 4.5
# Ts = 19.5
# σ_fun(tprime) = cos(tprime)#ifelse(mod(tprime/3600, 24) >= Tr && mod(t/3600, 24) >= Ts,
# # 0.5 + 0.5*cos(π*abs((2*mod(tprime/3600, 24) - Tr - Ts)/(Ts - Tr))*(2*mod(tprime/3600, 24) - Tr - Ts)/(Ts - Tr)),
# # 0.0)
# @register_symbolic σ_fun(t)
# σ_fun(z)
eqs = [
# Algebraic relations
σ ~ cos(6*π*t),
r1 ~ k1*O2*σ^3,
r2 ~ k2*O*O2,
r3 ~ k3*O3*σ,
r4 ~ k4*O3*O,
r5 ~ k5*O3*σ^2,
r6 ~ k6*M*O1D,
r7 ~ k7*O1D*O3,
r8 ~ k8*O3*NO,
r9 ~ k9*NO2*O,
r10 ~ k10*NO2*σ,
r11 ~ k11*NO*O,
# Differential relations
D(O1D) ~ r5 - r6 -r7,
D(O) ~ 2*r1 - r2 + r3 - r4 + r6 - r9 + r10 -r11,
D(O3) ~ r2 - r3 -r4 -r5 -r7 -r8,
D(O2) ~ -r1 -r2 + r3 + 2*r4 + r5 + 2*r7 + r8 + r9,
D(NO) ~ -r8 + r9 + r10 - r11,
D(NO2) ~ r8 -r9 -r10 + r11]
@named symbolic_strato = ODESystem(eqs,t,
[O1D, O, O3, O2, NO, NO2, σ, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11],
[k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, M],tspan=(0, 10.0))
symbolic_strato = structural_simplify(symbolic_strato)
f_strato = ODEFunction(symbolic_strato)
prob = ODEProblem(f_strato, 1.0 .+ 0.1*randn(17),
(0.0, 20.0), 0.1*rand(12))
Ut = Matrix([1 1 3 2 1 2;
0 0 0 0 1 1]')
sol = solve(prob, Rosenbrock23())
In this case, there are two conserved quantities given by the conservation of the oxygen atoms and the nitrogen atoms. Thus U^\top \boldsymbol{x}(t) is a constant, with U^\top = \begin{bmatrix}1 & 1 & 3 & 2 & 1 & 2\\ 0 & 0 & 0 & 0 & 1 & 1] \end{bmatrix} and \boldsymbol{x} the state.
Can we use ModelingToolkit.jl to automatically identify U from the symbolic system of equations?