Skip to content

Commit

Permalink
Merge pull request #973 from gyouhoc/adding-atan
Browse files Browse the repository at this point in the history
adding atan
  • Loading branch information
valentinsulzer authored May 1, 2020
2 parents 4e888cd + 9eb70c1 commit 4742a7e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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 @@ -434,3 +434,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

0 comments on commit 4742a7e

Please sign in to comment.