From 0bb44eebdedb84ebf1938d1da74ca103d94ea932 Mon Sep 17 00:00:00 2001 From: Luc Grosheintz Date: Thu, 10 Oct 2024 11:49:24 +0200 Subject: [PATCH] Add trivial test. --- test/usecases/nonlinear/nonlin.mod | 21 +++++++++++++++++++++ test/usecases/nonlinear/test_nonlin.py | 15 +++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/usecases/nonlinear/nonlin.mod create mode 100644 test/usecases/nonlinear/test_nonlin.py 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()