Skip to content

Commit 1674cca

Browse files
committed
enable 4 party reaction for edge analysis
1 parent 52d4b46 commit 1674cca

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

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
@@ -292,15 +292,19 @@ function rops!(ropmat,rarray,cs,kfs,krevs,V,start)
292292
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
293293
elseif @inbounds rarray[3,i] == 0
294294
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
295-
else
295+
elseif @inbounds rarray[4,i] == 0
296296
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
297+
else
298+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
297299
end
298-
if @inbounds rarray[5,i] == 0
299-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]
300-
elseif @inbounds rarray[6,i] == 0
301-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]
300+
if @inbounds rarray[6,i] == 0
301+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
302+
elseif @inbounds rarray[7,i] == 0
303+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
304+
elseif rarray[8,i] == 0
305+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
302306
else
303-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]*cs[rarray[6,i]]
307+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
304308
end
305309
@fastmath R = (fR - rR)*V
306310

@@ -309,35 +313,45 @@ function rops!(ropmat,rarray,cs,kfs,krevs,V,start)
309313
@inbounds @fastmath ropmat[i+start,rarray[2,i]] -= R
310314
if @inbounds rarray[3,i] != 0
311315
@inbounds @fastmath ropmat[i+start,rarray[3,i]] -= R
316+
if @inbounds rarray[4,i] != 0
317+
@inbounds @fastmath ropmat[i+start,rarray[4,i]] -= R
318+
end
312319
end
313320
end
314-
@inbounds @fastmath ropmat[i+start,rarray[4,i]] += R
315-
if @inbounds rarray[5,i] != 0
316-
@inbounds @fastmath ropmat[i+start,rarray[5,i]] += R
317-
if @inbounds rarray[6,i] != 0
318-
@inbounds @fastmath ropmat[i+start,rarray[6,i]] += R
321+
@inbounds @fastmath ropmat[i+start,rarray[5,i]] += R
322+
if @inbounds rarray[6,i] != 0
323+
@inbounds @fastmath ropmat[i+start,rarray[6,i]] += R
324+
if @inbounds rarray[7,i] != 0
325+
@inbounds @fastmath ropmat[i+start,rarray[7,i]] += R
326+
if @inbounds rarray[8,i] != 0
327+
@inbounds @fastmath ropmat[i+start,rarray[8,i]] += R
328+
end
319329
end
320330
end
321331
end
322332
end
323333

324334
function rops!(ropvec,rarray,cs,kfs,krevs,V,start,ind)
325335
for i = 1:length(kfs)
326-
c = count(isequal(ind),rarray[4:6,i])-count(isequal(ind),rarray[1:3,i])
336+
c = count(isequal(ind),rarray[5:8,i])-count(isequal(ind),rarray[1:4,i])
327337
if c != 0.0
328338
if @inbounds rarray[2,i] == 0
329339
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]
330340
elseif @inbounds rarray[3,i] == 0
331341
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]
332-
else
342+
elseif @inbounds rarray[4,i] == 0
333343
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]
344+
else
345+
@inbounds @fastmath fR = kfs[i]*cs[rarray[1,i]]*cs[rarray[2,i]]*cs[rarray[3,i]]*cs[rarray[4,i]]
334346
end
335-
if @inbounds rarray[5,i] == 0
336-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]
337-
elseif @inbounds rarray[6,i] == 0
338-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]
347+
if @inbounds rarray[6,i] == 0
348+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]
349+
elseif @inbounds rarray[7,i] == 0
350+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]
351+
elseif rarray[8,i] == 0
352+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]
339353
else
340-
@inbounds @fastmath rR = krevs[i]*cs[rarray[4,i]]*cs[rarray[5,i]]*cs[rarray[6,i]]
354+
@inbounds @fastmath rR = krevs[i]*cs[rarray[5,i]]*cs[rarray[6,i]]*cs[rarray[7,i]]*cs[rarray[8,i]]
341355
end
342356
@fastmath R = (fR - rR)*V
343357
@fastmath @inbounds ropvec[i+start] = c*R

0 commit comments

Comments
 (0)