The discretisation class, with methods to process a model and replace Spatial Operators with Matrices and Variables with StateVectors
mesh (pybamm.Mesh) – contains all submeshes to be used on each domain
spatial_methods (dict) – a dictionary of the spatial methods to be used on each domain. The keys correspond to the model domains and the values to the spatial method.
Perform some basic checks to make sure the discretised model makes sense.
Check any boundary conditions applied on “negative tab”, “positive tab” and “no tab”. For 1D current collector meshes, these conditions are converted into boundary conditions on “left” (tab at z=0) or “right” (tab at z=l_z) depending on the tab location stored in the mesh. For 2D current collector meshes, the boundary conditions can be applied on the tabs directly.
symbol (pybamm.expression_tree.symbol.Symbol
) – The symbol on which the boundary conditions are applied.
bcs (dict) – The dictionary of boundary conditions (a dict of {side: equation}).
The dictionary of boundary conditions, with the keys changed to “left” and “right” where necessary.
Check variables in variable list against rhs Be lenient with size check if the variable in model.variables is broadcasted, or a concatenation (if broadcasted, variable is a multiplication with a vector of ones)
Creates Jacobian of the discretised model. Note that the model is assumed to be of the form M*y_dot = f(t,y), where M is the (possibly singular) mass matrix. The Jacobian is df/dy.
Note: At present, calculation of the Jacobian is deferred until after simplification, since it is much faster to compute the Jacobian of the simplified model. However, in some use cases (e.g. running the same model multiple times but with different parameters) it may be more efficient to compute the Jacobian once, before simplification, so that parameters in the Jacobian can be updated (see PR #670).
model (pybamm.BaseModel
) – Discretised model. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
The expression trees corresponding to the Jacobian of the model
Creates mass matrix of the discretised model. Note that the model is assumed to be of the form M*y_dot = f(t,y), where M is the (possibly singular) mass matrix.
model (pybamm.BaseModel
) – Discretised model. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
pybamm.Matrix
– The mass matrix
pybamm.Matrix
– The inverse of the ode part of the mass matrix (required by solvers
which only accept the ODEs in explicit form)
Discretise model boundary_conditions, also converting keys to ids
model (pybamm.BaseModel
) – Model to dicretise. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
Dictionary of processed boundary conditions
Discretise a dictionary of {variable: equation}, broadcasting if necessary (can be model.rhs, model.algebraic, model.initial_conditions or model.variables).
Discretise model initial_conditions.
model (pybamm.BaseModel
) – Model to dicretise. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
Tuple of processed_initial_conditions (dict of initial conditions) and concatenated_initial_conditions (numpy array of concatenated initial conditions)
Discretise a model. Currently inplace, could be changed to return a new model.
model (pybamm.BaseModel
) – Model to dicretise. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
inplace (bool, optional) – If True, discretise the model in place. Otherwise, return a new discretised model. Default is True.
check_model (bool, optional) – If True, model checks are performed after discretisation. For large systems these checks can be slow, so can be skipped by setting this option to False. When developing, testing or debugging it is recommened to leave this option as True as it may help to identify any errors. Default is True.
model_disc – The discretised model. Note that if inplace
is True, model will
have also been discretised in place so model == model_disc. If
inplace
is False, model != model_disc
pybamm.ModelError – If an empty model is passed (model.rhs = {} and model.algebraic = {} and model.variables = {})
Discretise model equations - differential (‘rhs’) and algebraic.
model (pybamm.BaseModel
) – Model to dicretise. Must have attributes rhs, initial_conditions and
boundary_conditions (all dicts of {variable: equation})
Tuple of processed_rhs (dict of processed differential equations), processed_concatenated_rhs, processed_algebraic (dict of processed algebraic equations) and processed_concatenated_algebraic
Discretise operators in model equations. If a symbol has already been discretised, the stored value is returned.
symbol (pybamm.expression_tree.symbol.Symbol
) – Symbol to discretise
Discretised symbol
Add external variables to the list of variables to account for, being careful about concatenations