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