Skip to content

Commit 15d29f0

Browse files
hwpangmjohnson541
authored andcommitted
Add internal interface to simulate film growth
1 parent 1f285e5 commit 15d29f0

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed

src/Interface.jl

Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,115 @@ function getinterfaceignoremasstransferspcinds(domaingas,domainliq,ignoremasstra
383383
indices[i] = domainliq.indexes[1]-1+indliq
384384
end
385385
return indices
386-
end
386+
end
387+
388+
struct FragmentBasedReactiveFilmGrowthInterfaceConstantT{D1,D2,Q<:AbstractReaction,M1} <: AbstractReactiveInternalInterface
389+
domainfilm::D1
390+
domain2::D2
391+
reactions::Array{Q,1}
392+
rxnarray::Array{Int64,2}
393+
fragmentbasedrxnarray::Array{Int64,2}
394+
stoichmatrix::M1
395+
Nrp1::Array{Float64,1}
396+
Nrp2::Array{Float64,1}
397+
kfs::Array{Float64,1}
398+
krevs::Array{Float64,1}
399+
T::Float64
400+
parameterindexes::Array{Int64,1}
401+
domaininds::Array{Int64,1}
402+
p::Array{Float64,1}
403+
reversibililty::Array{Bool,1}
404+
forwardability::Array{Bool,1}
405+
Mws::Array{Float64,1}
406+
end
407+
408+
function FragmentBasedReactiveFilmGrowthInterfaceConstantT(domainfilm,domain2,reactions)
409+
@assert isa(domainfilm.phase,FragmentBasedIdealFilm)
410+
@assert domainfilm.T == domain2.T
411+
T = domainfilm.T
412+
413+
rxnarray, fragmentbasedrxnarray = getfragmentbasedinterfacereactioninds(domainfilm,domain2,reactions)
414+
415+
kfs = getkf.(reactions,nothing,T,0.0,0.0,Ref([]),0.0,0.0)
416+
Kc = getKc.(reactions,domainfilm.phase,domain2.phase,Ref(domainfilm.Gs),Ref(domain2.Gs),T,0.0)
417+
krevs = kfs./Kc
418+
419+
M,Nrp1,Nrp2 = getstoichmatrix(domainfilm,domain2,reactions)
420+
reversibility = Array{Bool,1}(getfield.(reactions,:reversible))
421+
forwardability = Array{Bool,1}(getfield.(reactions,:forwardable))
422+
423+
Mws = vcat(getfield.(domainfilm.phase.fragments,:molecularweight),getfield.(domain2.phase.species,:molecularweight))
424+
return FragmentBasedReactiveFilmGrowthInterfaceConstantT(domainfilm,domain2,reactions,rxnarray,fragmentbasedrxnarray,M,Nrp1,Nrp2,kfs,krevs,T,[1,length(reactions)],
425+
[0,1],kfs[1:end],reversibility,forwardability,Mws),kfs[1:end]
426+
end
427+
export FragmentBasedReactiveFilmGrowthInterfaceConstantT
428+
429+
function getfragmentbasedinterfacereactioninds(domainfilm,domain2,reactions)
430+
# find maximum number of species in fragment-based reaction and names of fragment-based species
431+
maxnumfragmentbasedreacprod = 0
432+
for rxn in reactions
433+
numfragmentbasedreac = length(rxn.fragmentbasedreactants)
434+
numfragmentbasedprod = length(rxn.fragmentbasedproducts)
435+
maxnumfragmentbasedreacprod = max(maxnumfragmentbasedreacprod,numfragmentbasedreac,numfragmentbasedprod)
436+
end
437+
fragmentbasedrxnarray = zeros(Int64,(maxnumfragmentbasedreacprod*2,length(reactions)))
438+
rxnarray = zeros(Int64, (8,length(reactions)))
439+
440+
N1 = length(domainfilm.phase.fragments)
441+
for (i,rxn) in enumerate(reactions)
442+
for (j,r) in enumerate(rxn.reactants)
443+
if !r.isfragmentintermediate
444+
isfirst = true
445+
ind = findfirst(isequal(r),domainfilm.phase.fragments)
446+
if ind === nothing
447+
isfirst = false
448+
ind = findfirst(isequal(r),domain2.phase.species)
449+
end
450+
rxnarray[j,i] = isfirst ? ind : ind+N1
451+
end
452+
end
453+
for (j,r) in enumerate(rxn.fragmentbasedreactants)
454+
isfirst = true
455+
ind = findfirst(isequal(r),domainfilm.phase.fragments)
456+
if ind === nothing
457+
isfirst = false
458+
ind = findfirst(isequal(r),domain2.phase.species)
459+
end
460+
fragmentbasedrxnarray[j,i] = isfirst ? ind : ind+N1
461+
end
462+
for (j,r) in enumerate(rxn.products)
463+
if !r.isfragmentintermediate
464+
isfirst = true
465+
ind = findfirst(isequal(r),domainfilm.phase.fragments)
466+
if ind === nothing
467+
isfirst = false
468+
ind = findfirst(isequal(r),domain2.phase.species)
469+
end
470+
rxnarray[j+4,i] = isfirst ? ind : ind+N1
471+
end
472+
end
473+
for (j,r) in enumerate(rxn.fragmentbasedproducts)
474+
isfirst = true
475+
ind = findfirst(isequal(r),domainfilm.phase.fragments)
476+
if ind === nothing
477+
isfirst = false
478+
ind = findfirst(isequal(r),domain2.phase.species)
479+
end
480+
fragmentbasedrxnarray[j+maxnumfragmentbasedreacprod,i] = isfirst ? ind : ind+N1
481+
end
482+
end
483+
return rxnarray, fragmentbasedrxnarray
484+
end
485+
486+
export getfragmentbasedinterfacereactioninds
487+
488+
function getkfskrevs(ri::FragmentBasedReactiveFilmGrowthInterfaceConstantT)
489+
return ri.kfs,ri.krevs
490+
end
491+
492+
function evaluate(ri::FragmentBasedReactiveFilmGrowthInterfaceConstantT,dydt,domainfilm,Vfilm,cstot)
493+
kfs, krevs = getkfskrevs(ri)
494+
addreactionratecontributions!(dydt,ri.fragmentbasedrxnarray,ri.rxnarray,cstot,kfs,krevs,Vfilm,domainfilm.indexes[3],ri.Mws,domainfilm.indexes[1]:domainfilm.indexes[2])
495+
end
496+
497+
export evaluate

0 commit comments

Comments
 (0)