MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ReacBase.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-2010 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 "lookupVolumeFromMesh.h"
13 #include "ReacBase.h"
14 
15 #define EPSILON 1e-15
16 
19  "subOut",
20  "Sends out increment of molecules on product each timestep"
21  );
22  return &subOut;
23 }
24 
27  "prdOut",
28  "Sends out increment of molecules on product each timestep"
29  );
30  return &prdOut;
31 }
32 
34 {
36  // Field Definitions
39  "numKf",
40  "Forward rate constant, in # units",
43  );
44 
46  "numKb",
47  "Reverse rate constant, in # units",
50  );
51 
53  "Kf",
54  "Forward rate constant, in concentration units",
57  );
58 
60  "Kb",
61  "Reverse rate constant, in concentration units",
64  );
65 
67  "numSubstrates",
68  "Number of substrates of reaction",
70  );
71 
73  "numProducts",
74  "Number of products of reaction",
76  );
77 
79  // MsgDest Definitions
81  static DestFinfo process( "process",
82  "Handles process call",
84  static DestFinfo reinit( "reinit",
85  "Handles reinit call",
87 
89  // Shared Msg Definitions
91 
92  static DestFinfo subDest( "subDest",
93  "Handles # of molecules of substrate",
95  static DestFinfo prdDest( "prdDest",
96  "Handles # of molecules of product",
98  static Finfo* subShared[] = {
99  subOut(), &subDest
100  };
101  static Finfo* prdShared[] = {
102  prdOut(), &prdDest
103  };
104  static SharedFinfo sub( "sub",
105  "Connects to substrate pool",
106  subShared, sizeof( subShared ) / sizeof( const Finfo* )
107  );
108  static SharedFinfo prd( "prd",
109  "Connects to substrate pool",
110  prdShared, sizeof( prdShared ) / sizeof( const Finfo* )
111  );
112  static Finfo* procShared[] = {
113  &process, &reinit
114  };
115  static SharedFinfo proc( "proc",
116  "Shared message for process and reinit",
117  procShared, sizeof( procShared ) / sizeof( const Finfo* )
118  );
119 
120 
121  static Finfo* reacFinfos[] = {
122  &kf, // Value
123  &kb, // Value
124  &Kf, // Value
125  &Kb, // Value
126  &numSub, // ReadOnlyValue
127  &numPrd, // ReadOnlyValue
128  &sub, // SharedFinfo
129  &prd, // SharedFinfo
130  &proc, // SharedFinfo
131  };
132 
133  static string doc[] =
134  {
135  "Name", "ReacBase",
136  "Author", "Upinder S. Bhalla, 2012, NCBS",
137  "Description", "Base class for reactions. Provides the MOOSE API"
138  "functions, but ruthlessly refers almost all of them to derived"
139  "classes, which have to provide the man page output."
140  };
141 
142  static ZeroSizeDinfo< int> dinfo;
143  static Cinfo reacBaseCinfo (
144  "ReacBase",
146  reacFinfos,
147  sizeof( reacFinfos ) / sizeof ( Finfo* ),
148  &dinfo,
149  doc,
150  sizeof( doc ) / sizeof( string ),
151  true // Ban creation, this is an abstract base class.
152  );
153 
154  return &reacBaseCinfo;
155 }
156 
158 
160 // ReacBase internal functions
162 
163 
165  : concKf_( 0.1 ), concKb_( 0.2 )
166 {
167  ;
168 }
169 
171 {;}
172 
174 // MsgDest Definitions
176 
177 void ReacBase::sub( double v )
178 {
179  vSub( v );
180 }
181 
182 void ReacBase::prd( double v )
183 {
184  vPrd( v );
185 }
186 
187 void ReacBase::process( const Eref& e, ProcPtr p )
188 {
189  vProcess( e, p );
190 }
191 
192 void ReacBase::reinit( const Eref& e, ProcPtr p )
193 {
194  vReinit( e, p );
195 }
196 
197 void ReacBase::remesh( const Eref& e )
198 {
199  vRemesh( e );
200 }
202 //
203 // Virtual MsgDest Definitions, all dummies, but many derived classes
204 // will want to use these dummies.
206 
207 void ReacBase::vSub( double v )
208 {
209  ;
210 }
211 
212 void ReacBase::vPrd( double v )
213 {
214  ;
215 }
216 
217 void ReacBase::vProcess( const Eref& e, ProcPtr p )
218 {
219  ;
220 }
221 
222 void ReacBase::vReinit( const Eref& e, ProcPtr p )
223 {
224  ;
225 }
226 
227 void ReacBase::vRemesh( const Eref& e )
228 {
229  ;
230 }
231 
233 // Field Definitions
235 
236 void ReacBase::setNumKf( const Eref& e, double v )
237 {
238  vSetNumKf( e, v );
239 }
240 
241 double ReacBase::getNumKf( const Eref& e) const
242 {
243  return vGetNumKf( e );
244 }
245 
246 void ReacBase::setNumKb( const Eref& e, double v )
247 {
248  vSetNumKb( e, v );
249 }
250 
251 double ReacBase::getNumKb( const Eref& e ) const
252 {
253  return vGetNumKb( e );
254 }
255 
257 
258 void ReacBase::setConcKf( const Eref& e, double v )
259 {
260  vSetConcKf( e, v );
261 }
262 
263 double ReacBase::getConcKf( const Eref& e ) const
264 {
265  return vGetConcKf( e );
266 }
267 
268 void ReacBase::setConcKb( const Eref& e, double v )
269 {
270  vSetConcKb( e, v );
271 }
272 
273 double ReacBase::getConcKb( const Eref& e ) const
274 {
275  return vGetConcKb( e );
276 }
277 
278 unsigned int ReacBase::getNumSub( const Eref& e ) const
279 {
280  const vector< MsgFuncBinding >* mfb =
281  e.element()->getMsgAndFunc( subOut()->getBindIndex() );
282  assert( mfb );
283  return ( mfb->size() );
284 }
285 
286 unsigned int ReacBase::getNumPrd( const Eref& e ) const
287 {
288  const vector< MsgFuncBinding >* mfb =
289  e.element()->getMsgAndFunc( prdOut()->getBindIndex() );
290  assert( mfb );
291  return ( mfb->size() );
292 }
293 
295 // Zombie conversion routine to convert between Reac subclasses.
297 // static func
298 
299 void ReacBase::zombify( Element* orig, const Cinfo* zClass, Id solver )
300 {
301  if ( orig->cinfo() == zClass )
302  return;
303  unsigned int start = orig->localDataStart();
304  unsigned int num = orig->numLocalData();
305  if ( num == 0 )
306  return;
307  vector< double > concKf( num, 0.0 );
308  vector< double > concKb( num, 0.0 );
309  for ( unsigned int i = 0; i < num; ++i ) {
310  Eref er( orig, i + start );
311  const ReacBase* rb =
312  reinterpret_cast< const ReacBase* >( er.data() );
313  concKf[ i ] = rb->getConcKf( er );
314  concKb[ i ] = rb->getConcKb( er );
315  }
316  orig->zombieSwap( zClass );
317  for ( unsigned int i = 0; i < num; ++i ) {
318  Eref er( orig, i + start );
319  ReacBase* rb = reinterpret_cast< ReacBase* >( er.data() );
320  rb->setSolver( solver, orig->id() );
321  rb->setConcKf( er, concKf[i] );
322  rb->setConcKb( er, concKb[i] );
323  }
324 }
325 
326 // Virtual func: default does nothing.
327 void ReacBase::setSolver( Id solver, Id orig )
328 {
329  ;
330 }
331 
unsigned int getNumSub(const Eref &e) const
Get number of substrates.
Definition: ReacBase.cpp:278
void sub(double v)
Definition: ReacBase.cpp:177
char * data() const
Definition: Eref.cpp:41
virtual double vGetConcKf(const Eref &e) const =0
void setNumKb(const Eref &e, double v)
Definition: ReacBase.cpp:246
double getNumKb(const Eref &e) const
Definition: ReacBase.cpp:251
virtual double vGetNumKf(const Eref &e) const =0
void prd(double v)
Definition: ReacBase.cpp:182
void reinit(const Eref &e, ProcPtr p)
Definition: ReacBase.cpp:192
static void zombify(Element *original, const Cinfo *zClass, Id solver)
Definition: ReacBase.cpp:299
void remesh(const Eref &e)
Definition: ReacBase.cpp:197
virtual void vSub(double v)
Definition: ReacBase.cpp:207
virtual void zombieSwap(const Cinfo *zCinfo)
virtual func, this base version must be called by all derived classes
Definition: Element.cpp:159
Element * element() const
Definition: Eref.h:42
static SrcFinfo2< double, double > * subOut()
Definition: ReacBase.cpp:17
void setConcKf(const Eref &e, double v)
set Kf in concentration units
Definition: ReacBase.cpp:258
virtual void vSetConcKf(const Eref &e, double v)=0
Id id() const
Definition: Element.cpp:71
double getNumKf(const Eref &e) const
Definition: ReacBase.cpp:241
virtual void vProcess(const Eref &e, ProcPtr p)
Definition: ReacBase.cpp:217
void setConcKb(const Eref &e, double v)
set Kb in concentration units
Definition: ReacBase.cpp:268
virtual double vGetNumKb(const Eref &e) const =0
unsigned int getNumPrd(const Eref &e) const
Get number of products.
Definition: ReacBase.cpp:286
static const Cinfo * initCinfo()
Definition: ReacBase.cpp:33
virtual void vReinit(const Eref &e, ProcPtr p)
Definition: ReacBase.cpp:222
virtual void vRemesh(const Eref &e)
Definition: ReacBase.cpp:227
Definition: OpFunc.h:27
Definition: Eref.h:26
virtual void vSetConcKb(const Eref &e, double v)=0
const vector< MsgFuncBinding > * getMsgAndFunc(BindIndex b) const
Definition: Element.cpp:300
const Cinfo * cinfo() const
Definition: Element.cpp:66
double getConcKf(const Eref &e) const
get Kf in concentration units
Definition: ReacBase.cpp:263
virtual ~ReacBase()
Definition: ReacBase.cpp:170
virtual void vPrd(double v)
Definition: ReacBase.cpp:212
virtual unsigned int localDataStart() const =0
Returns index of first data entry on this node.
virtual unsigned int numLocalData() const =0
Returns number of local data entries on this node.
virtual void setSolver(Id solver, Id orig)
Assign solver info.
Definition: ReacBase.cpp:327
double getConcKb(const Eref &e) const
get Kb in concentration units
Definition: ReacBase.cpp:273
Definition: Id.h:17
virtual void vSetNumKb(const Eref &e, double v)=0
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
static const Cinfo * reacBaseCinfo
Definition: ReacBase.cpp:157
void process(const Eref &e, ProcPtr p)
Definition: ReacBase.cpp:187
virtual double vGetConcKb(const Eref &e) const =0
static SrcFinfo2< double, double > * prdOut()
Definition: ReacBase.cpp:25
Definition: Cinfo.h:18
virtual void vSetNumKf(const Eref &e, double v)=0
void setNumKf(const Eref &e, double v)
Definition: ReacBase.cpp:236
Definition: Finfo.h:12