Skip to content

Commit

Permalink
Eigen solvers in ARTIFICIAL_CELLS can't use voltage. (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc authored Oct 15, 2024
1 parent 367da97 commit 186e550
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/codegen/codegen_neuron_cpp_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ void CodegenNeuronCppVisitor::print_sdlists_init([[maybe_unused]] bool print_ini

CodegenCppVisitor::ParamVector CodegenNeuronCppVisitor::functor_params() {
auto params = internal_method_parameters();
params.push_back({"", "double", "", "v"});
if (!info.artificial_cell) {
params.push_back({"", "double", "", "v"});
}

return params;
}
Expand Down
21 changes: 21 additions & 0 deletions test/usecases/nonlinear/art_nonlin.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
NEURON {
ARTIFICIAL_CELL art_nonlin
}

STATE { x }

FUNCTION solve() {
: Iterative solvers need a starting guess.
x = 1.0
SOLVE eq

solve = x
}

NONLINEAR eq {
~ x*x = 4.0
}

FUNCTION residual(x) {
residual = x - 2.0
}
14 changes: 12 additions & 2 deletions test/usecases/nonlinear/test_nonlin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
from neuron import h, gui


def test_nonlin():
def check_solve(make_inst):
s = h.Section()
s.insert("nonlin")
inst = s(0.5).nonlin

inst = make_inst(s)

x = inst.solve()
error = inst.residual(x)
assert abs(error) < 1e-9, f"{x = }, {error = }"


def test_nonlin():
check_solve(lambda s: s(0.5).nonlin)


def test_art_nonlin():
check_solve(lambda s: h.art_nonlin())


if __name__ == "__main__":
test_nonlin()
test_art_nonlin()

0 comments on commit 186e550

Please sign in to comment.