MarcBerliner / PETLION.jl

High-performance simulations of the Porous Electrode Theory for Li-ion batteries
MIT License
66 stars 11 forks source link

aging=: SEI, which will cause cc-cv to not work properly #92

Open steal-the-soul opened 2 years ago

steal-the-soul commented 2 years ago

Hi,

Yes, that is handled through the keyword argument aging to the Params function. For example, to enable a lithium plating side reaction degradation model with LCO chemistry run p = Params(LCO; aging=:SEI).

After evaluating the model, you can find state-of-health (SOH) by model.SOH and similarly calculate the fractional capacity fade by 1-model.SOH.

I just pushed a minor update, so be sure to update your packages before trying it out!

Best, Marc

Originally posted by @MarcBerliner in https://github.com/MarcBerliner/PETLION.jl/issues/89#issuecomment-1000899127

steal-the-soul commented 2 years ago

I've updated the package to the latest version, I think running p = petlion(LCO; aging=:SEI) as before in order to get sol.SOH[], however, when adding aging=:SEI to the cc-cv model , the model test will have this problem: Model failed to converge at t = 0.0. Try tightening the absolute and relative tolerances. I don't know what to do, hope to get your help, thank you. God bless you.

steal-the-soul commented 2 years ago

Here is the code.

p = petlion(LCO;
     aging=:SEI,
    N_p = 10, # discretizations in the cathode
    N_s = 10, # discretizations in the separator
    N_n = 10, # discretizations in the anode
    N_r_p = 10, # discretizations in the solid cathode particles
    N_r_n = 10, # discretizations in the solid anode particles
    temperature = false, # temperature enabled or disabled
    jacobian = :AD # :symbolic or :AD
    );

But when I want to simulate the battery with code below, the model is not converged and stacktrace is also listed below.

sol = simulate(p, I=2, SOC=0, V_max=4.1,outputs=:all)
simulate!(sol, p, V=:hold)
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] check_solve
   @ ~/.julia/packages/PETLION/cPcex/src/checks.jl:231 [inlined]
 [3] solve!(sol::PETLION.solution_states{Vector{Float64}, RecursiveArrayTools.VectorOfArray{Float64, 2, Vector{Vector{Float64}}}, Vector{PETLION.run_results}}, int::Sundials.IDAIntegrator{Sundials.NVector, Sundials.NVector, PETLION.run_constant{PETLION.method_V, Symbol}, Sundials.Handle{Sundials.IDAMem}, SciMLBase.DAESolution{Float64, 2, Vector{Vector{Float64}}, Nothing, Nothing, Nothing, Vector{Float64}, SciMLBase.DAEProblem{Vector{Float64}, Vector{Float64}, Tuple{Float64, Float64}, true, PETLION.run_constant{PETLION.method_V, Symbol}, SciMLBase.DAEFunction{true, PETLION.var"#118#120"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.residual_combined{PETLION.var"#226#227", PETLION.var"#224#225", typeof(PETLION.scalar_residual!)}}, Nothing, Nothing, PETLION.var"#119#121"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.jacobian_combined{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}, typeof(PETLION.scalar_jacobian!), KLU.KLUFactorization{Float64, Int64}}}, Nothing, Nothing, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, Vector{Int64}}, Sundials.IDA{:KLU, Nothing, Nothing}, SciMLBase.LinearInterpolation{Vector{Float64}, Vector{Vector{Float64}}}, DiffEqBase.DEStats}, Sundials.IDA{:KLU, Nothing, Nothing}, SciMLBase.DAEFunction{true, PETLION.var"#118#120"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.residual_combined{PETLION.var"#226#227", PETLION.var"#224#225", typeof(PETLION.scalar_residual!)}}, Nothing, Nothing, PETLION.var"#119#121"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.jacobian_combined{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}, typeof(PETLION.scalar_jacobian!), KLU.KLUFactorization{Float64, Int64}}}, Nothing, Nothing, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Sundials.FunJac{SciMLBase.DAEFunction{true, PETLION.var"#118#120"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.residual_combined{PETLION.var"#226#227", PETLION.var"#224#225", typeof(PETLION.scalar_residual!)}}, Nothing, Nothing, PETLION.var"#119#121"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.jacobian_combined{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}, typeof(PETLION.scalar_jacobian!), KLU.KLUFactorization{Float64, Int64}}}, Nothing, Nothing, SparseArrays.SparseMatrixCSC{Float64, Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Nothing, PETLION.var"#119#121"{PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, PETLION.jacobian_combined{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, SubArray{Float64, 1, Vector{Float64}, Tuple{Vector{Int64}}, false}, typeof(PETLION.scalar_jacobian!), KLU.KLUFactorization{Float64, Int64}}}, PETLION.run_constant{PETLION.method_V, Symbol}, Nothing, SparseArrays.SparseMatrixCSC{Float64, Int64}, Vector{Float64}, Vector{Float64}, Nothing, Nothing}, Ptr{Nothing}, Sundials.DEOptions{DataStructures.BinaryMinHeap{Float64}, DataStructures.BinaryMinHeap{Float64}, Vector{Float64}, Vector{Float64}, Nothing, SciMLBase.CallbackSet{Tuple{}, Tuple{}}, Float64, Float64, typeof(DiffEqBase.ODE_DEFAULT_PROG_MESSAGE)}, Vector{Float64}, Tuple{Int64}, Tuple{Int64}, Vector{Float64}, Sundials.LinSolHandle{Sundials.KLU}, Sundials.MatrixHandle{Sundials.SparseMatrix}, Nothing}, run::PETLION.run_constant{PETLION.method_V, Symbol}, p::PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, bounds::PETLION.boundary_stop_conditions_immutable, opts::PETLION.options_simulation_immutable{PETLION.var"#16#18"}, funcs::PETLION.Jac_and_res{Sundials.IDAIntegrator})
   @ PETLION ~/.julia/packages/PETLION/cPcex/src/model_evaluation.jl:351
 [4] simulate(p::PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}, tf::Float64; sol::PETLION.solution_states{Vector{Float64}, RecursiveArrayTools.VectorOfArray{Float64, 2, Vector{Vector{Float64}}}, Vector{PETLION.run_results}}, initial_states::Nothing, res_I_guess::Nothing, SOC::Float64, outputs::Tuple{Symbol}, abstol::Float64, reltol::Float64, abstol_init::Float64, reltol_init::Float64, maxiters::Int64, check_bounds::Bool, reinit::Bool, verbose::Bool, interp_final::Bool, tstops::Vector{Float64}, tdiscon::Vector{Float64}, interp_bc::Symbol, save_start::Bool, stop_function::PETLION.var"#16#18", calc_integrator::Bool, V_max::Float64, V_min::Float64, SOC_max::Float64, SOC_min::Float64, T_max::Float64, c_s_n_max::Float64, I_max::Float64, I_min::Float64, η_plating_min::Float64, c_e_min::Float64, dfilm_max::Float64, inputs::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:V,), Tuple{Symbol}}})
   @ PETLION ~/.julia/packages/PETLION/cPcex/src/model_evaluation.jl:75
 [5] simulate!(::PETLION.solution_states{Vector{Float64}, RecursiveArrayTools.VectorOfArray{Float64, 2, Vector{Vector{Float64}}}, Vector{PETLION.run_results}}, ::PETLION.model{PETLION.jacobian_AD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}, SparseDiffTools.ForwardColorJacCache{Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{ForwardDiff.Dual{ForwardDiff.Tag{PETLION.res_FD{PETLION.var"#132#134"{Int64, PETLION.var"#226#227", PETLION.var"#224#225"}}, Float64}, Float64, 7}}, Vector{Float64}, Vector{Vector{NTuple{7, Float64}}}, Vector{Int64}, SparseArrays.SparseMatrixCSC{Float64, Int64}}}, false, :Fickian, :finite_difference, :SEI}; outputs::Tuple{Symbol}, overwrite_sol::Bool, sol::Nothing, kw::Base.Pairs{Symbol, Symbol, Tuple{Symbol}, NamedTuple{(:V,), Tuple{Symbol}}})
   @ PETLION ~/.julia/packages/PETLION/cPcex/src/model_evaluation.jl:93
 [6] top-level scope
   @ In[4]:2
 [7] eval
   @ ./boot.jl:373 [inlined]
 [8] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
   @ Base ./loading.jl:1196
