From 9a98100f07f8b56133b84976056de8101621b50d Mon Sep 17 00:00:00 2001 From: Rachel Kurchin Date: Wed, 3 Aug 2022 13:11:05 -0400 Subject: [PATCH 1/2] add option for overpotential not to warn as it makes phase diagram construction really noisy Signed-off-by: Rachel Kurchin --- src/fitting.jl | 4 ++-- src/phase_diagrams.jl | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fitting.jl b/src/fitting.jl index 64fff02..684e0f2 100644 --- a/src/fitting.jl +++ b/src/fitting.jl @@ -45,7 +45,7 @@ Given values for current/rate constant and specified model parameters, find the NOTE that this currently only solves for net reaction rates. """ -function overpotential(k, model::KineticModel, guess = _get_guess(k, model); T = 298, loss = janky_log_loss, autodiff = true, verbose=false, kwargs...) +function overpotential(k, model::KineticModel, guess = _get_guess(k, model); T = 298, loss = janky_log_loss, autodiff = true, verbose=false, warn=true, kwargs...) # wherever k=0 we can shortcut since the answer has to be 0 k_solve = k if k==0 # scalar k=0, possibly vector model @@ -91,7 +91,7 @@ function overpotential(k, model::KineticModel, guess = _get_guess(k, model); T = else Vs = nlsolve(compare_k!, guess, show_trace=verbose) end - if !converged(Vs) + if !converged(Vs) && warn @warn "Overpotential fit not fully converged...you may have fed in an unreachable reaction rate!" end sol = Vs.zero diff --git a/src/phase_diagrams.jl b/src/phase_diagrams.jl index c1cf8a5..271436d 100644 --- a/src/phase_diagrams.jl +++ b/src/phase_diagrams.jl @@ -23,18 +23,18 @@ prefactor(x, intercalate::Bool) = intercalate ? (1 .- x) : x These functions return single-argument functions (to easily use common-tangent function below while still being able to swap out model parameters by calling "function-builders" with different arguments). """ -function µ_kinetic(I, km::KineticModel; intercalate=true, kwargs...) +function µ_kinetic(I, km::KineticModel; intercalate=true, warn=true, kwargs...) thermo_term(x) = μ_thermo(x; kwargs...) - μ(x::Real) = thermo_term(x) .+ overpotential(I, prefactor(x, intercalate)*km) - μ(x::AbstractVector) = thermo_term(x) .+ overpotential(I, prefactor(x, intercalate).*Ref(km)) + μ(x::Real) = thermo_term(x) .+ overpotential(I, prefactor(x, intercalate)*km, warn=warn) + μ(x::AbstractVector) = thermo_term(x) .+ overpotential(I, prefactor(x, intercalate).*Ref(km), warn=warn) return μ end -function g_kinetic(I, km::KineticModel; intercalate=true, kwargs...) +function g_kinetic(I, km::KineticModel; intercalate=true, warn=true, kwargs...) thermo_term(x) = g_thermo(x; kwargs...) #TODO: gradient of this term is just value of overpotential(x) function kinetic_term(x) - f(x) = ElectrochemicalKinetics.overpotential(I, prefactor(x, intercalate) * km) + f(x) = ElectrochemicalKinetics.overpotential(I, prefactor(x, intercalate) * km, warn=warn) n, w = ElectrochemicalKinetics.scale_coarse(zero.(x), x) map((w, n) -> sum(w .* f(n)), eachcol(w), eachcol(n)) end From 2e515d0dcfd28e2c5f1ff79e7a432e42a8bbee6c Mon Sep 17 00:00:00 2001 From: Rachel Kurchin Date: Wed, 3 Aug 2022 13:11:33 -0400 Subject: [PATCH 2/2] patch version bump Signed-off-by: Rachel Kurchin --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 7a1e3ec..0ce72be 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ElectrochemicalKinetics" uuid = "a2c6e634-85ca-418a-9c67-9b5417ce2d04" authors = ["Rachel Kurchin ", "Holden Parks ", "Dhairya Gandhi "] -version = "0.1.2" +version = "0.1.3" [deps] DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"