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

adding atan #973

Merged
merged 9 commits into from
May 1, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Added `ProcessedSymbolicVariable` class, which can handle symbolic variables (i.e. variables for which the inputs are symbolic) ([#940](https://github.com/pybamm-team/PyBaMM/pull/940))
- Made `QuickPlot` compatible with Google Colab ([#935](https://github.com/pybamm-team/PyBaMM/pull/935))
- Added `BasicFull` model for lead-acid ([#932](https://github.com/pybamm-team/PyBaMM/pull/932))
- Added 'arctan' function ([#973]https://github.com/pybamm-team/PyBaMM/pull/973)

## Optimizations

Expand Down
18 changes: 18 additions & 0 deletions pybamm/expression_tree/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,21 @@ def _function_diff(self, children, idx):
def tanh(child):
" Returns hyperbolic tan function of child. "
return pybamm.simplify_if_constant(Tanh(child), keep_domains=True)


class Arctan(SpecificFunction):
""" Arctan function """

def __init__(self, child):
super().__init__(np.arctan, child)

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


def arctan(child):
" Returns hyperbolic tan function of child. "
return pybamm.simplify_if_constant(Arctan(child), keep_domains=True)


16 changes: 16 additions & 0 deletions tests/unit/test_expression_tree/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ def test_arcsinh(self):
places=5,
)

def test_arctan(self):
a = pybamm.InputParameter("a")
fun = pybamm.arctan(a)
self.assertIsInstance(fun, pybamm.Arctan)
self.assertEqual(fun.evaluate(inputs={"a": 3}), np.arctan(3))
h = 0.0000001
self.assertAlmostEqual(
fun.diff(a).evaluate(inputs={"a": 3}),
(
pybamm.arctan(pybamm.Scalar(3 + h)).evaluate()
- fun.evaluate(inputs={"a": 3})
)
/ h,
places=5,
)

def test_cos(self):
a = pybamm.InputParameter("a")
fun = pybamm.cos(a)
Expand Down