MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RateLookup.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-2007 Upinder S. Bhalla, Niraj Dudani 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 <vector>
11 using namespace std;
12 
13 #include "RateLookup.h"
14 
16  double min, double max, unsigned int nDivs, unsigned int nSpecies )
17 {
18  min_ = min;
19  max_ = max;
20  // Number of points is 1 more than number of divisions.
21  // Then add one more since we may interpolate at the last point in the table.
22  nPts_ = nDivs + 1 + 1;
23  dx_ = ( max - min ) / nDivs;
24  // Every row has 2 entries for each type of gate
25  nColumns_ = 2 * nSpecies;
26 
27  //~ interpolate_.resize( nSpecies );
28  table_.resize( nPts_ * nColumns_ );
29 }
30 
32  int species,
33  const vector< double >& C1,
34  const vector< double >& C2 )
35  //~ const vector< double >& C2,
36  //~ bool interpolate )
37 {
38  vector< double >::const_iterator ic1 = C1.begin();
39  vector< double >::const_iterator ic2 = C2.begin();
40  vector< double >::iterator iTable = table_.begin() + 2 * species;
41  // Loop until last but one point
42  for ( unsigned int igrid = 0; igrid < nPts_ - 1 ; ++igrid ) {
43  *( iTable ) = *ic1;
44  *( iTable + 1 ) = *ic2;
45 
46  iTable += nColumns_;
47  ++ic1, ++ic2;
48  }
49  // Then duplicate the last point
50  *( iTable ) = C1.back();
51  *( iTable + 1 ) = C2.back();
52 
53  //~ interpolate_[ species ] = interpolate;
54 }
55 
56 void LookupTable::column( unsigned int species, LookupColumn& column )
57 {
58  column.column = 2 * species;
59  //~ column.interpolate = interpolate_[ species ];
60 }
61 
62 void LookupTable::row( double x, LookupRow& row )
63 {
64  if ( x < min_ )
65  x = min_;
66  else if ( x > max_ )
67  x = max_;
68 
69  double div = ( x - min_ ) / dx_;
70  unsigned int integer = ( unsigned int )( div );
71 
72  row.fraction = div - integer;
73  row.row = &( table_.front() ) + integer * nColumns_;
74 }
75 
77  const LookupColumn& column,
78  const LookupRow& row,
79  double& C1,
80  double& C2 )
81 {
82  double a, b;
83  double *ap, *bp;
84 
85  ap = row.row + column.column;
86 
87  //~ if ( ! column.interpolate ) {
88  //~ C1 = *ap;
89  //~ C2 = *( ap + 1 );
90  //~
91  //~ return;
92  //~ }
93 
94  bp = ap + nColumns_;
95 
96  a = *ap;
97  b = *bp;
98  C1 = a + ( b - a ) * row.fraction;
99 
100  a = *( ap + 1 );
101  b = *( bp + 1 );
102  C2 = a + ( b - a ) * row.fraction;
103 }
double fraction
Definition: RateLookup.h:16
void lookup(const LookupColumn &column, const LookupRow &row, double &C1, double &C2)
Actually performs the lookup and the linear interpolation.
Definition: RateLookup.cpp:76
unsigned int column
Definition: RateLookup.h:23
void row(double x, LookupRow &row)
Definition: RateLookup.cpp:62
void addColumns(int species, const vector< double > &C1, const vector< double > &C2)
Adds the columns for a given species. Columns supplied are C1 and C2.
Definition: RateLookup.cpp:31
void column(unsigned int species, LookupColumn &column)
Definition: RateLookup.cpp:56
double * row
Pointer to the first column on a row.
Definition: RateLookup.h:15