@@ -6,6 +6,7 @@ using Logging
66using Sundials
77using SparseArrays
88using DiffEqBase: build_solution
9+ using Base. Iterators: flatten
910
1011abstract type AbstractTerminationCriterion end
1112
@@ -129,7 +130,7 @@ Calculate key flux and concentration related quantities for edge analysis
129130 vcpdivR[1 ] = cpdivR
130131 vphi = Array {Any,1} (undef,length (domains))
131132 vphi[1 ] = phi
132- rtsall,frtsall,rrtsall = addreactionratecontributionsforwardreverse! (dydt,domain. rxnarray,cstot,kfs,krevs,V)
133+ rts,frts,rrts = addreactionratecontributionsforwardreverse! (dydt,domain. rxnarray,cstot,kfs,krevs,V)
133134 rtsall = [rts]
134135 frtsall = [frts]
135136 rrtsall = [rrts]
@@ -162,20 +163,21 @@ Calculate key flux and concentration related quantities for edge analysis
162163 for (i,domain) in enumerate (domains)
163164 calcdomainderivatives! (domain,dydt,interfaces;t= t,T= vT[i],P= vP[i],Us= vUs[i],Hs= vHs[i],V= vV[i],C= vC[i],ns= vns[i],N= vN[i],Cvave= vCvave[i])
164165 end
165- return dydt,rtsall, frtsall, rrtsall,cstot
166+ return dydt,collect ( flatten ( rtsall)), collect ( flatten ( frtsall)), collect ( flatten ( rrtsall)) ,cstot
166167end
167168export calcfluxes
168169
169170"""
170171Precalculate important indices and maps for use in edge analysis
171172"""
172- function getkeyselectioninds (coreeedgedomains ,coreedgeinters,domains,inters)
173- corespcsinds = flatten ([coreedgedomains[i]. indexes[1 ]: coreedgedomains[i]. indexes[1 ]+ domains[i]. indexes[2 ]- domains[i]. indexes[1 ] for i = 1 : length (domains)])
174- edgespcsinds = flatten ([coreedgedomains[i]. indexes[1 ]+ domains[i]. indexes[2 ]- domains[i]. indexes[1 ]: coreedgedomains[i]. indexes[2 ] for i = 1 : length (domains)])
173+ function getkeyselectioninds (coreedgedomains ,coreedgeinters,domains,inters)
174+ corespcsinds = collect ( flatten ([coreedgedomains[i]. indexes[1 ]: coreedgedomains[i]. indexes[1 ]+ domains[i]. indexes[2 ]- domains[i]. indexes[1 ] for i = 1 : length (domains)]) )
175+ edgespcsinds = collect ( flatten ([coreedgedomains[i]. indexes[1 ]+ domains[i]. indexes[2 ]- domains[i]. indexes[1 ]+ 1 : coreedgedomains[i]. indexes[2 ] for i = 1 : length (domains)]) )
175176 corerxninds = Array {Int64,1} ()
176177 edgerxninds = Array {Int64,1} ()
177- reactantindices = zeros (Int64,(3 ,length (corerxninds)))
178- productindices = zeros (Int64,(3 ,length (corerxninds)))
178+ Nrxns = sum (length (d. phase. reactions) for d in coreedgedomains)
179+ reactantindices = zeros (Int64,(3 ,Nrxns))
180+ productindices = zeros (Int64,(3 ,Nrxns))
179181 coretoedgespcmap = Dict {Int64,Int64} ()
180182 coretoedgerxnmap = Dict {Int64,Int64} ()
181183 spcindexcore = 0
@@ -194,18 +196,18 @@ function getkeyselectioninds(coreeedgedomains,coreedgeinters,domains,inters)
194196 for (j,rxn) in enumerate (coreedgedomains[i]. phase. reactions)
195197 coreind = findfirst (isequal (rxn),domains[i]. phase. reactions)
196198 if coreind === nothing
197- push! (edgerxninds,j+ indexedge )
198- else
199- coretoedgerxnmap[coreind+ indexcore ] = j+ indexedge
200- push! (corerxninds,j+ indexedge )
199+ push! (edgerxninds,j+ rxnindexedge )
200+ else
201+ coretoedgerxnmap[coreind+ rxnindexcore ] = j+ rxnindexedge
202+ push! (corerxninds,j+ rxnindexedge )
201203 end
202204 end
203205 spcindexcore += length (domains[i]. phase. species)
204206 spcindexedge += length (coreedgedomains[i]. phase. species)
205207 rxnindexcore += length (domains[i]. phase. reactions)
206208 rxnindexedge += length (coreedgedomains[i]. phase. reactions)
207-
208- indend = length (domains[i]. reactions)
209+
210+ indend = length (domains[i]. phase . reactions)
209211 reactantindices[:,ind: ind+ indend- 1 ] = domains[i]. rxnarray[1 : 3 ,:]
210212 productindices[:,ind: ind+ indend- 1 ] = domains[i]. rxnarray[4 : 6 ,:]
211213 ind += indend
@@ -223,10 +225,7 @@ function getkeyselectioninds(coreeedgedomains,coreedgeinters,domains,inters)
223225 ind += indend
224226 end
225227 end
226- corerxninds = flatten (corerxnrangearray)
227- edgerxninds = flatten (edgerxnrangearray)
228-
229- return corespcsinds,corerxninds,edgespcsinds,edgerxninds,reactantindices,productindices,coretoedgespcmap,coretoedgerxnmap
228+ return corespcsinds,collect (flatten (corerxninds)),edgespcsinds,collect (flatten (edgerxninds)),reactantindices,productindices,coretoedgespcmap,coretoedgerxnmap
230229end
231230
232231"""
@@ -269,55 +268,57 @@ function processfluxes(sim::SystemSimulation,
269268 # process core species consumption and production rates
270269 index = 1
271270 for d in getfield .(sim. sims,:domain )
272- for i = index : index + size (d. rxnarray)[2 ]
271+ for i = 1 : size (d. rxnarray)[2 ]
273272 if any (d. rxnarray[:,i]. > length (corespeciesconcentrations))
274273 continue
275274 end
276275 for j = 1 : 3
277276 if d. rxnarray[j,i] != 0
278- corespeciesconsumptionrates[d. rxnarray[j,i]] += frts[i]
279- corespeciesproductionrates[d. rxnarray[j,i]] += rrts[i]
277+ corespeciesconsumptionrates[d. rxnarray[j,i]] += frts[i+ index ]
278+ corespeciesproductionrates[d. rxnarray[j,i]] += rrts[i+ index ]
280279 else
281280 break
282281 end
283282 end
284283 for j = 4 : 6
285284 if d. rxnarray[j,i] != 0
286- corespeciesproductionrates[d. rxnarray[j,i]] += frts[i]
287- corespeciesconsumptionrates[d. rxnarray[j,i]] += rrts[i]
285+ corespeciesproductionrates[d. rxnarray[j,i]] += frts[i+ index ]
286+ corespeciesconsumptionrates[d. rxnarray[j,i]] += rrts[i+ index ]
288287 else
289288 break
290289 end
291290 end
292291 end
293292 index += size (d. rxnarray)[2 ]
294293 end
295- for d in inters
296- for i = index: index+ size (d. rxnarray)[2 ]
297- if any (d. rxnarray[:,i]. > length (corespeciesconcentrations))
298- continue
299- end
300- for j = 1 : 3
301- if d. rxnarray[j,i] != 0
302- corespeciesconsumptionrates[d. rxnarray[j,i]] += frts[i]
303- corespeciesproductionrates[d. rxnarray[j,i]] += rrts[i]
304- else
305- break
294+ for d in sim. interfaces
295+ if hasproperty (d,:rxnarray )
296+ for i = 1 : size (d. rxnarray)[2 ]
297+ if any (d. rxnarray[:,i]. > length (corespeciesconcentrations))
298+ continue
306299 end
307- end
308- for j = 4 : 6
309- if d. rxnarray[j,i] != 0
310- corespeciesproductionrates[d. rxnarray[j,i]] += frts[i]
311- corespeciesconsumptionrates[d. rxnarray[j,i]] += rrts[i]
312- else
313- break
300+ for j = 1 : 3
301+ if d. rxnarray[j,i] != 0
302+ corespeciesconsumptionrates[d. rxnarray[j,i]] += frts[i+ index]
303+ corespeciesproductionrates[d. rxnarray[j,i]] += rrts[i+ index]
304+ else
305+ break
306+ end
307+ end
308+ for j = 4 : 6
309+ if d. rxnarray[j,i] != 0
310+ corespeciesproductionrates[d. rxnarray[j,i]] += frts[i+ index]
311+ corespeciesconsumptionrates[d. rxnarray[j,i]] += rrts[i+ index]
312+ else
313+ break
314+ end
314315 end
315316 end
317+ index += size (d. rxnarray)[2 ]
316318 end
317- index += size (d. rxnarray)[2 ]
318319 end
319-
320- return dydt,rts,frts,rrts,cs,corespeciesratse ,charrate,edgespeciesrates,edgereactionrates,corespeciesrateratios,edgespeciesrateratios,corereactionrates,corespeciesconcentrations,corespeciesproductionrates,corespeciesconsumptionrates
320+
321+ return dydt,rts,frts,rrts,cs,corespeciesrates ,charrate,edgespeciesrates,edgereactionrates,corespeciesrateratios,edgespeciesrateratios,corereactionrates,corespeciesconcentrations,corespeciesproductionrates,corespeciesconsumptionrates
321322end
322323
323324"""
@@ -699,8 +700,8 @@ function selectobjects(react,coreedgedomains,coreedgeinters,domains,inters,
699700 inte = init (react. ode,solver,abstol= atol,reltol= rtol);
700701
701702 t = inte. t
702- sim = getsim (inte,react,coreedgedomains,inters ,corep,coretoedgespcmap)
703-
703+ sim = getsim (inte,react,coreedgedomains,coreedgeinters ,corep,coretoedgespcmap)
704+
704705 y0 = sim. sol[end ]
705706 spcsaddindices = Array {Int64,1} ()
706707 firsttime = true
@@ -712,7 +713,7 @@ function selectobjects(react,coreedgedomains,coreedgeinters,domains,inters,
712713 end
713714 code = check_error (inte)
714715 t = inte. t
715- sim = getsim (inte,react,coreedgedomains,inters ,coreedgep,coretoedgespcmap)
716+ sim = getsim (inte,react,coreedgedomains,coreedgeinters ,coreedgep,coretoedgespcmap)
716717 terminated,interrupt,conversion = identifyobjects! (sim,corespcsinds,corerxninds,edgespcsinds,
717718 edgerxninds,reactantindices,productindices,unimolecularthreshold,bimolecularthreshold,
718719 trimolecularthreshold,maxedgespeciesrateratios,tolmovetocore,tolinterruptsimulation,ignoreoverallfluxcriterion,filterreactions,
0 commit comments