MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DifShell.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-2008
5  ** Upinder S. Bhalla, Niraj Dudani and NCBS
6  ** It is made available under the terms of the
7  ** GNU Lesser General Public License version 2.1
8  ** See the file COPYING.LIB for the full notice.
9  **********************************************************************/
10 
11 #include "header.h"
12 #include "DifShellBase.h"
13 #include "DifShell.h"
14 
15 
16 const double DifShell::EPSILON = 1.0e-10;
17 const double DifShell::F = 96485.3415; /* C / mol like in genesis */
18 
20 {
21 
22 
23  static string doc[] =
24  {
25  "Name", "DifShell",
26  "Author", "Niraj Dudani. Ported to async13 by Subhasis Ray. Rewritten by Asia Jedrzejewska-Szmek",
27  "Description", "DifShell object: Models diffusion of an ion (typically calcium) within an "
28  "electric compartment. A DifShell is an iso-concentration region with respect to "
29  "the ion. Adjoining DifShells exchange flux of this ion, and also keep track of "
30  "changes in concentration due to pumping, buffering and channel currents, by "
31  "talking to the appropriate objects.",
32  };
33  static Dinfo< DifShell > dinfo;
34  static Cinfo difShellCinfo(
35  "DifShell",
37  0,
38  0,
39  &dinfo,
40  doc,
41  sizeof( doc ) / sizeof( string ));
42 
43  return &difShellCinfo;
44 }
45 
46 //Cinfo *object* corresponding to the class.
48 
50 // Class functions
52 
54 
55 
57  dCbyDt_( 0.0 ),
58  Cmultiplier_(0.0),
59  C_( 0.0 ),
60  Ceq_( 0.0 ),
61  prevC_(0.0),
62  D_( 0.0 ),
63  valence_( 0.0 ),
64  leak_( 0.0 ),
65  shapeMode_(0),
66  length_(0),
67  diameter_(0),
68  thickness_(0),
69  volume_(0),
70  outerArea_(0),
71  innerArea_(0)
72 { ; }
73 
75 // Field access functions
78 
79 
80 void DifShell::vSetC( const Eref& e, double C)
81 {
82  if ( C < 0.0 ) {
83  cerr << "Error: DifShell: C cannot be negative!\n";
84  return;
85  }
86 
87  C_ = C;
88  prevC_ = C_;
89 }
90 double DifShell::vGetC(const Eref& e) const
91 {
92  return C_;
93 }
94 
95 void DifShell::vSetCeq( const Eref& e, double Ceq )
96 {
97  if ( Ceq < 0.0 ) {
98  cerr << "Error: DifShell: Ceq cannot be negative!\n";
99  return;
100  }
101 
102  Ceq_ = Ceq;
103  prevC_ = Ceq;
104  C_ = Ceq;
105 }
106 
107 double DifShell::vGetCeq(const Eref& e ) const
108 {
109  return Ceq_;
110 }
111 
112 void DifShell::vSetD(const Eref& e, double D )
113 {
114  if ( D < 0.0 ) {
115  cerr << "Error: DifShell: D cannot be negative!\n";
116  return;
117  }
118 
119  D_ = D;
120 }
121 
122 double DifShell::vGetD(const Eref& e ) const
123 {
124  return D_;
125 }
126 
127 void DifShell::vSetValence(const Eref& e, double valence )
128 {
129  if ( valence < 0.0 ) {
130  cerr << "Error: DifShell: valence cannot be negative!\n";
131  return;
132  }
133 
134  valence_ = valence;
135 }
136 
137 double DifShell::vGetValence(const Eref& e ) const
138 {
139  return valence_;
140 }
141 
142 void DifShell::vSetLeak(const Eref& e, double leak )
143 {
144  leak_ = leak;
145 }
146 
147 double DifShell::vGetLeak(const Eref& e ) const
148 {
149  return leak_;
150 }
151 
152 
153 void DifShell::vSetShapeMode(const Eref& e, unsigned int shapeMode )
154 {
155  if ( shapeMode != 0 && shapeMode != 1 && shapeMode != 3 ) {
156  cerr << "Error: DifShell: I only understand shapeModes 0, 1 and 3.\n";
157  return;
158  }
159  shapeMode_ = shapeMode;
161 }
162 
163 unsigned int DifShell::vGetShapeMode(const Eref& e) const
164 {
165  return shapeMode_;
166 }
167 
168 void DifShell::vSetLength(const Eref& e, double length )
169 {
170  if ( length < 0.0 ) {
171  cerr << "Error: DifShell: length cannot be negative!\n";
172  return;
173  }
174 
175  length_ = length;
177 }
178 
179 double DifShell::vGetLength(const Eref& e ) const
180 {
181  return length_;
182 }
183 
184 void DifShell::vSetDiameter(const Eref& e, double diameter )
185 {
186  if ( diameter < 0.0 ) {
187  cerr << "Error: DifShell: diameter cannot be negative!\n";
188  return;
189  }
190 
191  diameter_ = diameter;
193 }
194 
195 double DifShell::vGetDiameter(const Eref& e ) const
196 {
197  return diameter_;
198 }
199 
200 void DifShell::vSetThickness( const Eref& e, double thickness )
201 {
202  if ( thickness < 0.0 ) {
203  cerr << "Error: DifShell: thickness cannot be negative!\n";
204  return;
205  }
206 
207  thickness_ = thickness;
209 }
210 
211 double DifShell::vGetThickness(const Eref& e) const
212 {
213  return thickness_;
214 }
215 
216 void DifShell::vSetVolume(const Eref& e, double volume )
217 {
218  if ( shapeMode_ != 3 )
219  cerr << "Warning: DifShell: Trying to set volume, when shapeMode is not USER-DEFINED\n";
220 
221  if ( volume < 0.0 ) {
222  cerr << "Error: DifShell: volume cannot be negative!\n";
223  return;
224  }
225 
226  volume_ = volume;
227 }
228 
229 double DifShell::vGetVolume(const Eref& e ) const
230 {
231  return volume_;
232 }
233 
234 void DifShell::vSetOuterArea(const Eref& e, double outerArea )
235 {
236  if (shapeMode_ != 3 )
237  cerr << "Warning: DifShell: Trying to set outerArea, when shapeMode is not USER-DEFINED\n";
238 
239  if ( outerArea < 0.0 ) {
240  cerr << "Error: DifShell: outerArea cannot be negative!\n";
241  return;
242  }
243 
244  outerArea_ = outerArea;
245 }
246 
247 double DifShell::vGetOuterArea(const Eref& e ) const
248 {
249  return outerArea_;
250 }
251 
252 void DifShell::vSetInnerArea(const Eref& e, double innerArea )
253 {
254  if ( shapeMode_ != 3 )
255  cerr << "Warning: DifShell: Trying to set innerArea, when shapeMode is not USER-DEFINED\n";
256 
257  if ( innerArea < 0.0 ) {
258  cerr << "Error: DifShell: innerArea cannot be negative!\n";
259  return;
260  }
261 
262  innerArea_ = innerArea;
263 }
264 
265 double DifShell::vGetInnerArea(const Eref& e) const
266 {
267  return innerArea_;
268 }
269 
270 
271 
273 // Local dest functions
275 double DifShell::integrate( double state, double dt, double A, double B )
276 {
277  if ( B > EPSILON ) {
278  double x = exp( -B * dt );
279  return state * x + ( A / B ) * ( 1 - x );
280  }
281 
282  return state + A * dt ;
283 }
284 
286 {
287 double rOut = diameter_/2.;
288 
289  double rIn = rOut - thickness_;
290 
291  if (rIn <0)
292  rIn = 0.;
293 
294  switch ( shapeMode_ )
295  {
296  /*
297  * Onion Shell
298  */
299  case 0:
300  if ( length_ == 0.0 ) { // Spherical shell
301  volume_ = 4./3.* M_PI * ( rOut * rOut * rOut - rIn * rIn * rIn );
302  outerArea_ = 4*M_PI * rOut * rOut;
303  innerArea_ = 4*M_PI * rIn * rIn;
304  } else { // Cylindrical shell
305  volume_ = ( M_PI * length_ ) * ( rOut * rOut - rIn * rIn );
306  outerArea_ = 2*M_PI * rOut * length_;
307  innerArea_ = 2*M_PI * rIn * length_;
308  }
309 
310  break;
311 
312  /*
313  * Cylindrical Slice
314  */
315  case 1:
316  volume_ = M_PI * diameter_ * diameter_ * thickness_ / 4.0;
317  outerArea_ = M_PI * diameter_ * diameter_ / 4.0;
319  break;
320 
321  /*
322  * User defined
323  */
324  case 3:
325  // Nothing to be done here. Volume and inner-, outer areas specified by
326  // user.
327  break;
328 
329  default:
330  assert( 0 );
331  }
332 }
333 
334 void DifShell::vReinit( const Eref& e, ProcPtr p )
335 {
336  dCbyDt_ = leak_;
337  Cmultiplier_ = 0;
339 
340  C_= Ceq_;
341  prevC_ = Ceq_;
342  concentrationOut()->send( e, C_ );
343  innerDifSourceOut()->send( e, prevC_, thickness_ );
344  outerDifSourceOut()->send( e, prevC_, thickness_ );
345 
346 }
347 
348 void DifShell::vProcess( const Eref & e, ProcPtr p )
349 {
357 
366  dCbyDt_ = leak_;
367  Cmultiplier_ = 0;
368  prevC_ = C_;
369 
370  innerDifSourceOut()->send( e, prevC_, thickness_ );
371  outerDifSourceOut()->send( e, prevC_, thickness_ );
372 
373  concentrationOut()->send( e, C_ );
374 
375 }
376 void DifShell::vBuffer(const Eref& e,
377  double kf,
378  double kb,
379  double bFree,
380  double bBound )
381 {
382  dCbyDt_ += kb * bBound;
383  Cmultiplier_ += kf * bFree;
384 }
385 
386 void DifShell::vFluxFromOut(const Eref& e, double outerC, double outerThickness )
387 {
388  double diff =2.* D_ /volume_ * outerArea_ / (outerThickness + thickness_) ;
389  //influx from outer shell
395  dCbyDt_ += diff * outerC;
396  Cmultiplier_ += diff ;
397 
398 }
399 
400 void DifShell::vFluxFromIn(const Eref& e, double innerC, double innerThickness )
401 {
402  //influx from inner shell
403  //double dx = ( innerThickness + thickness_ ) / 2.0;
404  double diff = 2.* D_/volume_ * innerArea_ / (innerThickness + thickness_);
405 
406  dCbyDt_ += diff * innerC ;
407  Cmultiplier_ += diff ;
408 }
409 
410 void DifShell::vInflux(const Eref& e, double I )
411 {
417  dCbyDt_ += I / ( F * valence_ * volume_ );
418 
419 }
420 
424 void DifShell::vOutflux(const Eref& e, double I )
425 {
426  dCbyDt_ -= I / ( F * valence_ * volume_ );
427 }
428 
429 void DifShell::vFInflux(const Eref& e, double I, double fraction )
430 {
431  dCbyDt_ += fraction * I / ( F * valence_ * volume_ );
432 }
433 
434 void DifShell::vFOutflux(const Eref& e, double I, double fraction )
435 {
436  dCbyDt_ -= fraction * I / ( F * valence_ * volume_ );
437 }
438 
439 void DifShell::vStoreInflux(const Eref& e, double flux )
440 {
441  dCbyDt_ += flux / volume_;
442 }
443 
444 void DifShell::vStoreOutflux(const Eref& e, double flux )
445 {
446  dCbyDt_ -= flux / volume_;
447 }
448 
449 void DifShell::vTauPump(const Eref& e, double kP, double Ceq )
450 {
451  //dCbyDt_ += -kP * ( C_ - Ceq );
452  dCbyDt_ += kP*Ceq;
453  Cmultiplier_ -= kP;
454 }
455 
459 void DifShell::vEqTauPump(const Eref& e, double kP )
460 {
461  dCbyDt_ += kP*Ceq_;
462  Cmultiplier_ -= kP;
463 }
464 
465 void DifShell::vMMPump(const Eref& e, double vMax, double Kd )
466 {
467  Cmultiplier_ += ( vMax / volume_ ) / ( C_ + Kd ) ;
468 
469 }
470 
471 void DifShell::vHillPump(const Eref& e, double vMax, double Kd, unsigned int hill )
472 {
473  //This needs fixing
474  double ch;
475  switch( hill )
476  {
477  case 0:
478  ch = 1.0;
479  break;
480  case 1:
481  ch = C_;
482  break;
483  case 2:
484  ch = C_ * C_;
485  break;
486  case 3:
487  ch = C_ * C_ * C_;
488  break;
489  case 4:
490  ch = C_ * C_;
491  ch = ch * ch;
492  break;
493  default:
494  ch = pow( C_, static_cast< double >( hill ) );
495  };
496 
497  dCbyDt_ += -( vMax / volume_ ) * ( ch / ( ch + Kd ) );
498 }
499 
501 
502 
static const Cinfo * initCinfo()
void vSetThickness(const Eref &e, double thickness)
Definition: DifShell.cpp:200
void vSetLength(const Eref &e, double length)
Definition: DifShell.cpp:168
void vSetDiameter(const Eref &e, double diameter)
Definition: DifShell.cpp:184
void vSetD(const Eref &e, double D)
Definition: DifShell.cpp:112
double leak_
Definition: DifShell.h:93
void vEqTauPump(const Eref &e, double kP)
Definition: DifShell.cpp:459
double valence_
Definition: DifShell.h:92
double dCbyDt_
Definition: DifShell.h:86
static const Cinfo * initCinfo()
Definition: DifShell.cpp:19
Definition: Dinfo.h:60
void vInflux(const Eref &e, double I)
Definition: DifShell.cpp:410
void vHillPump(const Eref &e, double vMax, double Kd, unsigned int hill)
Definition: DifShell.cpp:471
double innerArea_
Definition: DifShell.h:100
double vGetC(const Eref &e) const
Definition: DifShell.cpp:90
void vFOutflux(const Eref &e, double I, double fraction)
Definition: DifShell.cpp:434
unsigned int vGetShapeMode(const Eref &e) const
Definition: DifShell.cpp:163
void vSetShapeMode(const Eref &e, unsigned int shapeMode)
Definition: DifShell.cpp:153
static SrcFinfo1< double > * concentrationOut()
void vFInflux(const Eref &e, double I, double fraction)
Definition: DifShell.cpp:429
double integrate(double state, double dt, double A, double B)
Definition: DifShell.cpp:275
static const double F
Faraday's constant (Coulomb / Mole)
Definition: DifShell.h:104
#define M_PI
Definition: numutil.h:34
void vProcess(const Eref &e, ProcPtr p)
Definition: DifShell.cpp:348
static const Cinfo * difShellCinfo
Definition: DifShell.cpp:47
double outerArea_
Definition: DifShell.h:99
void vReinit(const Eref &e, ProcPtr p)
Definition: DifShell.cpp:334
void vTauPump(const Eref &e, double kP, double Ceq)
Definition: DifShell.cpp:449
double Ceq_
Definition: DifShell.h:89
double vGetValence(const Eref &e) const
Definition: DifShell.cpp:137
double thickness_
Definition: DifShell.h:97
void vSetLeak(const Eref &e, double leak)
Definition: DifShell.cpp:142
void vSetVolume(const Eref &e, double volume)
Definition: DifShell.cpp:216
void vFluxFromOut(const Eref &e, double outerC, double outerThickness)
Definition: DifShell.cpp:386
void vSetValence(const Eref &e, double valence)
Definition: DifShell.cpp:127
void vFluxFromIn(const Eref &e, double innerC, double innerThickness)
Definition: DifShell.cpp:400
static SrcFinfo2< double, double > * innerDifSourceOut()
void vSetC(const Eref &e, double C)
C is a read-only field.
Definition: DifShell.cpp:80
void vBuffer(const Eref &e, double kf, double kb, double bFree, double bBound)
Definition: DifShell.cpp:376
double dt
Definition: ProcInfo.h:18
void vMMPump(const Eref &e, double vMax, double Kd)
Definition: DifShell.cpp:465
Definition: Eref.h:26
double prevC_
Definition: DifShell.h:90
double vGetDiameter(const Eref &e) const
Definition: DifShell.cpp:195
double vGetVolume(const Eref &e) const
Definition: DifShell.cpp:229
DifShell()
Faraday's constant (Coulomb / Mole)
Definition: DifShell.cpp:56
static const double EPSILON
Definition: DifShell.h:102
double vGetThickness(const Eref &e) const
Definition: DifShell.cpp:211
double vGetLength(const Eref &e) const
Definition: DifShell.cpp:179
double C_
Definition: DifShell.h:88
double Cmultiplier_
Definition: DifShell.h:87
void vStoreInflux(const Eref &e, double flux)
Definition: DifShell.cpp:439
void vSetInnerArea(const Eref &e, double innerArea)
Definition: DifShell.cpp:252
void vStoreOutflux(const Eref &e, double flux)
Definition: DifShell.cpp:444
double vGetInnerArea(const Eref &e) const
Definition: DifShell.cpp:265
double vGetOuterArea(const Eref &e) const
Definition: DifShell.cpp:247
double D_
Definition: DifShell.h:91
double vGetLeak(const Eref &e) const
Definition: DifShell.cpp:147
void calculateVolumeArea(const Eref &e)
Definition: DifShell.cpp:285
void vOutflux(const Eref &e, double I)
Definition: DifShell.cpp:424
void vSetCeq(const Eref &e, double Ceq)
Definition: DifShell.cpp:95
static SrcFinfo2< double, double > * outerDifSourceOut()
double volume_
Definition: DifShell.h:98
double length_
Definition: DifShell.h:95
double diameter_
Definition: DifShell.h:96
unsigned int shapeMode_
Definition: DifShell.h:94
double vGetD(const Eref &e) const
Definition: DifShell.cpp:122
void vSetOuterArea(const Eref &e, double outerArea)
Definition: DifShell.cpp:234
Definition: Cinfo.h:18
double vGetCeq(const Eref &e) const
Definition: DifShell.cpp:107