# Unary Operators¶

class pybamm.UnaryOperator(name, child, 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
create_copy()[source]
evaluate(t=None, y=None, y_dot=None, inputs=None)[source]
is_constant()[source]
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: UnaryOperator

class pybamm.AbsoluteValue(child)[source]

A node in the expression tree representing an abs operator.

Extends: UnaryOperator

diff(variable)[source]
class pybamm.Sign(child)[source]

A node in the expression tree representing a sign operator.

Extends: UnaryOperator

diff(variable)[source]
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.

set_id()[source]
class pybamm.SpatialOperator(name, child, 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
diff(variable)[source]

A node in the expression tree representing a grad operator.

Extends: SpatialOperator

class pybamm.Divergence(child)[source]

A node in the expression tree representing a div operator.

Extends: 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: SpatialOperator

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

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
set_id()[source]
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
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
set_id()[source]
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) –

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

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

Parameters
evaluate_for_shape()[source]

See pybamm.Symbol.evaluate_for_shape_using_domain()

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

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

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

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

Parameters

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

Parameters
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: SpatialOperator

class pybamm.Upwind(child)[source]

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

Extends: UpwindDownwind

class pybamm.Downwind(child)[source]

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

Extends: UpwindDownwind

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

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)[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.size_average(symbol, f_a_dist=None)[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)[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.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