Utilities

class pbeis.SymbolReplacer(symbol_replacement_map, processed_symbols=None, process_initial_conditions=True)

Helper class to replace all instances of one or more symbols in an expression tree with another symbol, as defined by the dictionary symbol_replacement_map

Parameters

symbol_replacement_mapdict {pybamm.Symbol -> pybamm.Symbol}

Map of which symbols should be replaced by which.

processed_symbols: dict {pybamm.Symbol -> pybamm.Symbol}, optional

cached replaced symbols

process_initial_conditions: bool, optional

Whether to process initial conditions, default is True

process_boundary_conditions(model)

Process boundary conditions for a model Boundary conditions are dictionaries {“left”: left bc, “right”: right bc} in general, but may be imposed on the tabs (or not on the tab) for a small number of variables, e.g. {“negative tab”: neg. tab bc, “positive tab”: pos. tab bc “no tab”: no tab bc}.

process_model(unprocessed_model, inplace=True)

Replace all instances of a symbol in a model.

Parameters

unprocessed_modelpybamm.BaseModel

Model to assign parameter values for

inplace: bool, optional

If True, replace the parameters in the model in place. Otherwise, return a new model with parameter values set. Default is True.

process_symbol(symbol)

This function recurses down the tree, replacing any symbols in self._symbol_replacement_map.keys() with their corresponding value

Parameters

symbolpybamm.Symbol

The symbol to replace

Returns

pybamm.Symbol

Symbol with all replacements performed