Finite Volume

#### Next topic

Scikit Finite Elements

# 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, preprocess_external_variables, 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
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 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`)

References

1

Richard Baltensperger and Manfred R. Trummer. “Spectral Differencing With A Twist”. Society for Industrial and Applied Mathematics, 24(5):1465–1487, 2003

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 2.

References

2

Z. J. Wang. “Spectral (Finite) Volume Method for Conservation Laws on Unstructured Grids”. Journal of Computational Physics, 178:210–251, 2002

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

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
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`

`pybamm.Symbol`