-
-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating reactions programmatically using Reaction Systems #307
Conversation
This is a brief tutorial for generating reactions programmatically. Smoluchowski coagulation equations(population balance approach) system was found as a suitable example here as demonstration and we solve the system using Jump processes
example plot result for generating_reactions_programmatically.md
@yewalenikhil65 I'll go through tomorrow morning and give you some comments. Got busy with meetings and class stuff today. |
No problem ,Sir |
@yewalenikhil65 I started making some edits, but then ran into a couple questions. See below. |
You should be able to |
Hey @isaacsas updated according to your suggestions.. |
@yewalenikhil65 made some more updates. Slowly getting through it. (This week is pretty busy.) I do have one question for you, see below. |
Actually never mind; I forgot that I had figured out what I was confused about! |
I Made a mistake in writing constant kernel case . `kv = fill(C/V, nr)` should work. Earlier it was simply a single scalar..
Corrected a little mistake I spotted in writing |
OK, I updated it one more time. I'd be happy to merge it now. Some notes:
Let me know after you've taken a look, and if you approve I'll merge. |
Yes, you are right. But i guess pushing reactions into for loop uses ModelingToolkit .
Again you are right.I plotted for just
We can merge it now. Only bit I am unsure is how to reason no-match of multiplicative kernel case, so i skipped commenting on it. |
Hmm, perhaps we should just use the additive kernel then and remove the other two? |
Additive and constant kernels..Both are matching with analytical profiles.. |
Hey @isaacsas ..just realised something rx = []; # empty-reaction vector
reactant_stoich = Array{Array{Pair{Int64,Int64},1},1}(undef, nr);
net_stoich = Array{Array{Pair{Int64,Int64},1},1}(undef, nr);
@time for n = 1:nr
if (vᵢ[n] == vⱼ[n]) # checking the reactants
push!(rx, Reaction(2*k[n], [ X[vᵢ[n]] ] ,[ X[sum_vᵢvⱼ[n]] ] ,[2],[1]));
reactant_stoich[n] = [vᵢ[n] => 2]; # this
net_stoich[n] = [vᵢ[n] => -2, sum_vᵢvⱼ[n] => 1]; # this
else
push!(rx, Reaction(k[n], [ X[vᵢ[n]] , X[vⱼ[n]] ] ,[ X[sum_vᵢvⱼ[n]] ],
[1, 1],[1]));
reactant_stoich[n] = [vᵢ[n] => 1 , vⱼ[n] => 1]; # this
net_stoich[n] = [vᵢ[n] => -1 , vⱼ[n] => -1 , sum_vᵢvⱼ[n] => 1]; # this
end
end
rs = ReactionSystem(rx, t, X, k);
jumpsys = convert(JumpSystem, rs; combinatoric_ratelaws = true);
dprob = DiscreteProblem(jumpsys, u₀map, tspan, pₘₐₚ; parallel = true);
alg = Direct(); stepper = SSAStepper();
mass_act_jump = MassActionJump(kₛ ,reactant_stoich, net_stoich);
jprob = @btime JumpProblem(dprob, alg ,mass_act_jump ,save_positions=(false, false)); I am confused why it is such though. If you remove this |
The |
Unfortunately, I haven't read this exact solution paper / method, so can't comment on why the multiplicative case does not match it. |
Ahh.. understood now.. In that case, 58a703e seems correct and usage of |
OK, can you remove the multiplicative case from the tutorial text and code? I'll then take a look and merge. |
@isaacsas ..Done! |
All merged! Thanks! |
Tutorial for Implementation of (Smoluchowski coagulation equation) population balance equation- by programmatically generating the reactions using ReactionSystem
Based on discussion at #292