@@ -234,13 +234,27 @@ Precalculate important indices and maps for use in edge analysis
234234function getkeyselectioninds (coreedgedomain:: AbstractDomain ,coreedgeinters,domain,inters)
235235 corespcsinds = 1 : length (domain. phase. species)
236236 edgespcsinds = length (domain. phase. species)+ 1 : length (coreedgedomain. phase. species)
237- corerxninds = 1 : length (domain. phase. reactions)
238- edgerxninds = length (domain. phase. reactions)+ 1 : length (coreedgedomain. phase. reactions)
239- reactantindices = coreedgedomain. rxnarray[1 : 3 ,:]
240- productindices = coreedgedomain. rxnarray[4 : 6 ,:]
237+ corerxninds = zeros (Int64,length (domain. phase. reactions))
238+ corerxncount = 1
239+ edgerxninds = zeros (Int64,length (coreedgedomain. phase. reactions))
240+ edgerxncount = 1
241+ coretoedgerxnmap = Dict {Int64,Int64} ()
242+ for (j,rxn) in enumerate (coreedgedomain. phase. reactions)
243+ coreind = findfirst (x-> rxn. reactants== x. reactants && rxn. products== x. products && rxn. kinetics== x. kinetics,domain. phase. reactions)
244+ if coreind === nothing
245+ edgerxninds[edgerxncount] = j
246+ edgerxncount += 1
247+ else
248+ coretoedgerxnmap[coreind] = j
249+ corerxninds[corerxncount] = j
250+ corerxncount += 1
251+ end
252+ end
253+
254+ @views @inbounds reactantindices = coreedgedomain. rxnarray[1 : 3 ,:]
255+ @views @inbounds productindices = coreedgedomain. rxnarray[4 : 6 ,:]
241256 coretoedgespcmap = Dict ([i=> findfirst (isequal (spc),coreedgedomain. phase. species) for (i,spc) in enumerate (domain. phase. species)])
242- coretoedgerxnmap = Dict ([i=> findfirst (isequal (rxn),coreedgedomain. phase. reactions) for (i,rxn) in enumerate (domain. phase. reactions)])
243- for j = 3 : length (domain. indexes)
257+ @simd for j = 3 : length (domain. indexes)
244258 coretoedgespcmap[domain. indexes[j]] = coreedgedomain. indexes[j]
245259 end
246260 return corespcsinds,corerxninds,edgespcsinds,edgerxninds,reactantindices,productindices,coretoedgespcmap,coretoedgerxnmap
@@ -499,10 +513,11 @@ function identifyobjects!(sim,corespcsinds,corerxninds,edgespcsinds,
499513 if charrate == 0 && length (edgereactionrates) > 0
500514 maxspeciesindex = argmax (edgespeciesrates)
501515 maxspeciesrate = edgespeciesrates[maxspeciesindex]
502- name = sim. names[maxspeciesindex]
516+ index = edgespcsinds[maxspeciesindex]
517+ name = sim. names[index]
503518 @info " at time $t s, species $name was added to model core to avoid singularity"
504- push! (invalidobjects,sim. species[maxspeciesindex ])
505- return (false ,true )
519+ push! (invalidobjects,sim. species[index ])
520+ return (false ,true , 0.0 )
506521 end
507522
508523 if branchfactor != 0.0 && ! firsttime
0 commit comments