diff --git a/.gitignore b/.gitignore index c23dfde0164c2ce71be3a2113f47b2f96e793753..cd1f0915e298883234777e008bb6d127fa9be697 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ CMakeCache.txt cmake_install.cmake Makefile +# mechanism implementations generated my modparser +include/mechanisms diff --git a/src/fvm.hpp b/src/fvm.hpp index c6c458c738ffcc840f3b43154249b0c1f350dcd4..674c7d0e181c23997f83c1cf8a884bbdfd514081 100644 --- a/src/fvm.hpp +++ b/src/fvm.hpp @@ -88,6 +88,39 @@ class fvm_cell { return mechanisms_; } + /// return reference to list of ions + //std::map<mechanisms::ionKind, ion_type> ions_; + std::map<mechanisms::ionKind, ion_type>& ions() { + return ions_; + } + std::map<mechanisms::ionKind, ion_type> const& ions() const { + return ions_; + } + + /// return reference to sodium ion + ion_type& ion_na() { + return ions_[mechanisms::ionKind::na]; + } + ion_type const& ion_na() const { + return ions_[mechanisms::ionKind::na]; + } + + /// return reference to calcium ion + ion_type& ion_ca() { + return ions_[mechanisms::ionKind::ca]; + } + ion_type const& ion_ca() const { + return ions_[mechanisms::ionKind::ca]; + } + + /// return reference to pottasium ion + ion_type& ion_k() { + return ions_[mechanisms::ionKind::k]; + } + ion_type const& ion_k() const { + return ions_[mechanisms::ionKind::k]; + } + private: /// the linear system for implicit time stepping of cell state @@ -303,6 +336,24 @@ fvm_cell<T, I>::fvm_cell(nest::mc::cell const& cell) } } } + + // FIXME: Hard code parameters for now. + // Take defaults for reversal potential of sodium and potassium from + // the default values in Neuron. + // We don't use the other parameters for the HH model, so I leave the NaN. + // To set them I would have to go spelunking in the Neuron source. + using memory::all; + ion_ca().reversal_potential()(all) = std::numeric_limits<value_type>::quiet_NaN(); + ion_ca().internal_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); + ion_ca().external_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); + + ion_na().reversal_potential()(all) = -50.0; + ion_na().internal_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); + ion_na().external_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); + + ion_k().reversal_potential()(all) = -77.0; + ion_k().internal_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); + ion_k().external_concentration()(all) = std::numeric_limits<value_type>::quiet_NaN(); } template <typename T, typename I> @@ -348,7 +399,6 @@ void fvm_cell<T, I>::setup_matrix(T dt) } } - } // namespace fvm } // namespace mc } // namespace nest diff --git a/src/ion.hpp b/src/ion.hpp index 2f780616a530d1ce85b79fac844559b9b8014a5d..311e86003b4cfba2b4cd4ceb569fc97a346daca0 100644 --- a/src/ion.hpp +++ b/src/ion.hpp @@ -28,15 +28,17 @@ enum class ionKind {ca, na, k}; [[gnu::unused]] static std::string to_string(ionKind k) { - if(k==ionKind::na) return "sodium"; - if(k==ionKind::ca) return "calcium"; - if(k==ionKind::k) return "pottasium"; - return "unkown ion"; + switch(k) { + case ionKind::na : return "sodium"; + case ionKind::ca : return "calcium"; + case ionKind::k : return "pottasium"; + } + return "unkown"; } /// and a little helper to iterate over them [[gnu::unused]] static -std::initializer_list<ionKind> ion_kinds() +std::vector<ionKind> ion_kinds() { return {ionKind::ca, ionKind::na, ionKind::k}; } diff --git a/tests/test_run.cpp b/tests/test_run.cpp index 55c9c6fc62ac93a9006e376c8a5940fedd755ac0..55fb0d0f457ef66ac837518ea4b44add41e0fa70 100644 --- a/tests/test_run.cpp +++ b/tests/test_run.cpp @@ -9,6 +9,9 @@ TEST(run, cable) nest::mc::cell cell; + // setup global state for the mechanisms + nest::mc::mechanisms::setup_mechanism_helpers(); + cell.add_soma(6e-4); // 6um in cm // 1um radius and 4mm long, all in cm @@ -44,6 +47,17 @@ TEST(run, cable) fvcell.setup_matrix(0.02); EXPECT_EQ(fvcell.cv_areas().size(), J.size()); + // inspect ion channels + /* + std::cout << "ion na index : " << fvcell.ion_na().node_index() << "\n"; + std::cout << "ion ca index : " << fvcell.ion_ca().node_index() << "\n"; + std::cout << "ion k index : " << fvcell.ion_k().node_index() << "\n"; + + std::cout << "ion na E : " << fvcell.ion_na().reversal_potential() << "\n"; + std::cout << "ion ca E : " << fvcell.ion_ca().reversal_potential() << "\n"; + std::cout << "ion k E : " << fvcell.ion_k().reversal_potential() << "\n"; + */ + //auto& cable_parms = cell.segment(1)->mechanism("membrane"); //std::cout << soma_hh << std::endl; //std::cout << cable_parms << std::endl; @@ -65,6 +79,9 @@ TEST(run, init) nest::mc::cell cell; + // setup global state for the mechanisms + nest::mc::mechanisms::setup_mechanism_helpers(); + cell.add_soma(12.6157/2.0); //auto& props = cell.soma()->properties;