Skip to content

Commit 1bc806a

Browse files
committed
Use correct way to find edgerxninds and corerxninds
Tricky thing here is that RMS rearrange the reactions while constructing Phase object in order to vectorize kinetics, so the old way of getting rxninds is not correct. Preallocate vectors to help speeding up.
1 parent 26daeb1 commit 1bc806a

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

src/EdgeAnalysis.jl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,27 @@ Precalculate important indices and maps for use in edge analysis
234234
function 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

0 commit comments

Comments
 (0)