Skip to content

Commit f1cca83

Browse files
hwpangmjohnson541
authored andcommitted
Add fragment based constant T rho domain
1 parent 348122c commit f1cca83

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

src/Domain.jl

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,115 @@ function ConstantTAPhiDomain(;phase::E2,initialconds::Dict{X,X2},constantspecies
711711
end
712712
export ConstantTAPhiDomain
713713

714+
"""
715+
Fragment based constant T, rho domain is designed to simulate film growth with fragment based model.
716+
It simulates the growth of mass of a swollen film caused by the chemical reaction between
717+
the functional groups (fragments) on the solid and
718+
the liquid phase reactants encapsulated in the film.
719+
mass: the mass of the solid part in the swollen film
720+
rho: the density of the solid part in the swollen film
721+
"""
722+
mutable struct FragmentBasedConstantTrhoDomain{N<:AbstractPhase, S<:Integer, W<:Real, W2<:Real, I<:Integer, Q<:AbstractArray} <: AbstractConstantKDomain
723+
phase::N
724+
indexes::Q #assumed to be in ascending order
725+
parameterindexes::Q
726+
constantspeciesinds::Array{S,1}
727+
T::Float64
728+
rho::Float64
729+
A::Float64
730+
kfs::Array{W,1}
731+
krevs::Array{W,1}
732+
kfsnondiff::Array{W,1}
733+
efficiencyinds::Array{I,1}
734+
Gs::Array{W,1}
735+
rxnarray::Array{Int64,2}
736+
mu::W
737+
diffusivity::Array{W,1}
738+
jacobian::Array{W,2}
739+
sensitivity::Bool
740+
alternativepformat::Bool
741+
jacuptodate::MArray{Tuple{1},Bool,1,1}
742+
t::MArray{Tuple{1},W2,1,1}
743+
p::Array{W,1}
744+
thermovariabledict::Dict{String,Int64}
745+
end
746+
747+
function FragmentBasedConstantTrhoDomain(;phase::Z,initialconds::Dict{X,E},constantspecies::Array{X4,1}=Array{String,1}(),
748+
sparse::Bool=false,sensitivity::Bool=false) where {X,E,X1,E1,X3,X4,Z<:AbstractPhase}
749+
750+
T = 0.0
751+
rho = 0.0
752+
mass = 0.0
753+
P = 1.0e8
754+
A = 0.0
755+
756+
fragmentnames = getfield.(getphasespecies(phase), :name)
757+
758+
y0 = zeros(length(fragmentnames)+1) #track mass
759+
760+
for (key,val) in initialconds
761+
if key == "T"
762+
T = val
763+
elseif key == "A"
764+
A = val
765+
elseif key == "rho"
766+
rho = val
767+
elseif key == "mass"
768+
mass = val
769+
y0[end] = val
770+
else
771+
ind = findfirst(isequal(key),fragmentnames)
772+
@assert typeof(ind)<: Integer "$key not found in fragment list: $fragmentnames"
773+
y0[ind] = val
774+
end
775+
end
776+
@assert T != 0.0
777+
@assert rho != 0.0
778+
@assert mass != 0.0
779+
@assert A != 0.0
780+
781+
ns = y0[1:end-1]
782+
N = sum(ns)
783+
V = mass/rho
784+
785+
if length(constantspecies) > 0
786+
for spc in constantspecies
787+
@assert spc in fragmentnames "$spc is not in the fragment list: $fragmentnames"
788+
end
789+
constspcinds = [findfirst(isequal(k),fragmentnames) for k in constantspecies]
790+
else
791+
constspcinds = Array{Int64,1}()
792+
end
793+
efficiencyinds = [rxn.index for rxn in phase.reactions if typeof(rxn.kinetics)<:AbstractFalloffRate && length(rxn.kinetics.efficiencies) > 0]
794+
Gs = calcgibbs(phase,T)
795+
if :solvent in fieldnames(typeof(phase)) && typeof(phase.solvent) != EmptySolvent
796+
mu = phase.solvent.mu(T)
797+
else
798+
mu = 0.0
799+
end
800+
if phase.diffusionlimited
801+
diffs = [x(T=T,mu=mu,P=P) for x in getfield.(getphasespecies(phase),:diffusion)]
802+
else
803+
diffs = Array{Float64,1}()
804+
end
805+
806+
C = N/V
807+
kfs,krevs = getkfkrevs(phase,T,P,C,N,ns,Gs,diffs,V,0.0)
808+
kfsnondiff = getkfs(phase,T,P,C,ns,V,0.0)
809+
810+
p = vcat(Gs,kfsnondiff)
811+
if sparse
812+
jacobian=zeros(typeof(T),length(getphasespecies(phase)),length(getphasespecies(phase)))
813+
else
814+
jacobian=zeros(typeof(T),length(getphasespecies(phase)),length(getphasespecies(phase)))
815+
end
816+
rxnarray = getreactionindices(phase)
817+
return FragmentBasedConstantTrhoDomain(phase,[1,length(fragmentnames),length(fragmentnames)+1],[1,length(phase.species)+length(phase.reactions)],constspcinds,
818+
T,rho,A,kfs,krevs,kfsnondiff,efficiencyinds,Gs,rxnarray,mu,diffs,jacobian,sensitivity,false,MVector(false),MVector(0.0),p,Dict("mass"=>length(fragmentnames)+1)), y0, p
819+
end
820+
821+
export FragmentBasedConstantTrhoDomain
822+
714823
@inline function calcthermo(d::ConstantTPDomain{W,Y},y::J,t::Q,p::W3=SciMLBase.NullParameters()) where {W3<:SciMLBase.NullParameters,W<:IdealGas,Y<:Integer,J<:Array{Float64,1},Q} #no parameter input
715824
ns = y[d.indexes[1]:d.indexes[2]]
716825
V = y[d.indexes[3]]

0 commit comments

Comments
 (0)