Unary Operators#

class pybamm.UnaryOperator(name: str, child: Symbol, domains: dict[str, list[str] | str] | None = None)[source]#

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

Derived classes will specify the particular operator

Parameters:
  • name (str) – name of the node

  • child (Symbol) – child node

  • domains (dict) – A dictionary equivalent to {‘primary’: domain, auxiliary_domains}.

Extends: pybamm.expression_tree.symbol.Symbol

create_copy(new_children: list[Symbol] | None = None, perform_simplifications: bool = True)[source]#

See pybamm.Symbol.new_copy().

evaluate(t: float | None = None, y: ndarray | None = None, y_dot: ndarray | None = None, inputs: dict | str | None = None)[source]#

See pybamm.Symbol.evaluate().

is_constant()[source]#

See pybamm.Symbol.is_constant().

to_equation()[source]#

Convert the node and its subtree into a SymPy equation.

class pybamm.Negate(child)[source]#

A node in the expression tree representing a - negation operator.

Extends: pybamm.expression_tree.unary_operators.UnaryOperator

class pybamm.AbsoluteValue(child)[source]#

A node in the expression tree representing an abs operator.

Extends: pybamm.expression_tree.unary_operators.UnaryOperator

diff(variable)[source]#

See pybamm.Symbol.diff().

class pybamm.Sign(child)[source]#

A node in the expression tree representing a sign operator.

Extends: pybamm.expression_tree.unary_operators.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.

Extends: pybamm.expression_tree.unary_operators.UnaryOperator

set_id()[source]#

See pybamm.Symbol.set_id()

to_json()[source]#

Method to serialise an Index object into JSON.

class pybamm.SpatialOperator(name: str, child: Symbol, domains: dict[str, list[str] | str] | None = 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

Parameters:
  • name (str) – name of the node

  • child (Symbol) – child node

  • domains (dict) – A dictionary equivalent to {‘primary’: domain, auxiliary_domains}.

Extends: pybamm.expression_tree.unary_operators.UnaryOperator

to_json()[source]#

Method to serialise a Symbol object into JSON.

class pybamm.Gradient(child)[source]#

A node in the expression tree representing a grad operator.

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

class pybamm.Divergence(child)[source]#

A node in the expression tree representing a div operator.

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

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: pybamm.expression_tree.unary_operators.SpatialOperator

class pybamm.GradientSquared(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: pybamm.expression_tree.unary_operators.SpatialOperator

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: pybamm.expression_tree.unary_operators.SpatialOperator

class pybamm.BoundaryMass(child)[source]#

Returns the mass matrix for a given symbol assembled over the boundary of the domain, accounting for Dirchlet boundary conditions where necessary (e.g. in the finite element formualtion)

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

class pybamm.Integral(child, integration_variable: list[IndependentVariable] | IndependentVariable)[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:

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

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:

Extends: pybamm.expression_tree.unary_operators.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 (will become self.children[0])

  • vector_type (str, optional) – Whether to return a row or column vector (default is row)

Extends: pybamm.expression_tree.unary_operators.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: pybamm.expression_tree.unary_operators.SpatialOperator

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: pybamm.expression_tree.unary_operators.SpatialOperator

evaluate_for_shape()[source]#

See pybamm.Symbol.evaluate_for_shape_using_domain()

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 on its primary domain.

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: pybamm.expression_tree.unary_operators.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 on its primary domain.

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: pybamm.expression_tree.unary_operators.BoundaryOperator

class pybamm.BoundaryGradient(child, side)[source]#

A node in the expression tree which gets the boundary flux of a variable on its primary domain.

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: pybamm.expression_tree.unary_operators.BoundaryOperator

class pybamm.EvaluateAt(child, position)[source]#

A node in the expression tree which evaluates a symbol at a given position in space in its primary domain. Currently this is only implemented for 1D primary domains.

Parameters:
  • child (pybamm.Symbol) – The variable to evaluate

  • position (pybamm.Symbol) – The position in space on the symbol’s primary domain at which to evaluate the symbol.

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

set_id()[source]#

See pybamm.Symbol.set_id()

class pybamm.UpwindDownwind(name, child)[source]#

A node in the expression tree representing an upwinding or downwinding operator. Usually to be used for better stability in convection-dominated equations.

Extends: pybamm.expression_tree.unary_operators.SpatialOperator

class pybamm.Upwind(child)[source]#

Upwinding operator. To be used if flow velocity is positive (left to right).

Extends: pybamm.expression_tree.unary_operators.UpwindDownwind

class pybamm.Downwind(child)[source]#

Downwinding operator. To be used if flow velocity is negative (right to left).

Extends: pybamm.expression_tree.unary_operators.UpwindDownwind

pybamm.grad(symbol)[source]#

convenience function for creating a Gradient

Parameters:

symbol (Symbol) – the gradient will be performed on this sub-symbol

Returns:

the gradient of symbol

Return type:

Gradient

pybamm.div(symbol)[source]#

convenience function for creating a Divergence

Parameters:

symbol (Symbol) – the divergence will be performed on this sub-symbol

Returns:

the divergence of symbol

Return type:

Divergence

pybamm.laplacian(symbol)[source]#

convenience function for creating a Laplacian

Parameters:

symbol (Symbol) – the Laplacian will be performed on this sub-symbol

Returns:

the Laplacian of symbol

Return type:

Laplacian

pybamm.grad_squared(symbol)[source]#

convenience function for creating a GradientSquared

Parameters:

symbol (Symbol) – the inner product of the gradient with itself will be performed on this sub-symbol

Returns:

inner product of the gradient of symbol with itself

Return type:

GradientSquared

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: Symbol) 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: Symbol) 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.size_average(symbol: Symbol, f_a_dist: Symbol | None = None) Symbol[source]#

Convenience function for averaging over particle size R using the area-weighted particle-size distribution.

Parameters:

symbol (pybamm.Symbol) – The function to be averaged

Returns:

the new averaged symbol

Return type:

Symbol

pybamm.z_average(symbol: Symbol) 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: Symbol) 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.smooth_absolute_value(symbol, k)[source]#

Smooth approximation to the absolute value function. k is the smoothing parameter, set by pybamm.settings.abs_smoothing. The recommended value is k=10.

pybamm.sign(symbol)[source]#

Returns a Sign object.

pybamm.upwind(symbol)[source]#

convenience function for creating a Upwind

pybamm.downwind(symbol)[source]#

convenience function for creating a Downwind