State Vector

Unary Operators

# Binary Operators¶

class pybamm.BinaryOperator(name, left, right)[source]

A node in the expression tree representing a binary operator (e.g. +, *)

Derived classes will specify the particular operator

Extends: Symbol

Parameters: name (str) – name of the node left (Symbol or Number) – lhs child node (converted to Scalar if Number) right (Symbol or Number) – rhs child node (converted to Scalar if Number)
evaluate(t=None, y=None, known_evals=None)[source]
evaluate_for_shape()[source]
evaluates_on_edges()[source]
get_children_auxiliary_domains(l_aux_domains, r_aux_domains)[source]

Combine auxiliary domains from children, at all levels

get_children_domains(ldomain, rdomain)[source]

Combine domains from children in appropriate way

new_copy()[source]
class pybamm.Power(left, right)[source]

A node in the expression tree representing a ** power operator

Extends: BinaryOperator

class pybamm.Addition(left, right)[source]

A node in the expression tree representing an addition operator

Extends: BinaryOperator

class pybamm.Subtraction(left, right)[source]

A node in the expression tree representing a subtraction operator

Extends: BinaryOperator

class pybamm.Multiplication(left, right)[source]

A node in the expression tree representing a multiplication operator (Hadamard product). Overloads cases where the “*” operator would usually return a matrix multiplication (e.g. scipy.sparse.coo.coo_matrix)

Extends: BinaryOperator

class pybamm.MatrixMultiplication(left, right)[source]

A node in the expression tree representing a matrix multiplication operator

Extends: BinaryOperator

diff(variable)[source]
class pybamm.Division(left, right)[source]

A node in the expression tree representing a division operator

Extends: BinaryOperator

class pybamm.Inner(left, right)[source]

A node in the expression tree which represents the inner (or dot) product. This operator should be used to take the inner product of two mathematical vectors (as opposed to the computational vectors arrived at post-discretisation) of the form v = v_x e_x + v_y e_y + v_z e_z where v_x, v_y, v_z are scalars and e_x, e_y, e_z are x-y-z-directional unit vectors. For v and w mathematical vectors, inner product returns v_x * w_x + v_y * w_y + v_z * w_z. In addition, for some spatial discretisations mathematical vector quantities (such as i = grad(phi) ) are evaluated on a different part of the grid to mathematical scalars (e.g. for finite volume mathematical scalars are evaluated on the nodes but mathematical vectors are evaluated on cell edges). Therefore, inner also transfers the inner product of the vector onto the scalar part of the grid if required by a particular discretisation.

Extends: BinaryOperator

evaluates_on_edges()[source]
class pybamm.Outer(left, right)[source]

A node in the expression tree representing an outer product. This takes a 1D vector in the current collector domain of size (n,1) and a 1D variable of size (m,1), takes their outer product, and reshapes this into a vector of size (nm,1). It can also take in a vector in a single particle and a vector of the electrolyte domain to repeat that particle. Note: this class might be a bit dangerous, so at the moment it is very restrictive in what symbols can be passed to it

Extends: BinaryOperator

diff(variable)[source]
class pybamm.Kron(left, right)[source]

A node in the expression tree representing a (sparse) kronecker product operator

Extends: BinaryOperator

diff(variable)[source]
jac(variable)[source]
pybamm.outer(left, right)[source]

Return outer product of two symbols. If the symbols have the same domain, the outer product is just a multiplication. If they have different domains, make a copy of the left child with same domain as right child, and then take outer product.

pybamm.source(left, right, boundary=False)[source]

A convinience function for creating (part of) an expression tree representing a source term. This is necessary for spatial methods where the mass matrix is not the identity (e.g. finite element formulation with piecwise linear basis functions). The left child is the symbol representing the source term and the right child is the symbol of the equation variable (currently, the finite element formulation in PyBaMM assumes all functions are constructed using the same basis, and the matrix here is constructed accoutning for the boundary conditions of the right child). The method returns the matrix-vector product of the mass matrix (adjusted to account for any Dirichlet boundary conditions imposed the the right symbol) and the discretised left symbol.

Parameters: left (Symbol) – The left child node, which represents the expression for the source term. right (Symbol) – The right child node. This is the symbol whose boundary conditions are accounted for in the construction of the mass matrix. boundary (bool, optional) – If True, then the mass matrix should is assembled over the boundary, corresponding to a source term which only acts on the boundary of the domain. If False (default), the matrix is assembled over the entire domain, corresponding to a source term in the bulk.