Scikit Finite Elements 3D#

class pybamm.ScikitFiniteElement3D(options=None)[source]#

A class which implements the steps specific to the 3D finite element method during discretisation using scikit-fem.

Parameters:

options (dict-like, optional) – A dictionary of options to be passed to the spatial method.

Extends: pybamm.spatial_methods.spatial_method.SpatialMethod

assemble_mass_form(symbol, boundary_conditions, region='interior')[source]#

Assembles the form of the 3D finite element mass matrix.

Parameters:
  • symbol (pybamm.Variable) – The variable corresponding to the equation

  • boundary_conditions (dict) – The boundary conditions of the model

  • region (str, optional) – The domain over which to assemble

Returns:

The (sparse) mass matrix

Return type:

pybamm.Matrix

bc_apply(M, boundary_dofs, zero=False)[source]#

Adjusts matrices for 3D boundary conditions.

Parameters:
  • M (scipy.sparse matrix) – Matrix to modify

  • boundary_dofs (array_like) – Boundary degrees of freedom

  • zero (bool, optional) – Whether to zero the diagonal entries

boundary_integral(child, discretised_child, region)[source]#

Implementation of the 3D boundary integral operator.

Parameters:
  • child (pybamm.Symbol) – The symbol being integrated

  • discretised_child (pybamm.Symbol) – The discretised symbol being integrated

  • region (str) – The boundary region over which to integrate

Returns:

The result of the boundary integration

Return type:

pybamm.Symbol

boundary_integral_vector(domain, region)[source]#

A vector representing an integral operator over the boundary.

Parameters:
  • domain (list) – The domain(s) of the variable in the integrand

  • region (str) – The region of the boundary over which to integrate

Returns:

The finite element boundary integral vector

Return type:

pybamm.Matrix

boundary_mass_matrix(symbol, boundary_conditions)[source]#

Calculates the mass matrix assembled over the 3D boundary.

Parameters:
  • symbol (pybamm.Variable) – The variable corresponding to the equation

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The (sparse) boundary mass matrix

Return type:

pybamm.Matrix

boundary_value_or_flux(symbol, discretised_child, bcs=None)[source]#

Returns the boundary value or flux of a variable in 3D.

Parameters:
  • symbol (pybamm.Symbol) – The boundary symbol

  • discretised_child (pybamm.Symbol) – The discretised variable

  • bcs (dict, optional) – Boundary conditions

Returns:

The boundary value or flux

Return type:

pybamm.Symbol

definite_integral_matrix(child, vector_type='row')[source]#

Matrix for definite integral vector (vector of ones). The child is used to determine the domain and size.

Parameters:
  • child (pybamm.Symbol) – The symbol whose domain/mesh determines the size.

  • vector_type (str, optional) – “row” or “column” for the shape of the resulting vector of ones.

Returns:

A matrix representing a vector of ones (either row or column).

Return type:

pybamm.Matrix

divergence(symbol, discretised_symbol, boundary_conditions)[source]#

Matrix-vector multiplication to implement the 3D divergence operator. Expects discretised_symbol to be a Concatenation of [Fx, Fy, Fz].

Parameters:
  • symbol (pybamm.Symbol) – The symbol representing the divergence operation

  • discretised_symbol (pybamm.Concatenation) – The discretised vector field as concatenation [Fx, Fy, Fz]

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The divergence of the vector field

Return type:

pybamm.Symbol

gradient(symbol, discretised_symbol, boundary_conditions)[source]#

Matrix-vector multiplication to implement the 3D gradient operator. Returns a Concatenation of [grad_x, grad_y, grad_z] or [grad_r, grad_theta, grad_z].

Parameters:
  • symbol (pybamm.Symbol) – The symbol that we will take the gradient of.

  • discretised_symbol (pybamm.Symbol) – The discretised symbol of the correct size

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The 3D gradient as concatenation of x, y, z or z, r, theta components

Return type:

pybamm.Concatenation

gradient_matrix(symbol, boundary_conditions)[source]#

Gradient matrices for finite elements in 3D.

Parameters:
  • symbol (pybamm.Symbol) – The symbol for which we want to calculate the gradient matrix

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The (sparse) finite element gradient matrices.

Return type:

tuple of pybamm.Matrix

gradient_squared(symbol, discretised_symbol, boundary_conditions)[source]#

Multiplication to implement the inner product of the gradient operator with itself in 3D.

indefinite_integral(child, discretised_child, direction)[source]#

Implementation of the indefinite integral operator in 3D.

integral(child, discretised_child, integration_dimension, integration_variable)[source]#

Vector-vector dot product to implement the 3D integral operator.

Parameters:
  • child (pybamm.Symbol) – The symbol being integrated

  • discretised_child (pybamm.Symbol) – The discretised symbol being integrated (vector of nodal values)

  • integration_dimension (str) – The dimension over which to integrate (e.g. “primary” for volume)

Returns:

The result of the integration (a scalar value).

Return type:

pybamm.Symbol

laplacian(symbol, discretised_symbol, boundary_conditions)[source]#

Matrix-vector multiplication to implement the 3D Laplacian operator. This should be called only after boundary conditions have been properly discretised by the PyBaMM discretisation process.

Parameters:
  • symbol (pybamm.Symbol) – The symbol for which we want to calculate the Laplacian

  • discretised_symbol (pybamm.Symbol) – The discretised symbol of the correct size

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The Laplacian of the symbol

Return type:

pybamm.Symbol

laplacian_boundary_load(symbol_for_laplacian, boundary_conditions_dict)[source]#

Assembles the boundary load vector for the 3D Laplacian.

Parameters:
  • symbol (pybamm.Symbol) – The symbol for which we want to calculate the boundary load

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The boundary load vector

Return type:

pybamm.Vector

mass_matrix(symbol, boundary_conditions)[source]#

Calculates the mass matrix for the 3D finite element method.

Parameters:
  • symbol (pybamm.Variable) – The variable corresponding to the equation

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The (sparse) mass matrix for the spatial method.

Return type:

pybamm.Matrix

process_binary_operators(bin_op, left, right, disc_left, disc_right)[source]#

Process binary operators, with a specific fix for Inner products involving Concatenations that may have been created without a concatenation_function.

Parameters:
Returns:

The discretised binary operator.

Return type:

pybamm.Symbol

spatial_variable(symbol)[source]#

Creates a discretised spatial variable for x, y, z, r or theta.

Parameters:

symbol (pybamm.SpatialVariable) – The spatial variable to discretise (must be ‘x’, ‘y’, ‘z’, ‘r’ or ‘theta’)

Returns:

The discretised spatial variable as a vector of nodal values

Return type:

pybamm.Vector

stiffness_matrix(symbol, boundary_conditions)[source]#

Laplacian (stiffness) matrix for finite elements in 3D.

Parameters:
  • symbol (pybamm.Symbol) – The symbol for which we want to calculate the stiffness matrix

  • boundary_conditions (dict) – The boundary conditions of the model

Returns:

The (sparse) finite element stiffness matrix

Return type:

pybamm.Matrix