diff --git a/src/nmodl/nocpout.cpp b/src/nmodl/nocpout.cpp index b35308ef03..92c18d6b2d 100644 --- a/src/nmodl/nocpout.cpp +++ b/src/nmodl/nocpout.cpp @@ -428,35 +428,10 @@ extern void nrn_promote(Prop*, int, int);\n\ defs_list, "double get_loc_point_process(void*); return (get_loc_point_process(_vptr));\n}\n"); } - /* function to set up _p and _ppvar */ - Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n"); - Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n"); - if (!point_process) { - Lappendstr(defs_list, "_extcall_prop = _prop;\n"); - Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n"); - } - if (!vectorize) { - Lappendstr(defs_list, - "neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n" - "_ppvar = _nrn_mechanism_access_dparam(_prop);\n"); - } - Lappendstr(defs_list, "}\n"); - if (point_process) { - Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n"); - Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n"); - } else { - Lappendstr(defs_list, - "static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n"); - Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n"); - Lappendstr(defs_list, buf); - } - Lappendstr(defs_list, " _setdata(_prop);\n"); - if (point_process) { - Lappendstr(defs_list, "}\n"); - } else { - Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n"); - } + std::string hoc_setdata_arg = point_process ? "void*" : ""; + Sprintf(buf, "static void _hoc_setdata(%s);\n", hoc_setdata_arg.c_str()); + Lappendstr(defs_list, buf); /* functions */ Lappendstr(defs_list, "/* connect user functions to hoc names */\n"); @@ -755,6 +730,42 @@ extern void nrn_promote(Prop*, int, int);\n\ } } + /* function to set up _p and _ppvar */ + Lappendstr(defs_list, "extern void _nrn_setdata_reg(int, void(*)(Prop*));\n"); + Lappendstr(defs_list, "static void _setdata(Prop* _prop) {\n"); + if (!point_process) { + Lappendstr(defs_list, "_extcall_prop = _prop;\n"); + Lappendstr(defs_list, "_prop_id = _nrn_get_prop_id(_prop);\n"); + } + if (!vectorize) { + Lappendstr(defs_list, + "neuron::legacy::set_globals_from_prop(_prop, _ml_real, _ml, _iml);\n" + "_ppvar = _nrn_mechanism_access_dparam(_prop);\n"); + if (!artificial_cell) { + Lappendstr(defs_list, + "Node * _node = _nrn_mechanism_access_node(_prop);\n" + "v = _nrn_mechanism_access_voltage(_node);\n"); + } + } + Lappendstr(defs_list, "}\n"); + + if (point_process) { + Lappendstr(defs_list, "static void _hoc_setdata(void* _vptr) { Prop* _prop;\n"); + Lappendstr(defs_list, "_prop = ((Point_process*)_vptr)->_prop;\n"); + } else { + Lappendstr(defs_list, + "static void _hoc_setdata() {\n Prop *_prop, *hoc_getdata_range(int);\n"); + Sprintf(buf, "_prop = hoc_getdata_range(_mechtype);\n"); + Lappendstr(defs_list, buf); + } + Lappendstr(defs_list, " _setdata(_prop);\n"); + if (point_process) { + Lappendstr(defs_list, "}\n"); + } else { + Lappendstr(defs_list, "hoc_retpushx(1.);\n}\n"); + } + + /******** what normally goes into cabvars.h structures */ /*declaration of the range variables names to HOC */ diff --git a/src/nrnoc/membfunc.cpp b/src/nrnoc/membfunc.cpp index b6315cb3f5..e858536147 100644 --- a/src/nrnoc/membfunc.cpp +++ b/src/nrnoc/membfunc.cpp @@ -20,6 +20,11 @@ void Memb_func::invoke_initialize(neuron::model_sorted_token const& sorted_token long& _nrn_mechanism_access_alloc_seq(Prop* prop) { return prop->_alloc_seq; } + +Node* _nrn_mechanism_access_node(Prop* prop) { + return prop->node; +} + double& _nrn_mechanism_access_a(Node* node) { return node->a(); } diff --git a/src/nrnoc/membfunc.h b/src/nrnoc/membfunc.h index a3ada08d6d..ad80ed9d7e 100644 --- a/src/nrnoc/membfunc.h +++ b/src/nrnoc/membfunc.h @@ -296,6 +296,7 @@ namespace _get { // See https://github.com/neuronsimulator/nrn/issues/2234 for context of how this might be done // better in future... [[nodiscard]] long& _nrn_mechanism_access_alloc_seq(Prop*); +[[nodiscard]] Node* _nrn_mechanism_access_node(Prop* prop); [[nodiscard]] double& _nrn_mechanism_access_a(Node*); [[nodiscard]] double& _nrn_mechanism_access_b(Node*); [[nodiscard]] double& _nrn_mechanism_access_d(Node*); diff --git a/src/nrnoc/section.h b/src/nrnoc/section.h index 04622aae75..1e26dc8824 100644 --- a/src/nrnoc/section.h +++ b/src/nrnoc/section.h @@ -226,17 +226,20 @@ struct Node { #include "hocdec.h" /* Prop needs Datum and Datum needs Symbol */ #endif + #define PROP_PY_INDEX 10 struct Prop { // Working assumption is that we can safely equate "Prop" with "instance // of a mechanism" apart from a few special cases like CABLESECTION - Prop(short type) - : _type{type} { + Prop(Node* node, short type) + : node(node) + , _type{type} { if (type != CABLESECTION) { m_mech_handle = neuron::container::Mechanism::owning_handle{ neuron::model().mechanism_data(type)}; } } + Node* node; /* The node this property belongs to. */ Prop* next; /* linked list of properties */ short _type; /* type of membrane, e.g. passive, HH, etc. */ int dparam_size; /* for notifying hoc_free_val_array */ diff --git a/src/nrnoc/treeset.cpp b/src/nrnoc/treeset.cpp index 4ee251183a..fb36e8b897 100644 --- a/src/nrnoc/treeset.cpp +++ b/src/nrnoc/treeset.cpp @@ -674,7 +674,7 @@ Prop* prop_alloc(Prop** pp, int type, Node* nd) { nrn_alloc_node_ = nd; // this might be null v_structure_change = 1; current_prop_list = pp; - auto* p = new Prop{static_cast(type)}; + auto* p = new Prop{nd, static_cast(type)}; p->next = *pp; p->ob = nullptr; p->_alloc_seq = -1;