Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParametrizedTConstantVDomain must take "T" as a function or if an array of times for "ts" is supplied as an array of volumes #220

Open
alongd opened this issue Jun 28, 2023 · 7 comments

Comments

@alongd
Copy link
Member

alongd commented Jun 28, 2023

I'm running a liquid simulation using an RMG-generated .rms file.

When given initial conditions such as

initialconds = Dict(["T"=>300.0, "V"=>1.0e-6*1e6, "water" => 0.055332, "mol1" => 1.30E-5]);
domain, y0 = ParametrizedTConstantVDomain(phase=liq, initialconds=initial_conds);

RMS says:

ParametrizedTConstantVDomain must take "T" as a function or if an array of times for "ts" is supplied as an array of volumes

Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] ParametrizedTConstantVDomain(; phase::IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, initialconds::Dict{String, Float64}, constantspecies::Vector{String}, sparse::Bool, sensitivity::Bool)
   @ ReactionMechanismSimulator ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Domain.jl:613
 [3] top-level scope
   @ In[56]:1

The structure of the above input also appears in the docs. I can run if I give a list of ts and a list of Ts though

@mjohnson541, could you please take a look?

@mjohnson541
Copy link
Collaborator

For the code above you want ConstantTVDomain, ParametrizedTConstantVDomain is for cases when the temperature is variable...these are distinct because in the former the rate coefficients are constant and don't need recomputed.

@alongd
Copy link
Member Author

alongd commented Jun 29, 2023

Thanks! I should have payed more attention.

I'm still getting errors, let me know if you'd like me to open new issues or move the conversation offline

I'm now doing the following:

phaseDict = readinput(rms_file);
spcs = phaseDict["phase"]["Species"];
rxns = phaseDict["phase"]["Reactions"];
solv = Solvent("water", RiedelViscosity(-52.843, 3703.6, 5.866, -5.88e-29, 10.0));
liq = IdealDiluteSolution(spcs, rxns, solv, name="phase", diffusionlimited=true);

# BTW, concentration units below are mol/cm3 like in RMG, do I need to multiply by 1e6 to convert?
initialconds = Dict(["T" => 300.0, "V" => V, "water" => 0.055332, "mol1" => 1.30E-5]);

domain, y0 = ConstantTVDomain(phase=liq, initialconds=initialconds, constantspecies=[]);

reactor = Reactor(domain, y0, (0.0, max_time * 1.05));

But I get:

MethodError: calcthermo(::ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, ::Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, ::Float64, ::SciMLBase.NullParameters) is ambiguous. Candidates:
  calcthermo(d::ConstantTVDomain{W, Y}, y::J, t::Q, p::Q2) where {Q2<:SciMLBase.NullParameters, W<:IdealDiluteSolution, Y<:Integer, J<:AbstractArray, Q} in ReactionMechanismSimulator at /home/alon/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Domain.jl:1421
  calcthermo(d::ConstantTVDomain{W, Y}, y::Vector{W2}, t::Q, p::Q2) where {W2<:ForwardDiff.Dual, Q2, W<:IdealDiluteSolution, Y<:Integer, J<:AbstractArray, Q} in ReactionMechanismSimulator at /home/alon/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Domain.jl:1470
Possible fix, define
  calcthermo(::ConstantTVDomain{W, Y}, ::J, ::Q, ::SciMLBase.NullParameters) where {W2<:ForwardDiff.Dual, W<:IdealDiluteSolution, Y<:Integer, Q, J<:Vector{W2}}

