File: test_pure_diffusion.py

package info (click to toggle)
neuron 8.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,760 kB
  • sloc: cpp: 149,571; python: 58,465; ansic: 50,329; sh: 3,510; xml: 213; pascal: 51; makefile: 35; sed: 5
file content (55 lines) | stat: -rw-r--r-- 1,266 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from .testutils import compare_data, tol


def test_pure_diffusion(neuron_instance):
    """Test 1D diffusion in a single section"""

    h, rxd, data, save_path = neuron_instance
    dend = h.Section()
    dend.diam = 2
    dend.nseg = 101
    dend.L = 100

    diff_constant = 1

    r = rxd.Region([dend])
    ca = rxd.Species(
        r, d=diff_constant, initial=lambda node: 1 if 0.4 < node.x < 0.6 else 0
    )

    h.finitialize(-65)

    for t in [25, 50, 75, 100, 125]:
        h.continuerun(t)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol


def test_pure_diffusion_cvode(neuron_instance):
    """Test 1D diffusion in a single section with the variable step method."""

    h, rxd, data, save_path = neuron_instance
    dend = h.Section()
    dend.diam = 2
    dend.nseg = 101
    dend.L = 100

    diff_constant = 1

    r = rxd.Region(h.allsec())
    ca = rxd.Species(
        r, d=diff_constant, initial=lambda node: 1 if 0.4 < node.x < 0.6 else 0
    )

    # enable CVode and set atol
    h.CVode().active(1)
    h.CVode().atol(1e-6)

    h.finitialize(-65)

    for t in [25, 50, 75, 100, 125]:
        h.continuerun(t)
    if not save_path:
        max_err = compare_data(data)
        assert max_err < tol