Skip to content

Commit

Permalink
#858 add VariableDot
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Mar 6, 2020
1 parent 96c6a41 commit 5489aa3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def version(formatted=False):
ones_like,
)
from .expression_tree.scalar import Scalar
from .expression_tree.variable import Variable, ExternalVariable
from .expression_tree.variable import Variable, ExternalVariable, VariableDot
from .expression_tree.independent_variable import (
IndependentVariable,
Time,
Expand Down
32 changes: 31 additions & 1 deletion pybamm/expression_tree/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,38 @@ def _evaluate_for_shape(self):
)


class VariableDot(Variable):
"""
A node in the expression tree represending the time derviative of a dependent
variable
This node will be discretised by :class:`.Discretisation` and converted
to a :class:`pybamm.StateVectorDot` node.
Parameters
----------
name : str
name of the node
domain : iterable of str
list of domains that this variable is valid over
auxiliary_domains : dict
dictionary of auxiliary domains ({'secondary': ..., 'tertiary': ...}). For
example, for the single particle model, the particle concentration would be a
Variable with domain 'negative particle' and secondary auxiliary domain 'current
collector'. For the DFN, the particle concentration would be a Variable with
domain 'negative particle', secondary domain 'negative electrode' and tertiary
domain 'current collector'
*Extends:* :class:`Symbol`
"""

def __init__(self, name, domain=None, auxiliary_domains=None):
super().__init__(name, domain=domain, auxiliary_domains=auxiliary_domains)


class ExternalVariable(Variable):
"""A node in the expression tree represending an external variable variable
"""A node in the expression tree representing an external variable variable
This node will be discretised by :class:`.Discretisation` and converted
to a :class:`.Vector` node.
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_expression_tree/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ def test_variable_id(self):
self.assertNotEqual(a1.id, a3.id)
self.assertNotEqual(a1.id, a4.id)

class TestVariableDot(unittest.TestCase):
def test_variable_init(self):
a = pybamm.VariableDot("a'")
self.assertEqual(a.name, "a'")
self.assertEqual(a.domain, [])
a = pybamm.VariableDot("a", domain=["test"])
self.assertEqual(a.domain[0], "test")
self.assertRaises(TypeError, pybamm.Variable("a", domain="test"))

def test_variable_id(self):
a1 = pybamm.VariableDot("a", domain=["negative electrode"])
a2 = pybamm.VariableDot("a", domain=["negative electrode"])
self.assertEqual(a1.id, a2.id)
a3 = pybamm.VariableDot("b", domain=["negative electrode"])
a4 = pybamm.VariableDot("a", domain=["positive electrode"])
self.assertNotEqual(a1.id, a3.id)
self.assertNotEqual(a1.id, a4.id)


class TestExternalVariable(unittest.TestCase):
def test_external_variable_scalar(self):
Expand Down

0 comments on commit 5489aa3

Please sign in to comment.