MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HSolveInterface.cpp
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-2007 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 "HSolveStruct.h"
12 #include "HinesMatrix.h"
13 #include "HSolvePassive.h"
14 #include "RateLookup.h"
15 #include "HSolveActive.h"
16 #include "HSolve.h"
17 
18 
20 // Mapping global Id to local index.
22 
23 unsigned int HSolve::localIndex( Id id ) const
24 {
25  /* can easily replace with an array lookup with some holes, as
26  * done in the Stoich class. */
27  map< Id, unsigned int >::const_iterator i;
28 
29  i = localIndex_.find( id );
30  if ( i != localIndex_.end() )
31  return i->second;
32 
33  assert( 0 );
34 
35  return ~0;
36 }
37 
38 void HSolve::mapIds( vector< Id > id )
39 {
40  for ( unsigned int i = 0; i < id.size(); ++i )
41  {
42  // We don't expect these Id's to have been registered already.
43  assert( localIndex_.find( id[ i ] ) == localIndex_.end() );
44 
45  localIndex_[ id[ i ] ] = i;
46  }
47 }
48 
50 {
52  mapIds( caConcId_ );
53  mapIds( channelId_ );
54  //~ mapIds( gateId_ );
55 
56  // Doesn't seem to be needed. Perhaps even the externalChannelId_ vector
57  // is not needed.
58  //~ for ( unsigned int ic = 0; ic < compartmentId_.size(); ++ic )
59  //~ mapIds( externalChannelId_[ ic ] );
60 }
61 
63 // HSolvePassive interface.
65 
66 double HSolve::getVm( Id id ) const
67 {
68  assert(this);
69  unsigned int index = localIndex( id );
70  assert( index < V_.size() );
71  return V_[ index ];
72 }
73 
74 void HSolve::setVm( Id id, double value )
75 {
76  unsigned int index = localIndex( id );
77  assert( index < V_.size() );
78  V_[ index ] = value;
79 }
80 
81 double HSolve::getCm( Id id ) const
82 {
83  unsigned int index = localIndex( id );
84  assert( index < tree_.size() );
85  return tree_[ index ].Cm;
86 }
87 
88 void HSolve::setCm( Id id, double value )
89 {
90  unsigned int index = localIndex( id );
91  assert( index < tree_.size() );
92  // Also update data structures used for calculations.
93  tree_[ index ].Cm = value;
94 }
95 
96 double HSolve::getEm( Id id ) const
97 {
98  unsigned int index = localIndex( id );
99  assert( index < tree_.size() );
100  return tree_[ index ].Em;
101 }
102 
103 void HSolve::setEm( Id id, double value )
104 {
105  unsigned int index = localIndex( id );
106  assert( index < tree_.size() );
107  // Also update data structures used for calculations.
108  tree_[ index ].Em = value;
109 }
110 
111 double HSolve::getRm( Id id ) const
112 {
113  unsigned int index = localIndex( id );
114  assert( index < tree_.size() );
115  return tree_[ index ].Rm;
116 }
117 
118 void HSolve::setRm( Id id, double value )
119 {
120  unsigned int index = localIndex( id );
121  assert( index < tree_.size() );
122  // Also update data structures used for calculations.
123  tree_[ index ].Rm = value;
124 }
125 
126 double HSolve::getRa( Id id ) const
127 {
128  unsigned int index = localIndex( id );
129  assert( index < tree_.size() );
130  return tree_[ index ].Ra;
131 }
132 
133 void HSolve::setRa( Id id, double value )
134 {
135  unsigned int index = localIndex( id );
136  assert( index < tree_.size() );
137  tree_[ index ].Ra = value;
138 }
139 
140 double HSolve::getInitVm( Id id ) const
141 {
142  unsigned int index = localIndex( id );
143  assert( index < tree_.size() );
144  return tree_[ index ].initVm;
145 }
146 
147 void HSolve::setInitVm( Id id, double value )
148 {
149  unsigned int index = localIndex( id );
150  assert( index < tree_.size() );
151  tree_[ index ].initVm = value;
152 }
153 
154 // Read-only
155 double HSolve::getIm( Id id ) const
156 {
157  unsigned int index = localIndex( id );
158  assert( index < nCompt_ );
159 
160  double Im =
161  compartment_[ index ].EmByRm - V_[ index ] / tree_[ index ].Rm;
162 
163  vector< CurrentStruct >::const_iterator icurrent;
164 
165  if ( index == 0 )
166  icurrent = current_.begin();
167  else
168  icurrent = currentBoundary_[ index - 1 ];
169 
170  for ( ; icurrent < currentBoundary_[ index ]; ++icurrent )
171  Im += ( icurrent->Ek - V_[ index ] ) * icurrent->Gk;
172 
173  return Im;
174 }
175 
176 // Read-only
177 double HSolve::getIa( Id id ) const
178 {
179  return 0;
180 }
181 
182 double HSolve::getInject( Id id ) const
183 {
184  unsigned int index = localIndex( id );
185  // Not assert( index < inject_.size() ), because inject_ is a map.
186  assert( index < nCompt_ );
187 
188  map< unsigned int, InjectStruct >::const_iterator i;
189 
190  i = inject_.find( index );
191  if ( i != inject_.end() )
192  return i->second.injectBasal;
193 
194  return 0.0;
195 }
196 
197 void HSolve::setInject( Id id, double value )
198 {
199  unsigned int index = localIndex( id );
200  // Not assert( index < inject_.size() ), because inject_ is a map.
201  assert( index < nCompt_ );
202  inject_[ index ].injectBasal = value;
203 }
204 
205 void HSolve::addInject( Id id, double value )
206 {
207  unsigned int index = localIndex( id );
208  // Not assert( index < inject_.size() ), because inject_ is a map.
209  assert( index < nCompt_ );
210  inject_[ index ].injectVarying += value;
211 }
212 
213 
215 // HSolveActive interface.
217 
218 //~ const vector< Id >& HSolve::getCompartments() const
219 //~ {
220 //~ return compartmentId_;
221 //~ }
222 //~
223 //~ const vector< Id >& HSolve::getHHChannels() const
224 //~ {
225 //~ return channelId_;
226 //~ }
227 //~
228 //~ const vector< Id >& HSolve::getCaConcs() const
229 //~ {
230 //~ return caConcId_;
231 //~ }
232 //~
233 //~ const vector< vector< Id > >& HSolve::getExternalChannels() const
234 //~ {
235 //~ return externalChannelId_;
236 //~ }
237 
238 void HSolve::addGkEk( Id id, double Gk, double Ek )
239 {
240  unsigned int index = localIndex( id );
241  assert( 2 * index + 1 < externalCurrent_.size() );
242  externalCurrent_[ 2 * index ] += Gk;
243  externalCurrent_[ 2 * index + 1 ] += Gk * Ek;
244 }
245 
246 void HSolve::addConc( Id id, double conc )
247 {
248  unsigned int index = localIndex( id );
249  assert( index < externalCalcium_.size() );
250  externalCalcium_[ index ] = conc;
251 }
252 
253 
255  Id id,
256  double Xpower,
257  double Ypower,
258  double Zpower )
259 {
260  unsigned int index = localIndex( id );
261  assert( index < channel_.size() );
262  channel_[ index ].setPowers( Xpower, Ypower, Zpower );
263 }
264 
265 int HSolve::getInstant( Id id ) const
266 {
267  unsigned int index = localIndex( id );
268  assert( index < channel_.size() );
269  return channel_[ index ].instant_;
270 }
271 
272 void HSolve::setInstant( Id id, int instant )
273 {
274  unsigned int index = localIndex( id );
275  assert( index < channel_.size() );
276  channel_[ index ].instant_ = instant;
277 }
278 
279 double HSolve::getHHChannelGbar( Id id ) const
280 {
281  unsigned int index = localIndex( id );
282  assert( index < channel_.size() );
283  return channel_[ index ].Gbar_;
284 }
285 
287 {
288  unsigned int index = localIndex( id );
289  assert( index < channel_.size() );
290  channel_[ index ].Gbar_ = value;
291 
292 }
293 
294 double HSolve::getEk( Id id ) const
295 {
296  unsigned int index = localIndex( id );
297  assert( index < current_.size() );
298  return current_[ index ].Ek;
299 }
300 
301 void HSolve::setEk( Id id, double value )
302 {
303  unsigned int index = localIndex( id );
304  assert( index < current_.size() );
305  current_[ index ].Ek = value;
306 }
307 
308 double HSolve::getGk( Id id ) const
309 {
310  unsigned int index = localIndex( id );
311  assert( index < current_.size() );
312  return current_[ index ].Gk;
313 }
314 
315 void HSolve::setGk( Id id, double value )
316 {
317  unsigned int index = localIndex( id );
318  assert( index < current_.size() );
319  current_[ index ].Gk = value;
320 }
321 
322 double HSolve::getIk( Id id ) const
323 {
324  unsigned int index = localIndex( id );
325  assert( index < current_.size() );
326 
327  unsigned int comptIndex = chan2compt_[ index ];
328  assert( comptIndex < V_.size() );
329 
330  return ( current_[ index ].Ek - V_[ comptIndex ] ) * current_[ index ].Gk;
331 }
332 
333 double HSolve::getX( Id id ) const
334 {
335  unsigned int index = localIndex( id );
336  assert( index < channel_.size() );
337 
338  if ( channel_[ index ].Xpower_ == 0.0 )
339  return 0.0;
340 
341  unsigned int stateIndex = chan2state_[ index ];
342  assert( stateIndex < state_.size() );
343 
344  return state_[ stateIndex ];
345 }
346 
347 void HSolve::setX( Id id, double value )
348 {
349  unsigned int index = localIndex( id );
350  assert( index < channel_.size() );
351 
352  if ( channel_[ index ].Xpower_ == 0.0 )
353  return;
354 
355  unsigned int stateIndex = chan2state_[ index ];
356  assert( stateIndex < state_.size() );
357 
358  state_[ stateIndex ] = value;
359 }
360 
361 double HSolve::getY( Id id ) const
362 {
363  unsigned int index = localIndex( id );
364  assert( index < channel_.size() );
365 
366  if ( channel_[ index ].Ypower_ == 0.0 )
367  return 0.0;
368 
369  unsigned int stateIndex = chan2state_[ index ];
370 
371  if ( channel_[ index ].Xpower_ > 0.0 )
372  ++stateIndex;
373 
374  assert( stateIndex < state_.size() );
375 
376  return state_[ stateIndex ];
377 }
378 
379 void HSolve::setY( Id id, double value )
380 {
381  unsigned int index = localIndex( id );
382  assert( index < channel_.size() );
383 
384  if ( channel_[ index ].Ypower_ == 0.0 )
385  return;
386 
387  unsigned int stateIndex = chan2state_[ index ];
388 
389  if ( channel_[ index ].Xpower_ > 0.0 )
390  ++stateIndex;
391 
392  assert( stateIndex < state_.size() );
393 
394  state_[ stateIndex ] = value;
395 }
396 
397 double HSolve::getZ( Id id ) const
398 {
399  unsigned int index = localIndex( id );
400  assert( index < channel_.size() );
401 
402  if ( channel_[ index ].Zpower_ == 0.0 )
403  return 0.0;
404 
405  unsigned int stateIndex = chan2state_[ index ];
406 
407  if ( channel_[ index ].Xpower_ > 0.0 )
408  ++stateIndex;
409  if ( channel_[ index ].Ypower_ > 0.0 )
410  ++stateIndex;
411 
412  assert( stateIndex < state_.size() );
413 
414  return state_[ stateIndex ];
415 }
416 
417 void HSolve::setZ( Id id, double value )
418 {
419  unsigned int index = localIndex( id );
420  assert( index < channel_.size() );
421 
422  if ( channel_[ index ].Zpower_ == 0.0 )
423  return;
424 
425  unsigned int stateIndex = chan2state_[ index ];
426 
427  if ( channel_[ index ].Xpower_ > 0.0 )
428  ++stateIndex;
429  if ( channel_[ index ].Ypower_ > 0.0 )
430  ++stateIndex;
431 
432  assert( stateIndex < state_.size() );
433 
434  state_[ stateIndex ] = value;
435 }
436 
437 void HSolve::setHHmodulation( Id id, double value )
438 {
439  unsigned int index = localIndex( id );
440  assert( index < channel_.size() );
441  if ( value > 0.0 )
442  channel_[index].modulation_ = value;
443 }
444 
445 double HSolve::getCa( Id id ) const
446 {
447  unsigned int index = localIndex( id );
448  assert( index < caConc_.size() );
449  return ca_[ index ];
450 }
451 
452 void HSolve::setCa( Id id, double Ca )
453 {
454  unsigned int index = localIndex( id );
455  assert( index < caConc_.size() );
456 
457  ca_[ index ] = Ca;
458  caConc_[ index ].setCa( Ca );
459 }
460 
461 void HSolve::iCa( Id id, double iCa )
462 {
463  unsigned int index = localIndex( id );
464  assert( index < caConc_.size() );
465 
466  caActivation_[index] += iCa;
467 
468  /*
469  ca_[ index ] = Ca;
470  caConc_[ index ].setCa( Ca );
471  */
472 }
473 
474 double HSolve::getCaBasal( Id id ) const
475 {
476  unsigned int index = localIndex( id );
477  assert( index < caConc_.size() );
478  return caConc_[ index ].CaBasal_;
479 }
480 
481 void HSolve::setCaBasal( Id id, double CaBasal )
482 {
483  unsigned int index = localIndex( id );
484  assert( index < caConc_.size() );
485 
486  caConc_[ index ].setCaBasal( CaBasal );
487 }
488 
489 void HSolve::setTauB( Id id, double tau, double B )
490 {
491  unsigned int index = localIndex( id );
492  assert( index < caConc_.size() );
493 
494  caConc_[ index ].setTauB( tau, B, dt_ );
495 }
496 
497 double HSolve::getCaCeiling( Id id ) const
498 {
499  unsigned int index = localIndex( id );
500  assert( index < caConc_.size() );
501  return caConc_[ index ].ceiling_;
502 }
503 
504 void HSolve::setCaCeiling( Id id, double ceiling )
505 {
506  unsigned int index = localIndex( id );
507  assert( index < caConc_.size() );
508 
509  caConc_[ index ].ceiling_ = ceiling;
510 }
511 
512 double HSolve::getCaFloor( Id id ) const
513 {
514  unsigned int index = localIndex( id );
515  assert( index < caConc_.size() );
516  return caConc_[ index ].floor_;
517 }
518 
519 void HSolve::setCaFloor( Id id, double floor )
520 {
521  unsigned int index = localIndex( id );
522  assert( index < caConc_.size() );
523 
524  caConc_[ index ].floor_ = floor;
525 }
double getCaFloor(Id id) const
void setY(Id id, double value)
double getRm(Id id) const
void setCa(Id id, double Ca)
void setTauB(Id id, double tau, double B)
uint32_t value
Definition: moosemodule.h:42
void addConc(Id id, double conc)
vector< double > state_
Fraction of gates open.
Definition: HSolveActive.h:74
double getRa(Id id) const
double getVm(Id id) const
vector< unsigned int > chan2state_
a state index
Definition: HSolveActive.h:117
void setVm(Id id, double value)
double getInitVm(Id id) const
void setCaCeiling(Id id, double floor)
vector< double > ca_
Ca conc in each pool.
Definition: HSolveActive.h:81
double getCaBasal(Id id) const
vector< double > caActivation_
calcium pool
Definition: HSolveActive.h:82
double getGk(Id id) const
void setX(Id id, double value)
void setHHmodulation(Id id, double value)
Assign scale factor for HH channel conductance.
void setRa(Id id, double value)
vector< ChannelStruct > channel_
to compartment: chan2compt
Definition: HSolveActive.h:76
double getEm(Id id) const
void setCm(Id id, double value)
vector< Id > compartmentId_
Definition: HSolvePassive.h:37
unsigned int nCompt_
Definition: HinesMatrix.h:70
double getCm(Id id) const
void addInject(Id id, double value)
double getHHChannelGbar(Id id) const
void setInitVm(Id id, double value)
void setCaFloor(Id id, double floor)
vector< double > V_
Definition: HSolvePassive.h:38
vector< CaConcStruct > caConc_
Ca pool info.
Definition: HSolveActive.h:80
vector< CompartmentStruct > compartment_
Definition: HSolvePassive.h:36
void mapIds()
unsigned int localIndex(Id id) const
double getIm(Id id) const
double getIk(Id id) const
map< unsigned int, InjectStruct > inject_
Definition: HSolvePassive.h:45
void setGk(Id id, double value)
vector< TreeNodeStruct > tree_
Definition: HSolvePassive.h:41
map< Id, unsigned int > localIndex_
Definition: HSolve.h:167
double getY(Id id) const
double getZ(Id id) const
void setRm(Id id, double value)
vector< double > externalCalcium_
Definition: HSolveActive.h:122
void setEk(Id id, double value)
vector< currentVecIter > currentBoundary_
Definition: HSolveActive.h:111
void addGkEk(Id id, double v1, double v2)
Interface to compartments.
void setCaBasal(Id id, double CaBasal)
double getEk(Id id) const
vector< unsigned int > chan2compt_
Definition: HSolveActive.h:114
void setZ(Id id, double value)
int getInstant(Id id) const
void setPowers(Id id, double Xpower, double Ypower, double Zpower)
Interface to channels.
void setInstant(Id id, int instant)
void iCa(Id id, double iCa)
double getInject(Id id) const
vector< double > externalCurrent_
Definition: HSolveActive.h:119
void setHHChannelGbar(Id id, double value)
Definition: Id.h:17
double getX(Id id) const
double getCaCeiling(Id id) const
vector< Id > channelId_
Used for localIndex-ing.
Definition: HSolveActive.h:124
vector< CurrentStruct > current_
Channel current.
Definition: HSolveActive.h:73
void setEm(Id id, double value)
vector< Id > caConcId_
calcium from difshells
Definition: HSolveActive.h:123
double getIa(Id id) const
double getCa(Id id) const
Interface to CaConc.
double dt_
Definition: HSolve.h:169
void setInject(Id id, double value)