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 // hoc interface to a LinearModelAddition
13 // remember that the policy for equation additions to the tree matrix is
14 // cmat*y' + gmat*y = b and where the first nnode rows specify
15 // the number of equations (identfied by nodes)
16 // which are added to existing node equations in the tree structure
17 // and the first nnode columns specify the voltages (identified by nodes)
18 // which are coupled to the equations. i.e the number of new equations
19 // and states added to the tree matrix is nrow - nnode
20 
21 
22 class LinearMechanism: public Observer {
23  public:
25  virtual ~LinearMechanism();
26  virtual void disconnect(Observable*);
27  virtual void update(Observable*);
28  void create();
29  void lmfree();
30  bool valid() {
31  return model_ != NULL;
32  }
33 
37  Vect* y_;
39  Vect* b_;
40  int nnode_;
44 };
45 
46 static double valid(void* v) {
47  return double(((LinearMechanism*) v)->valid());
48 }
49 
50 static Member_func members[] = {{"valid", valid}, {nullptr, nullptr}};
51 
52 static void* cons(Object*) {
54  m->create();
55  return (void*) m;
56 }
57 
58 static void destruct(void* v) {
60  delete m;
61 }
62 
64  class2oc("LinearMechanism", cons, destruct, members, nullptr, nullptr);
65 }
66 
68  model_ = NULL;
69  c_ = NULL;
70  g_ = NULL;
71  y_ = NULL;
72  b_ = NULL;
73  nnode_ = 0;
74  nodes_ = NULL;
75  y0_ = NULL;
76  elayer_ = NULL;
77  f_callable_ = NULL;
78 }
79 
81  // printf("~LinearMechanism\n");
82  lmfree();
83 }
84 
86  if (f_callable_) {
88  f_callable_ = NULL;
89  }
90  if (model_) {
91  delete model_;
92  model_ = NULL;
93  }
94  if (nodes_) {
96  nnode_ = 0;
97  delete[] nodes_;
98  nodes_ = NULL;
99  elayer_ = NULL;
100  }
101 }
102 
105  lmfree();
106 }
107 
109  int i;
110  lmfree();
111  i = 0;
112  Object* o = *hoc_objgetarg(++i);
113 
114  if (strcmp(o->ctemplate->sym->name, "PythonObject") == 0) {
115  f_callable_ = o;
116  hoc_obj_ref(o);
117  c_ = matrix_arg(++i);
118  } else {
119  f_callable_ = NULL;
120  c_ = matrix_arg(1);
121  }
122  g_ = matrix_arg(++i);
123  y_ = vector_arg(++i);
124 
125  if (ifarg(i + 2) && hoc_is_object_arg(i + 2) && is_vector_arg(i + 2)) {
126  y0_ = vector_arg(++i);
127  }
128  b_ = vector_arg(++i);
129  if (ifarg(++i)) {
130 #if HAVE_IV
131  Oc oc;
132 #endif
133  if (hoc_is_double_arg(i)) {
134  nnode_ = 1;
135  nodes_ = new Node*[1];
136  double x = chkarg(i, 0., 1.);
137  Section* sec = chk_access();
138  nodes_[0] = node_exact(sec, x);
140  } else {
141  Object* o = *hoc_objgetarg(i);
142  check_obj_type(o, "SectionList");
143  SectionList* sl = new SectionList(o);
144  sl->ref();
145  Vect* x = vector_arg(i + 1);
146  Section* sec;
147  nnode_ = 0;
148  nodes_ = new Node*[x->size()];
149  for (sec = sl->begin(); sec; sec = sl->next()) {
152  ++nnode_;
153  }
154  if (ifarg(i + 2)) {
155  elayer_ = vector_arg(i + 2);
156  }
157  sl->unref();
158  }
159  }
161 }
Section * chk_access()
Definition: cabcode.cpp:449
Node * node_exact(Section *sec, double x)
like node_index but give proper node when x is 0 or 1 as well as in between
Definition: cabcode.cpp:1800
size_t size() const
Definition: ivocvect.h:42
double & elem(int n)
Definition: ivocvect.h:26
virtual ~LinearMechanism()
Definition: linmod1.cpp:80
virtual void disconnect(Observable *)
Definition: linmod1.cpp:103
virtual void update(Observable *)
Definition: linmod1.cpp:104
Matrix * g_
Definition: linmod1.cpp:36
Vect * elayer_
Definition: linmod1.cpp:43
Matrix * c_
Definition: linmod1.cpp:35
Node ** nodes_
Definition: linmod1.cpp:42
bool valid()
Definition: linmod1.cpp:30
void lmfree()
Definition: linmod1.cpp:85
LinearModelAddition * model_
Definition: linmod1.cpp:34
Object * f_callable_
Definition: linmod1.cpp:41
Definition: ivoc.h:36
virtual void ref() const
Definition: resource.cpp:42
virtual void unref() const
Definition: resource.cpp:47
Section * next()
Definition: ndatclas.cpp:275
Section * begin()
Definition: ndatclas.cpp:271
void class2oc(const char *, ctor_f *cons, dtor_f *destruct, Member_func *, Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1631
#define v
Definition: md1redef.h:11
#define sec
Definition: md1redef.h:20
#define i
Definition: md1redef.h:19
double chkarg(int, double low, double high)
Definition: code2.cpp:626
int hoc_is_object_arg(int narg)
Definition: code.cpp:876
int hoc_is_double_arg(int narg)
Definition: code.cpp:864
void check_obj_type(Object *obj, const char *type_name)
Definition: hoc_oop.cpp:2098
IvocVect * vector_arg(int i)
Definition: ivocvect.cpp:265
void hoc_obj_ref(Object *obj)
Definition: hoc_oop.cpp:1844
int is_vector_arg(int i)
Definition: ivocvect.cpp:378
void hoc_obj_unref(Object *obj)
Definition: hoc_oop.cpp:1881
Object ** hoc_objgetarg(int)
Definition: code.cpp:1614
void nrn_notify_pointer_disconnect(Observer *ob)
Definition: ivoc.cpp:70
static Member_func members[]
Definition: linmod1.cpp:50
void LinearMechanism_reg()
Definition: linmod1.cpp:63
static void * cons(Object *)
Definition: linmod1.cpp:52
static void destruct(void *v)
Definition: linmod1.cpp:58
static double valid(void *v)
Definition: linmod1.cpp:46
void notify_when_handle_dies(data_handle< double > dh, Observer *obs)
Register that obs should be notified when dh dies.
Definition: ivoc.cpp:91
int ifarg(int)
Definition: code.cpp:1607
#define NULL
Definition: spdefs.h:105
Matrix * matrix_arg(int i)
Definition: matrix.cpp:33
Definition: section.h:105
Definition: hocdec.h:173
cTemplate * ctemplate
Definition: hocdec.h:180
char * name
Definition: model.h:61
Symbol * sym
Definition: hocdec.h:147