User Guide
steadystate_visitor.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 /**
11  * \file
12  * \brief \copybrief nmodl::visitor::SteadystateVisitor
13  */
14 
15 #include "visitors/ast_visitor.hpp"
16 
17 namespace nmodl {
18 namespace visitor {
19 
20 /**
21  * @addtogroup visitor_classes
22  * @{
23  */
24 
25 /**
26  * \class SteadystateVisitor
27  * \brief %Visitor for STEADYSTATE solve statements
28  *
29  * For each `STEADYSTATE` solve statement, creates a clone of the corresponding
30  * DERIVATIVE block, with `_steadystate` appended to the name of the block. If
31  * the original `DERIVATIVE` block was called `X`, the new `DERIVATIVE` block will
32  * be called `X_steadystate`. Only difference in new block is that the value of `dt`
33  * is changed for the solve, to:
34  * - dt = 1e9 for sparse
35  * - dt = 1e-9 for derivimplicit
36  *
37  * where these values for `dt` in the steady state solves are taken from NEURON see
38  * https://github.com/neuronsimulator/nrn/blob/master/src/scopmath/ssimplic_thread.c
39  *
40  * Also updates the solve statement to point to the new `DERIVATIVE` block as a
41  * `METHOD solve`, not a `STEADYSTATE` one, e.g.
42  *
43  * \code{.mod}
44  * SOLVE X STEADYSTATE derivimplicit
45  * \endcode
46  *
47  * becomes
48  *
49  * \code{.mod}
50  * SOLVE X_steadystate METHOD derivimplicit
51  * \endcode
52  */
54  private:
55  /// create new steady state derivative block for given solve block
56  std::shared_ptr<ast::DerivativeBlock> create_steadystate_block(
57  const std::shared_ptr<ast::SolveBlock>& solve_block,
58  const std::vector<std::shared_ptr<ast::Ast>>& deriv_blocks);
59 
60  const double STEADYSTATE_SPARSE_DT = 1e9;
61 
62  const double STEADYSTATE_DERIVIMPLICIT_DT = 1e-9;
63 
64  public:
65  SteadystateVisitor() = default;
66 
67  void visit_program(ast::Program& node) override;
68 };
69 
70 /** @} */ // end of visitor_classes
71 
72 } // namespace visitor
73 } // namespace nmodl
nmodl::visitor::SteadystateVisitor::STEADYSTATE_DERIVIMPLICIT_DT
const double STEADYSTATE_DERIVIMPLICIT_DT
Definition: steadystate_visitor.hpp:62
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::visitor::SteadystateVisitor::create_steadystate_block
std::shared_ptr< ast::DerivativeBlock > create_steadystate_block(const std::shared_ptr< ast::SolveBlock > &solve_block, const std::vector< std::shared_ptr< ast::Ast >> &deriv_blocks)
create new steady state derivative block for given solve block
Definition: steadystate_visitor.cpp:18
nmodl::visitor::SteadystateVisitor::STEADYSTATE_SPARSE_DT
const double STEADYSTATE_SPARSE_DT
Definition: steadystate_visitor.hpp:60
nmodl::visitor::SteadystateVisitor
Visitor for STEADYSTATE solve statements
Definition: steadystate_visitor.hpp:53
nmodl::visitor::SteadystateVisitor::SteadystateVisitor
SteadystateVisitor()=default
nmodl::visitor::AstVisitor
Concrete visitor for all AST classes.
Definition: ast_visitor.hpp:37
nmodl::visitor::SteadystateVisitor::visit_program
void visit_program(ast::Program &node) override
visit node of type ast::Program
Definition: steadystate_visitor.cpp:88
nmodl::ast::Program
Represents top level AST node for whole NMODL input.
Definition: program.hpp:39
ast_visitor.hpp
Concrete visitor for all AST classes.