Skip to content

Commit

Permalink
#664 codacy
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Oct 26, 2019
1 parent 933354f commit b162699
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions pybamm/expression_tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def diff(self, variable):
# if variable appears in the function,use autograd to differentiate
# function, and apply chain rule
if variable.id in [symbol.id for symbol in child.pre_order()]:
partial_derivatives[i] = self._diff(children, i) * child.diff(
variable
)
partial_derivatives[i] = self._function_diff(
children, i
) * child.diff(variable)

# remove None entries
partial_derivatives = list(filter(None, partial_derivatives))
Expand All @@ -108,8 +108,11 @@ def diff(self, variable):

return derivative

def _diff(self, children, idx):
""" See :meth:`pybamm.Symbol._diff()`. """
def _function_diff(self, children, idx):
"""
Derivative with respect to child number 'idx'.
See :meth:`pybamm.Symbol._diff()`.
"""
# Store differentiated function, needed in case we want to convert to CasADi
if self.derivative == "autograd":
return Function(
Expand Down Expand Up @@ -146,7 +149,7 @@ def _function_jac(self, children_jacs):
children = self.orphans
for i, child in enumerate(children):
if not child.evaluates_to_number():
jac_fun = self._diff(children, i) * children_jacs[i]
jac_fun = self._function_diff(children, i) * children_jacs[i]
jac_fun.domain = []
if jacobian is None:
jacobian = jac_fun
Expand Down Expand Up @@ -272,8 +275,8 @@ class Cos(SpecificFunction):
def __init__(self, child):
super().__init__(np.cos, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Symbol._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Symbol._function_diff()`. """
return -Sin(children[0])


Expand All @@ -288,8 +291,8 @@ class Cosh(SpecificFunction):
def __init__(self, child):
super().__init__(np.cosh, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Function._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Function._function_diff()`. """
return Sinh(children[0])


Expand All @@ -304,8 +307,8 @@ class Exponential(SpecificFunction):
def __init__(self, child):
super().__init__(np.exp, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Function._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Function._function_diff()`. """
return Exponential(children[0])


Expand All @@ -320,8 +323,8 @@ class Log(SpecificFunction):
def __init__(self, child):
super().__init__(np.log, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Function._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Function._function_diff()`. """
return 1 / children[0]


Expand All @@ -346,8 +349,8 @@ class Sin(SpecificFunction):
def __init__(self, child):
super().__init__(np.sin, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Function._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Function._function_diff()`. """
return Cos(children[0])


Expand All @@ -362,8 +365,8 @@ class Sinh(SpecificFunction):
def __init__(self, child):
super().__init__(np.sinh, child)

def _diff(self, children, idx):
""" See :meth:`pybamm.Function._diff()`. """
def _function_diff(self, children, idx):
""" See :meth:`pybamm.Function._function_diff()`. """
return Cosh(children[0])


Expand Down

0 comments on commit b162699

Please sign in to comment.