Previous topic

Binary Operators

Next topic

Concatenations

This Page

Unary Operators

class pybamm.UnaryOperator(name, child, domain=None, auxiliary_domains=None)[source]

A node in the expression tree representing a unary operator (e.g. ‘-‘, grad, div)

Derived classes will specify the particular operator

Extends: Symbol

Parameters:
  • name (str) – name of the node
  • child (Symbol) – child node
evaluate(t=None, y=None, y_dot=None, inputs=None, known_evals=None)[source]

See pybamm.Symbol.evaluate().

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

new_copy()[source]

See pybamm.Symbol.new_copy().

class pybamm.Negate(child)[source]

A node in the expression tree representing a - negation operator

Extends: UnaryOperator

class pybamm.AbsoluteValue(child)[source]

A node in the expression tree representing an abs operator

Extends: UnaryOperator

diff(variable)[source]

See pybamm.Symbol.diff().

class pybamm.Sign(child)[source]

A node in the expression tree representing a sign operator

Extends: UnaryOperator

diff(variable)[source]

See pybamm.Symbol.diff().

class pybamm.Index(child, index, name=None, check_size=True)[source]

A node in the expression tree, which stores the index that should be extracted from its child after the child has been evaluated.

Parameters:
  • child (pybamm.Symbol) – The symbol of which to take the index
  • index (int or slice) – The index (if int) or indices (if slice) to extract from the symbol
  • name (str, optional) – The name of the symbol
  • check_size (bool, optional) – Whether to check if the slice size exceeds the child size. Default is True. This should always be True when creating a new symbol so that the appropriate check is performed, but should be False for creating a new copy to avoid unnecessarily repeating the check.
evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.SpatialOperator(name, child, domain=None, auxiliary_domains=None)[source]

A node in the expression tree representing a unary spatial operator (e.g. grad, div)

Derived classes will specify the particular operator

This type of node will be replaced by the Discretisation class with a Matrix

Extends: UnaryOperator

Parameters:
  • name (str) – name of the node
  • child (Symbol) – child node
diff(variable)[source]

See pybamm.Symbol.diff().

class pybamm.Gradient(child)[source]

A node in the expression tree representing a grad operator

Extends: SpatialOperator

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

class pybamm.Divergence(child)[source]

A node in the expression tree representing a div operator

Extends: SpatialOperator

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

class pybamm.Laplacian(child)[source]

A node in the expression tree representing a laplacian operator. This is currently only implemeted in the weak form for finite element formulations.

Extends: SpatialOperator

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

class pybamm.Gradient_Squared(child)[source]

A node in the expression tree representing a the inner product of the grad operator with itself. In particular, this is useful in the finite element formualtion where we only require the (sclar valued) square of the gradient, and not the gradient itself. Extends: SpatialOperator

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

class pybamm.Mass(child)[source]

Returns the mass matrix for a given symbol, accounting for Dirchlet boundary conditions where necessary (e.g. in the finite element formualtion) Extends: SpatialOperator

class pybamm.Integral(child, integration_variable)[source]

A node in the expression tree representing an integral operator

\[I = \int_{a}^{b}\!f(u)\,du,\]

where \(a\) and \(b\) are the left-hand and right-hand boundaries of the domain respectively, and \(u\in\text{domain}\).

Parameters:
evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.IndefiniteIntegral(child, integration_variable)[source]

A node in the expression tree representing an indefinite integral operator

\[I = \int_{x_ ext{min}}^{x}\!f(u)\,du\]

where \(u\in\text{domain}\) which can represent either a spatial or temporal variable.

Parameters:
  • function (pybamm.Symbol) – The function to be integrated (will become self.children[0])
  • integration_variable (pybamm.IndependentVariable) – The variable over which to integrate
  • **Extends (** BaseIndefiniteIntegral) –
class pybamm.DefiniteIntegralVector(child, vector_type='row')[source]

A node in the expression tree representing an integral of the basis used for discretisation

\[I = \int_{a}^{b}\!\psi(x)\,dx,\]

where \(a\) and \(b\) are the left-hand and right-hand boundaries of the domain respectively and \(\psi\) is the basis function.

Parameters:
  • variable (pybamm.Symbol) – The variable whose basis will be integrated over the entire domain
  • vector_type (str, optional) – Whether to return a row or column vector (default is row)
  • **Extends (** SpatialOperator) –
set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.BoundaryIntegral(child, region='entire')[source]

A node in the expression tree representing an integral operator over the boundary of a domain

