From 3e19099c6fdaa920b6ac877e477aaf3f73e25078 Mon Sep 17 00:00:00 2001 From: Sam Yates <halfflat@gmail.com> Date: Fri, 1 Jul 2016 17:06:28 +0200 Subject: [PATCH] Unit tests for probe functionality * Also exposes current values from fvm_cell by segment location. --- src/fvm_cell.hpp | 9 +++++ tests/CMakeLists.txt | 1 + tests/test_probe.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 tests/test_probe.cpp diff --git a/src/fvm_cell.hpp b/src/fvm_cell.hpp index 90e7f7be..932c0a48 100644 --- a/src/fvm_cell.hpp +++ b/src/fvm_cell.hpp @@ -133,6 +133,9 @@ public: /// returns voltage at a segment location value_type voltage(segment_location loc) const; + /// returns current at a segment location + value_type current(segment_location loc) const; + value_type time() const { return t_; } value_type probe(uint32_t i) const { @@ -484,6 +487,12 @@ T fvm_cell<T, I>::voltage(segment_location loc) const return voltage_[compartment_index(loc)]; } +template <typename T, typename I> +T fvm_cell<T, I>::current(segment_location loc) const +{ + return current_[compartment_index(loc)]; +} + template <typename T, typename I> void fvm_cell<T, I>::initialize() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ebebb306..9061fb8d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,6 +24,7 @@ set(TEST_SOURCES test_optional.cpp test_parameters.cpp test_point.cpp + test_probe.cpp test_segment.cpp test_spikes.cpp test_stimulus.cpp diff --git a/tests/test_probe.cpp b/tests/test_probe.cpp new file mode 100644 index 00000000..52ac4e7f --- /dev/null +++ b/tests/test_probe.cpp @@ -0,0 +1,78 @@ +#include "gtest.h" + +#include "cell.hpp" +#include "fvm_cell.hpp" + +TEST(probe, instantiation) +{ + using namespace nest::mc; + + cell c1; + + segment_location loc1{0, 0}; + segment_location loc2{1, 0.6}; + + auto p1 = c1.add_probe(loc1, probeKind::membrane_voltage); + auto p2 = c1.add_probe(loc2, probeKind::membrane_current); + + // expect locally provided probe ids to be numbered sequentially from zero. + + EXPECT_EQ(0, p1); + EXPECT_EQ(1, p2); + + // expect the probes() return to be a collection with these two probes. + + auto probes = c1.probes(); + EXPECT_EQ(2u, probes.size()); + + EXPECT_EQ(loc1, probes[0].location); + EXPECT_EQ(probeKind::membrane_voltage, probes[0].kind); + + EXPECT_EQ(loc2, probes[1].location); + EXPECT_EQ(probeKind::membrane_current, probes[1].kind); +} + +TEST(probe, fvm_cell) +{ + using namespace nest::mc; + + cell bs; + + // ball-and-stick model morphology + + bs.add_soma(12.6157/2.0); + bs.add_cable(0, segmentKind::dendrite, 0.5, 0.5, 200); + bs.soma()->set_compartments(5); + + segment_location loc0{0, 0}; + segment_location loc1{1, 1}; + segment_location loc2{1, 0.5}; + + auto pv0 = bs.add_probe(loc0, probeKind::membrane_voltage); + auto pv1 = bs.add_probe(loc1, probeKind::membrane_voltage); + auto pi2 = bs.add_probe(loc2, probeKind::membrane_current); + + i_clamp stim(0, 100, 0.3); + bs.add_stimulus({1, 1}, stim); + + fvm::fvm_cell<double, int> lcell(bs); + lcell.setup_matrix(0.01); + lcell.initialize(); + + EXPECT_EQ(3u, lcell.num_probes()); + + // expect probe values and direct queries of voltage and current + // to be equal in fvm cell + + EXPECT_EQ(lcell.voltage(loc0), lcell.probe(pv0)); + EXPECT_EQ(lcell.voltage(loc1), lcell.probe(pv1)); + EXPECT_EQ(lcell.current(loc2), lcell.probe(pi2)); + + lcell.advance(0.05); + + EXPECT_EQ(lcell.voltage(loc0), lcell.probe(pv0)); + EXPECT_EQ(lcell.voltage(loc1), lcell.probe(pv1)); + EXPECT_EQ(lcell.current(loc2), lcell.probe(pi2)); +} + + -- GitLab