diff --git a/test/usecases/nonlinear/nonlin.mod b/test/usecases/nonlinear/nonlin.mod new file mode 100644 index 000000000..ec0bed30f --- /dev/null +++ b/test/usecases/nonlinear/nonlin.mod @@ -0,0 +1,21 @@ +NEURON { + SUFFIX 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 +} diff --git a/test/usecases/nonlinear/test_nonlin.py b/test/usecases/nonlinear/test_nonlin.py new file mode 100644 index 000000000..eef75edbd --- /dev/null +++ b/test/usecases/nonlinear/test_nonlin.py @@ -0,0 +1,15 @@ +from neuron import h, gui + + +def test_nonlin(): + s = h.Section() + s.insert("nonlin") + inst = s(0.5).nonlin + + x = inst.solve() + error = inst.residual(x) + assert abs(error) < 1e-9, f"{x = }, {error = }" + + +if __name__ == "__main__": + test_nonlin()