Skip to content

Commit

Permalink
NetCon.preloc() and NetCon.preseg() returns the proper x value (or
Browse files Browse the repository at this point in the history
nrn.Segment) for the NetCon location instead of just 0, 1, or 0.5.  Note
that if the threshold variable is not v, then preloc returns -2 and
preseg returns None.  If the NetCon has no source (or its source gid is
associated with a cell not on this process) then preloc returns -1 and
preseg returns None.  Note that preseg does not push the section and so
does not require a corresponding h.pop_section().
  • Loading branch information
nrnhines committed Jan 26, 2018
1 parent 8e63569 commit af83c99
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/nrncvode/netcvode.cpp
Expand Up @@ -463,11 +463,16 @@ static double nc_preloc(void* v) { // user must pop section stack after call
double* v = d->src_->thvar_;
nrn_parent_info(s); // make sure parentnode exists
// there is no efficient search for the location of
// an arbitrary variable. Search only for v at 0, 1.
// an arbitrary variable. Search only for v at 0 - 1.
// Otherwise return .5 .
if (v == &NODEV(s->parentnode)) { return 0.; }
if (v == &NODEV(s->pnode[s->nnode-1])) { return 1.; }
return .5; // perhaps should search for v
for (int i = s->nnode - 2; i >= 0; --i) {
if (v == &NODEV(s->pnode[i])) {
return (double(i)+0.5)/double(s->nnode - 1);
}
}
return -2.; // not voltage
}else{
return -1.;
}
Expand All @@ -477,21 +482,29 @@ static Object** nc_preseg(void* v) { // user must pop section stack after call
NetCon* d = (NetCon*)v;
Section* s = NULL;
Object* obj = NULL;
double x = 0.5;
double x = -1.;
if (d->src_) {
s = d->src_->ssrc_;
}
if (s && nrnpy_seg_from_sec_x) {
double* v = d->src_->thvar_;
nrn_parent_info(s); // make sure parentnode exists
// there is no efficient search for the location of
// an arbitrary variable. Search only for v at 0, 1.
// Otherwise leave x at .5 .
// an arbitrary variable. Search only for v at 0 - 1.
// Otherwise return NULL.
if (v == &NODEV(s->parentnode)) { x = 0.; }
if (v == &NODEV(s->pnode[s->nnode-1])) { x = 1.; }
for (int i = s->nnode - 2; i >= 0; --i) {
if (v == &NODEV(s->pnode[i])) {
x = (double(i)+0.5)/double(s->nnode - 1);
continue;
}
}
// perhaps should search for v
obj = (*nrnpy_seg_from_sec_x)(s, x);
--obj->refcount;
if (x >= 0) {
obj = (*nrnpy_seg_from_sec_x)(s, x);
--obj->refcount;
}
}
return hoc_temp_objptr(obj);
}
Expand Down

0 comments on commit af83c99

Please sign in to comment.