Stacktrace:
  [1] #dydtreactor!#608
    @ ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:638 [inlined]
  [2] (::ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}})(dy::Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, y::Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}})
    @ ReactionMechanismSimulator ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:765
  [3] vector_mode_dual_eval!(f!::ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, cfg::ForwardDiff.JacobianConfig{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}}}, y::Vector{Float64}, x::Vector{Float64})
    @ ForwardDiff ~/mambaforge/envs/rmg_env/share/julia/site/packages/ForwardDiff/vXysl/src/apiutils.jl:31
  [4] vector_mode_jacobian!(result::SparseArrays.SparseMatrixCSC{Float64, Int64}, f!::ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, y::Vector{Float64}, x::Vector{Float64}, cfg::ForwardDiff.JacobianConfig{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}}})
    @ ForwardDiff ~/mambaforge/envs/rmg_env/share/julia/site/packages/ForwardDiff/vXysl/src/jacobian.jl:153
  [5] jacobian!(result::SparseArrays.SparseMatrixCSC{Float64, Int64}, f!::Function, y::Vector{Float64}, x::Vector{Float64}, cfg::ForwardDiff.JacobianConfig{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}}}, ::Val{true})
    @ ForwardDiff ~/mambaforge/envs/rmg_env/share/julia/site/packages/ForwardDiff/vXysl/src/jacobian.jl:78
  [6] jacobian!(result::SparseArrays.SparseMatrixCSC{Float64, Int64}, f!::Function, y::Vector{Float64}, x::Vector{Float64}, cfg::ForwardDiff.JacobianConfig{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9, Tuple{Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{ReactionMechanismSimulator.var"#f#612"{SciMLBase.NullParameters, Float64, ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, Vector{Any}}, Float64}, Float64, 9}}}}) (repeats 2 times)
    @ ForwardDiff ~/mambaforge/envs/rmg_env/share/julia/site/packages/ForwardDiff/vXysl/src/jacobian.jl:76
  [7] jacobianyforwarddiff!
    @ ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:766 [inlined]
  [8] jacyforwarddiff!
    @ ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:33 [inlined]
  [9] Reactor(domain::ConstantTVDomain{IdealDiluteSolution{Tuple{Arrheniusvec{Vector{Float64}, Vector{Float64}, Vector{Float64}}}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}}, Int64, Float64, Float64, Integer, Vector{Int64}}, y0::Vector{Float64}, tspan::Tuple{Float64, Int64}, interfaces::Vector{Any}; p::SciMLBase.NullParameters, forwardsensitivities::Bool, forwarddiff::Bool, modelingtoolkit::Bool, tau::Float64)
    @ ReactionMechanismSimulator ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:44
 [10] Reactor (repeats 2 times)
    @ ~/mambaforge/envs/rmg_env/share/julia/site/packages/ReactionMechanismSimulator/ztchp/src/Reactor.jl:30 [inlined]
 [11] top-level scope
    @ In[11]:1

Since I'm not calling calcthermo directly, I'm not sure what I need to change.

My code follows this RMS example.

@alongd
Copy link
Member Author

alongd commented Jun 29, 2023

Update:
solved by modifying

domain, y0 = ConstantTVDomain(phase=liq, initialconds=initialconds, constantspecies=[]);

reactor = Reactor(domain, y0, (0.0, max_time * 1.05));

into

domain, y0, p = ConstantTVDomain(phase=liq, initialconds=initialconds, constantspecies=[]);

reactor = Reactor(domain, y0, (0.0, max_time * 1.05), p=p);

Perhaps the examples should be updated if this is change is correct?

@mjohnson541
Copy link
Collaborator

Yes, that is the correct format now...it looks like that never got changed in the docs...

@mjohnson541
Copy link
Collaborator

mjohnson541 commented Jun 29, 2023

Also you may want to switch to commit: baba92a. There's some bugs on main right now related to plotting (#219).

@mjohnson541
Copy link
Collaborator

The first bit I understand, but I'm a little confused why the p=p is necessary. We may need to tweak the method typings. I'm particularly unsure why it was calling forwarddiff when it should be able to use analytic jacobians.

@hwpang
Copy link
Contributor

hwpang commented Oct 12, 2023

@mjohnson541 I think p=p is necessary because otherwise the default SciMLBase.NullParameters() is getting passed in, rather than the actual p. Why did we make this optional in the first place? I don't see why p can be optional. forwarddiff is called once in the beginning for all domains to determine their Jacobian sparsity pattern here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants