Skip to content

Commit

Permalink
#699 start removing autograd
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Oct 31, 2019
1 parent 44614d1 commit ec08db7
Show file tree
Hide file tree
Showing 27 changed files with 223 additions and 129 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.tmp
*.png
/local/
*.DS_Store

# don't ignore important .txt files
!requirements*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Open-circuit voltage in the negative (lead) electrode
#
import autograd.numpy as np
from pybamm import log10


def lead_ocp_Bode1977(m):
Expand All @@ -16,9 +16,9 @@ def lead_ocp_Bode1977(m):
"""
U = (
-0.294
- 0.074 * np.log10(m)
- 0.030 * np.log10(m) ** 2
- 0.031 * np.log10(m) ** 3
- 0.012 * np.log10(m) ** 4
- 0.074 * log10(m)
- 0.030 * log10(m) ** 2
- 0.031 * log10(m) ** 3
- 0.012 * log10(m) ** 4
)
return U
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Open-circuit voltage in the positive (lead-dioxide) electrode
#
import autograd.numpy as np
from pybamm import log10


def lead_dioxide_ocp_Bode1977(m):
Expand All @@ -16,9 +16,9 @@ def lead_dioxide_ocp_Bode1977(m):
"""
U = (
1.628
+ 0.074 * np.log10(m)
+ 0.033 * np.log10(m) ** 2
+ 0.043 * np.log10(m) ** 3
+ 0.022 * np.log10(m) ** 4
+ 0.074 * log10(m)
+ 0.033 * log10(m) ** 2
+ 0.043 * log10(m) ** 3
+ 0.022 * log10(m) ** 4
)
return U
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# Sulfuric acid conductivity
#
import autograd.numpy as np
from pybamm import exp


def conductivity_Gu1997(c_e):
Expand All @@ -23,4 +23,4 @@ def conductivity_Gu1997(c_e):
California Univ., Berkeley. Lawrence Radiation Lab., 1968.
"""
return c_e * np.exp(6.23 - 1.34e-4 * c_e - 1.61e-8 * c_e ** 2) * 1e-4
return c_e * exp(6.23 - 1.34e-4 * c_e - 1.61e-8 * c_e ** 2) * 1e-4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def graphite_electrolyte_reaction_rate_Dualfoil1998(T, T_inf, E_r, R_g):
Expand Down Expand Up @@ -26,6 +26,6 @@ def graphite_electrolyte_reaction_rate_Dualfoil1998(T, T_inf, E_r, R_g):
Reaction rate
"""
m_ref = 2 * 10 ** (-5)
arrhenius = np.exp(E_r / R_g * (1 / T_inf - 1 / T))
arrhenius = exp(E_r / R_g * (1 / T_inf - 1 / T))

return m_ref * arrhenius
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp, cosh


def graphite_entropic_change_Moura2016(sto, c_n_max):
Expand All @@ -19,15 +19,15 @@ def graphite_entropic_change_Moura2016(sto, c_n_max):
"""

du_dT = (
-1.5 * (120.0 / c_n_max) * np.exp(-120 * sto)
+ (0.0351 / (0.083 * c_n_max)) * ((np.cosh((sto - 0.286) / 0.083)) ** (-2))
- (0.0045 / (0.119 * c_n_max)) * ((np.cosh((sto - 0.849) / 0.119)) ** (-2))
- (0.035 / (0.05 * c_n_max)) * ((np.cosh((sto - 0.9233) / 0.05)) ** (-2))
- (0.0147 / (0.034 * c_n_max)) * ((np.cosh((sto - 0.5) / 0.034)) ** (-2))
- (0.102 / (0.142 * c_n_max)) * ((np.cosh((sto - 0.194) / 0.142)) ** (-2))
- (0.022 / (0.0164 * c_n_max)) * ((np.cosh((sto - 0.9) / 0.0164)) ** (-2))
- (0.011 / (0.0226 * c_n_max)) * ((np.cosh((sto - 0.124) / 0.0226)) ** (-2))
+ (0.0155 / (0.029 * c_n_max)) * ((np.cosh((sto - 0.105) / 0.029)) ** (-2))
-1.5 * (120.0 / c_n_max) * exp(-120 * sto)
+ (0.0351 / (0.083 * c_n_max)) * ((cosh((sto - 0.286) / 0.083)) ** (-2))
- (0.0045 / (0.119 * c_n_max)) * ((cosh((sto - 0.849) / 0.119)) ** (-2))
- (0.035 / (0.05 * c_n_max)) * ((cosh((sto - 0.9233) / 0.05)) ** (-2))
- (0.0147 / (0.034 * c_n_max)) * ((cosh((sto - 0.5) / 0.034)) ** (-2))
- (0.102 / (0.142 * c_n_max)) * ((cosh((sto - 0.194) / 0.142)) ** (-2))
- (0.022 / (0.0164 * c_n_max)) * ((cosh((sto - 0.9) / 0.0164)) ** (-2))
- (0.011 / (0.0226 * c_n_max)) * ((cosh((sto - 0.124) / 0.0226)) ** (-2))
+ (0.0155 / (0.029 * c_n_max)) * ((cosh((sto - 0.105) / 0.029)) ** (-2))
)

return du_dT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def graphite_mcmb2528_diffusivity_Dualfoil1998(sto, T, T_inf, E_D_s, R_g):
Expand Down Expand Up @@ -30,7 +30,7 @@ def graphite_mcmb2528_diffusivity_Dualfoil1998(sto, T, T_inf, E_D_s, R_g):
"""

D_ref = 3.9 * 10 ** (-14)
arrhenius = np.exp(E_D_s / R_g * (1 / T_inf - 1 / T))
arrhenius = exp(E_D_s / R_g * (1 / T_inf - 1 / T))

# Removing the fudge factor 0 * sto requires different handling of either
# either simplifications or how sto is passed into this function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp, tanh


def graphite_mcmb2528_ocp_Dualfoil1998(sto):
Expand All @@ -15,15 +15,15 @@ def graphite_mcmb2528_ocp_Dualfoil1998(sto):

u_eq = (
0.194
+ 1.5 * np.exp(-120.0 * sto)
+ 0.0351 * np.tanh((sto - 0.286) / 0.083)
- 0.0045 * np.tanh((sto - 0.849) / 0.119)
- 0.035 * np.tanh((sto - 0.9233) / 0.05)
- 0.0147 * np.tanh((sto - 0.5) / 0.034)
- 0.102 * np.tanh((sto - 0.194) / 0.142)
- 0.022 * np.tanh((sto - 0.9) / 0.0164)
- 0.011 * np.tanh((sto - 0.124) / 0.0226)
+ 0.0155 * np.tanh((sto - 0.105) / 0.029)
+ 1.5 * exp(-120.0 * sto)
+ 0.0351 * tanh((sto - 0.286) / 0.083)
- 0.0045 * tanh((sto - 0.849) / 0.119)
- 0.035 * tanh((sto - 0.9233) / 0.05)
- 0.0147 * tanh((sto - 0.5) / 0.034)
- 0.102 * tanh((sto - 0.194) / 0.142)
- 0.022 * tanh((sto - 0.9) / 0.0164)
- 0.011 * tanh((sto - 0.124) / 0.0226)
+ 0.0155 * tanh((sto - 0.105) / 0.029)
)

return u_eq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def lico2_diffusivity_Dualfoil1998(sto, T, T_inf, E_D_s, R_g):
Expand Down Expand Up @@ -30,7 +30,7 @@ def lico2_diffusivity_Dualfoil1998(sto, T, T_inf, E_D_s, R_g):
"""

D_ref = 1 * 10 ** (-13)
arrhenius = np.exp(E_D_s / R_g * (1 / T_inf - 1 / T))
arrhenius = exp(E_D_s / R_g * (1 / T_inf - 1 / T))

# Removing the fudge factor 0 * sto requires different handling of either
# either simplifications or how sto is passed into this function.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def lico2_electrolyte_reaction_rate_Dualfoil1998(T, T_inf, E_r, R_g):
Expand Down Expand Up @@ -26,6 +26,6 @@ def lico2_electrolyte_reaction_rate_Dualfoil1998(T, T_inf, E_r, R_g):
Reaction rate
"""
m_ref = 6 * 10 ** (-7)
arrhenius = np.exp(E_r / R_g * (1 / T_inf - 1 / T))
arrhenius = exp(E_r / R_g * (1 / T_inf - 1 / T))

return m_ref * arrhenius
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import cosh


def lico2_entropic_change_Moura2016(sto, c_p_max):
Expand All @@ -24,12 +24,12 @@ def lico2_entropic_change_Moura2016(sto, c_p_max):
sto = stretch * sto

