MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FuncRateTerm.h
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment,
4 ** also known as GENESIS 3 base code.
5 ** copyright (C) 2003-2010 Upinder S. Bhalla. 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 
22 class FuncRate: public ExternReac
23 {
24  public:
25  FuncRate( double k, unsigned int targetPoolIndex )
26  : k_( k ), funcVolPower_( 0.0 )
27  {
28  func_.setTarget( targetPoolIndex );
29  }
30 
31  double operator() ( const double* S ) const {
32  double t = Field< double >::get( Id(1), "currentTime" );
33  return func_( S, t ); // get rate from func calculation.
34  }
35 
36  unsigned int getReactants( vector< unsigned int >& molIndex ) const{
37  molIndex.resize( 1 );
38  molIndex[0] = func_.getTarget();
39 
40  // This is the number of substrates to the reac. It is zero.
41  return 0;
42  // The target molecule is handled as a product.
43  }
44 
45  void setReactants( const vector< unsigned int >& molIndex ) {
46  assert( molIndex.size() > 0 );
47  func_.setTarget( molIndex[0] );
48  }
49 
50  const vector< unsigned int >& getFuncArgIndex()
51  {
52  return func_.getReactantIndex();
53  }
54 
55  void setFuncArgIndex( const vector< unsigned int >& mol ) {
56  func_.setReactantIndex( mol );
57  }
58 
59  void setExpr( const string& s ) {
60  func_.setExpr( s );
61  }
62  const string& getExpr() const {
63  return func_.getExpr();
64  }
65 
67  double vol, double sub, double prd ) const
68  {
69  double ratio = sub * pow( NA * vol, funcVolPower_ );
70  FuncRate* ret = new FuncRate( k_ / ratio, func_.getTarget() );
72  ret->func_ = func_;
73  // return new FuncRate( k_ / ratio );
74  return ret;
75  }
76 
77  protected:
79  double k_;
80  double funcVolPower_;
81 
82 };
83 
84 
99 class FuncReac: public FuncRate
100 {
101  public:
102  FuncReac( double k, vector< unsigned int > v )
103  : FuncRate( k, 0 ),
104  v_( v )
105  {;}
106 
107  double operator() ( const double* S ) const {
108  // double ret = k_ * func_( S, 0.0 ); // get rate from func calculation.
109  double ret = func_( S, 0.0 ); // get rate from func calculation.
110  vector< unsigned int >::const_iterator i;
111  for ( i = v_.begin(); i != v_.end(); i++) {
112  assert( !std::isnan( S[ *i ] ) );
113  ret *= S[ *i ];
114  }
115  return ret;
116  }
117 
118  unsigned int getReactants( vector< unsigned int >& molIndex ) const{
119  molIndex = v_;
120  return numSubstrates_;
121  }
122 
123  void setReactants( const vector< unsigned int >& molIndex ) {
124  v_ = molIndex;
125  }
126 
127  void rescaleVolume( short comptIndex,
128  const vector< short >& compartmentLookup, double ratio )
129  {
130  for ( unsigned int i = 1; i < v_.size(); ++i ) {
131  if ( comptIndex == compartmentLookup[ v_[i] ] )
132  k_ /= ratio;
133  }
134  }
135 
136 
138  double vol, double sub, double prd ) const
139  {
140  assert( v_.size() > 0 );
141  double ratio = sub * pow( NA * vol,
142  funcVolPower_ + (int)( v_.size() ) - 1 );
143  FuncReac* ret = new FuncReac( k_ / ratio, v_ );
144  ret->func_ = func_;
146  return ret;
147  // return new FuncReac( k_ / ratio, v_ );
148  }
149 
150  private:
151  vector< unsigned int > v_;
152  unsigned int numSubstrates_;
153 };
154 
void setExpr(const string &e)
Definition: FuncTerm.cpp:83
double operator()(const double *S) const
Computes the rate. The argument is the molecule array.
Definition: FuncRateTerm.h:31
unsigned int getReactants(vector< unsigned int > &molIndex) const
Definition: FuncRateTerm.h:118
const double NA
Definition: consts.cpp:15
const unsigned int getTarget() const
Definition: FuncTerm.cpp:105
FuncTerm func_
Definition: FuncRateTerm.h:78
void setReactantIndex(const vector< unsigned int > &mol)
Definition: FuncTerm.cpp:47
RateTerm * copyWithVolScaling(double vol, double sub, double prd) const
Definition: FuncRateTerm.h:66
const vector< unsigned int > & getFuncArgIndex()
Definition: FuncRateTerm.h:50
double funcVolPower_
Definition: FuncRateTerm.h:80
RateTerm * copyWithVolScaling(double vol, double sub, double prd) const
Definition: FuncRateTerm.h:137
double operator()(const double *S) const
Computes the rate. The argument is the molecule array.
Definition: FuncRateTerm.h:107
void setReactants(const vector< unsigned int > &molIndex)
Definition: FuncRateTerm.h:123
void setTarget(unsigned int tgt)
Definition: FuncTerm.cpp:100
unsigned int getReactants(vector< unsigned int > &molIndex) const
Definition: FuncRateTerm.h:36
void setExpr(const string &s)
Definition: FuncRateTerm.h:59
void setReactants(const vector< unsigned int > &molIndex)
Definition: FuncRateTerm.h:45
const string & getExpr() const
Definition: FuncRateTerm.h:62
const vector< unsigned int > & getReactantIndex() const
Definition: FuncTerm.cpp:67
double k_
Definition: FuncRateTerm.h:79
FuncRate(double k, unsigned int targetPoolIndex)
Definition: FuncRateTerm.h:25
Definition: Id.h:17
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284
FuncReac(double k, vector< unsigned int > v)
Definition: FuncRateTerm.h:102
const string & getExpr() const
Definition: FuncTerm.cpp:95
vector< unsigned int > v_
Definition: FuncRateTerm.h:151
void setFuncArgIndex(const vector< unsigned int > &mol)
Definition: FuncRateTerm.h:55
unsigned int numSubstrates_
Definition: FuncRateTerm.h:152
void rescaleVolume(short comptIndex, const vector< short > &compartmentLookup, double ratio)
Definition: FuncRateTerm.h:127