Spectral Volume#

class pybamm.SpectralVolume(options=None, order=2)[source]#

A class which implements the steps specific to the Spectral Volume discretisation. It is implemented in such a way that it is very similar to FiniteVolume; that comes at the cost that it is only compatible with the SpectralVolume1DSubMesh (which is a certain subdivision of any 1D mesh, so it shouldn’t be a problem).

For broadcast and mass_matrix, we follow the default behaviour from SpatialMethod. For spatial_variable, divergence, divergence_matrix, laplacian, integral, definite_integral_matrix, indefinite_integral, indefinite_integral_matrix, indefinite_integral_matrix_nodes, indefinite_integral_matrix_edges, delta_function we follow the behaviour from FiniteVolume. This is possible since the node values are integral averages with Spectral Volume, just as with Finite Volume. delta_function assigns the integral value to a CV instead of a SV this way, but that doesn’t matter too much. Additional methods that are inherited by FiniteVolume which technically are not suitable for Spectral Volume are boundary_value_or_flux, process_binary_operators, concatenation, node_to_edge, edge_to_node and shift. While node_to_edge (as well as boundary_value_or_flux and process_binary_operators) could utilize the reconstruction approach of Spectral Volume, the inverse edge_to_node would still have to fall back to the Finite Volume behaviour. So these are simply inherited for consistency. boundary_value_or_flux might not benefit from the reconstruction approach at all, as it seems to only preprocess symbols.

Parameters:

mesh (pybamm.Mesh) – Contains all the submeshes for discretisation

Extends: pybamm.spatial_methods.finite_volume.FiniteVolume

chebyshev_collocation_points(noe, a=-1.0, b=1.0)[source]#

Calculates Chebyshev collocation points in descending order.

Parameters:
  • noe (integer) – The number of the collocation points. “number of edges”

  • a (float) – Left end of the interval on which the Chebyshev collocation points are constructed. Default is -1.

  • b (float) – Right end of the interval on which the Chebyshev collocation points are constructed. Default is 1.

Returns:

  • numpy.array

  • Chebyshev collocation points on [a,b].

chebyshev_differentiation_matrices(noe, dod)[source]#

Chebyshev differentiation matrices, from Baltensperger and Trummer[1].

Parameters:
  • noe (integer) – The number of the collocation points. “number of edges”

  • dod (integer) – The maximum order of differentiation for which a differentiation matrix shall be calculated. Note that it has to be smaller than ‘noe’. “degrees of differentiation”

Returns:

The differentiation matrices in ascending order of differentiation order. With exact arithmetic, the diff. matrix of order p would just be the pth matrix power of the diff. matrix of order 1. This method computes the higher orders in a more numerically stable way.

Return type:

list(numpy.array)

cv_boundary_reconstruction_matrix(domains)[source]#

“Broadcasts” the basic edge value reconstruction matrix to the actual shape of the discretised symbols. Note that the product of this and a discretised symbol is a vector which represents duplicate values for all inner SV edges. These are the reconstructed values from both sides.

Parameters:

domains (dict) – The domains in which to compute the gradient matrix

Returns:

The (sparse) CV reconstruction matrix for the domain

Return type:

pybamm.Matrix

cv_boundary_reconstruction_sub_matrix()[source]#

Coefficients for reconstruction of a function through averages. The resulting matrix is scale-invariant Wang[2].

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

Matrix-vector multiplication to implement the gradient operator. See pybamm.SpatialMethod.gradient()

gradient_matrix(domain, domains)[source]#

Gradient matrix for Spectral Volume in the appropriate domain. Note that it contains the averaging of the duplicate SV edge gradient values, such that the product of it and a reconstructed discretised symbol simply represents CV edge values. On its own, it only works on non-concatenated domains, since only then the boundary conditions ensure correct behaviour. More generally, it only works if gradients are a result of boundary conditions rather than continuity conditions. For example, two adjacent SVs with gradient zero in each of them but with different variable values will have zero gradient between them. This is fixed with “penalty_matrix”.

Parameters:

domains (dict) – The domains in which to compute the gradient matrix

Returns:

The (sparse) Spectral Volume gradient matrix for the domain

Return type:

pybamm.Matrix

penalty_matrix(domains)[source]#

Penalty matrix for Spectral Volume in the appropriate domain. This works the same as the “gradient_matrix” of FiniteVolume does, just between SVs and not between CVs. Think of it as a continuity penalty.

Parameters:

domains (dict) – The domains in which to compute the gradient matrix

Returns:

The (sparse) Spectral Volume penalty matrix for the domain

Return type:

pybamm.Matrix

replace_dirichlet_values(symbol, discretised_symbol, bcs)[source]#

Replace the reconstructed value at Dirichlet boundaries with the boundary condition.

Parameters:
  • symbol (pybamm.SpatialVariable) – The variable to be discretised

  • discretised_symbol (pybamm.Vector) – Contains the discretised variable

  • bcs (dict of tuples (pybamm.Scalar, str)) – Dictionary (with keys “left” and “right”) of boundary conditions. Each boundary condition consists of a value and a flag indicating its type (e.g. “Dirichlet”)

Returns:

Matrix @ discretised_symbol + bcs_vector. When evaluated, this gives the discretised_symbol, with its boundary values replaced by the Dirichlet boundary conditions.

Return type:

pybamm.Symbol

replace_neumann_values(symbol, discretised_gradient, bcs)[source]#

Replace the known values of the gradient from Neumann boundary conditions into the discretised gradient.

Parameters:
  • symbol (pybamm.SpatialVariable) – The variable to be discretised

  • discretised_gradient (pybamm.Vector) – Contains the discretised gradient of symbol

  • bcs (dict of tuples (pybamm.Scalar, str)) – Dictionary (with keys “left” and “right”) of boundary conditions. Each boundary condition consists of a value and a flag indicating its type (e.g. “Dirichlet”)

Returns:

Matrix @ discretised_gradient + bcs_vector. When evaluated, this gives the discretised_gradient, with its boundary values replaced by the Neumann boundary conditions.

Return type:

pybamm.Symbol

References