pybamm.
FiniteVolume
(options=None)[source]¶A class which implements the steps specific to the finite volume method during discretisation.
For broadcast and mass_matrix, we follow the default behaviour from SpatialMethod.
Parameters: |
|
---|
add_ghost_nodes
(symbol, discretised_symbol, bcs)[source]¶Add ghost nodes to a symbol.
For Dirichlet bcs, for a boundary condition “y = a at the left-hand boundary”, we concatenate a ghost node to the start of the vector y with value “2*a - y1” where y1 is the value of the first node. Similarly for the right-hand boundary condition.
For Neumann bcs no ghost nodes are added. Instead, the exact value provided
by the boundary condition is used at the cell edge when calculating the
gradient (see pybamm.FiniteVolume.add_neumann_values()
).
Parameters: |
|
---|---|
Returns: | Matrix @ discretised_symbol + bcs_vector. When evaluated, this gives the discretised_symbol, with appropriate ghost nodes concatenated at each end. |
Return type: |
add_neumann_values
(symbol, discretised_gradient, bcs, domain)[source]¶Add the known values of the gradient from Neumann boundary conditions to the discretised gradient.
Dirichlet bcs are implemented using ghost nodes, see
pybamm.FiniteVolume.add_ghost_nodes()
.
Parameters: |
|
---|---|
Returns: | Matrix @ discretised_gradient + bcs_vector. When evaluated, this gives the discretised_gradient, with the values of the Neumann boundary conditions concatenated at each end (if given). |
Return type: |
boundary_value_or_flux
(symbol, discretised_child, bcs=None)[source]¶Uses extrapolation to get the boundary value or flux of a variable in the Finite Volume Method.
See pybamm.SpatialMethod.boundary_value()
concatenation
(disc_children)[source]¶Discrete concatenation, taking edge_to_node for children that evaluate on
edges.
See pybamm.SpatialMethod.concatenation()
definite_integral_matrix
(child, vector_type='row', integration_dimension='primary')[source]¶Matrix for finite-volume implementation of the definite integral in the primary dimension
for where \(a\) and \(b\) are the left-hand and right-hand boundaries of the domain respectively
Parameters: |
|
---|---|
Returns: | The finite volume integral matrix for the domain |
Return type: |
delta_function
(symbol, discretised_symbol)[source]¶Delta function. Implemented as a vector whose only non-zero element is the first (if symbol.side = “left”) or last (if symbol.side = “right”), with appropriate value so that the integral of the delta function across the whole domain is the same as the integral of the discretised symbol across the whole domain.
divergence
(symbol, discretised_symbol, boundary_conditions)[source]¶Matrix-vector multiplication to implement the divergence operator.
See pybamm.SpatialMethod.divergence()
divergence_matrix
(domains)[source]¶Divergence matrix for finite volumes in the appropriate domain. Equivalent to div(N) = (N[1:] - N[:-1])/dx
Parameters: | domains (dict) – The domain(s) and auxiliary domain in which to compute the divergence matrix |
---|---|
Returns: | The (sparse) finite volume divergence matrix for the domain |
Return type: | pybamm.Matrix |
edge_to_node
(discretised_symbol, method='arithmetic')[source]¶Convert a discretised symbol evaluated on the cell edges to a discretised symbol
evaluated on the cell nodes.
See pybamm.FiniteVolume.shift()
gradient
(symbol, discretised_symbol, boundary_conditions)[source]¶Matrix-vector multiplication to implement the gradient operator.
See pybamm.SpatialMethod.gradient()
gradient_matrix
(domain, auxiliary_domains)[source]¶Gradient matrix for finite volumes in the appropriate domain. Equivalent to grad(y) = (y[1:] - y[:-1])/dx
Parameters: | |
---|---|
Returns: | The (sparse) finite volume gradient matrix for the domain |
Return type: |
indefinite_integral
(child, discretised_child, direction)[source]¶Implementation of the indefinite integral operator.
indefinite_integral_matrix_edges
(domains, direction)[source]¶Matrix for finite-volume implementation of the indefinite integral where the integrand is evaluated on mesh edges (shape (n+1, 1)). The integral will then be evaluated on mesh nodes (shape (n, 1)).
Parameters: | |
---|---|
Returns: | The finite volume integral matrix for the domain |
Return type: |
Notes
Forward integral
The indefinite integral must satisfy the following conditions:
or, in discrete form,
Hence we must have
Note that \(f_{-1/2}\) and \(f_{end+1/2}\) are included in the discrete integrand vector f, so we add a column of zeros at each end of the indefinite integral matrix to ignore these.
Backward integral
The indefinite integral must satisfy the following conditions:
or, in discrete form,
Hence we must have
Note that \(f_{-1/2}\) and \(f_{end+1/2}\) are included in the discrete integrand vector f, so we add a column of zeros at each end of the indefinite integral matrix to ignore these.
indefinite_integral_matrix_nodes
(domains, direction)[source]¶Matrix for finite-volume implementation of the (backward) indefinite integral where the integrand is evaluated on mesh nodes (shape (n, 1)). The integral will then be evaluated on mesh edges (shape (n+1, 1)). This is just a straightforward (backward) cumulative sum of the integrand
Parameters: | |
---|---|
Returns: | The finite volume integral matrix for the domain |
Return type: |
integral
(child, discretised_child, integration_dimension)[source]¶Vector-vector dot product to implement the integral operator.
internal_neumann_condition
(left_symbol_disc, right_symbol_disc, left_mesh, right_mesh)[source]¶A method to find the internal neumann conditions between two symbols on adjacent subdomains.
Parameters: |
|
---|
laplacian
(symbol, discretised_symbol, boundary_conditions)[source]¶Laplacian operator, implemented as div(grad(.))
See pybamm.SpatialMethod.laplacian()
node_to_edge
(discretised_symbol, method='arithmetic')[source]¶Convert a discretised symbol evaluated on the cell nodes to a discretised symbol
evaluated on the cell edges.
See pybamm.FiniteVolume.shift()
preprocess_external_variables
(var)[source]¶For finite volumes, we need the boundary fluxes for discretising properly. Here, we extrapolate and then add them to the boundary conditions.
Parameters: | var (pybamm.Variable or pybamm.Concatenation ) – The external variable that is to be processed |
---|---|
Returns: | new_bcs – A dictionary containing the new boundary conditions |
Return type: | dict |
process_binary_operators
(bin_op, left, right, disc_left, disc_right)[source]¶Discretise binary operators in model equations. Performs appropriate averaging of diffusivities if one of the children is a gradient operator, so that discretised sizes match up. For this averaging we use the harmonic mean [1].
[1] Recktenwald, Gerald. “The control-volume finite-difference approximation to the diffusion equation.” (2012).
Parameters: |
|
---|---|
Returns: | Discretised binary operator |
Return type: |
shift
(discretised_symbol, shift_key, method)[source]¶Convert a discretised symbol evaluated at edges/nodes, to a discretised symbol evaluated at nodes/edges. Can be the arithmetic mean or the harmonic mean.
Note: when computing fluxes at cell edges it is better to take the harmonic mean based on [1].
[1] Recktenwald, Gerald. “The control-volume finite-difference approximation to the diffusion equation.” (2012).
Parameters: |
|
---|---|
Returns: | Averaged symbol. When evaluated, this returns either a scalar or an array of shape (n+1,) (if shift_key = “node to edge”) or (n,) (if shift_key = “edge to node”) |
Return type: |
spatial_variable
(symbol)[source]¶Creates a discretised spatial variable compatible with the FiniteVolume method.
Parameters: | symbol (pybamm.SpatialVariable ) – The spatial variable to be discretised. |
---|---|
Returns: | Contains the discretised spatial variable |
Return type: | pybamm.Vector |