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 #include "nrnpy.h"
28 
30  Matrix* gmat,
31  Vect* yvec,
32  Vect* y0,
33  Vect* bvec,
34  int nnode,
35  Node** nodes,
36  Vect* elayer,
37  Object* f_callable)
38  : NrnDAE(cmat, yvec, y0, nnode, nodes, elayer)
39  , b_(*bvec)
40  , f_callable_(f_callable) {
41  // printf("LinearModelAddition %p\n", this);
42  g_ = new MatrixMap(gmat);
43 }
44 
46  // printf("~LinearModelAddition %p\n", this);
47  delete g_;
48 }
49 
50 void LinearModelAddition::alloc_(int size, int start, int nnode, Node** nodes, int* elayer) {
51  // printf("LinearModelAddition::alloc_ %p\n", this);
52  assert(b_.size() == size);
53  assert(g_->nrow() == size && g_->ncol() == size);
54  // printf("g_->alloc start=%d, nnode=%d\n", start_, nnode_);
55  g_->alloc(start, nnode, nodes, elayer);
56 }
57 
58 void LinearModelAddition::f_(Vect& y, Vect& yprime, int size) {
59  // printf("LinearModelAddition::f_ %p\n", this);
60  // right side portion of (c/dt +g)*[dy] = -g*y + b
61  // given y, returns y'
62  // vm,vext may be reinitialized between fixed steps and certainly
63  // has been adjusted by daspk
64  // size is the number of equations
65  if (f_callable_) {
67  hoc_execerror("LinearModelAddition runtime error", 0);
68  }
69  }
70  g_->mulv(y, yprime);
71  for (int i = 0; i < size; ++i) {
72  yprime[i] = b_[i] - yprime[i];
73  }
74 }
75 
76 // indicates that the returned Jacobian must be multiplied by -1 to be
77 // true value
79  return -1;
80 }
81 
83  return g_;
84 }
size_t size() const
Definition: ivocvect.h:42
MatrixMap * g_
Definition: linmod.h:29
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:29
void alloc_(int size, int start, int nnode, Node **nodes, int *elayer)
Additional allocation for subclasses.
Definition: linmod.cpp:50
Object * f_callable_
Definition: linmod.h:31
MatrixMap * jacobian_(Vect &y)
Compute the Jacobian.
Definition: linmod.cpp:82
void f_(Vect &y, Vect &yprime, int size)
The right-hand-side function.
Definition: linmod.cpp:58
virtual ~LinearModelAddition()
Definition: linmod.cpp:45
double jacobian_multiplier_()
Definition: linmod.cpp:78
void alloc(int, int, Node **, int *)
Definition: matrixmap.cpp:40
int nrow()
Definition: matrixmap.h:40
void mulv(Vect &in, Vect &out)
Definition: matrixmap.h:16
int ncol()
Definition: matrixmap.h:43
NEURON Differential Algebraic Equations.
Definition: nrndae.h:27
#define i
Definition: md1redef.h:19
#define b_(arg)
Definition: crout.hpp:137
#define assert(ex)
Definition: hocassrt.h:24
void hoc_execerror(const char *s1, const char *s2)
Definition: nrnoc_aux.cpp:39
impl_ptrs methods
Collection of pointers to functions with python-version-specific implementations.
Definition: nrnpy.cpp:21
static int hoccommand_exec(Object *ho)
Definition: nrnpy_p2h.cpp:339
Definition: section.h:105
Definition: hocdec.h:173