Skip to content

Commit 0c81645

Browse files
hwpangmjohnson541
authored andcommitted
Separate out rate calculation into a function
1 parent d496bd0 commit 0c81645

File tree

1 file changed

+25
-38
lines changed

1 file changed

+25
-38
lines changed

src/Simulation.jl

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,32 @@ end
358358

359359
export rops
360360

361+
function getrate(rarray,cs,kfs,krevs,V,i)
362+
if @inbounds rarray[2,i] == 0
363+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
364+
elseif @inbounds rarray[3,i] == 0
365+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
366+
elseif @inbounds rarray[4,i] == 0
367+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
368+
else
369+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
370+
end
371+
if @inbounds rarray[6,i] == 0
372+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
373+
elseif @inbounds rarray[7,i] == 0
374+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
375+
elseif rarray[8,i] == 0
376+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
377+
else
378+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
379+
end
380+
@fastmath R = (fR - rR)*V
381+
return R
382+
end
383+
361384
function rops!(ropmat,rarray,cs,kfs,krevs,V,start)
362385
for i = 1:length(kfs)
363-
if @inbounds rarray[2,i] == 0
364-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
365-
elseif @inbounds rarray[3,i] == 0
366-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
367-
elseif @inbounds rarray[4,i] == 0
368-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
369-
else
370-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
371-
end
372-
if @inbounds rarray[6,i] == 0
373-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
374-
elseif @inbounds rarray[7,i] == 0
375-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
376-
elseif rarray[8,i] == 0
377-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
378-
else
379-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
380-
end
381-
@fastmath R = (fR - rR)*V
386+
R = getrate(rarray,cs,kfs,krevs,V,i)
382387

383388
@inbounds @fastmath ropmat[i+start,rarray[1,i]] -= R
384389
if @inbounds rarray[2,i] != 0
@@ -407,25 +412,7 @@ function rops!(ropvec,rarray,cs,kfs,krevs,V,start,ind)
407412
for i = 1:length(kfs)
408413
c = count(isequal(ind),rarray[5:8,i])-count(isequal(ind),rarray[1:4,i])
409414
if c != 0.0
410-
if @inbounds rarray[2,i] == 0
411-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
412-
elseif @inbounds rarray[3,i] == 0
413-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
414-
elseif @inbounds rarray[4,i] == 0
415-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
416-
else
417-
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
418-
end
419-
if @inbounds rarray[6,i] == 0
420-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
421-
elseif @inbounds rarray[7,i] == 0
422-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
423-
elseif rarray[8,i] == 0
424-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
425-
else
426-
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
427-
end
428-
@fastmath R = (fR - rR)*V
415+
R = getrate(rarray,cs,kfs,krevs,V,i)
429416
@fastmath @inbounds ropvec[i+start] = c*R
430417
end
431418
end

0 commit comments

Comments
 (0)