MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MarkovSolverBase.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2011 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 #ifndef _MARKOVSOLVERBASE_H
10 #define _MARKOVSOLVERBASE_H
11 
13 //Class : MarkovSolverBase
14 //Author : Vishaka Datta S, 2011, NCBS
15 //Description : Base class for all current Markov solver(s) (and future ones,
16 //hopefully).
17 //
18 //After the setup of the MarkovRateTable class, where the user has entered
19 //the lookup tables for the various transition rates, we have enough
20 //information to compute all the exponential matrices that correspond to the
21 //solution of the kinetic equation at each time step.
22 //
23 //Before the channel simulation is run, the setup of the MarkovSolver requires
24 //that a table of matrix exponentials be computed and stored. In general,
25 //this would require a 2D lookup table where each exponential is index by
26 //([L],V) where [L] = ligand concentration and V = membrane voltage.
27 //In the case all rates are either ligand or voltage dependent, not both, a 1D
28 //lookup table of exponentials suffices.
29 //
30 //The above computations are achieved by going through the lookup tables
31 //of the MarkovRateTable class. In a general case, the number of divisions
32 //i.e. step sizes in each lookup table will be different. We choose the smallest
33 //such step size, and assume that rates with bigger step sizes stay constant
34 //over this time interval. By iterating over the whole range, we setup the
35 //exponential table.
36 //
37 //The MarkovSolverBase class handles all the bookkeeping for the table of matrix
38 //exponentials. It also handles all the above-mentioned interactions with the
39 //remaining MOOSE classes.
40 //
41 //Any MarkovSolver class that derives from this one only need implement
42 //a ComputeMatrixExponential() function, which handles the actual computation
43 //of a the matrix exponential given the Q_ matrix.
44 //
46 
48 //SrcFinfos
50 
52  public :
54 
55  virtual ~MarkovSolverBase();
56 
58  //Set-get stuff.
60  Matrix getQ() const ;
61  Vector getState() const;
62  Vector getInitialState() const;
63  void setInitialState( Vector );
64 
65  //Lookup table related stuff. Have stuck to the same naming
66  //used in the Interpol2D class for simplicity.
67  void setXmin( double );
68  double getXmin() const;
69  void setXmax( double );
70  double getXmax() const;
71  void setXdivs( unsigned int );
72  unsigned int getXdivs() const;
73  double getInvDx() const;
74 
75  void setYmin( double );
76  double getYmin() const;
77  void setYmax( double );
78  double getYmax() const;
79  void setYdivs( unsigned int );
80  unsigned int getYdivs() const;
81  double getInvDy() const;
82 
84  //Lookup table related stuff.
86 
87  //Fills up lookup table of matrix exponentials.
88  void innerFillupTable( vector< unsigned int >, string,
89  unsigned int, unsigned int );
90  void fillupTable();
91 
92  //This returns the pointer to the exponential of the Q matrix.
94 
95  //State space interpolation routines.
96  Vector* bilinearInterpolate() const;
97  Vector* linearInterpolate() const;
98 
99  //Computes the updated state of the system. Is called from the process
100  //function.
101  void computeState();
102 
104  //MsgDest functions.
106  void reinit( const Eref&, ProcPtr );
107  void process( const Eref&, ProcPtr );
108 
109  //Handles information about Vm from the compartment.
110  void handleVm( double );
111 
112  //Handles concentration information.
113  void handleLigandConc( double );
114 
115  //Takes the Id of a MarkovRateTable object to initialize the table of matrix
116  //exponentials.
117  void init( Id, double );
118 
119  static const Cinfo* initCinfo();
120 
122  //Unit test
124  #ifdef DO_UNIT_TESTS
125  friend void testMarkovSolverBase();
126  #endif
127 
128  protected :
129  //The instantaneous rate matrix.
131 
132  #ifdef DO_UNIT_TESTS
133  //Allows us to set Vm_ and ligandConc_ for the state space interpolation
134  //unit test in the MarkovSolver class.
135  void setVm( double );
136  void setLigandConc( double );
137  #endif
138 
139  private :
141  //Helper functions.
143 
144  //Sets the values of xMin, xMax, xDivs, yMin, yMax, yDivs.
145  void setLookupParams();
146 
148  //Lookup table related stuff.
150  /*
151  * Exponentials of all rate matrices that are generated over the
152  * duration of the simulation. The idea is that when copies of the channel
153  * are made, they will all refer this table to get the appropriate
154  * exponential matrix.
155  *
156  * The exponential matrices are computed over a range of voltage levels
157  * and/or ligand concentrations and stored in the appropriate lookup table.
158  *
159  * Depending on whether
160  * 1) All rates are constant,
161  * 2) Rates vary with only 1 parameter i.e. ligand/votage,
162  * 3) Some rates are 2D i.e. vary with two parameters,
163  * we store the table of exponentials in the appropriate pointers below.
164  *
165  * If a system contains both 2D and 1D rates, then, only the 2D pointer
166  * is used.
167  */
168  //Used for storing exponentials when at least one of the rates are 1D and
169  //none are 2D.
170  vector< Matrix* > expMats1d_;
171 
173 
174  //Used for storing exponentials when at least one of the rates are 2D.
175  vector< vector< Matrix* > > expMats2d_;
176 
177  double xMin_;
178  double xMax_;
179  double invDx_;
180  unsigned int xDivs_;
181  double yMin_;
182  double yMax_;
183  double invDy_;
184  unsigned int yDivs_;
185 
187  //Miscallenous stuff
189 
190  //Pointer to the MarkovRateTable object. Necessary to glean information
191  //about the properties of all the transition rates.
193 
194  //Instantaneous state of the system.
196 
197  //Initial state of the system.
199 
200  //Stands for a lot of things. The dimension of the Q matrix, the number of
201  //states in the rate table, etc which all happen to be the same.
202  unsigned int size_;
203 
204  //Membrane voltage.
205  double Vm_;
206  //Ligand concentration.
207  double ligandConc_;
208 
209  //Time step in simulation. The state at t = (t0 + dt) is given by
210  //exp( A * dt ) * [state at t = t0 ].
211  double dt_;
212 };
213 //End of class definition.
214 #endif
void init(Id, double)
vector< double > Vector
Definition: MatrixOps.h:23
void setInitialState(Vector)
Vector getState() const
virtual Matrix * computeMatrixExponential()
void setYdivs(unsigned int)
Matrix getQ() const
MarkovRateTable * rateTable_
unsigned int getYdivs() const
double getXmin() const
void setXdivs(unsigned int)
vector< Matrix * > expMats1d_
void innerFillupTable(vector< unsigned int >, string, unsigned int, unsigned int)
unsigned int yDivs_
Vector getInitialState() const
unsigned int getXdivs() const
static const Cinfo * initCinfo()
double getInvDx() const
Vector * linearInterpolate() const
Definition: Eref.h:26
double getXmax() const
unsigned int size_
double getInvDy() const
vector< vector< Matrix * > > expMats2d_
vector< vector< double > > Matrix
Definition: MatrixOps.h:22
Vector * bilinearInterpolate() const
Definition: Id.h:17
void handleLigandConc(double)
void reinit(const Eref &, ProcPtr)
unsigned int xDivs_
double getYmin() const
Definition: Cinfo.h:18
void process(const Eref &, ProcPtr)
double getYmax() const