8 #include <catch2/catch_test_macros.hpp>
21 using namespace nmodl;
22 using namespace visitor;
24 using namespace test_utils;
35 const std::string&
text,
36 const std::vector<AstNodeType>& ret_nodetypes = {AstNodeType::SOLVE_BLOCK,
37 AstNodeType::DERIVATIVE_BLOCK}) {
38 std::vector<std::string> results;
62 results.reserve(res.size());
63 for (
const auto& r: res) {
73 SCENARIO(
"Solving ODEs with STEADYSTATE solve method",
"[visitor][steadystate]") {
74 GIVEN(
"STEADYSTATE sparse solve") {
77 SOLVE states STEADYSTATE sparse
83 std::string expected_text1 = R"(
87 std::string expected_text2 = R"(
88 DERIVATIVE states_steadystate {
92 THEN("Construct DERIVATIVE block with steadystate solution & update SOLVE statement") {
94 REQUIRE(
result.size() == 3);
95 REQUIRE(
result[0] ==
"SOLVE states_steadystate METHOD sparse");
100 GIVEN(
"STEADYSTATE derivimplicit solve") {
103 SOLVE states STEADYSTATE derivimplicit
109 std::string expected_text1 = R"(
113 std::string expected_text2 = R"(
114 DERIVATIVE states_steadystate {
118 THEN("Construct DERIVATIVE block with steadystate solution & update SOLVE statement") {
120 REQUIRE(
result.size() == 3);
121 REQUIRE(
result[0] ==
"SOLVE states_steadystate METHOD derivimplicit");
126 GIVEN(
"two STEADYSTATE solves") {
133 SOLVE states0 STEADYSTATE derivimplicit
134 SOLVE states1 STEADYSTATE sparse
138 Z'[1] = Z[0] + 2*Z[2]
139 Z'[2] = Z[0]*Z[0] - 3.10
145 std::string expected_text1 = R"(
149 Z'[2] = Z[0]*Z[0]-3.10
151 std::string expected_text2 = R"(
155 std::string expected_text3 = R"(
156 DERIVATIVE states0_steadystate {
160 Z'[2] = Z[0]*Z[0]-3.10
162 std::string expected_text4 = R"(
163 DERIVATIVE states1_steadystate {
167 THEN("Construct DERIVATIVE blocks with steadystate solution & update SOLVE statements") {
169 REQUIRE(
result.size() == 6);
170 REQUIRE(
result[0] ==
"SOLVE states0_steadystate METHOD derivimplicit");
171 REQUIRE(
result[1] ==
"SOLVE states1_steadystate METHOD sparse");
Visitor for checking parents of ast nodes
Class that binds all pieces together for parsing nmodl file.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Perform constant folding of integer/float/double expressions.
Visitor for kinetic block statements
void visit_program(ast::Program &node) override
visit node of type ast::Program
Unroll for loop in the AST.
Visitor for STEADYSTATE solve statements
void visit_program(ast::Program &node) override
visit node of type ast::Program
Concrete visitor for constructing symbol table from AST.
void visit_program(ast::Program &node) override
visit node of type ast::Program
Visitor for checking parents of ast nodes
int check_ast(const ast::Ast &node)
A small wrapper to have a nicer call in parser.cpp.
Perform constant folding of integer/float/double expressions.
AstNodeType
Enum type for every AST node type.
bool parse_string(const std::string &input)
parser Units provided as string (used for testing)
Visitor for kinetic block statements
Unroll for loop in the AST.
std::string reindent_text(const std::string &text, int indent_level)
Reindent nmodl text for text-to-text comparison.
encapsulates code generation backend implementations
std::vector< std::shared_ptr< const ast::Ast > > collect_nodes(const ast::Ast &node, const std::vector< ast::AstNodeType > &types)
traverse node recursively and collect nodes of given types
std::string to_nmodl(const ast::Ast &node, const std::set< ast::AstNodeType > &exclude_types)
Given AST node, return the NMODL string representation.
Auto generated AST classes declaration.
std::vector< std::string > run_steadystate_visitor(const std::string &text, const std::vector< AstNodeType > &ret_nodetypes={AstNodeType::SOLVE_BLOCK, AstNodeType::DERIVATIVE_BLOCK})
SCENARIO("Solving ODEs with STEADYSTATE solve method", "[visitor][steadystate]")
Visitor for STEADYSTATE solve statements
THIS FILE IS GENERATED AT BUILD TIME AND SHALL NOT BE EDITED.
nmodl::parser::UnitDriver driver
Utility functions for visitors implementation.