Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1785 override sympy operators exp and atan #1786

Merged
merged 3 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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