MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RateTerm.cpp
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 
11 #include <math.h>
12 #include <vector>
13 #include <algorithm>
14 #include <cassert>
15 using namespace std;
16 #include "header.h"
17 #include "RateTerm.h"
18 
19 const double RateTerm::EPSILON = 1.0e-6;
20 
21 StochNOrder::StochNOrder( double k, vector< unsigned int > v )
22  : NOrder( k, v )
23 {
24  // Here we sort the y vector so that if there are repeated
25  // substrates, they are put consecutively. This lets us use
26  // the algorithm below to deal with repeats.
27  sort( v_.begin(), v_.end() );
28 }
29 
30 double StochNOrder::operator() ( const double* S ) const {
31  double ret = k_;
32  vector< unsigned int >::const_iterator i;
33  unsigned int lasty = 0;
34  double y = 0.0;
35  for ( i = v_.begin(); i != v_.end(); i++) {
36  assert( !std::isnan( S[ *i ] ) );
37  if ( lasty == *i )
38  y -= 1.0;
39  else
40  y = S[ *i ];
41  ret *= y;
42  lasty = *i;
43  }
44  return ret;
45 }
double k_
Definition: RateTerm.h:311
static const double EPSILON
Definition: RateTerm.h:52
double operator()(const double *S) const
Computes the rate. The argument is the molecule array.
Definition: RateTerm.cpp:30
StochNOrder(double k, vector< unsigned int > v)
Definition: RateTerm.cpp:21
vector< unsigned int > v_
Definition: RateTerm.h:512