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
+45-33Lines changed: 45 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,47 +6,58 @@ The Smoluchowski coagulation equation describes a system of reactions in which m
6
6
We begin by importing some necessary packages.
7
7
```julia
8
8
using ModelingToolkit, Catalyst, LinearAlgebra
9
-
usingDiffEqBase, JumpProcesses
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
13
13
```julia
14
-
## Parameter
15
-
N =10# maximum cluster size
16
-
Vₒ = (4π/3)*(10e-06*100)^3# volume of a monomers in cm³
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ⱼ`
26
34
27
35
```julia
28
36
# possible pairs of reactant multimers
29
-
pair = []
37
+
pair =Int[]
30
38
for i =2:N
31
-
push!(pair, [1:integ(i/2) i .- (1:integ(i/2))])
39
+
halfi =floor(Int, i/2)
40
+
push!(pair, [(1:halfi) (i .- (1:halfi))])
32
41
end
33
42
pair =vcat(pair...)
34
-
vᵢ =@view pair[:,1] # Reactant 1 indices
35
-
vⱼ =@view pair[:,2] # Reactant 2 indices
36
-
volᵢ = Vₒ*vᵢ # cm⁻³
37
-
volⱼ = Vₒ*vⱼ # cm⁻³
43
+
vᵢ =@view pair[:,1]# Reactant 1 indices
44
+
vⱼ =@view pair[:,2]# Reactant 2 indices
45
+
volᵢ = Vₒ* vᵢ# cm⁻³
46
+
volⱼ = Vₒ* vⱼ# cm⁻³
38
47
sum_vᵢvⱼ =@. vᵢ + vⱼ # Product index
39
48
```
40
49
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)
41
50
```julia
42
51
# set i to 1 for additive kernel, 2 for constant
43
52
i =1
44
-
if i==1
45
-
B =1.53e03# s⁻¹
46
-
kv =@. B*(volᵢ + volⱼ)/V # dividing by volume as its a bi-molecular reaction chain
53
+
if i ==1
54
+
B =1.53e03# s⁻¹
55
+
56
+
# dividing by volume as it is a bimolecular reaction chain
57
+
kv =@. B * (volᵢ + volⱼ) / V
47
58
elseif i==2
48
-
C =1.84e-04# cm³ s⁻¹
49
-
kv =fill(C/V, nr)
59
+
C =1.84e-04# cm³ s⁻¹
60
+
kv =fill(C/V, nr)
50
61
end
51
62
```
52
63
We'll store the reaction rates in `pars` as `Pair`s, and set the initial condition that only monomers are present at ``t=0`` in `u₀map`.
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