-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
References for 'BlueBrain/nmodl#1260'.
- Loading branch information
GitHub Actions Bot
committed
May 14, 2024
1 parent
2cb3d7c
commit 66580b3
Showing
4 changed files
with
184 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,6 +147,9 @@ namespace neuron { | |
hoc_retpushx(1.); | ||
} | ||
/* Mechanism procedures and functions */ | ||
inline int func_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt); | ||
inline int func_with_v_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt, double v); | ||
inline int func_with_other_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt, double q); | ||
|
||
|
||
/** connect global (scalar) variables to hoc -- */ | ||
|
@@ -162,15 +165,146 @@ namespace neuron { | |
|
||
|
||
/* declaration of user functions */ | ||
static void _hoc_func(void); | ||
static void _hoc_func_with_v(void); | ||
static void _hoc_func_with_other(void); | ||
static double _npy_func(Prop*); | ||
static double _npy_func_with_v(Prop*); | ||
static double _npy_func_with_other(Prop*); | ||
|
||
|
||
/* connect user functions to hoc names */ | ||
static VoidFunc hoc_intfunc[] = { | ||
{"setdata_leonhard", _hoc_setdata}, | ||
{"func_leonhard", _hoc_func}, | ||
{"func_with_v_leonhard", _hoc_func_with_v}, | ||
{"func_with_other_leonhard", _hoc_func_with_other}, | ||
{0, 0} | ||
}; | ||
static NPyDirectMechFunc npy_direct_func_proc[] = { | ||
{"func", _npy_func}, | ||
{"func_with_v", _npy_func_with_v}, | ||
{"func_with_other", _npy_func_with_other}, | ||
}; | ||
static void _hoc_func(void) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
Prop* _local_prop = _prop_id ? _extcall_prop : nullptr; | ||
_nrn_mechanism_cache_instance _ml_real{_local_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _local_prop ? _nrn_mechanism_access_dparam(_local_prop) : nullptr; | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_leonhard(_ml, inst, id, _ppvar, _thread, _nt); | ||
hoc_retpushx(_r); | ||
} | ||
static double _npy_func(Prop* _prop) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
_nrn_mechanism_cache_instance _ml_real{_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _nrn_mechanism_access_dparam(_prop); | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_leonhard(_ml, inst, id, _ppvar, _thread, _nt); | ||
return(_r); | ||
} | ||
static void _hoc_func_with_v(void) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
Prop* _local_prop = _prop_id ? _extcall_prop : nullptr; | ||
_nrn_mechanism_cache_instance _ml_real{_local_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _local_prop ? _nrn_mechanism_access_dparam(_local_prop) : nullptr; | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_with_v_leonhard(_ml, inst, id, _ppvar, _thread, _nt, *getarg(1)); | ||
hoc_retpushx(_r); | ||
} | ||
static double _npy_func_with_v(Prop* _prop) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
_nrn_mechanism_cache_instance _ml_real{_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _nrn_mechanism_access_dparam(_prop); | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_with_v_leonhard(_ml, inst, id, _ppvar, _thread, _nt, *getarg(1)); | ||
return(_r); | ||
} | ||
static void _hoc_func_with_other(void) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
Prop* _local_prop = _prop_id ? _extcall_prop : nullptr; | ||
_nrn_mechanism_cache_instance _ml_real{_local_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _local_prop ? _nrn_mechanism_access_dparam(_local_prop) : nullptr; | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_with_other_leonhard(_ml, inst, id, _ppvar, _thread, _nt, *getarg(1)); | ||
hoc_retpushx(_r); | ||
} | ||
static double _npy_func_with_other(Prop* _prop) { | ||
double _r{}; | ||
Datum* _ppvar; | ||
Datum* _thread; | ||
NrnThread* _nt; | ||
_nrn_mechanism_cache_instance _ml_real{_prop}; | ||
auto* const _ml = &_ml_real; | ||
size_t const id{}; | ||
_ppvar = _nrn_mechanism_access_dparam(_prop); | ||
_thread = _extcall_thread.data(); | ||
_nt = nrn_threads; | ||
auto inst = make_instance_leonhard(_ml_real); | ||
_r = 1.; | ||
func_with_other_leonhard(_ml, inst, id, _ppvar, _thread, _nt, *getarg(1)); | ||
return(_r); | ||
} | ||
|
||
|
||
inline int func_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt) { | ||
int ret_func = 0; | ||
auto v = inst.v_unused[id]; | ||
return ret_func; | ||
} | ||
|
||
|
||
inline int func_with_v_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt, double v) { | ||
int ret_func_with_v = 0; | ||
return ret_func_with_v; | ||
} | ||
|
||
|
||
inline int func_with_other_leonhard(_nrn_mechanism_cache_range* _ml, leonhard_Instance& inst, size_t id, Datum* _ppvar, Datum* _thread, NrnThread* _nt, double q) { | ||
int ret_func_with_other = 0; | ||
auto v = inst.v_unused[id]; | ||
return ret_func_with_other; | ||
} | ||
|
||
|
||
void nrn_init_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type) { | ||
|
@@ -190,8 +324,15 @@ namespace neuron { | |
} | ||
|
||
|
||
inline double nrn_current_leonhard(size_t id, leonhard_Instance& inst, leonhard_NodeData& node_data, double v) { | ||
inline double nrn_current_leonhard(_nrn_model_sorted_token const& _sorted_token, NrnThread* _nt, Memb_list* _ml_arg, int _type, size_t id, leonhard_Instance& inst, leonhard_NodeData& node_data, double v) { | ||
_nrn_mechanism_cache_range _lmr{_sorted_token, *_nt, *_ml_arg, _type}; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
auto* const _ml = &_lmr; | ||
auto* _thread = _ml_arg->_thread; | ||
auto* _ppvar = _ml_arg->pdata[id]; | ||
double current = 0.0; | ||
func_leonhard(_ml, inst, id, _ppvar, _thread, _nt); | ||
This comment has been minimized.
Sorry, something went wrong.
1uc
Collaborator
|
||
func_with_v_leonhard(_ml, inst, id, _ppvar, _thread, _nt, v); | ||
func_with_other_leonhard(_ml, inst, id, _ppvar, _thread, _nt, inst.c[id]); | ||
inst.il[id] = inst.c[id] * (v - 1.5); | ||
current += inst.il[id]; | ||
return current; | ||
|
@@ -209,8 +350,8 @@ namespace neuron { | |
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 I1 = nrn_current_leonhard(_sorted_token, _nt, _ml_arg, _type, id, inst, node_data, v+0.001); | ||
double I0 = nrn_current_leonhard(_sorted_token, _nt, _ml_arg, _type, id, inst, node_data, v); | ||
double rhs = I0; | ||
double g = (I1-I0)/0.001; | ||
node_data.node_rhs[node_id] -= rhs; | ||
|
Setting up
_lmr
should happen outside the loop.nrn_current_*
is a function that's only called in the loop body ofnrn_cur_*
.It might be better to pass it in.