MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DifBuffer.cpp
Go to the documentation of this file.
1 // DifBuffer.cpp ---
2 //
3 // Filename: DifBuffer.cpp
4 // Description:
5 // Author: Subhasis Ray
6 // Maintainer:
7 // Created: Mon Feb 16 12:02:11 2015 (-0500)
8 // Version:
9 // Package-Requires: ()
10 // Last-Updated: Mon Feb 23 13:07:56 2015 (-0500)
11 // By: Subhasis Ray
12 // Update #: 130
13 // URL:
14 // Doc URL:
15 // Keywords:
16 // Compatibility:
17 //
18 //
19 
20 // Commentary:
21 //
22 //
23 //
24 //
25 
26 // Change Log:
27 // 5/25/16 Completing DifBuffer -- Asia J-Szmek (GMU)
28 // 9/21/16 rewrote DifBuffer to account for DifBufferBase (AJS)
29 //
30 //
31 // This program is free software: you can redistribute it and/or modify
32 // it under the terms of the GNU General Public License as published by
33 // the Free Software Foundation, either version 3 of the License, or (at
34 // your option) any later version.
35 //
36 // This program is distributed in the hope that it will be useful, but
37 // WITHOUT ANY WARRANTY; without even the implied warranty of
38 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 // General Public License for more details.
40 //
41 // You should have received a copy of the GNU General Public License
42 // along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
43 //
44 //
45 
46 // Code:
47 
48 #include "header.h"
49 #include "DifBufferBase.h"
50 #include "DifBuffer.h"
51 #include "ElementValueFinfo.h"
52 #include "../utility/numutil.h"
53 #include <cmath>
54 const double DifBuffer::EPSILON = 1.0e-10;
55 
56 
58 {
59 
60  static string doc[] = {
61  "Name", "DifBuffer",
62  "Author", "Subhasis Ray (ported from GENESIS2)",
63  "Description", "Models diffusible buffer where total concentration is constant. It is"
64  " coupled with a DifShell.",
65  };
66  static Dinfo<DifBuffer> dinfo;
67  static Cinfo difBufferCinfo(
68  "DifBuffer",
70  0,
71  0,
72  &dinfo,
73  doc,
74  sizeof(doc)/sizeof(string));
75 
76  return &difBufferCinfo;
77 }
78 
80 
81 
83 // Class functions
85 
87  activation_(0),
88  Af_(0),
89  Bf_(0),
90  bFree_(0),
91  bBound_(0),
92  prevFree_(0),
93  prevBound_(0),
94  bTot_(0),
95  kf_(0),
96  kb_(0),
97  D_(0),
98  shapeMode_(0),
99  length_(0),
100  diameter_(0),
101  thickness_(0),
102  volume_(0),
103  outerArea_(0),
104  innerArea_(0)
105 
106 {}
107 
109 // Field access functions
111 double DifBuffer::vGetActivation(const Eref& e) const
112 {
113  return activation_;
114 }
115 
116 void DifBuffer::vSetActivation(const Eref& e,double value)
117 {
118  if ( value < 0.0 ) {
119  cerr << "Error: DifBuffer: Activation cannot be negative!\n";
120  return;
121  }
122  activation_ = value;
123 }
124 
125 
126 double DifBuffer::vGetBFree(const Eref& e) const
127 {
128  return bFree_;
129 }
130 void DifBuffer::vSetBFree(const Eref& e,double value)
131 {
132  if ( value < 0.0 ) {
133  cerr << "Error: DifBuffer: Free Buffer cannot be negative!\n";
134  return;
135  }
136  if (value > bTot_){
137  cerr << "Error: DifBuffer: Free Buffer cannot exceed total buffer!\n";
138  return;
139  }
140  bFree_ = value;
141  bBound_ = bTot_ - bFree_;
142  prevFree_= bFree_;
144 
145 }
146 
147 double DifBuffer::vGetBBound(const Eref& e) const
148 {
149  return bBound_;
150 }
151 
152 void DifBuffer::vSetBBound(const Eref& e,double value)
153 {
154  if ( value < 0.0 ) {
155  cerr << "Error: DifBuffer: Bound Buffer cannot be negative!\n";
156  return;
157  }
158  if (value > bTot_){
159  cerr << "Error: DifBuffer: Bound Buffer cannot exceed total buffer!\n";
160  return;
161  }
162  bBound_ = value;
163  bFree_ = bTot_ - bBound_;
164  prevFree_= bFree_;
166 }
167 
168 
169 double DifBuffer::vGetBTot(const Eref& e) const
170 {
171  return bTot_;
172 }
173 
174 void DifBuffer::vSetBTot(const Eref& e,double value)
175 {
176  if ( value < 0.0 ) {
177  cerr << "Error: DifBuffer: Total buffer concentration cannot be negative!\n";
178  return;
179  }
180  bTot_ = value;
181  bFree_ = bTot_;
182  bBound_ = 0;
183 }
184 
185 
186 double DifBuffer::vGetKf(const Eref& e) const
187 {
188  return kf_;
189 }
190 
191 void DifBuffer::vSetKf(const Eref& e,double value)
192 {
193  if ( value < 0.0 ) {
194  cerr << "Error: DifBuffer: Kf cannot be negative!\n";
195  return;
196  }
197  kf_ = value;
198 }
199 
200 
201 double DifBuffer::vGetKb(const Eref& e) const
202 {
203  return kb_;
204 }
205 
206 void DifBuffer::vSetKb(const Eref& e,double value)
207 {
208  if ( value < 0.0 ) {
209  cerr << "Error: DifBuffer: Kb cannot be negative!\n";
210  return;
211  }
212  kb_ = value;
213 }
214 
215 double DifBuffer::vGetD(const Eref& e) const
216 {
217  return D_;
218 }
219 
220 void DifBuffer::vSetD(const Eref& e,double value)
221 {
222 
223  if ( value < 0.0 ) {
224  cerr << " Error: DifBuffer: Diffusion constant, D, cannot be negative!\n";
225  return;
226  }
227  D_ = value;
228 }
229 
230 
231 void DifBuffer::vSetShapeMode(const Eref& e, unsigned int shapeMode )
232 {
233  if ( shapeMode != 0 && shapeMode != 1 && shapeMode != 3 ) {
234  cerr << "Error: DifBuffer: I only understand shapeModes 0, 1 and 3.\n";
235  return;
236  }
237  shapeMode_ = shapeMode;
239 }
240 
241 unsigned int DifBuffer::vGetShapeMode(const Eref& e) const
242 {
243  return shapeMode_;
244 }
245 
246 void DifBuffer::vSetLength(const Eref& e, double length )
247 {
248  if ( length < 0.0 ) {
249  cerr << "Error: DifBuffer: length cannot be negative!\n";
250  return;
251  }
252 
253  length_ = length;
255 }
256 
257 double DifBuffer::vGetLength(const Eref& e ) const
258 {
259  return length_;
260 }
261 
262 void DifBuffer::vSetDiameter(const Eref& e, double diameter )
263 {
264  if ( diameter < 0.0 ) {
265  cerr << "Error: DifBuffer: diameter cannot be negative!\n";
266  return;
267  }
268 
269  diameter_ = diameter;
271 }
272 
273 double DifBuffer::vGetDiameter(const Eref& e ) const
274 {
275  return diameter_;
276 }
277 
278 void DifBuffer::vSetThickness( const Eref& e, double thickness )
279 {
280  if ( thickness < 0.0 ) {
281  cerr << "Error: DifBuffer: thickness cannot be negative!\n";
282  return;
283  }
284 
285  thickness_ = thickness;
287 }
288 
289 double DifBuffer::vGetThickness(const Eref& e) const
290 {
291  return thickness_;
292 }
293 
294 void DifBuffer::vSetVolume(const Eref& e, double volume )
295 {
296  if ( shapeMode_ != 3 )
297  cerr << "Warning: DifBuffer: Trying to set volume, when shapeMode is not USER-DEFINED\n";
298 
299  if ( volume < 0.0 ) {
300  cerr << "Error: DifBuffer: volume cannot be negative!\n";
301  return;
302  }
303 
304  volume_ = volume;
305 }
306 
307 double DifBuffer::vGetVolume(const Eref& e ) const
308 {
309  return volume_;
310 }
311 
312 void DifBuffer::vSetOuterArea(const Eref& e, double outerArea )
313 {
314  if (shapeMode_ != 3 )
315  cerr << "Warning: DifBuffer: Trying to set outerArea, when shapeMode is not USER-DEFINED\n";
316 
317  if ( outerArea < 0.0 ) {
318  cerr << "Error: DifBuffer: outerArea cannot be negative!\n";
319  return;
320  }
321 
322  outerArea_ = outerArea;
323 }
324 
325 double DifBuffer::vGetOuterArea(const Eref& e ) const
326 {
327  return outerArea_;
328 }
329 
330 void DifBuffer::vSetInnerArea(const Eref& e, double innerArea )
331 {
332  if ( shapeMode_ != 3 )
333  cerr << "Warning: DifBuffer: Trying to set innerArea, when shapeMode is not USER-DEFINED\n";
334 
335  if ( innerArea < 0.0 ) {
336  cerr << "Error: DifBuffer: innerArea cannot be negative!\n";
337  return;
338  }
339 
340  innerArea_ = innerArea;
341 }
342 
343 double DifBuffer::vGetInnerArea(const Eref& e) const
344 {
345  return innerArea_;
346 }
347 
348 
349 
350 
351 void DifBuffer::vBuffer(const Eref& e,
352  double C )
353 {
354  activation_ = C;
355  //cout<<"Buffer"<< C<<" ";
356 }
357 
358 
359 double DifBuffer::integrate( double state, double dt, double A, double B )
360 {
361  if ( B > EPSILON ) {
362  double x = exp( -B * dt );
363  return state * x + ( A / B ) * ( 1 - x );
364  }
365  return state + A * dt ;
366 }
368 {
369 double rOut = diameter_/2.;
370 
371  double rIn = rOut - thickness_;
372 
373  if (rIn <0)
374  rIn = 0.;
375 
376  switch ( shapeMode_ )
377  {
378  /*
379  * Onion Shell
380  */
381  case 0:
382  if ( length_ == 0.0 ) { // Spherical shell
383  volume_ = 4./3.* M_PI * ( rOut * rOut * rOut - rIn * rIn * rIn );
384  outerArea_ = 4*M_PI * rOut * rOut;
385  innerArea_ = 4*M_PI * rIn * rIn;
386  } else { // Cylindrical shell
387  volume_ = ( M_PI * length_ ) * ( rOut * rOut - rIn * rIn );
388  outerArea_ = 2*M_PI * rOut * length_;
389  innerArea_ = 2*M_PI * rIn * length_;
390  }
391 
392  break;
393 
394  /*
395  * Cylindrical Slice
396  */
397  case 1:
398  volume_ = M_PI * diameter_ * diameter_ * thickness_ / 4.0;
399  outerArea_ = M_PI * diameter_ * diameter_ / 4.0;
401  break;
402 
403  /*
404  * User defined
405  */
406  case 3:
407  // Nothing to be done here. Volume and inner-, outer areas specified by
408  // user.
409  break;
410 
411  default:
412  assert( 0 );
413  }
414 }
415 
416 void DifBuffer::vProcess( const Eref & e, ProcPtr p )
417 {
425  Af_ += kb_ * bBound_;
426  Bf_ += kf_ * activation_;
427 
429  bBound_ = bTot_ - bFree_;
430  prevFree_ = bFree_;
432 
439  innerDifSourceOut()->send( e, prevFree_, thickness_ );
440  outerDifSourceOut()->send( e, prevFree_, thickness_ );
441  reactionOut()->send(e,kf_,kb_,bFree_,bBound_);
442  Af_ = 0;
443  Bf_= 0;
444 
445 }
446 
447 void DifBuffer::vReinit( const Eref& e, ProcPtr p )
448 {
449 
450  Af_ = 0;
451  Bf_= 0;
452  double rOut = diameter_/2.;
453 
454  double rIn = rOut - thickness_;
455 
456  if (rIn<0)
457  rIn = 0.;
458  switch ( shapeMode_ )
459  {
460  /*
461  * Onion Shell
462  */
463  case 0:
464  if ( length_ == 0.0 ) { // Spherical shell
465  volume_ = 4./3.* M_PI * ( rOut * rOut * rOut - rIn * rIn * rIn );
466  outerArea_ = 4*M_PI * rOut * rOut;
467  innerArea_ = 4*M_PI * rIn * rIn;
468  } else { // Cylindrical shell
469  volume_ = ( M_PI * length_ ) * ( rOut * rOut - rIn * rIn );
470  outerArea_ = 2*M_PI * rOut * length_;
471  innerArea_ = 2*M_PI * rIn * length_;
472  }
473 
474  break;
475 
476  /*
477  * Cylindrical Slice
478  */
479  case 1:
480  volume_ = M_PI * diameter_ * diameter_ * thickness_ / 4.0;
481  outerArea_ = M_PI * diameter_ * diameter_ / 4.0;
483  break;
484 
485  /*
486  * User defined
487  */
488  case 3:
489  // Nothing to be done here. Volume and inner-, outer areas specified by
490  // user.
491  break;
492 
493  default:
494  assert( 0 );
495  }
496 
498  prevFree_ = bFree_;
499  bBound_ = bTot_ - bFree_;
501  innerDifSourceOut()->send( e, prevFree_, thickness_ );
502  outerDifSourceOut()->send( e, prevFree_, thickness_ );
503 
504 }
505 
506 void DifBuffer::vFluxFromIn(const Eref& e,double innerC, double innerThickness)
507 {
508  double dif = 2 * D_ / volume_* innerArea_ / (thickness_ + innerThickness);
509  Af_ += dif * innerC;
510  Bf_ += dif;
511 }
512 
513 void DifBuffer::vFluxFromOut(const Eref& e,double outerC, double outerThickness)
514 {
515  double dif = 2 * D_ / volume_* outerArea_ / (thickness_ + outerThickness);
516  Af_ += dif * outerC;
517  Bf_ += dif;
518 }
static const Cinfo * initCinfo()
unsigned int vGetShapeMode(const Eref &e) const
Definition: DifBuffer.cpp:241
void vProcess(const Eref &e, ProcPtr p)
Definition: DifBuffer.cpp:416
double vGetKf(const Eref &e) const
Definition: DifBuffer.cpp:186
uint32_t value
Definition: moosemodule.h:42
double vGetInnerArea(const Eref &e) const
Definition: DifBuffer.cpp:343
double kf_
Definition: DifBuffer.h:83
double prevBound_
Definition: DifBuffer.h:79
double activation_
Definition: DifBuffer.h:73
void vSetDiameter(const Eref &e, double diameter)
Definition: DifBuffer.cpp:262
double innerArea_
Definition: DifBuffer.h:92
double vGetLength(const Eref &e) const
Definition: DifBuffer.cpp:257
Definition: Dinfo.h:60
void vSetLength(const Eref &e, double length)
Definition: DifBuffer.cpp:246
double vGetBBound(const Eref &e) const
Definition: DifBuffer.cpp:147
double vGetVolume(const Eref &e) const
Definition: DifBuffer.cpp:307
void vSetKf(const Eref &e, double value)
Definition: DifBuffer.cpp:191
double length_
Definition: DifBuffer.h:87
double integrate(double state, double dt, double A, double B)
Definition: DifBuffer.cpp:359
static SrcFinfo4< double, double, double, double > * reactionOut()
double D_
Definition: DifBuffer.h:85
double kb_
Definition: DifBuffer.h:84
#define M_PI
Definition: numutil.h:34
void vSetBFree(const Eref &e, double value)
Definition: DifBuffer.cpp:130
static SrcFinfo2< double, double > * outerDifSourceOut()
void vBuffer(const Eref &e, double C)
Definition: DifBuffer.cpp:351
void vFluxFromIn(const Eref &e, double innerC, double innerThickness)
Definition: DifBuffer.cpp:506
void vSetOuterArea(const Eref &e, double outerArea)
Definition: DifBuffer.cpp:312
double vGetOuterArea(const Eref &e) const
Definition: DifBuffer.cpp:325
static const Cinfo * initCinfo()
Definition: DifBuffer.cpp:57
void vSetBTot(const Eref &e, double value)
Definition: DifBuffer.cpp:174
double prevFree_
Definition: DifBuffer.h:78
void vSetKb(const Eref &e, double value)
Definition: DifBuffer.cpp:206
double Bf_
Definition: DifBuffer.h:75
double vGetThickness(const Eref &e) const
Definition: DifBuffer.cpp:289
double volume_
Definition: DifBuffer.h:90
double vGetDiameter(const Eref &e) const
Definition: DifBuffer.cpp:273
void vSetD(const Eref &e, double value)
Definition: DifBuffer.cpp:220
double dt
Definition: ProcInfo.h:18
double vGetKb(const Eref &e) const
Definition: DifBuffer.cpp:201
double Af_
Definition: DifBuffer.h:74
Definition: Eref.h:26
void vSetShapeMode(const Eref &e, unsigned int shapeMode)
Definition: DifBuffer.cpp:231
void vSetActivation(const Eref &e, double value)
Definition: DifBuffer.cpp:116
void vSetThickness(const Eref &e, double thickness)
Definition: DifBuffer.cpp:278
double vGetBTot(const Eref &e) const
Definition: DifBuffer.cpp:169
void vReinit(const Eref &e, ProcPtr p)
Definition: DifBuffer.cpp:447
double vGetBFree(const Eref &e) const
Definition: DifBuffer.cpp:126
void vSetVolume(const Eref &e, double volume)
Definition: DifBuffer.cpp:294
double bBound_
Definition: DifBuffer.h:77
double diameter_
Definition: DifBuffer.h:88
double bTot_
Definition: DifBuffer.h:82
void vFluxFromOut(const Eref &e, double outerC, double outerThickness)
Definition: DifBuffer.cpp:513
static SrcFinfo2< double, double > * innerDifSourceOut()
void vSetInnerArea(const Eref &e, double innerArea)
Definition: DifBuffer.cpp:330
static const Cinfo * difBufferCinfo
Definition: DifBuffer.cpp:79
static const double EPSILON
Definition: DifBuffer.h:93
unsigned int shapeMode_
Definition: DifBuffer.h:86
double outerArea_
Definition: DifBuffer.h:91
double thickness_
Definition: DifBuffer.h:89
double vGetActivation(const Eref &e) const
Definition: DifBuffer.cpp:111
void vSetBBound(const Eref &e, double value)
Definition: DifBuffer.cpp:152
double vGetD(const Eref &e) const
Definition: DifBuffer.cpp:215
Definition: Cinfo.h:18
double bFree_
Definition: DifBuffer.h:76
void calculateVolumeArea(const Eref &e)
Definition: DifBuffer.cpp:367