diff --git a/cnexp_array/neuron/leonhard.cpp b/cnexp_array/neuron/leonhard.cpp index 5a0c9be..dc66bc0 100644 --- a/cnexp_array/neuron/leonhard.cpp +++ b/cnexp_array/neuron/leonhard.cpp @@ -100,6 +100,14 @@ namespace neuron { }; + struct leonhard_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static leonhard_Instance make_instance_leonhard(_nrn_mechanism_cache_range& _ml) { return leonhard_Instance { _ml.template data_array_ptr<0, 3>(), @@ -113,6 +121,16 @@ namespace neuron { } + static leonhard_NodeData make_node_data_leonhard(NrnThread& _nt, Memb_list& _ml_arg) { + return leonhard_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_leonhard(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -165,6 +183,7 @@ namespace neuron { void nrn_init_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = 42.0; @@ -180,6 +199,7 @@ namespace neuron { void nrn_state_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = inst.x[id] + (1.0 - exp(_nt->_dt * ((((inst.s+id*2)[static_cast(0)] + (inst.s+id*2)[static_cast(1)]) * ((inst.z+id*3)[static_cast(0)] * (inst.z+id*3)[static_cast(1)] * (inst.z+id*3)[static_cast(2)])) * (1.0)))) * ( -(0.0) / (((((inst.s+id*2)[static_cast(0)] + (inst.s+id*2)[static_cast(1)])) * (((((inst.z+id*3)[static_cast(0)]) * ((inst.z+id*3)[static_cast(1)])) * ((inst.z+id*3)[static_cast(2)])))) * (1.0)) - inst.x[id]); diff --git a/cnexp_scalar/neuron/leonhard.cpp b/cnexp_scalar/neuron/leonhard.cpp index 15e225d..9d82dc2 100644 --- a/cnexp_scalar/neuron/leonhard.cpp +++ b/cnexp_scalar/neuron/leonhard.cpp @@ -94,6 +94,14 @@ namespace neuron { }; + struct leonhard_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static leonhard_Instance make_instance_leonhard(_nrn_mechanism_cache_range& _ml) { return leonhard_Instance { _ml.template fpfield_ptr<0>(), @@ -104,6 +112,16 @@ namespace neuron { } + static leonhard_NodeData make_node_data_leonhard(NrnThread& _nt, Memb_list& _ml_arg) { + return leonhard_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_leonhard(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -156,6 +174,7 @@ namespace neuron { void nrn_init_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = 42.0; @@ -166,6 +185,7 @@ namespace neuron { void nrn_state_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = inst.x[id] + (1.0 - exp(_nt->_dt * ( -1.0))) * ( -(0.0) / ( -1.0) - inst.x[id]); diff --git a/func_proc/neuron/func_proc.cpp b/func_proc/neuron/func_proc.cpp index 3cfe408..b15e8d0 100644 --- a/func_proc/neuron/func_proc.cpp +++ b/func_proc/neuron/func_proc.cpp @@ -90,6 +90,14 @@ namespace neuron { }; + struct test_func_proc_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static test_func_proc_Instance make_instance_test_func_proc(_nrn_mechanism_cache_range& _ml) { return test_func_proc_Instance { _ml.template fpfield_ptr<0>(), @@ -98,6 +106,16 @@ namespace neuron { } + static test_func_proc_NodeData make_node_data_test_func_proc(NrnThread& _nt, Memb_list& _ml_arg) { + return test_func_proc_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_test_func_proc(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -341,6 +359,7 @@ namespace neuron { void nrn_init_test_func_proc(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_test_func_proc(_lmr); + auto node_data = make_node_data_test_func_proc(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { } diff --git a/func_proc_pnt/neuron/func_proc_pnt.cpp b/func_proc_pnt/neuron/func_proc_pnt.cpp index 726da27..5ef3ee3 100644 --- a/func_proc_pnt/neuron/func_proc_pnt.cpp +++ b/func_proc_pnt/neuron/func_proc_pnt.cpp @@ -89,6 +89,14 @@ namespace neuron { }; + struct test_func_proc_pnt_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static test_func_proc_pnt_Instance make_instance_test_func_proc_pnt(_nrn_mechanism_cache_range& _ml) { return test_func_proc_pnt_Instance { _ml.template fpfield_ptr<0>(), @@ -98,6 +106,16 @@ namespace neuron { } + static test_func_proc_pnt_NodeData make_node_data_test_func_proc_pnt(NrnThread& _nt, Memb_list& _ml_arg) { + return test_func_proc_pnt_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_test_func_proc_pnt(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -267,6 +285,7 @@ namespace neuron { void nrn_init_test_func_proc_pnt(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_test_func_proc_pnt(_lmr); + auto node_data = make_node_data_test_func_proc_pnt(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { } diff --git a/global_breakpoint/neuron/leonhard.cpp b/global_breakpoint/neuron/leonhard.cpp index 8b0f021..6971917 100644 --- a/global_breakpoint/neuron/leonhard.cpp +++ b/global_breakpoint/neuron/leonhard.cpp @@ -94,6 +94,14 @@ namespace neuron { }; + struct leonhard_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static leonhard_Instance make_instance_leonhard(_nrn_mechanism_cache_range& _ml) { return leonhard_Instance { _ml.template fpfield_ptr<0>(), @@ -104,6 +112,16 @@ namespace neuron { } + static leonhard_NodeData make_node_data_leonhard(NrnThread& _nt, Memb_list& _ml_arg) { + return leonhard_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_leonhard(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -157,6 +175,7 @@ namespace neuron { void nrn_init_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = 42.0; @@ -167,6 +186,7 @@ namespace neuron { void nrn_state_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { inst.x[id] = inst.global->c; diff --git a/nonspecific_current/coreneuron/leonhard.cpp b/nonspecific_current/coreneuron/leonhard.cpp new file mode 100644 index 0000000..d3c8242 --- /dev/null +++ b/nonspecific_current/coreneuron/leonhard.cpp @@ -0,0 +1,316 @@ +/********************************************************* +Model Name : leonhard +Filename : leonhard.mod +NMODL Version : 7.7.0 +Vectorized : true +Threadsafe : true +Created : DATE +Simulator : CoreNEURON +Backend : C++ (api-compatibility) +NMODL Compiler : VERSION +*********************************************************/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace coreneuron { + #ifndef NRN_PRCELLSTATE + #define NRN_PRCELLSTATE 0 + #endif + + + /** channel information */ + static const char *mechanism_info[] = { + "7.7.0", + "leonhard", + 0, + "il_leonhard", + 0, + 0, + 0 + }; + + + /** all global variables */ + struct leonhard_Store { + int reset{}; + int mech_type{}; + }; + static_assert(std::is_trivially_copy_constructible_v); + static_assert(std::is_trivially_move_constructible_v); + static_assert(std::is_trivially_copy_assignable_v); + static_assert(std::is_trivially_move_assignable_v); + static_assert(std::is_trivially_destructible_v); + leonhard_Store leonhard_global; + + + /** all mechanism instance variables and global variables */ + struct leonhard_Instance { + double* il{}; + double* v_unused{}; + double* g_unused{}; + leonhard_Store* global{&leonhard_global}; + }; + + + /** connect global (scalar) variables to hoc -- */ + static DoubScal hoc_scalar_double[] = { + {nullptr, nullptr} + }; + + + /** connect global (array) variables to hoc -- */ + static DoubVec hoc_vector_double[] = { + {nullptr, nullptr, 0} + }; + + + static inline int first_pointer_var_index() { + return -1; + } + + + static inline int first_random_var_index() { + return -1; + } + + + static inline int float_variables_size() { + return 3; + } + + + static inline int int_variables_size() { + return 0; + } + + + static inline int get_mech_type() { + return leonhard_global.mech_type; + } + + + static inline Memb_list* get_memb_list(NrnThread* nt) { + if (!nt->_ml_list) { + return nullptr; + } + return nt->_ml_list[get_mech_type()]; + } + + + static inline void* mem_alloc(size_t num, size_t size, size_t alignment = 16) { + void* ptr; + posix_memalign(&ptr, alignment, num*size); + memset(ptr, 0, size); + return ptr; + } + + + static inline void mem_free(void* ptr) { + free(ptr); + } + + + static inline void coreneuron_abort() { + abort(); + } + + // Allocate instance structure + static void nrn_private_constructor_leonhard(NrnThread* nt, Memb_list* ml, int type) { + assert(!ml->instance); + assert(!ml->global_variables); + assert(ml->global_variables_size == 0); + auto* const inst = new leonhard_Instance{}; + assert(inst->global == &leonhard_global); + ml->instance = inst; + ml->global_variables = inst->global; + ml->global_variables_size = sizeof(leonhard_Store); + } + + // Deallocate the instance structure + static void nrn_private_destructor_leonhard(NrnThread* nt, Memb_list* ml, int type) { + auto* const inst = static_cast(ml->instance); + assert(inst); + assert(inst->global); + assert(inst->global == &leonhard_global); + assert(inst->global == ml->global_variables); + assert(ml->global_variables_size == sizeof(leonhard_Store)); + delete inst; + ml->instance = nullptr; + ml->global_variables = nullptr; + ml->global_variables_size = 0; + } + + /** initialize mechanism instance variables */ + static inline void setup_instance(NrnThread* nt, Memb_list* ml) { + auto* const inst = static_cast(ml->instance); + assert(inst); + assert(inst->global); + assert(inst->global == &leonhard_global); + assert(inst->global == ml->global_variables); + assert(ml->global_variables_size == sizeof(leonhard_Store)); + int pnodecount = ml->_nodecount_padded; + Datum* indexes = ml->pdata; + inst->il = ml->data+0*pnodecount; + inst->v_unused = ml->data+1*pnodecount; + inst->g_unused = ml->data+2*pnodecount; + } + + + + static void nrn_alloc_leonhard(double* data, Datum* indexes, int type) { + // do nothing + } + + + void nrn_constructor_leonhard(NrnThread* nt, Memb_list* ml, int type) { + #ifndef CORENEURON_BUILD + int nodecount = ml->nodecount; + int pnodecount = ml->_nodecount_padded; + const int* node_index = ml->nodeindices; + double* data = ml->data; + const double* voltage = nt->_actual_v; + Datum* indexes = ml->pdata; + ThreadDatum* thread = ml->_thread; + auto* const inst = static_cast(ml->instance); + + #endif + } + + + void nrn_destructor_leonhard(NrnThread* nt, Memb_list* ml, int type) { + #ifndef CORENEURON_BUILD + int nodecount = ml->nodecount; + int pnodecount = ml->_nodecount_padded; + const int* node_index = ml->nodeindices; + double* data = ml->data; + const double* voltage = nt->_actual_v; + Datum* indexes = ml->pdata; + ThreadDatum* thread = ml->_thread; + auto* const inst = static_cast(ml->instance); + + #endif + } + + + /** initialize channel */ + void nrn_init_leonhard(NrnThread* nt, Memb_list* ml, int type) { + int nodecount = ml->nodecount; + int pnodecount = ml->_nodecount_padded; + const int* node_index = ml->nodeindices; + double* data = ml->data; + const double* voltage = nt->_actual_v; + Datum* indexes = ml->pdata; + ThreadDatum* thread = ml->_thread; + + setup_instance(nt, ml); + auto* const inst = static_cast(ml->instance); + + if (_nrn_skip_initmodel == 0) { + #pragma omp simd + #pragma ivdep + for (int id = 0; id < nodecount; id++) { + int node_id = node_index[id]; + double v = voltage[node_id]; + #if NRN_PRCELLSTATE + inst->v_unused[id] = v; + #endif + } + } + } + + + inline double nrn_current_leonhard(int id, int pnodecount, leonhard_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v) { + double current = 0.0; + inst->il[id] = 0.005 * (v - 1.5); + current += inst->il[id]; + return current; + } + + + /** update current */ + void nrn_cur_leonhard(NrnThread* nt, Memb_list* ml, int type) { + int nodecount = ml->nodecount; + int pnodecount = ml->_nodecount_padded; + const int* node_index = ml->nodeindices; + double* data = ml->data; + const double* voltage = nt->_actual_v; + double* vec_rhs = nt->_actual_rhs; + double* vec_d = nt->_actual_d; + Datum* indexes = ml->pdata; + ThreadDatum* thread = ml->_thread; + auto* const inst = static_cast(ml->instance); + + #pragma omp simd + #pragma ivdep + for (int id = 0; id < nodecount; id++) { + int node_id = node_index[id]; + double v = voltage[node_id]; + #if NRN_PRCELLSTATE + inst->v_unused[id] = v; + #endif + double g = nrn_current_leonhard(id, pnodecount, inst, data, indexes, thread, nt, v+0.001); + double rhs = nrn_current_leonhard(id, pnodecount, inst, data, indexes, thread, nt, v); + g = (g-rhs)/0.001; + #if NRN_PRCELLSTATE + inst->g_unused[id] = g; + #endif + vec_rhs[node_id] -= rhs; + vec_d[node_id] += g; + } + } + + + /** update state */ + void nrn_state_leonhard(NrnThread* nt, Memb_list* ml, int type) { + int nodecount = ml->nodecount; + int pnodecount = ml->_nodecount_padded; + const int* node_index = ml->nodeindices; + double* data = ml->data; + const double* voltage = nt->_actual_v; + Datum* indexes = ml->pdata; + ThreadDatum* thread = ml->_thread; + auto* const inst = static_cast(ml->instance); + + #pragma omp simd + #pragma ivdep + for (int id = 0; id < nodecount; id++) { + int node_id = node_index[id]; + double v = voltage[node_id]; + #if NRN_PRCELLSTATE + inst->v_unused[id] = v; + #endif + } + } + + + /** register channel with the simulator */ + void _leonhard_reg() { + + int mech_type = nrn_get_mechtype("leonhard"); + leonhard_global.mech_type = mech_type; + if (mech_type == -1) { + return; + } + + _nrn_layout_reg(mech_type, 0); + register_mech(mechanism_info, nrn_alloc_leonhard, nrn_cur_leonhard, nullptr, nrn_state_leonhard, nrn_init_leonhard, nrn_private_constructor_leonhard, nrn_private_destructor_leonhard, first_pointer_var_index(), 1); + + hoc_register_prop_size(mech_type, float_variables_size(), int_variables_size()); + hoc_register_var(hoc_scalar_double, hoc_vector_double, NULL); + } +} diff --git a/nonspecific_current/neuron/leonhard.cpp b/nonspecific_current/neuron/leonhard.cpp new file mode 100644 index 0000000..9042934 --- /dev/null +++ b/nonspecific_current/neuron/leonhard.cpp @@ -0,0 +1,243 @@ +/********************************************************* +Model Name : leonhard +Filename : leonhard.mod +NMODL Version : 7.7.0 +Vectorized : true +Threadsafe : true +Created : DATE +Simulator : NEURON +Backend : C++ (api-compatibility) +NMODL Compiler : VERSION +*********************************************************/ + +#include +#include +#include + +#include "mech_api.h" +#include "neuron/cache/mechanism_range.hpp" +#include "nrniv_mf.h" +#include "section_fwd.hpp" + +/* NEURON global macro definitions */ +/* VECTORIZED */ +#define NRN_VECTORIZED 1 + +static constexpr auto number_of_datum_variables = 0; +static constexpr auto number_of_floating_point_variables = 3; + +namespace { +template +using _nrn_mechanism_std_vector = std::vector; +using _nrn_model_sorted_token = neuron::model_sorted_token; +using _nrn_mechanism_cache_range = neuron::cache::MechanismRange; +using _nrn_mechanism_cache_instance = neuron::cache::MechanismInstance; +using _nrn_non_owning_id_without_container = neuron::container::non_owning_identifier_without_container; +template +using _nrn_mechanism_field = neuron::mechanism::field; +template +void _nrn_mechanism_register_data_fields(Args&&... args) { + neuron::mechanism::register_data_fields(std::forward(args)...); +} +} // namespace + +Prop* hoc_getdata_range(int type); + + +namespace neuron { + #ifndef NRN_PRCELLSTATE + #define NRN_PRCELLSTATE 0 + #endif + + + /** channel information */ + static const char *mechanism_info[] = { + "7.7.0", + "leonhard", + 0, + "il_leonhard", + 0, + 0, + 0 + }; + + + /* NEURON global variables */ + static int mech_type; + static Prop* _extcall_prop; + /* _prop_id kind of shadows _extcall_prop to allow validity checking. */ + static _nrn_non_owning_id_without_container _prop_id{}; + static int hoc_nrnpointerindex = -1; + static _nrn_mechanism_std_vector _extcall_thread; + + + /** all global variables */ + struct leonhard_Store { + }; + static_assert(std::is_trivially_copy_constructible_v); + static_assert(std::is_trivially_move_constructible_v); + static_assert(std::is_trivially_copy_assignable_v); + static_assert(std::is_trivially_move_assignable_v); + static_assert(std::is_trivially_destructible_v); + leonhard_Store leonhard_global; + + + /** all mechanism instance variables and global variables */ + struct leonhard_Instance { + double* il{}; + double* v_unused{}; + double* g_unused{}; + leonhard_Store* global{&leonhard_global}; + }; + + + struct leonhard_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + + static leonhard_Instance make_instance_leonhard(_nrn_mechanism_cache_range& _ml) { + return leonhard_Instance { + _ml.template fpfield_ptr<0>(), + _ml.template fpfield_ptr<1>(), + _ml.template fpfield_ptr<2>() + }; + } + + + static leonhard_NodeData make_node_data_leonhard(NrnThread& _nt, Memb_list& _ml_arg) { + return leonhard_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + + static void nrn_alloc_leonhard(Prop* _prop) { + Prop *prop_ion{}; + Datum *_ppvar{}; + _nrn_mechanism_cache_instance _ml_real{_prop}; + auto* const _ml = &_ml_real; + size_t const _iml{}; + assert(_nrn_mechanism_get_num_vars(_prop) == 3); + /*initialize range parameters*/ + } + + + /* Neuron setdata functions */ + extern void _nrn_setdata_reg(int, void(*)(Prop*)); + static void _setdata(Prop* _prop) { + _extcall_prop = _prop; + _prop_id = _nrn_get_prop_id(_prop); + } + static void _hoc_setdata() { + Prop *_prop = hoc_getdata_range(mech_type); + _setdata(_prop); + hoc_retpushx(1.); + } + /* Mechanism procedures and functions */ + + + /** connect global (scalar) variables to hoc -- */ + static DoubScal hoc_scalar_double[] = { + {nullptr, nullptr} + }; + + + /** connect global (array) variables to hoc -- */ + static DoubVec hoc_vector_double[] = { + {nullptr, nullptr, 0} + }; + + + /* declaration of user functions */ + + + /* connect user functions to hoc names */ + static VoidFunc hoc_intfunc[] = { + {"setdata_leonhard", _hoc_setdata}, + {0, 0} + }; + static NPyDirectMechFunc npy_direct_func_proc[] = { + }; + + + void nrn_init_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { + _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; + auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); + auto nodecount = _ml_arg->nodecount; + for (int id = 0; id < nodecount; id++) { + } + } + + + inline double nrn_current_leonhard(size_t id, leonhard_Instance& inst, leonhard_NodeData& node_data, double v) { + double current = 0.0; + inst.il[id] = 0.005 * (v - 1.5); + current += inst.il[id]; + return current; + } + + + /** update current */ + void nrn_cur_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { + _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; + auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); + auto nodecount = _ml_arg->nodecount; + for (int id = 0; id < nodecount; id++) { + int node_id = node_data.nodeindices[id]; + double v = node_data.node_voltages[node_id]; + double I1 = nrn_current_leonhard(id, inst, node_data, v+0.001); + double I0 = nrn_current_leonhard(id, inst, node_data, v); + double rhs = I0; + double g = (I1-I0)/0.001; + node_data.node_rhs[node_id] -= rhs; + } + } + + + void nrn_state_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { + _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; + auto inst = make_instance_leonhard(_lmr); + auto node_data = make_node_data_leonhard(*_nt, *_ml_arg); + auto nodecount = _ml_arg->nodecount; + for (int id = 0; id < nodecount; id++) { + } + } + + + /** nrn_jacob function */ + static void nrn_jacob_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) {} + + + static void _initlists() { + } + + + /** register channel with the simulator */ + extern "C" void _leonhard_reg() { + _initlists(); + + + + register_mech(mechanism_info, nrn_alloc_leonhard, nrn_cur_leonhard, nrn_jacob_leonhard, nrn_state_leonhard, nrn_init_leonhard, hoc_nrnpointerindex, 1); + + mech_type = nrn_get_mechtype(mechanism_info[1]); + _nrn_mechanism_register_data_fields(mech_type, + _nrn_mechanism_field{"il"} /* 0 */, + _nrn_mechanism_field{"v_unused"} /* 1 */, + _nrn_mechanism_field{"g_unused"} /* 2 */ + ); + + hoc_register_prop_size(mech_type, 3, 0); + hoc_register_var(hoc_scalar_double, hoc_vector_double, hoc_intfunc); + hoc_register_npy_direct(mech_type, npy_direct_func_proc); + } +} diff --git a/parameter/neuron/test_parameter.cpp b/parameter/neuron/test_parameter.cpp index 212c5d2..b7690f9 100644 --- a/parameter/neuron/test_parameter.cpp +++ b/parameter/neuron/test_parameter.cpp @@ -89,6 +89,14 @@ namespace neuron { }; + struct test_parameter_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static test_parameter_Instance make_instance_test_parameter(_nrn_mechanism_cache_range& _ml) { return test_parameter_Instance { _ml.template fpfield_ptr<0>(), @@ -98,6 +106,16 @@ namespace neuron { } + static test_parameter_NodeData make_node_data_test_parameter(NrnThread& _nt, Memb_list& _ml_arg) { + return test_parameter_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_test_parameter(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -176,6 +194,7 @@ namespace neuron { void nrn_init_test_parameter(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_test_parameter(_lmr); + auto node_data = make_node_data_test_parameter(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { } diff --git a/point_process/neuron/test_pp.cpp b/point_process/neuron/test_pp.cpp index 52c89c5..f4d4b48 100644 --- a/point_process/neuron/test_pp.cpp +++ b/point_process/neuron/test_pp.cpp @@ -87,6 +87,14 @@ namespace neuron { }; + struct test_pp_NodeData { + int const * nodeindices; + double const * node_voltages; + double * node_rhs; + int nodecount; + }; + + static test_pp_Instance make_instance_test_pp(_nrn_mechanism_cache_range& _ml) { return test_pp_Instance { _ml.template fpfield_ptr<0>(), @@ -95,6 +103,16 @@ namespace neuron { } + static test_pp_NodeData make_node_data_test_pp(NrnThread& _nt, Memb_list& _ml_arg) { + return test_pp_NodeData { + _ml_arg.nodeindices, + _nt.node_voltage_storage(), + _nt.node_rhs_storage(), + _ml_arg.nodecount + }; + } + + static void nrn_alloc_test_pp(Prop* _prop) { Prop *prop_ion{}; Datum *_ppvar{}; @@ -172,6 +190,7 @@ namespace neuron { void nrn_init_test_pp(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { _nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; auto inst = make_instance_test_pp(_lmr); + auto node_data = make_node_data_test_pp(*_nt, *_ml_arg); auto nodecount = _ml_arg->nodecount; for (int id = 0; id < nodecount; id++) { }