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  Vect* yvec, Vect* y0, Vect* bvec, int nnode, Node** nodes, Vect* elayer, Object* f_callable)
33  : NrnDAE(cmat, yvec, y0, nnode, nodes, elayer), b_(*bvec), f_callable_(f_callable) {
34 //printf("LinearModelAddition %p\n", this);
35  g_ = new MatrixMap(gmat);
36 }
37 
39 //printf("~LinearModelAddition %p\n", this);
40  delete g_;
41 }
42 
43 void LinearModelAddition::alloc_(int size, int start, int nnode, Node** nodes, int* elayer) {
44 //printf("LinearModelAddition::alloc_ %p\n", this);
45  assert(b_.size() == size);
46  assert(g_->nrow() == size && g_->ncol() == size);
47 //printf("g_->alloc start=%d, nnode=%d\n", start_, nnode_);
48  g_->alloc(start, nnode, nodes, elayer);
49 }
50 
51 void LinearModelAddition::f_(Vect& y, Vect& yprime, int size) {
52 //printf("LinearModelAddition::f_ %p\n", this);
53  //right side portion of (c/dt +g)*[dy] = -g*y + b
54  // given y, returns y'
55  // vm,vext may be reinitialized between fixed steps and certainly
56  // has been adjusted by daspk
57  // size is the number of equations
58  if (f_callable_) {
60  hoc_execerror("LinearModelAddition runtime error",0);
61  }
62  }
63  g_->mulv(y, yprime);
64  for (int i = 0; i < size; ++i) {
65  yprime[i] = b_[i] - yprime[i];
66  }
67 }
68 
69 // indicates that the returned Jacobian must be multiplied by -1 to be
70 // true value
72  return -1;
73 }
74 
76  return g_;
77 }
#define assert(ex)
Definition: hocassrt.h:26
double jacobian_multiplier_()
Definition: linmod.cpp:71
void f_(Vect &y, Vect &yprime, int size)
The right-hand-side function.
Definition: linmod.cpp:51
#define Vect
Definition: ivocvect.h:14
j< sec-> nnode
Definition: treeset.cpp:905
void start()
Definition: hel2mos.cpp:205
virtual ~LinearModelAddition()
Definition: linmod.cpp:38
void alloc(int, int, Node **, int *)
Definition: matrixmap.cpp:36
int
Definition: nrnmusic.cpp:71
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
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
int(* nrnpy_hoccommand_exec)(Object *)
Definition: objcmd.cpp:17
int ncol()
Definition: matrixmap.h:30
NEURON Differential Algebraic Equations.
Definition: nrndae.h:27
int nrow()
Definition: matrixmap.h:29
Definition: hocdec.h:226
#define i
Definition: md1redef.h:12
void alloc_(int size, int start, int nnode, Node **nodes, int *elayer)
Additional allocation for subclasses.
Definition: linmod.cpp:43
MatrixMap * jacobian_(Vect &y)
Compute the Jacobian.
Definition: linmod.cpp:75
Definition: section.h:132
void mulv(Vect &in, Vect &out)
Definition: matrixmap.h:21
MatrixPtr Matrix
Definition: sputils.c:601
static realtype b_
Object * f_callable_
Definition: linmod.h:26
MatrixMap * g_
Definition: linmod.h:24