Skip to content

Commit

Permalink
Merge pull request #1786 from pybamm-team/issue-1785-exp-sympy
Browse files Browse the repository at this point in the history
#1785 override sympy operators exp and atan
  • Loading branch information
brosaplanella authored Nov 5, 2021
2 parents 1a624af + e7d1005 commit 93ead88
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Bug fixes

- Fixed `sympy` operators for `Arctan` and `Exponential` ([#1786](https://github.com/pybamm-team/PyBaMM/pull/1786))

# [v21.10](https://github.com/pybamm-team/PyBaMM/tree/v21.9) - 2021-10-31

## Features
Expand Down
8 changes: 8 additions & 0 deletions pybamm/expression_tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ def _function_diff(self, children, idx):
"""See :meth:`pybamm.Function._function_diff()`."""
return 1 / (children[0] ** 2 + 1)

def _sympy_operator(self, child):
"""Override :meth:`pybamm.Function._sympy_operator`"""
return sympy.atan(child)


def arctan(child):
"""Returns hyperbolic tan function of child."""
Expand Down Expand Up @@ -390,6 +394,10 @@ def _function_diff(self, children, idx):
"""See :meth:`pybamm.Function._function_diff()`."""
return Exponential(children[0])

def _sympy_operator(self, child):
"""Override :meth:`pybamm.Function._sympy_operator`"""
return sympy.exp(child)


def exp(child):
"""Returns exponential function of child."""
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_expression_tree/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ def test_to_equation(self):
# Test Arcsinh
self.assertEqual(pybamm.Arcsinh(a).to_equation(), sympy.asinh(a))

# Test Arctan
self.assertEqual(pybamm.Arctan(a).to_equation(), sympy.atan(a))

# Test Exponential
self.assertEqual(pybamm.Exponential(a).to_equation(), sympy.exp(a))

# Test log
self.assertEqual(pybamm.Log(54.0).to_equation(), sympy.log(54.0))

Expand Down

0 comments on commit 93ead88

Please sign in to comment.