MarcBerliner commented 2 years ago

Strange, running the code worked on my machine. Can you please update the packages in your Julia environment and try again? If that does not work, try running empty!(p);PETLION.options[:FACTORIZATION_METHOD] = :LU.

steal-the-soul commented 2 years ago

Excuse me, May I ask what version of Julia and the corresponding PETLION you have successfully run?

MarcBerliner commented 2 years ago

I am using Julia 1.7.2 and the master version of PETLION.

steal-the-soul commented 2 years ago

thank you. God bless you Hi dear Dr, thanks for your help, my PETLION model can run successfully. I have a new question that I would like to ask you, how does PETLION perform constant power operation and how to perform constant power initialization. thank you. God bless you. ''' sol = simulate(p=300,1800,I,V_max=4.1,SOC=0,outputs=:all) d=length(sol.t) sol.SOC[d] simulate!(sol,p,V=:hold) d1=length(sol.t) sol.SOC[d1] '''

MarcBerliner commented 2 years ago

You run constant power with

sol = simulate(p,1800,P=300,V_max=4.1,SOC=0,outputs=:all)
steal-the-soul commented 2 years ago

You run constant power with

sol = simulate(p,1800,P=300,V_max=4.1,SOC=0,outputs=:all)

Thank you very much for your answer. I am very happy to be friends with you. I hope that when you have the opportunity to travel to China, I can invite you to enjoy Chinese food. I took your advice and used this code: sol = simulate(p,P=300,V_max=4.1,SOC=0,outputs=:all). The code can run successfully, but the output power when simulating is only about P=3.8, not the P=300 that I inputed. I don't understand this and hope to get your help.

sol = simulate(p,P=300,V_max=4.1,SOC=0,outputs=:all)
sol.P
Below is the output result of the power:
87-element Vector{Float64}:
3.799866825192766
3.799866825191172
3.7998668250765357
3.7998668251880696
3.7998668339340487
3.7998668396476134
3.7998668286590744
3.7998668200132957
3.799866825188943
3.7998667948145766
3.799866772711421
3.799866782867297
3.799866825188544
⋮
3.79985329873509
3.7998760762804538
3.7998265400457765
3.7998668251892602
3.79986234203909
3.799859887609495
3.7998552217572765
3.799865036759412
3.7998641715392663
3.7998668252106618
3.799810704433561
3.8001208175050523
MarcBerliner commented 2 years ago

Thank you for the offer, I will let you know if I ever make the trip!

I just pushed a bug fix which corrects this problem -- I accidentally replaced the initial power with the initial current. It should work now properly now.

steal-the-soul commented 2 years ago

dear MarcBerliner hello, It's been a long time since I wrote you an email. I hope you live a happy life and your research goes well. Thank you for your last answer and bug fixes. May I know what is the battery corresponding to the basic parameters of PETLION? And what is the power rating of the battery? sincerely steal-of-soul