NEURON
linmod1.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #include <stdio.h>
3 #include <InterViews/observe.h>
4 #include "ocnotify.h"
5 #if HAVE_IV
6 #include "ivoc.h"
7 #endif
8 #include "classreg.h"
9 #include "linmod.h"
10 #include "nrnoc2iv.h"
11 
12 extern "C" double* nrn_recalc_ptr(double*);
13 // hoc interface to a LinearModelAddition
14 // remember that the policy for equation additions to the tree matrix is
15 // cmat*y' + gmat*y = b and where the first nnode rows specify
16 // the number of equations (identfied by nodes)
17 // which are added to existing node equations in the tree structure
18 // and the first nnode columns specify the voltages (identified by nodes)
19 // which are coupled to the equations. i.e the number of new equations
20 // and states added to the tree matrix is nrow - nnode
21 
22 
23 class LinearMechanism: public Observer {
24  public:
26  virtual ~LinearMechanism();
27  virtual void disconnect(Observable*);
28  virtual void update(Observable*);
29  void create();
30  void lmfree();
31  bool valid() {
32  return model_ != NULL;
33  }
34  void update_ptrs();
35 
39  Vect* y_;
41  Vect* b_;
42  int nnode_;
46 };
47 
48 extern void nrn_linmod_update_ptrs(void*);
51  lm->update_ptrs();
52 }
53 
54 static double valid(void* v) {
55  return double(((LinearMechanism*) v)->valid());
56 }
57 
58 static Member_func members[] = {"valid", valid, 0, 0};
59 
60 static void* cons(Object*) {
62  m->create();
63  return (void*) m;
64 }
65 
66 static void destruct(void* v) {
68  delete m;
69 }
70 
72  class2oc("LinearMechanism", cons, destruct, members, NULL, NULL, NULL);
73 }
74 
76  model_ = NULL;
77  c_ = NULL;
78  g_ = NULL;
79  y_ = NULL;
80  b_ = NULL;
81  nnode_ = 0;
82  nodes_ = NULL;
83  y0_ = NULL;
84  elayer_ = NULL;
85  f_callable_ = NULL;
86 }
87 
89  // printf("~LinearMechanism\n");
90  lmfree();
91 }
92 
94  if (f_callable_) {
96  f_callable_ = NULL;
97  }
98  if (model_) {
99  delete model_;
100  model_ = NULL;
101  }
102  if (nodes_) {
104  nnode_ = 0;
105  delete[] nodes_;
106  nodes_ = NULL;
107  elayer_ = NULL;
108  }
109 }
110 
112  if (nodes_) {
114  for (int i = 0; i < nnode_; ++i) {
115  double* pd = nrn_recalc_ptr(&(NODEV(nodes_[i])));
116  if (pd != &(NODEV(nodes_[i]))) {
118  }
119  }
120  }
121 }
122 
125  lmfree();
126 }
127 
129  int i;
130  lmfree();
131  i = 0;
132  Object* o = *hoc_objgetarg(++i);
133 
134  if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) {
135  f_callable_ = o;
136  hoc_obj_ref(o);
137  c_ = matrix_arg(++i);
138  } else {
139  f_callable_ = NULL;
140  c_ = matrix_arg(1);
141  }
142  g_ = matrix_arg(++i);
143  y_ = vector_arg(++i);
144 
145  if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) {
146  y0_ = vector_arg(++i);
147  }
148  b_ = vector_arg(++i);
149  if (ifarg(++i)) {
150 #if HAVE_IV
151  Oc oc;
152 #endif
153  if (hoc_is_double_arg(i)) {
154  nnode_ = 1;
155  nodes_ = new Node*[1];
156  double x = chkarg(i, 0., 1.);
157  Section* sec = chk_access();
158  nodes_[0] = node_exact(sec, x);
160  } else {
161  Object* o = *hoc_objgetarg(i);
162  check_obj_type(o, "SectionList");
163  SectionList* sl = new SectionList(o);
164  sl->ref();
165  Vect* x = vector_arg(i + 1);
166  Section* sec;
167  nnode_ = 0;
168  nodes_ = new Node*[x->size()];
169  for (sec = sl->begin(); sec; sec = sl->next()) {
170  nodes_[nnode_] = node_exact(sec, x->elem(nnode_));
172  ++nnode_;
173  }
174  if (ifarg(i + 2)) {
175  elayer_ = vector_arg(i + 2);
176  }
177  sl->unref();
178  }
179  }
181 }
Section * chk_access(void)
Definition: cabcode.cpp:444
Node * node_exact(Section *sec, double x)
Definition: cabcode.cpp:1940
virtual ~LinearMechanism()
Definition: linmod1.cpp:88
virtual void disconnect(Observable *)
Definition: linmod1.cpp:123
virtual void update(Observable *)
Definition: linmod1.cpp:124
Matrix * g_
Definition: linmod1.cpp:38
Vect * elayer_
Definition: linmod1.cpp:45
Matrix * c_
Definition: linmod1.cpp:37
Node ** nodes_
Definition: linmod1.cpp:44
bool valid()
Definition: linmod1.cpp:31
void update_ptrs()
Definition: linmod1.cpp:111
void lmfree()
Definition: linmod1.cpp:93
LinearModelAddition * model_
Definition: linmod1.cpp:36
Object * f_callable_
Definition: linmod1.cpp:43
Definition: ivoc.h:36
double chkarg(int, double low, double high)
Definition: code2.cpp:638
int hoc_is_object_arg(int narg)
Definition: code.cpp:756
int hoc_is_double_arg(int narg)
Definition: code.cpp:744
Vect * vector_arg(int i)
Definition: ivocvect.cpp:397
void hoc_obj_ref(Object *obj)
Definition: hoc_oop.cpp:1810
int is_vector_arg(int i)
Definition: ivocvect.cpp:405
void hoc_obj_unref(Object *obj)
Definition: hoc_oop.cpp:1828
Object ** hoc_objgetarg(int)
Definition: code.cpp:1587
void nrn_notify_when_double_freed(double *p, Observer *ob)
Definition: ivoc.cpp:61
void nrn_notify_pointer_disconnect(Observer *ob)
Definition: ivoc.cpp:70
int ifarg(int)
Definition: code.cpp:1581
#define Vect
Definition: ivocvect.h:14
static Member_func members[]
Definition: linmod1.cpp:58
void LinearMechanism_reg()
Definition: linmod1.cpp:71
static void * cons(Object *)
Definition: linmod1.cpp:60
static void destruct(void *v)
Definition: linmod1.cpp:66
double * nrn_recalc_ptr(double *)
Definition: treeset.cpp:2179
void nrn_linmod_update_ptrs(void *)
Definition: linmod1.cpp:49
static double valid(void *v)
Definition: linmod1.cpp:54
Matrix * matrix_arg(int i)
Definition: matrix.cpp:45
#define v
Definition: md1redef.h:4
#define sec
Definition: md1redef.h:13
#define i
Definition: md1redef.h:12
size_t p
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1560
check_obj_type(o, "SectionList")
sl
Definition: seclist.cpp:181
o
Definition: seclist.cpp:175
#define NODEV(n)
Definition: section.h:115
#define NULL
Definition: sptree.h:16
MatrixPtr Matrix
Definition: sputils.c:601
Definition: section.h:133
Definition: hocdec.h:227