Nektar++
|
Public Member Functions | |
def | analyse_for_jacobian |
def | find_linear_odes |
def | rearrange_linear_odes |
def | show |
Static Public Attributes | |
tuple | LINEAR_KINDS = Enum('None', 'Linear', 'Nonlinear') |
Private Member Functions | |
def | _get_rhs |
def | _check_expr |
def | _clone |
def | _make_apply |
def | _transfer_lut |
def | _rearrange_expr |
Private Attributes | |
__expr | |
Analyse linearity aspects of a model. This class performs analyses to determine which ODEs have a linear dependence on their state variable, discounting the presence of the transmembrane potential. This can be used to decouple the ODEs for more efficient solution, especially in a multi-cellular context. analyse_for_jacobian(doc) must be called before rearrange_linear_odes(doc).
Definition at line 903 of file optimize.py.
|
private |
The actual linearity checking function. Recursively determine the type of dependence expr has on state_var. The presence of any members of bad_vars indicates a non-linear dependency. Return a member of the self.LINEAR_KINDS enum.
Definition at line 959 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser._check_expr(), CellMLToNektar.optimize.LinearityAnalyser._get_rhs(), CellMLToNektar.pycml.child_i(), CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.optimize.LinearityAnalyser.LINEAR_KINDS.
Referenced by CellMLToNektar.optimize.LinearityAnalyser._check_expr(), and CellMLToNektar.optimize.LinearityAnalyser.find_linear_odes().
|
private |
Properly clone a MathML sub-expression.
Definition at line 1084 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser._make_apply().
Referenced by CellMLToNektar.optimize.LinearityAnalyser._make_apply(), and CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr().
|
private |
Return the RHS of an assignment expression.
Definition at line 953 of file optimize.py.
Referenced by CellMLToNektar.optimize.LinearityAnalyser._check_expr(), CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr(), CellMLToNektar.optimize.LinearityAnalyser.find_linear_odes(), and CellMLToNektar.optimize.LinearityAnalyser.rearrange_linear_odes().
|
private |
Construct a new apply expression for g or h. ghs is an iterable of (g,h) pairs for operands. i indicates whether to construct g (0) or h (1). filter_none indicates the behaviour of 0 under this operator. If True, it's an additive zero, otherwise it's a multiplicative zero.
Definition at line 1093 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser.__expr, and CellMLToNektar.optimize.LinearityAnalyser._clone().
Referenced by CellMLToNektar.optimize.LinearityAnalyser._clone().
|
private |
Rearrange an expression into the form g + h*var. Performs a post-order traversal of this expression's tree, and returns a pair (g, h)
Definition at line 1156 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser._clone(), CellMLToNektar.optimize.LinearityAnalyser._get_rhs(), CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr(), CellMLToNektar.optimize.LinearityAnalyser._transfer_lut(), and CellMLToNektar.pycml.child_i().
Referenced by CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr(), and CellMLToNektar.optimize.LinearityAnalyser.rearrange_linear_odes().
|
private |
Transfer lookup table annotations from expr to gh. gh is a pair (g, h) s.t. expr = g + h*var. If expr can be represented by a lookup table, then the lookup variable cannot be var, since if it were, then expr would have a non-linear dependence on var. Hence h must be 0, since otherwise expr would contain a (state) variable other than the lookup variable, and hence not be a candidate for a table. Thus expr=g, so we transfer the annotations to g.
Definition at line 1133 of file optimize.py.
Referenced by CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr().
def CellMLToNektar.optimize.LinearityAnalyser.analyse_for_jacobian | ( | self, | |
doc, | |||
V = None |
|||
) |
Analyse the model for computing a symbolic Jacobian. Determines automatically which variables will need to be solved for using Newton's method, and stores their names in doc.model._cml_nonlinear_system_variables, as a list of variable objects. Also stores doc.model._cml_linear_vars, doc.model._cml_free_var, doc.model._cml_transmembrane_potential.
Definition at line 918 of file optimize.py.
References CellMLToNektar.utilities.DEBUG(), and CellMLToNektar.optimize.LinearityAnalyser.find_linear_odes().
def CellMLToNektar.optimize.LinearityAnalyser.find_linear_odes | ( | self, | |
state_vars, | |||
V, | |||
free_var | |||
) |
Identify linear ODEs. For each ODE (except that for V), determine whether it has a linear dependence on the dependent variable, and thus can be updated directly, without using Newton's method. We also require it to not depend on any other state variable, except for V.
Definition at line 1064 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser._check_expr(), CellMLToNektar.optimize.LinearityAnalyser._get_rhs(), and CellMLToNektar.optimize.LinearityAnalyser.LINEAR_KINDS.
Referenced by CellMLToNektar.optimize.LinearityAnalyser.analyse_for_jacobian().
def CellMLToNektar.optimize.LinearityAnalyser.rearrange_linear_odes | ( | self, | |
doc | |||
) |
Rearrange the linear ODEs so they can be updated directly on solving. Each ODE du/dt = f(u, t) can be written in the form du/dt = g(t) + h(t)u. A backward Euler update step is then as simple as u_n = (u_{n-1} + g(t)dt) / (1 - h(t)dt) (assuming that the transmembrane potential has already been solved for at t_n. Stores the results in doc.model._cml_linear_update_exprs, a mapping from variable object u to pair (g, h).
Definition at line 1280 of file optimize.py.
References CellMLToNektar.optimize.LinearityAnalyser._get_rhs(), and CellMLToNektar.optimize.LinearityAnalyser._rearrange_expr().
def CellMLToNektar.optimize.LinearityAnalyser.show | ( | self, | |
d | |||
) |
Print out a more readable report on a rearrangement, as given by self.rearrange_linear_odes.
Definition at line 1310 of file optimize.py.
|
private |
Definition at line 1221 of file optimize.py.
Referenced by CellMLToNektar.optimize.LinearityAnalyser._make_apply().
|
static |
Definition at line 916 of file optimize.py.
Referenced by CellMLToNektar.optimize.LinearityAnalyser._check_expr(), and CellMLToNektar.optimize.LinearityAnalyser.find_linear_odes().