Skip to content

Commit

Permalink
compare DERIVATIVE blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Cornu authored and Nicolas Cornu committed Sep 27, 2022
1 parent 4e98736 commit e708238
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions test/unit/visitor/sympy_solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ SCENARIO("Solve NONLINEAR block using SympySolver Visitor", "[visitor][solver][s
}
}
SCENARIO("Solve KINETIC block using SympySolver Visitor", "[visitor][solver][sympy][kinetic]") {
GIVEN("NONLINEAR block with not inlined function should work") {
GIVEN("KINETIC block with not inlined function should work") {
std::string nmodl_text = R"(
BREAKPOINT {
SOLVE kstates METHOD sparse
Expand All @@ -2145,8 +2145,33 @@ SCENARIO("Solve KINETIC block using SympySolver Visitor", "[visitor][solver][sym
KINETIC kstates {
~ C1 <-> C2 (alfa(v), alfa(v))
})";
std::string expected_text = R"(
DERIVATIVE kstates {
EIGEN_NEWTON_SOLVE[2]{
LOCAL old_C1, old_C2
}{
old_C1 = C1
old_C2 = C2
}{
nmodl_eigen_x[0] = C1
nmodl_eigen_x[1] = C2
}{
nmodl_eigen_f[0] = -nmodl_eigen_x[0]*dt*alfa(v)-nmodl_eigen_x[0]+nmodl_eigen_x[1]*dt*alfa(v)+old_C1
nmodl_eigen_j[0] = -dt*alfa(v)-1.0
nmodl_eigen_j[2] = dt*alfa(v)
nmodl_eigen_f[1] = nmodl_eigen_x[0]*dt*alfa(v)-nmodl_eigen_x[1]*dt*alfa(v)-nmodl_eigen_x[1]+old_C2
nmodl_eigen_j[1] = dt*alfa(v)
nmodl_eigen_j[3] = -dt*alfa(v)-1.0
}{
C1 = nmodl_eigen_x[0]
C2 = nmodl_eigen_x[1]
}{
}
})";
THEN("Run Kinetic and Sympy Visitor") {
REQUIRE_NOTHROW(run_sympy_solver_visitor(nmodl_text, false, false, {}, true));
std::vector<std::string> result;
REQUIRE_NOTHROW(result = run_sympy_solver_visitor(nmodl_text, false, false, AstNodeType::DERIVATIVE_BLOCK, true));
compare_blocks(reindent_text(result[0]), reindent_text(expected_text));
}
}
}

0 comments on commit e708238

Please sign in to comment.