MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Cell.cpp
Go to the documentation of this file.
1 /**********************************************************************
2  ** This program is part of 'MOOSE', the
3  ** Multiscale Object Oriented Simulation Environment.
4  ** copyright (C) 2003-2011 Upinder S. Bhalla, Niraj Dudani 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 
10 #include "header.h"
11 #include "../shell/Shell.h"
12 #include "Cell.h"
13 
14 #include "HSolveStruct.h"
15 #include "HinesMatrix.h"
16 #include "HSolvePassive.h"
17 #include "RateLookup.h"
18 #include "HSolveActive.h"
19 #include "HSolve.h"
20 
21 map< string, Cell::MethodInfo > Cell::methodMap_;
22 
24 {
25  static DestFinfo process(
26  "process",
27  "Cell does not process at simulation time--"
28  "it only sets up the solver at reset.",
30  );
31 
32  static DestFinfo reinit(
33  "reinit",
34  "Handles 'reinit' call: This triggers setting up the solver.",
36  //~ new EpFunc0< Cell >( &Cell::reinit )
37  );
38 
39  static Finfo* processShared[] =
40  {
41  &process,
42  &reinit
43  };
44 
45  static SharedFinfo proc(
46  "proc",
47  "This shared message exists only to receive a 'reinit' call, which is "
48  "taken as a trigger to create and set up HSolve.",
49  processShared,
50  sizeof( processShared ) / sizeof( Finfo* )
51  );
52 
53  static DestFinfo setup1(
54  "setup1",
55  "Setup.",
57  );
58 
59  static ValueFinfo< Cell, Id > setup2(
60  "setupv",
61  "Setupv.",
62  &Cell::setupf,
64  );
65 
66  static ValueFinfo< Cell, string > method(
67  "method",
68  "Specifies the integration method to be used for the neuron managed "
69  "by this Cell object.",
72  );
73 
74  static ValueFinfo< Cell, unsigned int > solverClock(
75  "solverClock",
76  "Specifies which clock to use for the HSolve, if it is used.",
79  );
80 
81  static ValueFinfo< Cell, string > solverName(
82  "solverName",
83  "Specifies name for the solver object.",
86  );
87 
88  static ReadOnlyValueFinfo< Cell, int > variableDt(
89  "variableDt",
90  "Read-only field which tells if the current method is a variable "
91  "time-step method.",
93  );
94 
95  static ReadOnlyValueFinfo< Cell, int > implicit(
96  "implicit",
97  "Read-only field which tells if the current method is an implicit "
98  "method.",
100  );
101 
102  static ReadOnlyValueFinfo< Cell, string > description(
103  "description",
104  "Read-only field giving a short description of the currently selected "
105  "integration method.",
107  );
108 
109  static Finfo* cellFinfos[] =
110  {
111  &method, // Value
112  &solverClock, // Value
113  &solverName, // Value
114  &setup2,
115  &variableDt, // ReadOnlyValue
116  &implicit, // ReadOnlyValue
117  &description, // ReadOnlyValue
118  &setup1,
119  &proc, // Shared
120  };
121 
122  static string doc[] =
123  {
124  "Name", "Cell",
125  "Author", "Niraj Dudani, 2012, NCBS",
126  "Description", "Container for a neuron's components. "
127  "Also manages automatic solver setup. "
128  "In case of solver setup, assumes that all the "
129  "compartments under this Cell belong to a single "
130  "neuron. If more than 1 group of axially "
131  "connected compartments are present, then only "
132  "one of them will be taken over by the solver.",
133  };
134 
135  static Cinfo cellCinfo(
136  "Cell",
138  cellFinfos,
139  sizeof( cellFinfos ) / sizeof( Finfo* ),
140  new Dinfo< Cell >()
141  );
142 
143  Cell::addMethod( "ee",
144  "Exponential Euler.",
145  0, 0 );
146  Cell::addMethod( "hsolve",
147  "Hines' algorithm.",
148  0, 1 );
149 
150  return &cellCinfo;
151 }
152 
153 static const Cinfo* cellCinfo = Cell::initCinfo();
154 
156 // Class function definitions
158 
160  :
161  solverClock_( 2 ),
162  solverName_( "_integ" ),
163  shell_( reinterpret_cast< Shell* >( Id().eref().data() ) )
164 {
165  setMethod( "hsolve" );
166 }
167 
169  const string& name,
170  const string& description,
171  int isVariableDt,
172  int isImplicit )
173 {
174  methodMap_[ name ] = MethodInfo( description, isVariableDt, isImplicit );
175 }
176 
178 // Dest function definitions
180 
181 void Cell::processDummy( const Eref& cell, ProcPtr p )
182 {
183  ;
184 }
185 
186 void Cell::reinit( const Eref& cell, ProcPtr p )
187 //~ void Cell::reinit( const Eref& cell, const Qinfo* q )
188 {
189  cout << ".. Cell::reinit()" << endl;
190  //~ if ( q->protectedAddToStructuralQ() )
191  //~ return;
192 
193  // Delete existing solver
194  //~ string solverPath = cell.id().path() + "/" + solverName_;
195  //~ Id solver( solverPath );
196  //~ if ( solver.path() == solverPath )
197  //~ solver.destroy();
198 
199  if ( method_ == "ee" )
200  return;
201 
202  // Find any compartment that is a descendant of this cell
203  Id seed = findCompt( cell.id() );
204  if ( seed == Id() ) // No compartment found.
205  return;
206 
207  setupSolver( cell.id(), seed );
208 }
209 
211 {
212  return Id();
213 }
214 void Cell::setupf( Id cell )
215 {
216  cout << "Cell::setup()" << endl;
217  cout << ".... cell path: " << cell.path() << endl;
218  //~ return;
219 
220  // Delete existing solver
221  string solverPath = cell.path() + "/" + solverName_;
222  Id solver( solverPath );
223  if ( solver.path() == solverPath )
224  solver.destroy();
225 
226  if ( method_ == "ee" )
227  return;
228 
229  // Find any compartment that is a descendant of this cell
230  Id seed = findCompt( cell );
231  if ( seed == Id() ) // No compartment found.
232  return;
233 
234  setupSolver( cell, seed );
235 }
236 
237 vector< Id > Cell::children( Id obj )
238 {
239  //~ return Field< vector< Id > >::get( obj, "children" );
240  //~ return Field< vector< Id > >::fastGet( obj.eref(), "children" );
241  //~ return localGet< Neutral, vector< Id > >( obj.eref(), "children" );
242 
243  vector< Id > c;
244  Neutral::children( obj.eref(), c );
245  return c;
246 }
247 
253 {
254  /* 'curr' is the current element under consideration. 'cstack' is a list
255  * of all elements (and their immediate siblings) found on the path from
256  * the root element (the Cell) to the current element.
257  */
258  vector< vector< Id > > cstack;
259  Id seed;
260 
261  const Cinfo* compartmentCinfo = Cinfo::find( "Compartment" );
262 
263  cstack.push_back( children( cell ) );
264  while ( !cstack.empty() )
265  {
266  const vector< Id >& child = cstack.back();
267 
268  if ( child.empty() )
269  {
270  cstack.pop_back();
271  if ( !cstack.empty() )
272  cstack.back().pop_back();
273  }
274  else
275  {
276  dump("TODO", "TODO: Commented out code. ");
277  Id curr = child.back();
278 
279 #if 0 /* ----- #if 0 : If0Label_1 ----- */
280 
281  //~ string className = Field< string >::get( curr, "class" );
282  if ( curr()->cinfo() == compartmentCinfo )
283  {
284  seed = curr;
285  break;
286  }
287 #endif /* ----- #if 0 : If0Label_1 ----- */
288 
289 
290  cstack.push_back( children( curr ) );
291  }
292  }
293 
294  return seed;
295 }
296 
297 void Cell::setupSolver( Id cell, Id seed ) const
298 {
299  Id solver = Id::nextId();
300  dump("FIXME"
301  , "Using 0 for parentMsgIndex in function call Shell::innerCreate"
302  "0 in first and third argument to NodeBalance. "
303  "I am not sure if I should be doing this here in this function."
304  " -- Dilawar"
305  );
306  NodeBalance nb(0, MooseBlockBalance, 0);
307  shell_->innerCreate("HSolve", cell, solver, solverName_, nb, 0);
308  HSolve* data = reinterpret_cast< HSolve* >( solver.eref().data() );
309  data->setSeed( seed );
310 }
311 
313 // Field function definitions
315 
316 void Cell::setMethod( string value )
317 {
318  map< string, MethodInfo >::iterator i = methodMap_.find( value );
319 
320  if ( i != methodMap_.end() )
321  {
322  method_ = value;
323  }
324  else
325  {
326  method_ = "hsolve";
327  cerr << "Warning: Cell::setMethod(): method '" << value
328  << "' not known. Using '" << method_ << "'.\n";
329  setMethod( method_ );
330  }
331 }
332 
333 string Cell::getMethod() const
334 {
335  return method_;
336 }
337 
338 void Cell::setSolverClock( unsigned int value )
339 {
341 }
342 
343 unsigned int Cell::getSolverClock() const
344 {
345  return solverClock_;
346 }
347 
349 {
350  solverName_ = value;
351 }
352 
353 string Cell::getSolverName() const
354 {
355  return solverName_;
356 }
357 
359 {
360  return methodMap_[ method_ ].isVariableDt;
361 }
362 
363 int Cell::getImplicit() const
364 {
365  return methodMap_[ method_ ].isImplicit;
366 }
367 
368 string Cell::getDescription() const
369 {
370  return methodMap_[ method_ ].description;
371 }
Id id() const
Definition: Eref.cpp:62
char * data() const
Definition: Eref.cpp:41
uint32_t value
Definition: moosemodule.h:42
void reinit(const Eref &e, ProcPtr p)
Definition: Cell.cpp:186
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
void setupf(Id cell)
Definition: Cell.cpp:214
Definition: Dinfo.h:60
static const Cinfo * find(const std::string &name)
Definition: Cinfo.cpp:200
Shell * shell_
Definition: Cell.h:74
static const Cinfo * compartmentCinfo
Definition: Compartment.cpp:53
static map< string, MethodInfo > methodMap_
Definition: Cell.h:79
Eref eref() const
Definition: Id.cpp:125
static void children(const Eref &e, vector< Id > &ret)
Definition: Neutral.cpp:342
int getVariableDt() const
Definition: Cell.cpp:358
void destroy() const
Definition: Id.cpp:176
unsigned int solverClock_
Definition: Cell.h:72
void setSolverName(string value)
Definition: Cell.cpp:348
string solverName_
Definition: Cell.h:73
static Id nextId()
Definition: Id.cpp:132
string getMethod() const
Definition: Cell.cpp:333
Definition: HSolve.h:16
static vector< Id > children(Id obj)
Definition: Cell.cpp:237
Definition: OpFunc.h:27
Definition: Eref.h:26
static void addMethod(const string &name, const string &description, int isVariableDt, int isImplicit)
Definition: Cell.cpp:168
void setupSolver(Id cell, Id seed) const
Definition: Cell.cpp:297
static const Cinfo * cellCinfo
Definition: Cell.cpp:153
string getSolverName() const
Definition: Cell.cpp:353
static char name[]
Definition: mfield.cpp:401
void setSeed(Id seed)
Definition: HSolve.cpp:281
unsigned int getSolverClock() const
Definition: Cell.cpp:343
int getImplicit() const
Definition: Cell.cpp:363
Definition: Id.h:17
string method_
Definition: Cell.h:71
void setSolverClock(unsigned int value)
Definition: Cell.cpp:338
void innerCreate(string type, ObjId parent, Id newElm, string name, const NodeBalance &nb, unsigned int parentMsgIndex)
Definition: Shell.cpp:690
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
static const Cinfo * initCinfo()
Definition: Cell.cpp:23
void processDummy(const Eref &e, ProcPtr p)
Definition: Cell.cpp:181
static Id findCompt(Id cell)
Definition: Cell.cpp:252
Cell()
Definition: Cell.cpp:159
Id getSetup() const
Definition: Cell.cpp:210
Definition: Cinfo.h:18
void setMethod(string value)
Definition: Cell.cpp:316
Definition: Shell.h:43
Definition: Finfo.h:12
string getDescription() const
Definition: Cell.cpp:368