Skip to content

Commit

Permalink
Fix for a problem with anisotropic extracellular diffusion, found by @…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjhn authored and nrnhines committed Feb 2, 2021
1 parent d9b44b1 commit 1279151
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 3 additions & 1 deletion share/lib/python/neuron/rxd/species.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 26 additions & 2 deletions test/rxd/ecs/test_ecs_pure_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down Expand Up @@ -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



2 changes: 1 addition & 1 deletion test/rxd/testdata

0 comments on commit 1279151

Please sign in to comment.