MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
HHGate.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. 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 "ElementValueFinfo.h"
12 #include "HHGate.h"
13 
14 static const double SINGULARITY = 1.0e-6;
15 
17 {
19  // Field definitions.
22  "lookupA: Look up the A gate value from a double. Usually does"
23  "so by direct scaling and offset to an integer lookup, using"
24  "a fine enough table granularity that there is little error."
25  "Alternatively uses linear interpolation."
26  "The range of the double is predefined based on knowledge of"
27  "voltage or conc ranges, and the granularity is specified by"
28  "the xmin, xmax, and dV fields.",
29  &HHGate::lookupA );
31  "lookupB: Look up the B gate value from a double."
32  "Note that this looks up the raw tables, which are transformed"
33  "from the reference parameters.",
34  &HHGate::lookupB );
35 
36  static ElementValueFinfo< HHGate, vector< double > > alpha( "alpha",
37  "Parameters for voltage-dependent rates, alpha:"
38  "Set up alpha term using 5 parameters, as follows:"
39  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
40  "The original HH equations can readily be cast into this form",
43  );
44 
45  static ElementValueFinfo< HHGate, vector< double > > beta( "beta",
46  "Parameters for voltage-dependent rates, beta:"
47  "Set up beta term using 5 parameters, as follows:"
48  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
49  "The original HH equations can readily be cast into this form",
52  );
53 
55  "Parameters for voltage-dependent rates, tau:"
56  "Set up tau curve using 5 parameters, as follows:"
57  "y(x) = (A + B * x) / (C + exp((x + D) / F))",
60  );
61 
63  "mInfinity",
64  "Parameters for voltage-dependent rates, mInfinity:"
65  "Set up mInfinity curve using 5 parameters, as follows:"
66  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
67  "The original HH equations can readily be cast into this form",
70  );
71 
72  static ElementValueFinfo< HHGate, double > min( "min",
73  "Minimum range for lookup",
76  );
77 
78  static ElementValueFinfo< HHGate, double > max( "max",
79  "Minimum range for lookup",
82  );
83 
85  "Divisions for lookup. Zero means to use linear interpolation",
88  );
89 
91  "tableA",
92  "Table of A entries",
95  );
96 
98  "tableB",
99  "Table of alpha + beta entries",
102  );
103 
104  static ElementValueFinfo< HHGate, bool > useInterpolation(
105  "useInterpolation",
106  "Flag: use linear interpolation if true, else direct lookup",
109  );
110 
112  "alphaParms",
113  "Set up both gates using 13 parameters, as follows:"
114  "setupAlpha AA AB AC AD AF BA BB BC BD BF xdivs xmin xmax"
115  "Here AA-AF are Coefficients A to F of the alpha (forward) term"
116  "Here BA-BF are Coefficients A to F of the beta (reverse) term"
117  "Here xdivs is the number of entries in the table,"
118  "xmin and xmax define the range for lookup."
119  "Outside this range the returned value will be the low [high]"
120  "entry of the table."
121  "The equation describing each table is:"
122  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
123  "The original HH equations can readily be cast into this form",
126  );
127 
129  // DestFinfos
131  static DestFinfo setupAlpha( "setupAlpha",
132  "Set up both gates using 13 parameters, as follows:"
133  "setupAlpha AA AB AC AD AF BA BB BC BD BF xdivs xmin xmax"
134  "Here AA-AF are Coefficients A to F of the alpha (forward) term"
135  "Here BA-BF are Coefficients A to F of the beta (reverse) term"
136  "Here xdivs is the number of entries in the table,"
137  "xmin and xmax define the range for lookup."
138  "Outside this range the returned value will be the low [high]"
139  "entry of the table."
140  "The equation describing each table is:"
141  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
142  "The original HH equations can readily be cast into this form",
143  new EpFunc1< HHGate, vector< double > >( &HHGate::setupAlpha )
144  );
145  static DestFinfo setupTau( "setupTau",
146  "Identical to setupAlpha, except that the forms specified by"
147  "the 13 parameters are for the tau and m-infinity curves rather"
148  "than the alpha and beta terms. So the parameters are:"
149  "setupTau TA TB TC TD TF MA MB MC MD MF xdivs xmin xmax"
150  "As before, the equation describing each curve is:"
151  "y(x) = (A + B * x) / (C + exp((x + D) / F))",
152  new EpFunc1< HHGate, vector< double > >( &HHGate::setupTau )
153  );
154  static DestFinfo tweakAlpha( "tweakAlpha",
155  "Dummy function for backward compatibility. It used to convert"
156  "the tables from alpha, beta values to alpha, alpha+beta"
157  "because the internal calculations used these forms. Not"
158  "needed now, deprecated.",
160  );
161  static DestFinfo tweakTau( "tweakTau",
162  "Dummy function for backward compatibility. It used to convert"
163  "the tables from tau, minf values to alpha, alpha+beta"
164  "because the internal calculations used these forms. Not"
165  "needed now, deprecated.",
167  );
168  static DestFinfo setupGate( "setupGate",
169  "Sets up one gate at a time using the alpha/beta form."
170  "Has 9 parameters, as follows:"
171  "setupGate A B C D F xdivs xmin xmax is_beta"
172  "This sets up the gate using the equation:"
173  "y(x) = (A + B * x) / (C + exp((x + D) / F))"
174  "Deprecated.",
175  new EpFunc1< HHGate, vector< double > >( &HHGate::setupGate )
176  );
177  static Finfo* HHGateFinfos[] =
178  {
179  &A, // ReadOnlyLookupValue
180  &B, // ReadOnlyLookupValue
181  &alpha, // ElementValue
182  &beta, // ElementValue
183  &tau, // ElementValue
184  &mInfinity, // ElementValue
185  &min, // ElementValue
186  &max, // ElementValue
187  &divs, // ElementValue
188  &tableA, // ElementValue
189  &tableB, // ElementValue
190  &useInterpolation, // ElementValue
191  &alphaParms, // ElementValue
192  &setupAlpha, // Dest
193  &setupTau, // Dest
194  &tweakAlpha, // Dest
195  &tweakTau, // Dest
196  &setupGate, // Dest
197  };
198 
199  static string doc[] =
200  {
201  "Name", "HHGate",
202  "Author", "Upinder S. Bhalla, 2011, NCBS",
203  "Description", "HHGate: Gate for Hodkgin-Huxley type channels, equivalent to the "
204  "m and h terms on the Na squid channel and the n term on K. "
205  "This takes the voltage and state variable from the channel, "
206  "computes the new value of the state variable and a scaling, "
207  "depending on gate power, for the conductance.",
208  };
209 
210  static Dinfo< HHGate > dinfo;
211  static Cinfo HHGateCinfo(
212  "HHGate",
214  HHGateFinfos, sizeof(HHGateFinfos)/sizeof(Finfo *),
215  &dinfo,
216  doc,
217  sizeof(doc)/sizeof(string)
218  );
219 
220  return &HHGateCinfo;
221 }
222 
225 // Core class functions
228  : xmin_(0), xmax_(1), invDx_(1),
229  originalChanId_(0),
230  originalGateId_(0),
231  lookupByInterpolation_(0),
232  isDirectTable_(0)
233 {;}
234 
235 HHGate::HHGate( Id originalChanId, Id originalGateId )
236  :
237  A_( 1, 0.0 ),
238  B_( 1, 0.0 ),
239  xmin_(0), xmax_(1), invDx_(1),
240  originalChanId_( originalChanId ),
241  originalGateId_( originalGateId ),
242  lookupByInterpolation_(0),
243  isDirectTable_(0)
244 {;}
245 
247 // Field function definitions
249 
250 double HHGate::lookupTable( const vector< double >& tab, double v ) const
251 {
252  if ( v <= xmin_ ) return tab[0];
253  if ( v >= xmax_ ) return tab.back();
254  if ( lookupByInterpolation_ ) {
255  unsigned int index =
256  static_cast< unsigned int >( ( v - xmin_ ) * invDx_ );
257  assert( tab.size() > index );
258  double frac = ( v - xmin_ - index / invDx_ ) * invDx_;
259  return tab[ index ] * ( 1 - frac ) + tab[ index + 1 ] * frac;
260  } else {
261  return tab[ static_cast< unsigned int >( (v - xmin_) * invDx_ ) ];
262  }
263 }
264 
265 double HHGate::lookupA( double v ) const
266 {
267  return lookupTable( A_, v );
268 }
269 
270 double HHGate::lookupB( double v ) const
271 {
272  return lookupTable( B_, v );
273 }
274 
275 void HHGate::lookupBoth( double v, double* A, double* B ) const
276 {
277  if ( v <= xmin_ ) {
278  *A = A_[0];
279  *B = B_[0];
280  } else if ( v >= xmax_ ) {
281  *A = A_.back();
282  *B = B_.back();
283  } else {
284  unsigned int index =
285  static_cast< unsigned int >( ( v - xmin_ ) * invDx_ );
286  assert( A_.size() > index && B_.size() > index );
287  if ( lookupByInterpolation_ ) {
288  double frac = ( v - xmin_ - index / invDx_ ) * invDx_;
289  *A = A_[ index ] * ( 1 - frac ) + A_[ index + 1 ] * frac;
290  *B = B_[ index ] * ( 1 - frac ) + B_[ index + 1 ] * frac;
291  } else {
292  *A = A_[ index ];
293  *B = B_[ index ];
294  }
295  }
296 }
297 
298 vector< double > HHGate::getAlpha( const Eref& e) const
299 {
300  return alpha_;
301 }
302 
303 void HHGate::setAlpha( const Eref& e, vector< double > val )
304 {
305  if ( val.size() != 5 ) {
306  cout << "Error: HHGate::setAlpha on " << e.id().path() <<
307  ": Number of entries on argument vector should be 5, was " <<
308  val.size() << endl;
309  return;
310  }
311  if ( checkOriginal( e.id(), "alpha" ) ) {
312  alpha_ = val;
313  updateTauMinf();
314  updateTables();
315  }
316 }
317 
318 vector< double > HHGate::getBeta( const Eref& e) const
319 {
320  return beta_;
321 }
322 
323 void HHGate::setBeta( const Eref& e, vector< double > val )
324 {
325  if ( val.size() != 5 ) {
326  cout << "Error: HHGate::setBeta on " << e.id().path() <<
327  ": Number of entries on argument vector should be 5, was " <<
328  val.size() << endl;
329  return;
330  }
331  if ( checkOriginal( e.id(), "beta" ) ) {
332  beta_ = val;
333  updateTauMinf();
334  updateTables();
335  }
336 }
337 
338 vector< double > HHGate::getTau( const Eref& e) const
339 {
340  return tau_;
341 }
342 
343 void HHGate::setTau( const Eref& e, vector< double > val )
344 {
345  if ( val.size() != 5 ) {
346  cout << "Error: HHGate::setTau on " << e.id().path() <<
347  ": Number of entries on argument vector should be 5, was " <<
348  val.size() << endl;
349  return;
350  }
351  if ( checkOriginal( e.id(), "tau" ) ) {
352  tau_ = val;
353  updateAlphaBeta();
354  updateTables();
355  }
356 }
357 
358 vector< double > HHGate::getMinfinity( const Eref& e) const
359 {
360  return mInfinity_;
361 }
362 
363 void HHGate::setMinfinity( const Eref& e, vector< double > val )
364 {
365  if ( val.size() != 5 ) {
366  cout << "Error: HHGate::setMinfinity on " << e.id().path() <<
367  ": Number of entries on argument vector should be 5, was " <<
368  val.size() << endl;
369  return;
370  }
371  if ( checkOriginal( e.id(), "mInfinity" ) ) {
372  mInfinity_ = val;
373  updateAlphaBeta();
374  updateTables();
375  }
376 }
377 
378 double HHGate::getMin( const Eref& e) const
379 {
380  return xmin_;
381 }
382 
383 void HHGate::setMin( const Eref& e, double val )
384 {
385  if ( checkOriginal( e.id(), "min" ) ) {
386  xmin_ = val;
387  unsigned int xdivs = A_.size() - 1;
388  if ( isDirectTable_ && xdivs > 0 ) {
389  // Stuff here to stretch out table using interpolation.
390  invDx_ = static_cast< double >( xdivs ) / ( xmax_ - val );
391  tabFill( A_, xdivs, val, xmax_ );
392  tabFill( B_, xdivs, val, xmax_ );
393  } else {
394  updateTables();
395  }
396  }
397 }
398 
399 double HHGate::getMax( const Eref& e) const
400 {
401  return xmax_;
402 }
403 
404 void HHGate::setMax( const Eref& e, double val )
405 {
406  if ( checkOriginal( e.id(), "max" ) ) {
407  xmax_ = val;
408  unsigned int xdivs = A_.size() - 1;
409  if ( isDirectTable_ && xdivs > 0 ) {
410  // Set up using direct assignment of table values.
411  invDx_ = static_cast< double >( xdivs ) / ( val - xmin_ );
412  tabFill( A_, xdivs, xmin_, val );
413  tabFill( B_, xdivs, xmin_, val );
414  } else {
415  // Set up using functional form. here we just recalculate.
416  updateTables();
417  }
418  }
419 }
420 
421 unsigned int HHGate::getDivs( const Eref& e) const
422 {
423  return A_.size() - 1;
424 }
425 
426 void HHGate::setDivs( const Eref& e, unsigned int val )
427 {
428  if ( checkOriginal( e.id(), "divs" ) ) {
429  if ( isDirectTable_ ) {
430  invDx_ = static_cast< double >( val ) / ( xmax_ - xmin_ );
431  tabFill( A_, val, xmin_, xmax_ );
432  tabFill( B_, val, xmin_, xmax_ );
433  } else {
435  A_.resize( val + 1 );
436  B_.resize( val + 1 );
437  invDx_ = static_cast< double >( val ) / ( xmax_ - xmin_ );
438  updateTables();
439  }
440  }
441 }
442 
443 vector< double > HHGate::getTableA( const Eref& e) const
444 {
445  return A_;
446 }
447 
448 void HHGate::setTableA( const Eref& e, vector< double > v )
449 {
450  if ( v.size() < 2 ) {
451  cout << "Warning: HHGate::setTableA: size must be >= 2 entries on "
452  << e.id().path() << endl;
453  return;
454  }
455  if ( checkOriginal( e.id(), "tableA" ) ) {
456  isDirectTable_ = 1;
457  A_ = v;
458  unsigned int xdivs = A_.size() - 1;
459  invDx_ = static_cast< double >( xdivs ) / ( xmax_ - xmin_ );
460  }
461 }
462 
463 vector< double > HHGate::getTableB( const Eref& e) const
464 {
465  return B_;
466 }
467 
468 void HHGate::setTableB( const Eref& e, vector< double > v )
469 {
470  if ( checkOriginal( e.id(), "tableB" ) ) {
471  isDirectTable_ = 1;
472  if ( A_.size() != v.size() ) {
473  cout << "Warning: HHGate::setTableB: size should be same as table A: " << v.size() << " != " << A_.size() << ". Ignoring.\n";
474  return;
475  }
476  B_ = v;
477  }
478 }
479 
480 bool HHGate::getUseInterpolation( const Eref& e) const
481 {
482  return lookupByInterpolation_;
483 }
484 
485 void HHGate::setUseInterpolation( const Eref& e, bool val )
486 {
487  if ( checkOriginal( e.id(), "useInterpolation" ) )
489 }
490 
491 void HHGate::setupAlpha( const Eref& e,
492  vector< double > parms )
493 {
494  if ( checkOriginal( e.id(), "setupAlpha" ) ) {
495  if ( parms.size() != 13 ) {
496  cout << "HHGate::setupAlpha: Error: parms.size() != 13\n";
497  return;
498  }
499  setupTables( parms, false );
500  alpha_.resize( 5, 0 );
501  beta_.resize( 5, 0 );
502  for ( unsigned int i = 0; i < 5; ++i )
503  alpha_[i] = parms[i];
504  for ( unsigned int i = 5; i < 10; ++i )
505  beta_[i - 5] = parms[i];
506  }
507 }
508 
509 vector< double > HHGate::getAlphaParms( const Eref& e ) const
510 {
511  vector< double > ret = alpha_;
512  ret.insert( ret.end(), beta_.begin(), beta_.end() );
513  ret.push_back( A_.size() );
514  ret.push_back( xmin_ );
515  ret.push_back( xmax_ );
516 
517  return ret;
518 }
519 
521 // Dest function definitions
523 
524 void HHGate::setupTau( const Eref& e,
525  vector< double > parms )
526 {
527  if ( checkOriginal( e.id(), "setupTau" ) ) {
528  if ( parms.size() != 13 ) {
529  cout << "HHGate::setupTau: Error: parms.size() != 13\n";
530  return;
531  }
532  setupTables( parms, true );
533  }
534 }
535 
537 {
538  ; // Dummy
539 }
540 
542 {
543  ; // Dummy
544 }
545 
551 void HHGate::setupTables( const vector< double >& parms, bool doTau )
552 {
553  assert( parms.size() == 13 );
554  static const int XDIVS = 10;
555  static const int XMIN = 11;
556  static const int XMAX = 12;
557  if ( parms[XDIVS] < 1 ) return;
558  unsigned int xdivs = static_cast< unsigned int >( parms[XDIVS] );
559 
560  A_.resize( xdivs + 1 );
561  B_.resize( xdivs + 1 );
562  xmin_ = parms[XMIN];
563  xmax_ = parms[XMAX];
564  assert( xmax_ > xmin_ );
565  invDx_ = xdivs / (xmax_ - xmin_ );
566  double dx = ( xmax_ - xmin_ ) / xdivs;
567 
568  double x = xmin_;
569  double prevAentry = 0.0;
570  double prevBentry = 0.0;
571  double temp;
572  double temp2 = 0.0;
573  unsigned int i;
574 
575  for( i = 0; i <= xdivs; i++ ) {
576  if ( fabs( parms[4] ) < SINGULARITY ) {
577  temp = 0.0;
578  A_[i] = temp;
579  } else {
580  temp2 = parms[2] + exp( ( x + parms[3] ) / parms[4] );
581  if ( fabs( temp2 ) < SINGULARITY ) {
582  temp2 = parms[2] + exp( ( x + dx/10.0 + parms[3] ) / parms[4] );
583  temp = ( parms[0] + parms[1] * (x + dx/10 ) ) / temp2;
584 
585  temp2 = parms[2] + exp( ( x - dx/10.0 + parms[3] ) / parms[4] );
586  temp += ( parms[0] + parms[1] * (x - dx/10 ) ) / temp2;
587  temp /= 2.0;
588  // cout << "interpolated temp = " << temp << ", prev = " << prevAentry << endl;
589 
590  // temp = prevAentry;
591  A_[i] = temp;
592  } else {
593  temp = ( parms[0] + parms[1] * x) / temp2;
594  A_[i] = temp;
595  }
596  }
597  if ( fabs( parms[9] ) < SINGULARITY ) {
598  B_[i] = 0.0;
599  } else {
600  temp2 = parms[7] + exp( ( x + parms[8] ) / parms[9] );
601  if ( fabs( temp2 ) < SINGULARITY ) {
602  temp2 = parms[7] + exp( ( x + dx/10.0 + parms[8] ) / parms[9] );
603  temp = (parms[5] + parms[6] * (x + dx/10) ) / temp2;
604  temp2 = parms[7] + exp( ( x - dx/10.0 + parms[8] ) / parms[9] );
605  temp += (parms[5] + parms[6] * (x - dx/10) ) / temp2;
606  temp /= 2.0;
607  B_[i] = temp;
608  // B_[i] = prevBentry;
609  } else {
610  B_[i] = (parms[5] + parms[6] * x ) / temp2;
611  // B_.table_[i] = ( parms[5] + parms[6] * x ) / temp2;
612  }
613  }
614  // There are cleaner ways to do this, but this keeps
615  // the relation to the GENESIS version clearer.
616  // Note the additional SINGULARITY check, to fix a bug
617  // in the earlier code.
618  if ( doTau == 0 && fabs( temp2 ) > SINGULARITY )
619  B_[i] += temp;
620 
621  prevAentry = A_[i];
622  prevBentry = B_[i];
623  x += dx;
624  }
625 
626  prevAentry = 0.0;
627  prevBentry = 0.0;
628  if ( doTau ) {
629  for( i = 0; i <= xdivs; i++ ) {
630  temp = A_[i];
631  temp2 = B_[i];
632  if ( fabs( temp ) < SINGULARITY ) {
633  A_[i] = prevAentry;
634  B_[i] = prevBentry;
635  } else {
636  A_[i] = temp2 / temp;
637  B_[i] = 1.0 / temp;
638  }
639  prevAentry = A_[i];
640  prevBentry = B_[i];
641  }
642  }
643 }
644 
650 void HHGate::tweakTables( bool doTau )
651 {
652  unsigned int i;
653  unsigned int size = A_.size();
654  assert( size == B_.size() );
655  if ( doTau ) {
656  for ( i = 0; i < size; i++ ) {
657  double temp = A_[ i ];
658  double temp2 = B_[ i ];
659  if ( fabs( temp ) < SINGULARITY ) {
660  if ( temp < 0.0 )
661  temp = -SINGULARITY;
662  else
663  temp = SINGULARITY;
664  }
665  A_[ i ] = temp2 / temp;
666  B_[ i ] = 1.0 / temp;
667  }
668  } else {
669  for ( i = 0; i < size; i++ )
670  B_[i] = A_[i] + B_[i];
671  }
672 }
673 
674 void HHGate::setupGate( const Eref& e,
675  vector< double > parms )
676 {
677  // The nine arguments are :
678  // A B C D F size min max isbeta
679  // If size == 0 then we check that the gate has already been allocated.
680  // If isbeta is true then we also have to do the conversion to
681  // HHGate form of alpha, alpha+beta, assuming that the alpha gate
682  // has already been setup. This uses tweakTables.
683  // We may need to resize the tables if they don't match here.
684  if ( !checkOriginal( e.id(), "setupGate" ) )
685  return;
686 
687  if ( parms.size() != 9 ) {
688  cout << "HHGate::setupGate: Error: parms.size() != 9\n";
689  return;
690  }
691 
692  double A = parms[0];
693  double B = parms[1];
694  double C = parms[2];
695  double D = parms[3];
696  double F = parms[4];
697  int size = static_cast< int > (parms[5] );
698  double min = parms[6];
699  double max = parms[7];
700  bool isBeta = static_cast< bool >( parms[8] );
701 
702  vector< double >& ip = ( isBeta ) ? B_ : A_;
703 
704  if ( size <= 0 ) { // Look up size, min, max from the interpol
705  size = ip.size() - 1;
706  if ( size <= 0 ) {
707  cout << "Error: setupGate has zero size\n";
708  return;
709  }
710  } else {
711  ip.resize( size + 1 );
712  }
713 
714  double dx = ( max - min ) / static_cast< double >( size );
715  double x = min + dx / 2.0;
716  for ( int i = 0; i <= size; i++ ) {
717  if ( fabs ( F ) < SINGULARITY ) {
718  ip[i] = 0.0;
719  } else {
720  double temp2 = C + exp( ( x + D ) / F );
721  if ( fabs( temp2 ) < SINGULARITY )
722  ip[i] = ip[i-1];
723  else
724  ip[i] = ( A + B * x ) / temp2;
725  }
726  }
727 
728  if ( isBeta ) {
729  assert( A_.size() > 0 );
730  // Here we ensure that the tables are the same size
731  if ( A_.size() != B_.size() ) {
732  if ( A_.size() > B_.size() ) {
733  // Note that the tabFill expects to allocate the
734  // terminating entry, so we put in size - 1.
735  tabFill( B_, A_.size() - 1, xmin_, xmax_ );
736  } else {
737  tabFill( A_, B_.size() - 1, xmin_, xmax_ );
738  }
739  }
740  // Then we do the tweaking to convert to HHChannel form.
741  tweakTables( 0 );
742  }
743 }
744 
746 // Utility funcs
748 
755 void HHGate::tabFill( vector< double >& table,
756  unsigned int newXdivs, double newXmin, double newXmax )
757 {
758  if ( newXdivs < 3 ) {
759  cout << "Error: tabFill: # divs must be >= 3. Not filling table.\n";
760  return;
761  }
762 
763  vector< double > old = table;
764  double newDx = ( newXmax - newXmin ) / newXdivs;
765  table.resize( newXdivs + 1 );
766  bool origLookupMode = lookupByInterpolation_;
768 
769  for( unsigned int i = 0; i <= newXdivs; ++i ) {
770  table[i] = lookupTable( table, newXmin + i * newDx );
771  }
772 
773  lookupByInterpolation_ = origLookupMode;
774 }
775 
776 bool HHGate::checkOriginal( Id id, const string& field ) const
777 {
778  if ( id == originalGateId_ )
779  return 1;
780 
781  cout << "Warning: HHGate: attempt to set field '" << field << "' on " <<
782  id.path() << "\nwhich is not the original Gate element. Ignored.\n";
783  return 0;
784 }
785 
787 {
788  return ( id == originalChanId_ );
789 }
790 
791 bool HHGate::isOriginalGate( Id id ) const
792 {
793  return ( id == originalGateId_ );
794 }
795 
797 {
798  return originalChanId_;
799 }
800 
802 {
803  return originalGateId_;
804 }
805 
807 {
808 }
809 
811 {
812 }
813 
815 {
816  if ( alpha_.size() == 0 || beta_.size() == 0 )
817  return;
818  vector< double > parms = alpha_;
819  parms.insert( parms.end(), beta_.begin(), beta_.end() );
820  parms.push_back( A_.size() );
821  parms.push_back( xmin_ );
822  parms.push_back( xmax_ );
823 
824  setupTables( parms, 0 );
825 }
vector< double > getTableB(const Eref &e) const
Definition: HHGate.cpp:463
Id id() const
Definition: Eref.cpp:62
vector< double > beta_
5 parameters for beta
Definition: HHGate.h:190
double getMin(const Eref &e) const
Definition: HHGate.cpp:378
Definition: HHGate.h:31
Id originalGateId_
Definition: HHGate.h:224
void setBeta(const Eref &e, vector< double > val)
Definition: HHGate.cpp:323
std::string path(const std::string &separator="/") const
Definition: Id.cpp:76
static const Cinfo * hhGateCinfo
Definition: HHGate.cpp:223
Definition: Dinfo.h:60
void setTableA(const Eref &e, vector< double > v)
Definition: HHGate.cpp:448
Definition: EpFunc.h:64
Id originalGateId() const
Definition: HHGate.cpp:801
void setUseInterpolation(const Eref &e, bool val)
Definition: HHGate.cpp:485
static const double SINGULARITY
Definition: HHGate.cpp:14
vector< double > getAlpha(const Eref &e) const
Definition: HHGate.cpp:298
double lookupA(double v) const
Definition: HHGate.cpp:265
double lookupB(double v) const
Definition: HHGate.cpp:270
vector< double > tau_
5 parameters for tau
Definition: HHGate.h:193
void tabFill(vector< double > &table, unsigned int newXdivs, double newXmin, double newXmax)
Definition: HHGate.cpp:755
void setTau(const Eref &e, vector< double > val)
Definition: HHGate.cpp:343
void setupTau(const Eref &e, vector< double > parms)
Definition: HHGate.cpp:524
vector< double > A_
The actual lookup table for calculations. Holds alpha(V).
Definition: HHGate.h:199
vector< double > getTau(const Eref &e) const
Definition: HHGate.cpp:338
vector< double > B_
The lookup table for calculations. Holds alpha(V) + beta(V).
Definition: HHGate.h:202
vector< double > getBeta(const Eref &e) const
Definition: HHGate.cpp:318
void updateAlphaBeta()
Definition: HHGate.cpp:806
double lookupTable(const vector< double > &tab, double v) const
Definition: HHGate.cpp:250
void lookupBoth(double v, double *A, double *B) const
Definition: HHGate.cpp:275
void tweakTau()
Definition: HHGate.cpp:541
void tweakAlpha()
Definition: HHGate.cpp:536
unsigned int getDivs(const Eref &e) const
Definition: HHGate.cpp:421
bool isDirectTable_
Definition: HHGate.h:238
vector< double > getMinfinity(const Eref &e) const
Definition: HHGate.cpp:358
vector< double > mInfinity_
5 parameters for mInfinity
Definition: HHGate.h:196
void updateTauMinf()
Definition: HHGate.cpp:810
static const Cinfo * initCinfo()
Definition: HHGate.cpp:16
void setMax(const Eref &e, double val)
Definition: HHGate.cpp:404
bool isOriginalGate(Id id) const
Definition: HHGate.cpp:791
Definition: Eref.h:26
void tweakTables(bool doTau)
Definition: HHGate.cpp:650
void setMin(const Eref &e, double val)
Definition: HHGate.cpp:383
vector< double > getAlphaParms(const Eref &e) const
Definition: HHGate.cpp:509
void setDivs(const Eref &e, unsigned int val)
Definition: HHGate.cpp:426
void updateTables()
Definition: HHGate.cpp:814
void setupAlpha(const Eref &e, vector< double > parms)
Definition: HHGate.cpp:491
vector< double > getTableA(const Eref &e) const
Definition: HHGate.cpp:443
double xmax_
Max of the voltage (or conc) range.
Definition: HHGate.h:208
void setupGate(const Eref &e, vector< double > parms)
Definition: HHGate.cpp:674
bool checkOriginal(Id id, const string &field) const
Definition: HHGate.cpp:776
void setTableB(const Eref &e, vector< double > v)
Definition: HHGate.cpp:468
Id originalChannelId() const
Definition: HHGate.cpp:796
bool getUseInterpolation(const Eref &e) const
Definition: HHGate.cpp:480
Definition: Id.h:17
void setAlpha(const Eref &e, vector< double > val)
Definition: HHGate.cpp:303
Definition: OpFunc.h:13
bool lookupByInterpolation_
Definition: HHGate.h:230
void setMinfinity(const Eref &e, vector< double > val)
Definition: HHGate.cpp:363
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
double xmin_
Minimum of the voltage (or conc) range.
Definition: HHGate.h:205
double invDx_
increment of the range.
Definition: HHGate.h:211
vector< double > alpha_
5 parameters for alpha
Definition: HHGate.h:187
void setupTables(const vector< double > &parms, bool doTau)
Definition: HHGate.cpp:551
Definition: Cinfo.h:18
double getMax(const Eref &e) const
Definition: HHGate.cpp:399
bool isOriginalChannel(Id id) const
Definition: HHGate.cpp:786
Definition: Finfo.h:12
HHGate()
Definition: HHGate.cpp:227
Id originalChanId_
Definition: HHGate.h:217