pybamm.
Symbol
(name, children=None, domain=None, auxiliary_domains=None)[source]¶Base node class for the expression tree
Parameters: 

__abs__
()[source]¶return an AbsoluteValue
object
__init__
(name, children=None, domain=None, auxiliary_domains=None)[source]¶Initialize self. See help(type(self)) for accurate signature.
__matmul__
(other)[source]¶return a MatrixMultiplication
object
__mul__
(other)[source]¶return a Multiplication
object
__rmatmul__
(other)[source]¶return a MatrixMultiplication
object
__rmul__
(other)[source]¶return a Multiplication
object
__rsub__
(other)[source]¶return a Subtraction
object
__sub__
(other)[source]¶return a Subtraction
object
children
¶returns the cached children of this node.
Note: it is assumed that children of a node are not modified after initial creation
diff
(variable)[source]¶Differentiate a symbol with respect to a variable. For any symbol that can be differentiated, return 1 if differentiating with respect to yourself, self._diff(variable) if variable is in the expression tree of the symbol, and zero otherwise.
Parameters:  variable (pybamm.Symbol ) – The variable with respect to which to differentiate 

domain
¶list of applicable domains
Returns:  

Return type:  iterable of str 
evaluate
(t=None, y=None, known_evals=None)[source]¶Evaluate expression tree (wrapper to allow using dict of known values).
If the dict ‘known_evals’ is provided, the dict is searched for self.id; if
self.id is in the keys, return that value; otherwise, evaluate using
_base_evaluate()
and add that value to known_evals
Parameters:  

Returns: 

evaluate_for_shape
()[source]¶Evaluate expression tree to find its shape. For symbols that cannot be
evaluated directly (e.g. Variable or Parameter), a vector of the appropriate
shape is returned instead, using the symbol’s domain.
See pybamm.Symbol.evaluate()
evaluate_ignoring_errors
()[source]¶Evaluates the expression. If a node exists in the tree that cannot be evaluated as a scalar or vectr (e.g. Parameter, Variable, StateVector), then None is returned. Otherwise the result of the evaluation is given
See also
evaluate()
evaluates_on_edges
()[source]¶Returns True if a symbol evaluates on an edge, i.e. symbol contains a gradient operator, but not a divergence operator, and is not an IndefiniteIntegral.
evaluates_to_number
()[source]¶Returns True if evaluating the expression returns a number. Returns False otherwise, including if NotImplementedError or TyperError is raised. !Not to be confused with isinstance(self, pybamm.Scalar)!
See also
evaluate()
has_symbol_of_classes
(symbol_classes)[source]¶Returns True if equation has a term of the class(es) symbol_class.
Parameters:  symbol_classes (pybamm class or iterable of classes) – The classes to test the symbol against 

is_constant
()[source]¶returns true if evaluating the expression is not dependent on t or y
See also
evaluate()
jac
(variable)[source]¶Differentiate a symbol with respect to a (slice of) a State Vector. Default behaviour is to return 1 if differentiating with respect to yourself and zero otherwise. Binary and Unary Operators override this.
Parameters:  variable (pybamm.Symbol ) – The variable with respect to which to differentiate 

name
¶name of the node
new_copy
()[source]¶Make a new copy of a symbol, to avoid Tree corruption errors while bypassing copy.deepcopy(), which is slow.
orphans
¶Returning new copies of the children, with parents removed to avoid corrupting the expression tree internal data
pre_order
()[source]¶returns an iterable that steps through the tree in preorder fashion
Examples
>>> import pybamm
>>> a = pybamm.Symbol('a')
>>> b = pybamm.Symbol('b')
>>> for node in (a*b).pre_order():
... print(node.name)
*
a
b
relabel_tree
(symbol, counter)[source]¶Finds all children of a symbol and assigns them a new id so that they can be visualised properly using the graphviz output
set_id
()[source]¶Set the immutable “identity” of a variable (e.g. for identifying y_slices).
This is identical to what we’d put in a __hash__ function However, implementing __hash__ requires also implementing __eq__, which would then mess with loopchecking in the anytree module.
Hashing can be slow, so we set the id when we create the node, and hence only need to hash once.
shape
¶Shape of an object, found by evaluating it with appropriate t and y.
shape_for_testing
¶Shape of an object for cases where it cannot be evaluated directly. If a symbol cannot be evaluated directly (e.g. it is a Variable or Parameter), it is instead given an arbitrary domaindependent shape.
simplify
(simplified_symbols=None)[source]¶Simplify the expression tree. See pybamm.Simplification
.
size
¶Size of an object, found by evaluating it with appropriate t and y
size_for_testing
¶Size of an object, based on shape for testing