Skip to content

Commit

Permalink
Merge pull request #101 from MarcBerliner/rc_1_0_0
Browse files Browse the repository at this point in the history
RC for v1.0.0
  • Loading branch information
MarcBerliner authored Oct 21, 2022
2 parents 6cd0104 + 23e9988 commit 05ea156
Show file tree
Hide file tree
Showing 19 changed files with 4,319 additions and 593 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PETLION"
uuid = "5e0a28e4-193c-47fa-bbb8-9c901cc1ac2c"
authors = ["Marc D. Berliner", "Richard D. Braatz"]
version = "0.2.6"
version = "1.0.0"

[deps]
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
Expand Down
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@ import Pkg; Pkg.add("PETLION")
```

# Getting started
To [get started](examples/getting_started.ipynb), we recommend checking out the [list of examples](examples). To simulate a simple [constant current-constant voltage (CC-CV) charge](examples/CC-CV.ipynb), run the following:
To [get started](examples/getting_started.ipynb), we recommend checking out the [list of examples](examples). To simulate a [constant current-constant temperature-constant voltage (CC-CT-CV) fast charge](examples/fast_charging_CC-CT-CV.ipynb), run the following:
```julia
using PETLION
p = petlion(LCO)
p = petlion(LCO; temperature=true)

sol = simulate(p, I=2, SOC=0, V_max=4.1)
simulate!(sol, p, 1800, V=:hold, I_min=1/20)
sol = simulate(p, I=4, SOC=0, V_max=4.1, T_max=40+273.15)
simulate!(sol, p, dT=:hold, V_max=4.1)
simulate!(sol, p, V=:hold)
```
<img src="https://raw.githubusercontent.com/MarcBerliner/PETLION.jl/master/docs/example_pictures/CCCV_I.png" width="50%"><img src="https://raw.githubusercontent.com/MarcBerliner/PETLION.jl/master/docs/example_pictures/CCCV_V.png" width="50%">
<img src="https://raw.githubusercontent.com/MarcBerliner/PETLION.jl/master/docs/example_pictures/CC-CT-CV.png" width="100%"
```julia
PETLION simulation
--------
Runs: I V
Time: 2440.61 s
Current: 0.1955C
Voltage: 4.1 V
Power: 23.432 W
SOC: 1.0001
Exit: Above maximum SOC limit
--------
Runs: I dT V
Time: 1865.61 s
Current: 0.1959C
Voltage: 4.1 V
Power: 23.47 W/
SOC: 1.0
Temp.: 25.6963 °C
Exit: Above max. SOC
```

# Credits
Expand Down
Binary file added docs/example_pictures/CC-CT-CV.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,782 changes: 1,782 additions & 0 deletions examples/.ipynb_checkpoints/fast_charging_CC-CT-CV-checkpoint.ipynb

Large diffs are not rendered by default.

1,782 changes: 1,782 additions & 0 deletions examples/fast_charging_CC-CT-CV.ipynb

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/PETLION.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ using BSON: @load, @save

export simulate, simulate!
export solution
export final_exit_reason, exit_reasons

export petlion
export boundary_stop_conditions, options_simulation, discretizations_per_section, options_numerical
Expand All @@ -44,11 +45,11 @@ export rxn_BV, rxn_BV_γMod_01
export rxn_MHC


include("states_definition.jl")
include("outputs.jl")
include("structures.jl")
include("params.jl")
include("external.jl")
include("set_variables.jl")
include("model_evaluation.jl")
include("generate_functions.jl")
include("physics_equations/residuals.jl")
Expand All @@ -58,6 +59,7 @@ include("physics_equations/custom_functions.jl")
include("physics_equations/numerical_tools.jl")
include("physics_equations/input_methods.jl")
include("checks.jl")
include("save_outputs.jl")

## Backwards compatability
Params(x...;kw...) = petlion(x...;kw...)
Expand Down
34 changes: 25 additions & 9 deletions src/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ end
end

@inline check_stop_dfilm(::model_age{false}, run, sol, Y, YP, bounds, ϵ, I) = nothing
@inline check_stop_dfilm(::model_age{:stress}, run, sol, Y, YP, bounds, ϵ, I) = nothing
@inline function check_stop_dfilm(p::R4, run::R3, sol, Y::R2, YP::R2, bounds::R5, ϵ::Float64, I::Float64
) where {R2<:Vector{Float64}, R3<:AbstractRun, R4<:model_age{:SEI}, R5<:boundary_stop_conditions_immutable}

Expand All @@ -224,7 +223,7 @@ end
return nothing
end

@inline function check_solve(run::run_constant, sol::R1, int::R2, p, bounds, opts::R5, funcs, keep_Y::Bool, iter::Int64, Y::Vector{Float64}, t::Float64) where {R1<:solution,R2<:Sundials.IDAIntegrator,R5<:AbstractOptionsModel}
@inline function check_solve(run::Union{run_constant,run_residual}, sol::R1, int::R2, p, bounds, opts::R5, funcs, keep_Y::Bool, iter::Int64, Y::Vector{Float64}, t::Float64) where {R1<:solution,R2<:Sundials.IDAIntegrator,R5<:AbstractOptionsModel}
if t == int.tprev
# Sometimes the initial step at t = 0 can be too large. This reduces the step size
if t == 0.0
Expand Down Expand Up @@ -356,7 +355,7 @@ end

# if the function values at t vs. t + Δt are very different (i.e., there is a discontinuity)
# then reinitialize the DAE at t + Δt
if !(value_old, value_new, atol=opts.abstol, rtol=opts.reltol)
if !(value_old, value_new; atol=opts.abstol, rtol=opts.reltol)
initialize_states!(p,Y,YP,run,opts,funcs,(@inbounds sol.SOC[end]); t=t_new)

Sundials.IDAReInit(int.mem, t_new, Y, YP)
Expand All @@ -375,18 +374,35 @@ end
return nothing
end

function check_errors_initial(θ, numerics, N)
@inline function check_errors_initial(θ, numerics, N)
if numerics.jacobian (:symbolic, :AD)
error("`jacobian` can either be :symbolic or :AD")
end

return nothing
end

check_is_hold(x::Symbol,sol::solution) = (x == :hold) && (!isempty(sol) ? true : error("Cannot use `:hold` without a previous sol."))
check_is_hold(::Any,::solution) = false
@inline check_is_hold(x::Symbol,sol::solution) = (x == :hold) && (!isempty(sol) ? true : error("Cannot use `:hold` without a previous simulation."))
@inline check_is_hold(::Any,::solution) = false

check_is_rest(run::run_constant{method_I, Symbol}) = run.input == :rest
check_is_rest(::Any) = false
@inline check_is_rest(run::run_constant{method_I, Symbol}) = run.input == :rest
@inline check_is_rest(::Any) = false

check_is_half_cell(p::AbstractModel) = p.numerics.anode == lithium_foil
@inline check_is_half_cell(p::AbstractModel) = p.numerics.anode == lithium_foil

@inline function final_exit_reason(sol::solution)
```
Return the final exit reason as a string
```
@assert !isempty(sol)

return @inbounds sol.results[end].run.info.exit_reason
end
@inline function exit_reasons(sol::solution)
```
Return the list of exit reasons as a vector of strings
```
@assert !isempty(sol)

return String[result.run.info.exit_reason for result in sol.results]
end
Loading

0 comments on commit 05ea156

Please sign in to comment.