Skip to content

Commit

Permalink
Generalize parsing and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran committed Dec 3, 2024
1 parent 8a2cd24 commit 34824f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/visitors/cvode_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ static void remove_conserve_statements(ast::StatementBlock& node) {
}
}

// remove units using state-of-the-art technology
// remove units from CVODE block so sympy can parse it properly
static void remove_units(ast::BinaryExpression& node) {
std::regex unit_pattern(R"((\d*\.?\d+)\([a-zA-Z]+\))");
// matches either an int or a float, followed by any (including zero)
// number of spaces, followed by an expression in parentheses, that only
// has letters of the alphabet
std::regex unit_pattern(R"((\d+\.?\d*|\.\d+)\s*\([a-zA-Z]+\))");
auto rhs_string = to_nmodl(node.get_rhs());
auto rhs_string_no_units = fmt::format("{} = {}",
to_nmodl(node.get_lhs()),
Expand Down
8 changes: 7 additions & 1 deletion test/usecases/cvode/derivative.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ NEURON {
SUFFIX scalar
}

UNITS {
(um) = (micron)
}

PARAMETER {
freq = 10
a = 5
Expand All @@ -14,7 +18,7 @@ PARAMETER {
k = 0.2
}

STATE {var1 var2 var3}
STATE {var1 var2 var3 var4}

INITIAL {
var1 = v1
Expand All @@ -34,4 +38,6 @@ DERIVATIVE equation {
var2' = -var2 * a
: logistic ODE
var3' = r * var3 * (1 - var3 / k)
: ODE with some units
var4' = 1(um) * var4 + a * .1(um) + r * 1.(um) + 1.0 (um)
}

0 comments on commit 34824f6

Please sign in to comment.