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.
mesh (pybamm.Mesh
) – Contains all the submeshes for discretisation
**Extends (“”: pybamm.FiniteVolume
) –
Calculates Chebyshev collocation points in descending order.
numpy.array
Chebyshev collocation points on [a,b].
Chebyshev differentiation matrices 1.
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”
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.
list(numpy.array
)
References
Richard Baltensperger and Manfred R. Trummer. “Spectral Differencing With A Twist”. Society for Industrial and Applied Mathematics, 24(5):1465–1487, 2003
“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.
domains (dict) – The domains in which to compute the gradient matrix
The (sparse) CV reconstruction matrix for the domain
Coefficients for reconstruction of a function through averages. The resulting matrix is scale-invariant 2.
References
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”.
domains (dict) – The domains in which to compute the gradient matrix
The (sparse) Spectral Volume gradient matrix for the domain
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.
domains (dict) – The domains in which to compute the gradient matrix
The (sparse) Spectral Volume penalty matrix for the domain
Replace the reconstructed value at Dirichlet boundaries with the boundary condition.
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”)
Matrix @ discretised_symbol + bcs_vector. When evaluated, this gives the discretised_symbol, with its boundary values replaced by the Dirichlet boundary conditions.
Replace the known values of the gradient from Neumann boundary conditions into the discretised gradient.
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”)
Matrix @ discretised_gradient + bcs_vector. When evaluated, this gives the discretised_gradient, with its boundary values replaced by the Neumann boundary conditions.