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() { return model_ != NULL; }
32  void update_ptrs();
33 
37  Vect* y_;
39  Vect* b_;
40  int nnode_;
44 };
45 
46 extern void nrn_linmod_update_ptrs(void*);
49  lm->update_ptrs();
50 }
51 
52 static double valid(void* v) {
53  return double(((LinearMechanism*)v)->valid());
54 }
55 
56 static Member_func members[] = {
57  "valid", valid,
58  0, 0
59 };
60 
61 static void* cons(Object*) {
63  m->create();
64  return (void*)m;
65 }
66 
67 static void destruct(void* v) {
69  delete m;
70 }
71 
73  class2oc("LinearMechanism", cons, destruct, members, NULL, NULL, NULL);
74 }
75 
77  model_ = NULL;
78  c_ = NULL; g_ = NULL; y_ = NULL; b_ = NULL; nnode_ = 0; nodes_ = NULL;
80 }
81 
83 //printf("~LinearMechanism\n");
84  lmfree();
85 }
86 
88  if (f_callable_) {
90  f_callable_ = NULL;
91  }
92  if (model_) {
93  delete model_;
94  model_ = NULL;
95  }
96  if (nodes_) {
98  nnode_ = 0;
99  delete [] nodes_;
100  nodes_ = NULL;
101  elayer_ = NULL;
102  }
103 }
104 
106  if (nodes_) {
108  for (int i=0; i < nnode_; ++i) {
109  double* pd = nrn_recalc_ptr(&(NODEV(nodes_[i])));
110  if (pd != &(NODEV(nodes_[i]))) {
112  }
113  }
114  }
115 }
116 
119  lmfree();
120 }
121 
123 {
124  int i;
125  lmfree();
126  i = 0;
127  Object* o = *hoc_objgetarg(++i);
128 
129  if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) {
130  f_callable_ = o;
131  hoc_obj_ref(o);
132  c_ = matrix_arg(++i);
133  } else {
134  f_callable_ = NULL;
135  c_ = matrix_arg(1);
136  }
137  g_ = matrix_arg(++i);
138  y_ = vector_arg(++i);
139 
140  if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) {
141  y0_ = vector_arg(++i);
142  }
143  b_ = vector_arg(++i);
144  if (ifarg(++i)) {
145 #if HAVE_IV
146  Oc oc;
147 #endif
148  if (hoc_is_double_arg(i)) {
149  nnode_ = 1;
150  nodes_ = new Node*[1];
151  double x = chkarg(i, 0., 1.);
152  Section* sec = chk_access();
153  nodes_[0] = node_exact(sec, x);
155  }else{
156  Object* o = *hoc_objgetarg(i);
157  check_obj_type(o, "SectionList");
158  SectionList* sl = new SectionList(o);
159  sl->ref();
160  Vect* x = vector_arg(i+1);
161  Section* sec;
162  nnode_ = 0;
163  nodes_ = new Node*[x->size()];
164  for (sec = sl->begin(); sec; sec = sl->next()) {
165  nodes_[nnode_] = node_exact(sec, x->elem(nnode_));
167  ++nnode_;
168  }
169  if (ifarg(i+2)) {
170  elayer_ = vector_arg(i+2);
171  }
172  sl->unref();
173  }
174  }
175  model_ = new LinearModelAddition(c_, g_, y_, y0_, b_,
177 }
o
Definition: seclist.cpp:180
Section * next()
Definition: ndatclas.cpp:252
Matrix * c_
Definition: linmod1.cpp:35
Matrix * matrix_arg(int i)
Definition: matrix.cpp:45
#define NODEV(n)
Definition: section.h:114
#define Vect
Definition: ivocvect.h:14
virtual void update(Observable *)
Definition: linmod1.cpp:118
Definition: ivoc.h:36
int hoc_is_double_arg(int narg)
Definition: code.cpp:733
size_t p
Vect * elayer_
Definition: linmod1.cpp:43
check_obj_type(o, "SectionList")
#define v
Definition: md1redef.h:4
Object * f_callable_
Definition: linmod1.cpp:41
virtual void ref() const
Definition: resource.cpp:47
void LinearMechanism_reg()
Definition: linmod1.cpp:72
LinearModelAddition * model_
Definition: linmod1.cpp:34
int is_vector_arg(int i)
Definition: ivocvect.cpp:340
Node ** nodes_
Definition: linmod1.cpp:42
sl
Definition: seclist.cpp:186
void nrn_linmod_update_ptrs(void *)
Definition: linmod1.cpp:47
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:1581
void hoc_obj_unref(Object *obj)
Definition: hoc_oop.cpp:1998
static Member_func members[]
Definition: linmod1.cpp:56
void update_ptrs()
Definition: linmod1.cpp:105
bool valid()
Definition: linmod1.cpp:31
virtual void unref() const
Definition: resource.cpp:52
double * nrn_recalc_ptr(double *)
Definition: treeset.cpp:2158
void hoc_obj_ref(Object *obj)
Definition: hoc_oop.cpp:1980
static void * cons(Object *)
Definition: linmod1.cpp:61
int ifarg(int)
Definition: code.cpp:1562
Vect * vector_arg(int i)
Definition: ivocvect.cpp:332
void nrn_notify_when_double_freed(double *p, Observer *ob)
Definition: ivoc.cpp:63
Matrix * g_
Definition: linmod1.cpp:36
void lmfree()
Definition: linmod1.cpp:87
virtual ~LinearMechanism()
Definition: linmod1.cpp:82
Definition: hocdec.h:226
virtual void disconnect(Observable *)
Definition: linmod1.cpp:117
#define i
Definition: md1redef.h:12
sec
Definition: solve.cpp:885
void nrn_notify_pointer_disconnect(Observer *ob)
Definition: ivoc.cpp:72
int hoc_is_object_arg(int narg)
Definition: code.cpp:745
Definition: section.h:132
static void destruct(void *v)
Definition: linmod1.cpp:67
Object ** hoc_objgetarg(int)
Definition: code.cpp:1568
Section * chk_access(void)
Definition: cabcode.cpp:437
return NULL
Definition: cabcode.cpp:461
Section * begin()
Definition: ndatclas.cpp:248
Node * node_exact(Section *sec, double x)
Definition: cabcode.cpp:1956
double chkarg(int, double low, double high)
Definition: code2.cpp:608
MatrixPtr Matrix
Definition: sputils.c:601