NEURON
linmod.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 // linear model whose equations are solved simultaneously with the
3 // voltage equations.
4 // The c*dy/dt + g*y = b equations are added to the node equations
5 // and the policy is that the the list of nodes pertains to the first
6 // equations.
7 
8 // this has only the essential info with regard to solving equations and
9 // nothing with regard to parameterization.
10 
11 // the matrices are assumed to be constant during a simulation run.
12 // and there is no provision here for changing bvec.
13 
14 // MatrixMap gives fast copying of linear model matrix to main tree matrix
15 
16 // In DASPK, the equation order for voltage equations is the same as for
17 // the fixed step method (see nrncvode/occcvode.cpp Cvode::daspk_)
18 // This is a different order than that of cvode in which cap nodes are first
19 // followed by no-cap nodes.
20 // The parallel extends to the additional equations in these linear mechanisms
21 // along with extracellular nodes.
22 // Therefore bmap_ can be used directly for the map to the
23 // daspk equation indices.
24 
25 #include <cstdio>
26 #include "linmod.h"
27 
28 extern int (*nrnpy_hoccommand_exec)(Object*);
29 
30 
32  Matrix* gmat,
33  Vect* yvec,
34  Vect* y0,
35  Vect* bvec,
36  int nnode,
37  Node** nodes,
38  Vect* elayer,
39  Object* f_callable)
40  : NrnDAE(cmat, yvec, y0, nnode, nodes, elayer)
41  , b_(*bvec)
42  , f_callable_(f_callable) {
43  // printf("LinearModelAddition %p\n", this);
44  g_ = new MatrixMap(gmat);
45 }
46 
48  // printf("~LinearModelAddition %p\n", this);
49  delete g_;
50 }
51 
52 void LinearModelAddition::alloc_(int size, int start, int nnode, Node** nodes, int* elayer) {
53  // printf("LinearModelAddition::alloc_ %p\n", this);
54  assert(b_.size() == size);
55  assert(g_->nrow() == size && g_->ncol() == size);
56  // printf("g_->alloc start=%d, nnode=%d\n", start_, nnode_);
57  g_->alloc(start, nnode, nodes, elayer);
58 }
59 
60 void LinearModelAddition::f_(Vect& y, Vect& yprime, int size) {
61  // printf("LinearModelAddition::f_ %p\n", this);
62  // right side portion of (c/dt +g)*[dy] = -g*y + b
63  // given y, returns y'
64  // vm,vext may be reinitialized between fixed steps and certainly
65  // has been adjusted by daspk
66  // size is the number of equations
67  if (f_callable_) {
69  hoc_execerror("LinearModelAddition runtime error", 0);
70  }
71  }
72  g_->mulv(y, yprime);
73  for (int i = 0; i < size; ++i) {
74  yprime[i] = b_[i] - yprime[i];
75  }
76 }
77 
78 // indicates that the returned Jacobian must be multiplied by -1 to be
79 // true value
81  return -1;
82 }
83 
85  return g_;
86 }
MatrixMap * g_
Definition: linmod.h:31
LinearModelAddition(Matrix *c, Matrix *g, Vect *y, Vect *y0, Vect *b, int nnode=0, Node **nodes=NULL, Vect *elayer=NULL, Object *f_callable=NULL)
Definition: linmod.cpp:31
void alloc_(int size, int start, int nnode, Node **nodes, int *elayer)
Additional allocation for subclasses.
Definition: linmod.cpp:52
Object * f_callable_
Definition: linmod.h:33
MatrixMap * jacobian_(Vect &y)
Compute the Jacobian.
Definition: linmod.cpp:84
void f_(Vect &y, Vect &yprime, int size)
The right-hand-side function.
Definition: linmod.cpp:60
virtual ~LinearModelAddition()
Definition: linmod.cpp:47
double jacobian_multiplier_()
Definition: linmod.cpp:80
void alloc(int, int, Node **, int *)
Definition: matrixmap.cpp:40
int nrow()
Definition: matrixmap.h:45
void mulv(Vect &in, Vect &out)
Definition: matrixmap.h:21
int ncol()
Definition: matrixmap.h:48
NEURON Differential Algebraic Equations.
Definition: nrndae.h:27
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
void start()
Definition: hel2mos.cpp:204
#define assert(ex)
Definition: hocassrt.h:32
#define Vect
Definition: ivocvect.h:14
int(* nrnpy_hoccommand_exec)(Object *)
Definition: objcmd.cpp:17
#define i
Definition: md1redef.h:12
static realtype b_
MatrixPtr Matrix
Definition: sputils.c:601
Definition: section.h:133
Definition: hocdec.h:227