You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/model_creation/examples/smoluchowski_coagulation_equation.md
+14-11Lines changed: 14 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,13 +4,13 @@ This tutorial shows how to programmatically construct a [`ReactionSystem`](@ref)
4
4
The Smoluchowski coagulation equation describes a system of reactions in which monomers may collide to form dimers, monomers and dimers may collide to form trimers, and so on. This models a variety of chemical/physical processes, including polymerization and flocculation.
5
5
6
6
We begin by importing some necessary packages.
7
-
```julia
7
+
```@example smcoag1
8
8
using ModelingToolkit, Catalyst, LinearAlgebra
9
9
using JumpProcesses
10
10
using Plots, SpecialFunctions
11
11
```
12
12
Suppose the maximum cluster size is `N`. We assume an initial concentration of monomers, `Nₒ`, and let `uₒ` denote the initial number of monomers in the system. We have `nr` total reactions, and label by `V` the bulk volume of the system (which plays an important role in the calculation of rate laws since we have bimolecular reactions). Our basic parameters are then
The [Smoluchowski coagulation equation](https://en.wikipedia.org/wiki/Smoluchowski_coagulation_equation) Wikipedia page illustrates the set of possible reactions that can occur. We can easily enumerate the `pair`s of multimer reactants that can combine when allowing a maximal cluster size of `N` monomers. We initialize the volumes of the reactant multimers as `volᵢ` and `volⱼ`
We next specify the rates (i.e. kernel) at which reactants collide to form products. For simplicity, we allow a user-selected additive kernel or constant kernel. The constants(`B` and `C`) are adopted from Scott's paper [2](https://journals.ametsoc.org/view/journals/atsc/25/1/1520-0469_1968_025_0054_asocdc_2_0_co_2.xml)
50
-
```julia
52
+
```@example smcoag1
51
53
# set i to 1 for additive kernel, 2 for constant
52
54
i = 1
53
55
if i == 1
@@ -61,7 +63,7 @@ elseif i==2
61
63
end
62
64
```
63
65
We'll set the parameters and the initial condition that only monomers are present at ``t=0`` in `u₀map`.
64
-
```julia
66
+
```@example smcoag1
65
67
# k is a vector of the parameters, with values given by the vector kv
66
68
@parameters k[1:nr] = kv
67
69
@@ -80,9 +82,10 @@ end
80
82
u₀ = zeros(Int64, N)
81
83
u₀[1] = uₒ
82
84
u₀map = Pair.(collect(X), u₀) # map species to its initial value
85
+
nothing #hide
83
86
```
84
87
Here we generate the reactions programmatically. We systematically create Catalyst `Reaction`s for each possible reaction shown in the figure on [Wikipedia](https://en.wikipedia.org/wiki/Smoluchowski_coagulation_equation). When `vᵢ[n] == vⱼ[n]`, we set the stoichiometric coefficient of the reactant multimer to two.
85
-
```julia
88
+
```@example smcoag1
86
89
# vector to store the Reactions in
87
90
rx = []
88
91
for n = 1:nr
@@ -98,15 +101,15 @@ end
98
101
rs = complete(rs)
99
102
```
100
103
We now convert the [`ReactionSystem`](@ref) into a `ModelingToolkit.JumpSystem`, and solve it using Gillespie's direct method. For details on other possible solvers (SSAs), see the [DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/types/jump_types/) documentation
0 commit comments