![]() |
User Guide
|
Visitor for systems of algebraic and differential equations More...
Visitor for systems of algebraic and differential equations
For DERIVATIVE block, solver method cnexp
:
(1,1)
order Pade approximant in dtFor DERIVATIVE
block, solver method euler
:
For DERIVATIVE
block, solver method sparse
and derivimplicit
:
For LINEAR
blocks:
For NON_LINEAR
blocks:
Definition at line 56 of file sympy_solver_visitor.hpp.
#include <sympy_solver_visitor.hpp>
Private Member Functions | |
void | init_block_data (ast::Node *node) |
clear any data from previous block & get set of block local vars + global vars More... | |
void | init_state_vars_vector (const ast::Node *node) |
construct vector from set of state vars in correct order More... | |
void | check_expr_statements_in_same_block () |
raise error if kinetic/ode/(non)linear statements are spread over multiple blocks More... | |
ast::StatementVector::const_iterator | get_solution_location_iterator (const ast::StatementVector &statements) |
return iterator pointing to where solution should be inserted in statement block More... | |
void | construct_eigen_solver_block (const std::vector< std::string > &pre_solve_statements, const std::vector< std::string > &solutions, bool linear) |
construct solver block More... | |
void | solve_linear_system (const ast::Node &node, const std::vector< std::string > &pre_solve_statements={}) |
solve linear system (for "LINEAR") More... | |
void | solve_non_linear_system (const ast::Node &node, const std::vector< std::string > &pre_solve_statements={}) |
solve non-linear system (for "derivimplicit", "sparse" and "NONLINEAR") More... | |
Static Private Member Functions | |
static void | replace_diffeq_expression (ast::DiffEqExpression &expr, const std::string &new_expr) |
replace binary expression with new expression provided as string More... | |
static std::string | to_nmodl_for_sympy (ast::Ast &node) |
return NMODL string version of node, excluding any units More... | |
static std::string & | replaceAll (std::string &context, const std::string &from, const std::string &to) |
Function used by SympySolverVisitor::filter_X to replace the name X in a std::string to X_operator. More... | |
static std::vector< std::string > | filter_string_vector (const std::vector< std::string > &original_vector, const std::string &original_string, const std::string &substitution_string) |
Check original_vector for elements that contain a variable named original_string and rename it to substitution_string. More... | |
Private Attributes | |
std::set< std::string > | global_vars |
global variables More... | |
std::set< std::string > | vars |
local variables in current block + globals More... | |
std::set< std::string > | function_calls |
custom function calls used in ODE block More... | |
std::unordered_map< std::string, std::string > | derivative_block_solve_method {} |
map between derivative block names and associated solver method More... | |
std::unordered_set< ast::Statement * > | expression_statements |
expression statements appearing in the block (these can be of type DiffEqExpression, LinEquation or NonLinEquation) More... | |
ast::ExpressionStatement * | current_expression_statement |
current expression statement being visited (to track ODEs / (non)lineqs) More... | |
ast::ExpressionStatement * | last_expression_statement = nullptr |
last expression statement visited (to know where to insert solutions in statement block) More... | |
ast::StatementBlock * | current_statement_block = nullptr |
current statement block being visited More... | |
ast::StatementBlock * | block_with_expression_statements = nullptr |
block where expression statements appear (to check there is only one) More... | |
std::string | solve_method |
method specified in solve block More... | |
std::vector< std::string > | eq_system |
vector of {ODE, linear eq, non-linear eq} system to solve More... | |
bool | eq_system_is_valid = true |
only solve eq_system system of equations if this is true: More... | |
bool | collect_state_vars = false |
true for (non)linear eqs, to identify all state vars used in equations More... | |
std::vector< std::string > | all_state_vars |
vector of all state variables (in order specified in STATE block in mod file) More... | |
std::set< std::string > | state_vars_in_block |
set of state variables used in block More... | |
std::vector< std::string > | state_vars |
vector of state vars used in block (in same order as all_state_vars) More... | |
std::unordered_map< std::string, std::string > | conserve_equation |
map from state vars to the algebraic equation from CONSERVE statement that should replace their ODE, if any More... | |
bool | use_pade_approx |
optionally replace cnexp solution with (1,1) pade approx More... | |
bool | elimination |
optionally do CSE (common subexpression elimination) for sparse solver More... | |
int | SMALL_LINEAR_SYSTEM_MAX_STATES |
max number of state vars allowed for small system linear solver More... | |
|
inlineexplicit |
Definition at line 168 of file sympy_solver_visitor.hpp.
|
private |
raise error if kinetic/ode/(non)linear statements are spread over multiple blocks
all ode/kinetic/(non)linear statements (typically) appear in the same statement block if this is not the case, for now return an error (and should instead use fallback solver)
Definition at line 92 of file sympy_solver_visitor.cpp.
|
private |
construct solver block
functor and initialize block converge in the same block
replace statement block with solver block as it contains all statements
create eigen newton solver block
replace statement block with solver block as it contains all statements
Definition at line 177 of file sympy_solver_visitor.cpp.
|
staticprivate |
Check original_vector for elements that contain a variable named original_string and rename it to substitution_string.
Definition at line 165 of file sympy_solver_visitor.cpp.
|
private |
return iterator pointing to where solution should be inserted in statement block
Definition at line 105 of file sympy_solver_visitor.cpp.
|
private |
clear any data from previous block & get set of block local vars + global vars
Definition at line 27 of file sympy_solver_visitor.cpp.
|
private |
construct vector from set of state vars in correct order
Definition at line 55 of file sympy_solver_visitor.cpp.
|
staticprivate |
replace binary expression with new expression provided as string
Definition at line 83 of file sympy_solver_visitor.cpp.
|
staticprivate |
Function used by SympySolverVisitor::filter_X to replace the name X in a std::string to X_operator.
Definition at line 153 of file sympy_solver_visitor.cpp.
|
private |
solve linear system (for "LINEAR")
Definition at line 310 of file sympy_solver_visitor.cpp.
|
private |
solve non-linear system (for "derivimplicit", "sparse" and "NONLINEAR")
Definition at line 361 of file sympy_solver_visitor.cpp.
|
inlinestaticprivate |
return NMODL string version of node, excluding any units
Definition at line 88 of file sympy_solver_visitor.hpp.
|
overridevirtual |
visit node of type ast::Conserve
Implements nmodl::visitor::Visitor.
Definition at line 476 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::CvodeBlock
Implements nmodl::visitor::Visitor.
Definition at line 403 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::DerivativeBlock
clear information from previous block, get global vars + block local vars
Implements nmodl::visitor::Visitor.
Definition at line 500 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::DiffEqExpression
Implements nmodl::visitor::Visitor.
Definition at line 405 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::ExpressionStatement
Implements nmodl::visitor::Visitor.
Definition at line 637 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::LinEquation
Implements nmodl::visitor::Visitor.
Definition at line 581 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::LinearBlock
clear information from previous block, get global vars + block local vars
Implements nmodl::visitor::Visitor.
Definition at line 595 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::NonLinEquation
Implements nmodl::visitor::Visitor.
Definition at line 609 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::NonLinearBlock
clear information from previous block, get global vars + block local vars
Implements nmodl::visitor::Visitor.
Definition at line 623 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::Program
Implements nmodl::visitor::Visitor.
Definition at line 651 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::StatementBlock
Implements nmodl::visitor::Visitor.
Definition at line 644 of file sympy_solver_visitor.cpp.
|
overridevirtual |
visit node of type ast::VarName
Implements nmodl::visitor::Visitor.
Definition at line 382 of file sympy_solver_visitor.cpp.
|
private |
vector of all state variables (in order specified in STATE block in mod file)
Definition at line 146 of file sympy_solver_visitor.hpp.
|
private |
block where expression statements appear (to check there is only one)
Definition at line 131 of file sympy_solver_visitor.hpp.
|
private |
true for (non)linear eqs, to identify all state vars used in equations
Definition at line 143 of file sympy_solver_visitor.hpp.
|
private |
map from state vars to the algebraic equation from CONSERVE statement that should replace their ODE, if any
Definition at line 156 of file sympy_solver_visitor.hpp.
|
private |
current expression statement being visited (to track ODEs / (non)lineqs)
Definition at line 122 of file sympy_solver_visitor.hpp.
|
private |
current statement block being visited
Definition at line 128 of file sympy_solver_visitor.hpp.
|
private |
map between derivative block names and associated solver method
Definition at line 115 of file sympy_solver_visitor.hpp.
|
private |
optionally do CSE (common subexpression elimination) for sparse solver
Definition at line 162 of file sympy_solver_visitor.hpp.
|
private |
vector of {ODE, linear eq, non-linear eq} system to solve
Definition at line 137 of file sympy_solver_visitor.hpp.
|
private |
only solve eq_system system of equations if this is true:
Definition at line 140 of file sympy_solver_visitor.hpp.
|
private |
expression statements appearing in the block (these can be of type DiffEqExpression, LinEquation or NonLinEquation)
Definition at line 119 of file sympy_solver_visitor.hpp.
|
private |
custom function calls used in ODE block
Definition at line 112 of file sympy_solver_visitor.hpp.
|
private |
global variables
Definition at line 106 of file sympy_solver_visitor.hpp.
|
private |
last expression statement visited (to know where to insert solutions in statement block)
Definition at line 125 of file sympy_solver_visitor.hpp.
|
private |
max number of state vars allowed for small system linear solver
Definition at line 165 of file sympy_solver_visitor.hpp.
|
private |
method specified in solve block
Definition at line 134 of file sympy_solver_visitor.hpp.
|
private |
vector of state vars used in block (in same order as all_state_vars)
Definition at line 152 of file sympy_solver_visitor.hpp.
|
private |
set of state variables used in block
Definition at line 149 of file sympy_solver_visitor.hpp.
|
private |
optionally replace cnexp solution with (1,1) pade approx
Definition at line 159 of file sympy_solver_visitor.hpp.
|
private |
local variables in current block + globals
Definition at line 109 of file sympy_solver_visitor.hpp.