\[I = \int_{\partial a}\!f(u)\,du,\]

where \(\partial a\) is the boundary of the domain, and \(u\in\text{domain boundary}\).

Parameters:
  • function (pybamm.Symbol) – The function to be integrated (will become self.children[0])
  • region (str, optional) – The region of the boundary over which to integrate. If region is entire (default) the integration is carried out over the entire boundary. If region is negative tab or positive tab then the integration is only carried out over the appropriate part of the boundary corresponding to the tab.
  • **Extends (** SpatialOperator) –
evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.DeltaFunction(child, side, domain)[source]

Delta function. Currently can only be implemented at the edge of a domain

Parameters:
  • child (pybamm.Symbol) – The variable that sets the strength of the delta function
  • side (str) – Which side of the domain to implement the delta function on
  • **Extends (** SpatialOperator) –
evaluate_for_shape()[source]

See pybamm.Symbol.evaluate_for_shape_using_domain()

evaluates_on_edges(dimension)[source]

See pybamm.Symbol.evaluates_on_edges().

set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.BoundaryOperator(name, child, side)[source]

A node in the expression tree which gets the boundary value of a variable.

Parameters:
  • name (str) – The name of the symbol
  • child (pybamm.Symbol) – The variable whose boundary value to take
  • side (str) – Which side to take the boundary value on (“left” or “right”)
  • **Extends (** SpatialOperator) –
set_id()[source]

See pybamm.Symbol.set_id()

class pybamm.BoundaryValue(child, side)[source]

A node in the expression tree which gets the boundary value of a variable.

Parameters:
  • child (pybamm.Symbol) – The variable whose boundary value to take
  • side (str) – Which side to take the boundary value on (“left” or “right”)
  • **Extends (** BoundaryOperator) –
class pybamm.BoundaryGradient(child, side)[source]

A node in the expression tree which gets the boundary flux of a variable.

Parameters:
  • child (pybamm.Symbol) – The variable whose boundary flux to take
  • side (str) – Which side to take the boundary flux on (“left” or “right”)
  • **Extends (** BoundaryOperator) –
pybamm.grad(expression)[source]

convenience function for creating a Gradient

Parameters:expression (Symbol) – the gradient will be performed on this sub-expression
Returns:the gradient of expression
Return type:Gradient
pybamm.div(expression)[source]

convenience function for creating a Divergence

Parameters:expression (Symbol) – the divergence will be performed on this sub-expression
Returns:the divergence of expression
Return type:Divergence
pybamm.laplacian(expression)[source]

convenience function for creating a Laplacian

Parameters:expression (Symbol) – the laplacian will be performed on this sub-expression
Returns:the laplacian of expression
Return type:Laplacian
pybamm.grad_squared(expression)[source]

convenience function for creating a Gradient_Squared

Parameters:expression (Symbol) – the inner product of the gradient with itself will be performed on this sub-expression
Returns:inner product of the gradient of expression with itself
Return type:Gradient_Squared
pybamm.surf(symbol)[source]

convenience function for creating a right BoundaryValue, usually in the spherical geometry

Parameters:symbol (pybamm.Symbol) – the surface value of this symbol will be returned
Returns:the surface value of symbol
Return type:pybamm.BoundaryValue
pybamm.x_average(symbol)[source]

convenience function for creating an average in the x-direction

Parameters:symbol (pybamm.Symbol) – The function to be averaged
Returns:the new averaged symbol
Return type:Symbol
pybamm.r_average(symbol)[source]

convenience function for creating an average in the r-direction

Parameters:symbol (pybamm.Symbol) – The function to be averaged
Returns:the new averaged symbol
Return type:Symbol
pybamm.z_average(symbol)[source]

convenience function for creating an average in the z-direction

Parameters:symbol (pybamm.Symbol) – The function to be averaged
Returns:the new averaged symbol
Return type:Symbol
pybamm.yz_average(symbol)[source]

convenience function for creating an average in the y-z-direction

Parameters:symbol (pybamm.Symbol) – The function to be averaged
Returns:the new averaged symbol
Return type:Symbol
pybamm.boundary_value(symbol, side)[source]

convenience function for creating a pybamm.BoundaryValue

Parameters:
  • symbol (pybamm.Symbol) – The symbol whose boundary value to take
  • side (str) – Which side to take the boundary value on (“left” or “right”)
Returns:

the new integrated expression tree

Return type:

BoundaryValue

pybamm.sign(symbol)[source]

Returns a Sign object.