Previous topic

Base Models

Next topic

Base Battery Model

This Page

Base Model

class pybamm.BaseModel(name='Unnamed model')[source]

Base model class for other models to extend.

name

A string giving the name of the model

Type:str
options

A dictionary of options to be passed to the model

Type:dict
rhs

A dictionary that maps expressions (variables) to expressions that represent the rhs

Type:dict
algebraic

A dictionary that maps expressions (variables) to expressions that represent the algebraic equations. The algebraic expressions are assumed to equate to zero. Note that all the variables in the model must exist in the keys of rhs or algebraic.

Type:dict
initial_conditions

A dictionary that maps expressions (variables) to expressions that represent the initial conditions for the state variables y. The initial conditions for algebraic variables are provided as initial guesses to a root finding algorithm that calculates consistent initial conditions.

Type:dict
boundary_conditions

A dictionary that maps expressions (variables) to expressions that represent the boundary conditions

Type:dict
variables

A dictionary that maps strings to expressions that represent the useful variables

Type:dict
events

A list of events. Each event can either cause the solver to terminate (e.g. concentration goes negative), or be used to inform the solver of the existance of a discontinuity (e.g. discontinuity in the input current)

Type:list of pybamm.Event
concatenated_rhs

After discretisation, contains the expressions representing the rhs equations concatenated into a single expression

Type:pybamm.Concatenation
concatenated_algebraic

After discretisation, contains the expressions representing the algebraic equations concatenated into a single expression

Type:pybamm.Concatenation
concatenated_initial_conditions

After discretisation, contains the vector of initial conditions

Type:numpy.array
mass_matrix

After discretisation, contains the mass matrix for the model. This is computed automatically

Type:pybamm.Matrix
mass_matrix_inv

After discretisation, contains the inverse mass matrix for the differential (rhs) part of model. This is computed automatically

Type:pybamm.Matrix
jacobian

Contains the Jacobian for the model. If model.use_jacobian is True, the Jacobian is computed automatically during solver set up

Type:pybamm.Concatenation
jacobian_rhs

Contains the Jacobian for the part of the model which contains time derivatives. If model.use_jacobian is True, the Jacobian is computed automatically during solver set up

Type:pybamm.Concatenation
jacobian_algebraic

Contains the Jacobian for the algebraic part of the model. This may be used by the solver when calculating consistent initial conditions. If model.use_jacobian is True, the Jacobian is computed automatically during solver set up

Type:pybamm.Concatenation
use_jacobian

Whether to use the Jacobian when solving the model (default is True)

Type:bool
convert_to_format

Whether to convert the expression trees representing the rhs and algebraic equations, Jacobain (if using) and events into a different format:

  • None: keep PyBaMM expression tree structure.
  • “python”: convert into pure python code that will calculate the result of calling evaluate(t, y) on the given expression treeself.
  • “casadi”: convert into CasADi expression tree, which then uses CasADi’s algorithm to calculate the Jacobian.

Default is “casadi”.

Type:str
check_algebraic_equations(post_discretisation)[source]

Check that the algebraic equations are well-posed. Before discretisation, each algebraic equation key must appear in the equation After discretisation, there must be at least one StateVector in each algebraic equation

check_default_variables_dictionaries()[source]

Check that the right variables are provided.

check_ics_bcs()[source]

Check that the initial and boundary conditions are well-posed.

check_no_repeated_keys()[source]

Check that no equation keys are repeated.

check_well_determined(post_discretisation)[source]

Check that the model is not under- or over-determined.

check_well_posedness(post_discretisation=False)[source]

Check that the model is well-posed by executing the following tests: - Model is not over- or underdetermined, by comparing keys and equations in rhs and algebraic. Overdetermined if more equations than variables, underdetermined if more variables than equations. - There is an initial condition in self.initial_conditions for each variable/equation pair in self.rhs - There are appropriate boundary conditions in self.boundary_conditions for each variable/equation pair in self.rhs and self.algebraic

Parameters:post_discretisation (boolean) – A flag indicating tests to be skipped after discretisation
default_solver

Return default solver based on whether model is ODE model or DAE model.

export_casadi_objects(variable_names, input_parameter_order=None)[source]

Export the constituent parts of the model (rhs, algebraic, initial conditions, etc) as casadi objects.

Parameters:
  • variable_names (list) – Variables to be exported alongside the model structure
  • input_parameter_order (list, optional) – Order in which the input parameters should be stacked. If None, the order returned by BaseModel.input_parameters() is used
Returns:

casadi_dict – Dictionary of {str: casadi object} pairs representing the model in casadi format

Return type:

dict

generate(filename, variable_names, input_parameter_order=None, cg_options=None)[source]

Generate the model in C, using CasADi.

Parameters:
info(symbol_name)[source]

Provides helpful summary information for a symbol.

Parameters:parameter_name (str) –
input_parameters

Returns all the input parameters in the model

new_copy()[source]

Creates an identical copy of the model, using the functionality of pybamm.SymbolReplacer but without performing any replacements

new_empty_copy()[source]

Create an empty copy of the model with the same name and “parameters” (convert_to_format, etc), but empty equations and variables. This is usually then called by pybamm.ParameterValues, pybamm.Discretisation, or pybamm.SymbolReplacer.

parameters

Returns all the parameters in the model

set_initial_conditions_from(solution, inplace=True)[source]

Update initial conditions with the final states from a Solution object or from a dictionary. This assumes that, for each variable in self.initial_conditions, there is a corresponding variable in the solution with the same name and size.

Parameters:
  • solution (pybamm.Solution, or dict) – The solution to use to initialize the model
  • inplace (bool) – Whether to modify the model inplace or create a new model
timescale

Timescale of model, to be used for non-dimensionalising time when solving

update(*submodels)[source]

Update model to add new physics from submodels

Parameters:submodel (iterable of pybamm.BaseModel) – The submodels from which to create new model