du_dT = (
0.07645 * (-54.4806 / c_p_max) * ((1.0 / np.cosh(30.834 - 54.4806 * sto)) ** 2)
+ 2.1581 * (-50.294 / c_p_max) * ((np.cosh(52.294 - 50.294 * sto)) ** (-2))
+ 0.14169 * (19.854 / c_p_max) * ((np.cosh(11.0923 - 19.8543 * sto)) ** (-2))
- 0.2051 * (5.4888 / c_p_max) * ((np.cosh(1.4684 - 5.4888 * sto)) ** (-2))
- (0.2531 / 0.1316 / c_p_max) * ((np.cosh((-sto + 0.56478) / 0.1316)) ** (-2))
- (0.02167 / 0.006 / c_p_max) * ((np.cosh((sto - 0.525) / 0.006)) ** (-2))
0.07645 * (-54.4806 / c_p_max) * ((1.0 / cosh(30.834 - 54.4806 * sto)) ** 2)
+ 2.1581 * (-50.294 / c_p_max) * ((cosh(52.294 - 50.294 * sto)) ** (-2))
+ 0.14169 * (19.854 / c_p_max) * ((cosh(11.0923 - 19.8543 * sto)) ** (-2))
- 0.2051 * (5.4888 / c_p_max) * ((cosh(1.4684 - 5.4888 * sto)) ** (-2))
- (0.2531 / 0.1316 / c_p_max) * ((cosh((-sto + 0.56478) / 0.1316)) ** (-2))
- (0.02167 / 0.006 / c_p_max) * ((cosh((sto - 0.525) / 0.006)) ** (-2))
)

return du_dT
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import tanh


def lico2_ocp_Dualfoil1998(sto):
Expand Down Expand Up @@ -28,12 +28,12 @@ def lico2_ocp_Dualfoil1998(sto):

u_eq = (
2.16216
+ 0.07645 * np.tanh(30.834 - 54.4806 * sto)
+ 2.1581 * np.tanh(52.294 - 50.294 * sto)
- 0.14169 * np.tanh(11.0923 - 19.8543 * sto)
+ 0.2051 * np.tanh(1.4684 - 5.4888 * sto)
+ 0.2531 * np.tanh((-sto + 0.56478) / 0.1316)
- 0.02167 * np.tanh((sto - 0.525) / 0.006)
+ 0.07645 * tanh(30.834 - 54.4806 * sto)
+ 2.1581 * tanh(52.294 - 50.294 * sto)
- 0.14169 * tanh(11.0923 - 19.8543 * sto)
+ 0.2051 * tanh(1.4684 - 5.4888 * sto)
+ 0.2531 * tanh((-sto + 0.56478) / 0.1316)
- 0.02167 * tanh((sto - 0.525) / 0.006)
)

return u_eq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def electrolyte_conductivity_Capiglia1999(c_e, T, T_inf, E_k_e, R_g):
Expand Down Expand Up @@ -38,6 +38,6 @@ def electrolyte_conductivity_Capiglia1999(c_e, T, T_inf, E_k_e, R_g):
+ 0.1554 * (c_e / 1000) ** 3
)

arrhenius = np.exp(E_k_e / R_g * (1 / T_inf - 1 / T))
arrhenius = exp(E_k_e / R_g * (1 / T_inf - 1 / T))

return sigma_e * arrhenius
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import autograd.numpy as np
from pybamm import exp


def electrolyte_diffusivity_Capiglia1999(c_e, T, T_inf, E_D_e, R_g):
Expand Down Expand Up @@ -32,7 +32,7 @@ def electrolyte_diffusivity_Capiglia1999(c_e, T, T_inf, E_D_e, R_g):
Solid diffusivity
"""

D_c_e = 5.34e-10 * np.exp(-0.65 * c_e / 1000)
arrhenius = np.exp(E_D_e / R_g * (1 / T_inf - 1 / T))
D_c_e = 5.34e-10 * exp(-0.65 * c_e / 1000)
arrhenius = exp(E_D_e / R_g * (1 / T_inf - 1 / T))

return D_c_e * arrhenius
32 changes: 1 addition & 31 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,37 +94,7 @@ def version(formatted=False):
)
from .expression_tree.array import Array
from .expression_tree.matrix import Matrix
from .expression_tree.unary_operators import (
UnaryOperator,
Negate,
AbsoluteValue,
Index,
SpatialOperator,
Gradient,
Divergence,
Laplacian,
Gradient_Squared,
Mass,
BoundaryMass,
BoundaryOperator,
BoundaryValue,
BoundaryGradient,
Integral,
IndefiniteIntegral,
DefiniteIntegralVector,
BoundaryIntegral,
DeltaFunction,
grad,
div,
laplacian,
grad_squared,
surf,
x_average,
z_average,
yz_average,
boundary_value,
r_average,
)
from .expression_tree.unary_operators import *
from .expression_tree.functions import *
from .expression_tree.interpolant import Interpolant
from .expression_tree.parameter import Parameter, FunctionParameter
Expand Down
2 changes: 1 addition & 1 deletion pybamm/expression_tree/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
import pybamm

import autograd.numpy as np
import numpy as np
import numbers
from scipy.sparse import issparse, csr_matrix, kron

Expand Down
Loading

0 comments on commit ec08db7

Please sign in to comment.