Skip to content

Commit 2865c2e

Browse files
Matexp solver: add unit test for exponential decay
1 parent ac7efe4 commit 2865c2e

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/nmodl/transpiler/unit/visitor/matexp.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,84 @@ SCENARIO("Solve a KINETIC block using the matexp method", "[visitor][matexp]") {
152152
}
153153
}
154154

155+
SCENARIO("Test exponential decay using the matexp method", "[visitor][matexp]") {
156+
GIVEN("KINETIC block, to be solved in initial and breakpoint blocks") {
157+
std::string input_nmodl = R"(
158+
INITIAL {
159+
SOLVE test_kin STEADYSTATE matexp
160+
}
161+
BREAKPOINT {
162+
SOLVE test_kin METHOD matexp
163+
}
164+
PARAMETER {
165+
a = 0.129
166+
}
167+
STATE {
168+
x
169+
}
170+
KINETIC test_kin {
171+
~ x -> (a)
172+
})";
173+
std::string expect_output = R"(
174+
VERBATIM
175+
#undef g
176+
#undef F
177+
#undef t
178+
#include <unsupported/Eigen/MatrixFunctions>
179+
ENDVERBATIM
180+
INITIAL {
181+
SOLVE test_kin_steadystate
182+
}
183+
BREAKPOINT {
184+
SOLVE test_kin_matexp
185+
}
186+
PARAMETER {
187+
a = 0.129
188+
}
189+
STATE {
190+
x
191+
}
192+
PROCEDURE test_kin_steadystate() (){
193+
VERBATIM
194+
Eigen::Matrix<double, 1, 1> nmodl_eigen_jm = Eigen::Matrix<double, 1, 1>::Zero();
195+
double* nmodl_eigen_j = nmodl_eigen_jm.data();
196+
ENDVERBATIM
197+
nmodl_eigen_j[0] = nmodl_eigen_j[0]-(a)*1000000000
198+
VERBATIM
199+
Eigen::Matrix<double, 1, 1> nmodl_eigen_xm;
200+
double* nmodl_eigen_x = nmodl_eigen_xm.data();
201+
ENDVERBATIM
202+
nmodl_eigen_x[0] = x
203+
VERBATIM
204+
Eigen::Matrix<double, 1, 1> nmodl_eigen_ym = nmodl_eigen_jm.exp() * nmodl_eigen_xm;
205+
double* nmodl_eigen_y = nmodl_eigen_ym.data();
206+
ENDVERBATIM
207+
x = nmodl_eigen_y[0]
208+
}
209+
PROCEDURE test_kin_matexp() (){
210+
VERBATIM
211+
Eigen::Matrix<double, 1, 1> nmodl_eigen_jm = Eigen::Matrix<double, 1, 1>::Zero();
212+
double* nmodl_eigen_j = nmodl_eigen_jm.data();
213+
ENDVERBATIM
214+
nmodl_eigen_j[0] = nmodl_eigen_j[0]-(a)*dt
215+
VERBATIM
216+
Eigen::Matrix<double, 1, 1> nmodl_eigen_xm;
217+
double* nmodl_eigen_x = nmodl_eigen_xm.data();
218+
ENDVERBATIM
219+
nmodl_eigen_x[0] = x
220+
VERBATIM
221+
Eigen::Matrix<double, 1, 1> nmodl_eigen_ym = nmodl_eigen_jm.exp() * nmodl_eigen_xm;
222+
double* nmodl_eigen_y = nmodl_eigen_ym.data();
223+
ENDVERBATIM
224+
x = nmodl_eigen_y[0]
225+
})";
226+
THEN("Replace the kinetic block with its solution in a procedure") {
227+
auto result = run_matexp_visitor(input_nmodl, true);
228+
REQUIRE(trim_text(expect_output) == trim_text(result));
229+
}
230+
}
231+
}
232+
155233
SCENARIO("Mix matexp and sparse solver methods", "[visitor][matexp]") {
156234
GIVEN("KINETIC block, to be solved by multiple methods") {
157235
std::string input_nmodl = R"(

0 commit comments

Comments
 (0)