From d28fcb8184ea9b61fc3fbc6a0e9e85da98405c3e Mon Sep 17 00:00:00 2001 From: adamjhn Date: Sat, 30 Jan 2021 09:32:48 -0500 Subject: [PATCH] Fix for a problem with anisotropic extracellular diffusion, found by @alexsavulescu. (#946) --- share/lib/python/neuron/rxd/species.py | 4 +++- test/rxd/ecs/test_ecs_pure_diffusion.py | 28 +++++++++++++++++++++++-- test/rxd/testdata | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/share/lib/python/neuron/rxd/species.py b/share/lib/python/neuron/rxd/species.py index 7136461700..0fa922279f 100644 --- a/share/lib/python/neuron/rxd/species.py +++ b/share/lib/python/neuron/rxd/species.py @@ -1225,7 +1225,9 @@ def __init__(self, regions=None, d=0, name=None, charge=0, initial=None, atolsca else: from .rxd import _domain_lookup reglist = regions if hasattr(regions,'__len__') else [regions] - dims = [_domain_lookup(sec) for reg in reglist for sec in reg.secs] + dims = [_domain_lookup(sec) for reg in reglist + if not isinstance(reg, region.Extracellular) + for sec in reg.secs] if not all([dim == dims[0] for dim in dims]): raise RxDException('Hybrid 1D/3D diffusion does not currently support anisotropy or inhomogeneous grids. For separate 1D and 3D diffusion please create separate regions and species for 3D and 1D sections') else: diff --git a/test/rxd/ecs/test_ecs_pure_diffusion.py b/test/rxd/ecs/test_ecs_pure_diffusion.py index 5640fff747..f5acb63e79 100644 --- a/test/rxd/ecs/test_ecs_pure_diffusion.py +++ b/test/rxd/ecs/test_ecs_pure_diffusion.py @@ -5,7 +5,7 @@ @pytest.fixture def ecs_diffusion(neuron_instance): h, rxd, data, save_path = neuron_instance - def make_model(nx, ny, nz, alpha, lambd): + def make_model(nx, ny, nz, alpha, lambd, d=1.0): dx = 10 # the extracellular space ecs = rxd.Extracellular( @@ -15,7 +15,7 @@ def make_model(nx, ny, nz, alpha, lambd): ) # Who? - k = rxd.Species([ecs], name='k', d=1.0, charge=1, + k = rxd.Species([ecs], name='k', d=d, charge=1, initial=lambda nd: 1 if nd.x3d**2 + nd.y3d**2 + nd.z3d**2 < (2*dx)**2 else 0) model = (ecs, k) @@ -212,3 +212,27 @@ def test_ecs_diffusion_0d_cvode_alpha(ecs_diffusion): if not save_path: assert k[ecs].states3d[0] == 1.0 + +def test_ecs_diffusion_anisotropic(ecs_diffusion): + neuron_instance, make_model = ecs_diffusion + model = make_model(11, 11, 11, 0.2, 1.6, d=(0.25,0.5,1.0)) + h, rxd, data, save_path = neuron_instance + h.CVode().active(True) + h.finitialize(1000) + h.continuerun(10) + if not save_path: + max_err = compare_data(data) + assert max_err < tol + +def test_ecs_diffusion_cvode_anisotropic(ecs_diffusion): + neuron_instance, make_model = ecs_diffusion + model = make_model(11, 11, 11, 0.2, 1.6, d=(0.25,0.5,1.0)) + h, rxd, data, save_path = neuron_instance + h.finitialize(1000) + h.continuerun(10) + if not save_path: + max_err = compare_data(data) + assert max_err < tol + + + diff --git a/test/rxd/testdata b/test/rxd/testdata index 3055cfe0fc..2b09bfefa1 160000 --- a/test/rxd/testdata +++ b/test/rxd/testdata @@ -1 +1 @@ -Subproject commit 3055cfe0fceaf2ec77d8d07ab727b720954996e1 +Subproject commit 2b09bfefa1ef0650b4837e8bc357dfe562f5c530