Skip to content

Commit 10a62c2

Browse files
committed
enable 4 party reaction for edge analysis
1 parent 2947bb3 commit 10a62c2

3 files changed

Lines changed: 46 additions & 32 deletions

File tree

src/EdgeAnalysis.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ function getkeyselectioninds(coreedgedomains,coreedgeinters,domains,inters)
208208
rxnindexedge += length(coreedgedomains[i].phase.reactions)
209209

210210
indend = length(domains[i].phase.reactions)
211-
reactantindices[:,ind:ind+indend-1] = domains[i].rxnarray[1:3,:]
212-
productindices[:,ind:ind+indend-1] = domains[i].rxnarray[4:6,:]
211+
reactantindices[:,ind:ind+indend-1] = domains[i].rxnarray[1:4,:]
212+
productindices[:,ind:ind+indend-1] = domains[i].rxnarray[5:8,:]
213213
ind += indend
214214
end
215215

@@ -220,8 +220,8 @@ function getkeyselectioninds(coreedgedomains,coreedgeinters,domains,inters)
220220
index += length(coreedgeinters[i].phase.reactions)
221221

222222
indend = length(inters[i].reactions)
223-
reactantindices[:,ind:ind+indend] = inters[i].rxnarray[1:3,:]
224-
productindices[:,ind:ind+indend] = inters[i].rxnarray[4:6,:]
223+
reactantindices[:,ind:ind+indend] = inters[i].rxnarray[1:4,:]
224+
productindices[:,ind:ind+indend] = inters[i].rxnarray[5:8,:]
225225
ind += indend
226226
end
227227
end
@@ -251,8 +251,8 @@ function getkeyselectioninds(coreedgedomain::AbstractDomain,coreedgeinters,domai
251251
end
252252
end
253253

254-
@views @inbounds reactantindices = coreedgedomain.rxnarray[1:3,:]
255-
@views @inbounds productindices = coreedgedomain.rxnarray[4:6,:]
254+
@views @inbounds reactantindices = coreedgedomain.rxnarray[1:4,:]
255+
@views @inbounds productindices = coreedgedomain.rxnarray[5:8,:]
256256
coretoedgespcmap = Dict([i=>findfirst(isequal(spc),coreedgedomain.phase.species) for (i,spc) in enumerate(domain.phase.species)])
257257
@simd for j = 3:length(domain.indexes)
258258
coretoedgespcmap[domain.indexes[j]] = coreedgedomain.indexes[j]
@@ -286,15 +286,15 @@ function processfluxes(sim::SystemSimulation,
286286
if any(d.rxnarray[:,i].>length(corespeciesconcentrations))
287287
continue
288288
end
289-
for j = 1:3
289+
for j = 1:4
290290
if d.rxnarray[j,i] != 0
291291
corespeciesconsumptionrates[d.rxnarray[j,i]] += frts[i+index]
292292
corespeciesproductionrates[d.rxnarray[j,i]] += rrts[i+index]
293293
else
294294
break
295295
end
296296
end
297-
for j = 4:6
297+
for j = 5:8
298298
if d.rxnarray[j,i] != 0
299299
corespeciesproductionrates[d.rxnarray[j,i]] += frts[i+index]
300300
corespeciesconsumptionrates[d.rxnarray[j,i]] += rrts[i+index]
@@ -311,15 +311,15 @@ function processfluxes(sim::SystemSimulation,
311311
if any(d.rxnarray[:,i].>length(corespeciesconcentrations))
312312
continue
313313
end
314-
for j = 1:3
314+
for j = 1:4
315315
if d.rxnarray[j,i] != 0
316316
corespeciesconsumptionrates[d.rxnarray[j,i]] += frts[i+index]
317317
corespeciesproductionrates[d.rxnarray[j,i]] += rrts[i+index]
318318
else
319319
break
320320
end
321321
end
322-
for j = 4:6
322+
for j = 5:8
323323
if d.rxnarray[j,i] != 0
324324
corespeciesproductionrates[d.rxnarray[j,i]] += frts[i+index]
325325
corespeciesconsumptionrates[d.rxnarray[j,i]] += rrts[i+index]
@@ -359,15 +359,15 @@ function processfluxes(sim::Simulation,corespcsinds,corerxninds,edgespcsinds,edg
359359
if any(d.rxnarray[:,i].>length(corespeciesconcentrations))
360360
continue
361361
end
362-
for j = 1:3
362+
for j = 1:4
363363
if d.rxnarray[j,i] != 0
364364
corespeciesconsumptionrates[d.rxnarray[j,i]] += frts[i]
365365
corespeciesproductionrates[d.rxnarray[j,i]] += rrts[i]
366366
else
367367
break
368368
end
369369
end
370-
for j = 4:6
370+
for j = 5:8
371371
if d.rxnarray[j,i] != 0
372372
corespeciesproductionrates[d.rxnarray[j,i]] += frts[i]
373373
corespeciesconsumptionrates[d.rxnarray[j,i]] += rrts[i]

src/Phase.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Broadcast.broadcastable(p::T) where {T<:AbstractPhase} = Ref(p)
257257
export broadcastable
258258

259259
function getreactionindices(spcs,rxns) where {Q<:AbstractPhase}
260-
arr = zeros(Int64,(6,length(rxns)))
260+
arr = zeros(Int64,(8,length(rxns)))
261261
names = [spc.name for spc in spcs]
262262
for (i,rxn) in enumerate(rxns)
263263
inds = [findfirst(isequal(spc),spcs) for spc in rxn.reactants]
@@ -268,7 +268,7 @@ function getreactionindices(spcs,rxns) where {Q<:AbstractPhase}
268268
end
269269
for (j,spc) in enumerate(rxn.products)
270270
ind = findfirst(isequal(spc),spcs)
271-
arr[j+3,i] = ind
271+
arr[j+4,i] = ind
272272
rxn.productinds[j] = ind
273273
end
274274
if hasproperty(rxn.kinetics,:efficiencies) && length(rxn.kinetics.nameefficiencies) > 0

src/Simulation.jl

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,19 @@ function rops!(ropmat,rarray,cs,kfs,krevs,V,start)
304304
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
305305
elseif @inbounds rarray[3,i] == 0
306306
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
307-
else
307+
elseif @inbounds rarray[4,i] == 0
308308
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
309+
else
310+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
309311
end
310-
if @inbounds rarray[5,i] == 0
311-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]
312-
elseif @inbounds rarray[6,i] == 0
313-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]
312+
if @inbounds rarray[6,i] == 0
313+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
314+
elseif @inbounds rarray[7,i] == 0
315+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
316+
elseif rarray[8,i] == 0
317+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
314318
else
315-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]*cs[rarray[6,i]]
319+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
316320
end
317321
@fastmath R = (fR - rR)*V
318322

@@ -321,35 +325,45 @@ function rops!(ropmat,rarray,cs,kfs,krevs,V,start)
321325
@inbounds @fastmath ropmat[i+start,rarray[2,i]] -= R
322326
if @inbounds rarray[3,i] != 0
323327
@inbounds @fastmath ropmat[i+start,rarray[3,i]] -= R
328+
if @inbounds rarray[4,i] != 0
329+
@inbounds @fastmath ropmat[i+start,rarray[4,i]] -= R
330+
end
324331
end
325332
end
326-
@inbounds @fastmath ropmat[i+start,rarray[4,i]] += R
327-
if @inbounds rarray[5,i] != 0
328-
@inbounds @fastmath ropmat[i+start,rarray[5,i]] += R
329-
if @inbounds rarray[6,i] != 0
330-
@inbounds @fastmath ropmat[i+start,rarray[6,i]] += R
333+
@inbounds @fastmath ropmat[i+start,rarray[5,i]] += R
334+
if @inbounds rarray[6,i] != 0
335+
@inbounds @fastmath ropmat[i+start,rarray[6,i]] += R
336+
if @inbounds rarray[7,i] != 0
337+
@inbounds @fastmath ropmat[i+start,rarray[7,i]] += R
338+
if @inbounds rarray[8,i] != 0
339+
@inbounds @fastmath ropmat[i+start,rarray[8,i]] += R
340+
end
331341
end
332342
end
333343
end
334344
end
335345

336346
function rops!(ropvec,rarray,cs,kfs,krevs,V,start,ind)
337347
for i = 1:length(kfs)
338-
c = count(isequal(ind),rarray[4:6,i])-count(isequal(ind),rarray[1:3,i])
348+
c = count(isequal(ind),rarray[5:8,i])-count(isequal(ind),rarray[1:4,i])
339349
if c != 0.0
340350
if @inbounds rarray[2,i] == 0
341351
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
342352
elseif @inbounds rarray[3,i] == 0
343353
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
344-
else
354+
elseif @inbounds rarray[4,i] == 0
345355
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
356+
else
357+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
346358
end
347-
if @inbounds rarray[5,i] == 0
348-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]
349-
elseif @inbounds rarray[6,i] == 0
350-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]
359+
if @inbounds rarray[6,i] == 0
360+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
361+
elseif @inbounds rarray[7,i] == 0
362+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
363+
elseif rarray[8,i] == 0
364+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
351365
else
352-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]*cs[rarray[6,i]]
366+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
353367
end
354368
@fastmath R = (fR - rR)*V
355369
@fastmath @inbounds ropvec[i+start] = c*R

0 commit comments

Comments
 (0)