MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Interpol2D Class Reference

#include <Interpol2D.h>

+ Collaboration diagram for Interpol2D:

Public Member Functions

void appendTableVector (vector< vector< double > > value)
 
void appendTableVector (const vector< vector< double > > &value)
 
double getDx () const
 
double getDy () const
 
double getInterpolatedValue (vector< double > xy) const
 
double getSy () const
 
double getTableValue (vector< unsigned int > index) const
 
vector< vector< double > > getTableVector () const
 
unsigned int getXdivs () const
 
double getXmax () const
 
double getXmin () const
 
unsigned int getYdivs () const
 
double getYmax () const
 
double getYmin () const
 
double indexWithoutCheck (double x, double y) const
 
double innerLookup (double x, double y) const
 
 Interpol2D ()
 
 Interpol2D (unsigned int xdivs, double xmin, double xmax, unsigned int ydivs, double ymin, double ymax)
 
double interpolate (double x, double y) const
 
double invDy () const
 
void load (const string &fname, unsigned int skiplines)
 
void lookup (double v1, double v2)
 
void lookupReturn (const Eref &e, double v1, double v2)
 
bool operator< (const Interpol2D &other) const
 
bool operator== (const Interpol2D &other) const
 
void print (const string &fname, bool doAppend) const
 
void resize (unsigned int xsize, unsigned int ysize, double init=0.0)
 
void setDx (double value)
 
void setDy (double value)
 
void setSy (double value)
 
void setTableValue (vector< unsigned int > index, double value)
 
void setTableVector (vector< vector< double > > value)
 
void setXdivs (unsigned int value)
 
void setXmax (double value)
 
void setXmin (double value)
 
void setYdivs (unsigned int value)
 
void setYmax (double value)
 
void setYmin (double value)
 
unsigned int xdivs () const
 
unsigned int ydivs () const
 

Static Public Member Functions

static const CinfoinitCinfo ()
 

Static Public Attributes

static const unsigned int MAX_DIVS = 100000
 

Private Attributes

double invDx_
 
double invDy_
 
double sy_
 
vector< vector< double > > table_
 
double xmax_
 
double xmin_
 
double ymax_
 
double ymin_
 

Friends

istream & operator>> (istream &, Interpol2D &)
 

Detailed Description

2 Dimensional table, with interpolation. The internal vector is accessed like this: table_[ xIndex ][ yIndex ], with the x- and y-coordinates used as the first and second indices respectively.

Definition at line 18 of file Interpol2D.h.

Constructor & Destructor Documentation

Interpol2D::Interpol2D ( )

Definition at line 163 of file Interpol2D.cpp.

References table_.

164  : xmin_( 0.0 ), xmax_( 1.0 ), invDx_( 1.0 ),
165  ymin_( 0.0 ), ymax_( 1.0 ), invDy_( 1.0 ),
166  sy_( 1.0 )
167 {
168  table_.resize( 2 );
169  table_[ 0 ].resize( 2, 0.0 );
170  table_[ 1 ].resize( 2, 0.0 );
171 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double sy_
Definition: Interpol2D.h:109
double invDx_
Definition: Interpol2D.h:105
Interpol2D::Interpol2D ( unsigned int  xdivs,
double  xmin,
double  xmax,
unsigned int  ydivs,
double  ymin,
double  ymax 
)

Definition at line 173 of file Interpol2D.cpp.

References doubleEq(), invDx_, invDy_, resize(), xmax_, xmin_, ymax_, and ymin_.

176  : xmin_( xmin ), xmax_( xmax ),
177  ymin_( ymin ), ymax_( ymax ),
178  sy_( 1.0 )
179 {
180  resize( xdivs+1, ydivs+1 );
181 
182  if ( !doubleEq( xmax_, xmin ) )
183  invDx_ = xdivs / ( xmax_ - xmin_);
184  else
185  invDx_ = 1.0;
186 
187  if ( !doubleEq( ymax_, ymin ) )
188  invDy_ = ydivs / ( ymax_ - ymin_);
189  else
190  invDy_ = 1.0;
191 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
double xmin_
Definition: Interpol2D.h:103
double sy_
Definition: Interpol2D.h:109
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

Member Function Documentation

void Interpol2D::appendTableVector ( vector< vector< double > >  value)
void Interpol2D::appendTableVector ( const vector< vector< double > > &  value)
double Interpol2D::getDx ( ) const

Definition at line 282 of file Interpol2D.cpp.

References xdivs(), xmax_, and xmin_.

Referenced by initCinfo().

282  {
283  if ( xdivs() == 0 )
284  return 0.0;
285  else
286  return ( xmax_ - xmin_ ) / xdivs();
287 }
double xmax_
Definition: Interpol2D.h:104
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
double xmin_
Definition: Interpol2D.h:103

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double Interpol2D::getDy ( ) const

Definition at line 352 of file Interpol2D.cpp.

References ydivs(), ymax_, and ymin_.

Referenced by initCinfo().

352  {
353  if ( ydivs() == 0 )
354  return 0.0;
355  else
356  return ( ymax_ - ymin_ ) / ydivs();
357 }
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
unsigned int ydivs() const
Definition: Interpol2D.cpp:434

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double Interpol2D::getInterpolatedValue ( vector< double >  xy) const

Definition at line 443 of file Interpol2D.cpp.

References interpolate(), xmax_, xmin_, ymax_, and ymin_.

Referenced by initCinfo().

444 {
445  double x, y;
446  if (xy.size() < 2){
447  x = xmin_;
448  y = ymin_;
449  } else {
450  if (xy[0] < xmin_){
451  x = xmin_;
452  } else if (xy[0] > xmax_){
453  x = xmax_;
454  } else {
455  x = xy[0];
456  }
457  if (xy[1] < ymin_){
458  y = ymin_;
459  } else if (xy[1] > ymax_){
460  y = ymax_;
461  } else {
462  y = xy[1];
463  }
464  }
465  return interpolate(x, y);
466 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double xmin_
Definition: Interpol2D.h:103
double interpolate(double x, double y) const
Definition: Interpol2D.cpp:508

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double Interpol2D::getSy ( ) const

Definition at line 359 of file Interpol2D.cpp.

References sy_.

360 {
361  return sy_;
362 }
double sy_
Definition: Interpol2D.h:109
double Interpol2D::getTableValue ( vector< unsigned int >  index) const

Definition at line 402 of file Interpol2D.cpp.

References table_.

Referenced by initCinfo().

403 {
404  assert( index.size() == 2 );
405  unsigned int i0 = index[ 0 ];
406  unsigned int i1 = index[ 1 ];
407 
408  //Above-said modifications.
409  if ( i0 >= table_.size() )
410  i0 = table_.size() - 1;
411 
412  if ( i1 >= table_[i0].size() )
413  i1 = table_[i0].size() - 1;
414 
415  return table_[ i0 ][ i1 ];
416 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

vector< vector< double > > Interpol2D::getTableVector ( ) const

Definition at line 379 of file Interpol2D.cpp.

References table_.

Referenced by HHGate2D::getTableA(), HHGate2D::getTableB(), and initCinfo().

380 {
381  return table_;
382 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

unsigned int Interpol2D::getXdivs ( ) const

Definition at line 262 of file Interpol2D.cpp.

References table_.

Referenced by HHGate2D::getXdivsA(), HHGate2D::getXdivsB(), initCinfo(), and MarkovSolverBase::setLookupParams().

262  {
263  if ( table_.empty() )
264  return 0;
265  return table_.size() - 1;
266 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

double Interpol2D::getXmax ( ) const

Definition at line 252 of file Interpol2D.cpp.

References xmax_.

Referenced by HHGate2D::getXmaxA(), HHGate2D::getXmaxB(), initCinfo(), and MarkovSolverBase::setLookupParams().

253 {
254  return xmax_;
255 }
double xmax_
Definition: Interpol2D.h:104

+ Here is the caller graph for this function:

double Interpol2D::getXmin ( ) const

Definition at line 238 of file Interpol2D.cpp.

References xmin_.

Referenced by HHGate2D::getXminA(), HHGate2D::getXminB(), initCinfo(), and MarkovSolverBase::setLookupParams().

239 {
240  return xmin_;
241 }
double xmin_
Definition: Interpol2D.h:103

+ Here is the caller graph for this function:

unsigned int Interpol2D::getYdivs ( ) const

Definition at line 325 of file Interpol2D.cpp.

References table_.

Referenced by HHGate2D::getYdivsA(), HHGate2D::getYdivsB(), initCinfo(), and MarkovSolverBase::setLookupParams().

325  {
326  if ( table_.size() > 0 )
327  if ( table_[0].size() > 0 )
328  return table_[0].size() - 1;
329  return 0;
330 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

double Interpol2D::getYmax ( ) const

Definition at line 316 of file Interpol2D.cpp.

References ymax_.

Referenced by HHGate2D::getYmaxA(), HHGate2D::getYmaxB(), initCinfo(), and MarkovSolverBase::setLookupParams().

317 {
318  return ymax_;
319 }
double ymax_
Definition: Interpol2D.h:107

+ Here is the caller graph for this function:

double Interpol2D::getYmin ( ) const

Definition at line 302 of file Interpol2D.cpp.

References ymin_.

Referenced by HHGate2D::getYminA(), HHGate2D::getYminB(), initCinfo(), and MarkovSolverBase::setLookupParams().

303 {
304  return ymin_;
305 }
double ymin_
Definition: Interpol2D.h:106

+ Here is the caller graph for this function:

double Interpol2D::indexWithoutCheck ( double  x,
double  y 
) const

Definition at line 489 of file Interpol2D.cpp.

References invDx_, invDy_, table_, xmin_, and ymin_.

490 {
491  assert( table_.size() > 1 );
492 
493  unsigned long xInteger = static_cast< unsigned long >( ( x - xmin_ ) * invDx_ );
494  assert( xInteger < table_.size() );
495 
496  unsigned long yInteger = static_cast< unsigned long >( ( y - ymin_ ) * invDy_ );
497  assert( yInteger < table_[ 0 ].size() );
498 
499  return table_[ xInteger ][ yInteger ];
500 }
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105
const Cinfo * Interpol2D::initCinfo ( )
static

Definition at line 25 of file Interpol2D.cpp.

References getDx(), getDy(), getInterpolatedValue(), getTableValue(), getTableVector(), getXdivs(), getXmax(), getXmin(), getYdivs(), getYmax(), getYmin(), Neutral::initCinfo(), interpol2DCinfo, lookup(), lookupOut(), lookupReturn(), setDx(), setDy(), setTableValue(), setTableVector(), setXdivs(), setXmax(), setXmin(), setYdivs(), setYmax(), setYmin(), xdivs(), and ydivs().

26 {
28  // Shared message definitions
30 
31  static DestFinfo lookup( "lookup",
32  "Looks up table value based on indices v1 and v2, and sends"
33  "value back using the 'lookupOut' message",
35  );
36  static Finfo* lookupReturnShared[] =
37  {
38  lookupOut(), &lookup
39  };
40 
41  static SharedFinfo lookupReturn2D( "lookupReturn2D",
42  "This is a shared message for doing lookups on the table. "
43  "Receives 2 doubles: x, y. "
44  "Sends back a double with the looked-up z value.",
45  lookupReturnShared, sizeof( lookupReturnShared ) / sizeof( Finfo * )
46  );
47 
49  // Field definitions
51  static ValueFinfo< Interpol2D, double > xmin( "xmin",
52  "Minimum value for x axis of lookup table",
55  );
56  static ValueFinfo< Interpol2D, double > xmax( "xmax",
57  "Maximum value for x axis of lookup table",
60  );
62  "# of divisions on x axis of lookup table",
65  );
66  static ValueFinfo< Interpol2D, double > dx( "dx",
67  "Increment on x axis of lookup table",
70  );
71  static ValueFinfo< Interpol2D, double > ymin( "ymin",
72  "Minimum value for y axis of lookup table",
75  );
76  static ValueFinfo< Interpol2D, double > ymax( "ymax",
77  "Maximum value for y axis of lookup table",
80  );
82  "# of divisions on y axis of lookup table",
85  );
86  static ValueFinfo< Interpol2D, double > dy( "dy",
87  "Increment on y axis of lookup table",
90  );
92  table( "table",
93  "Lookup an entry on the table",
96  );
98  tableVector2D( "tableVector2D",
99  "Get the entire table.",
102  );
104  z("z",
105  "Interpolated value for specified x and y. This is provided for"
106  " debugging. Normally other objects will retrieve interpolated values"
107  " via lookup message.",
110  // MsgSrc definitions
112 
114  // MsgDest definitions
117  static Finfo* interpol2DFinfos[] =
118  {
119  &lookupReturn2D, // Shared
120  &xmin, // Value
121  &xmax, // Value
122  &xdivs, // Value
123  &dx, // Value
124  &ymin, // Value
125  &ymax, // Value
126  &ydivs, // Value
127  &dy, // Value
128  &table, // Lookup
129  &z, // Lookup
130  &tableVector2D, // Value
131  };
132 
133  static string doc[] =
134  {
135  "Name", "Interpol2D",
136  "Author", "Niraj Dudani, 2009, NCBS",
137  "Description", "Interpol2D: Interpolation class. "
138  "Handles lookup from a 2-dimensional grid of real-numbered values. "
139  "Returns 'z' value based on given 'x' and 'y' values. "
140  "Can either use interpolation or roundoff to the nearest index.",
141  };
142 
143  static Dinfo< Interpol2D > dinfo;
144  static Cinfo interpol2DCinfo(
145  "Interpol2D",
147  interpol2DFinfos, sizeof( interpol2DFinfos ) / sizeof( Finfo * ),
148  &dinfo,
149  doc,
150  sizeof(doc)/sizeof(string)
151  );
152 
153  return &interpol2DCinfo;
154 }
void lookupReturn(const Eref &e, double v1, double v2)
Definition: Interpol2D.cpp:478
double getTableValue(vector< unsigned int > index) const
Definition: Interpol2D.cpp:402
void lookup(double v1, double v2)
void setXmin(double value)
Definition: Interpol2D.cpp:229
void setYdivs(unsigned int value)
Definition: Interpol2D.cpp:321
Definition: Dinfo.h:60
double getXmin() const
Definition: Interpol2D.cpp:238
vector< vector< double > > getTableVector() const
Definition: Interpol2D.cpp:379
void setXdivs(unsigned int value)
Definition: Interpol2D.cpp:257
unsigned int getXdivs() const
Definition: Interpol2D.cpp:262
static const Cinfo * interpol2DCinfo
Definition: Interpol2D.cpp:156
double getInterpolatedValue(vector< double > xy) const
Definition: Interpol2D.cpp:443
double getYmin() const
Definition: Interpol2D.cpp:302
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
void setTableVector(vector< vector< double > > value)
Definition: Interpol2D.cpp:420
double getYmax() const
Definition: Interpol2D.cpp:316
unsigned int getYdivs() const
Definition: Interpol2D.cpp:325
void setYmax(double value)
Definition: Interpol2D.cpp:307
void setTableValue(vector< unsigned int > index, double value)
Definition: Interpol2D.cpp:384
void setDy(double value)
Definition: Interpol2D.cpp:336
static SrcFinfo1< double > * lookupOut()
Definition: Interpol2D.cpp:18
void setDx(double value)
Definition: Interpol2D.cpp:268
double getDy() const
Definition: Interpol2D.cpp:352
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void setYmin(double value)
Definition: Interpol2D.cpp:293
double getDx() const
Definition: Interpol2D.cpp:282
double getXmax() const
Definition: Interpol2D.cpp:252
Definition: Cinfo.h:18
void setXmax(double value)
Definition: Interpol2D.cpp:243
Definition: EpFunc.h:79
Definition: Finfo.h:12

+ Here is the call graph for this function:

double Interpol2D::innerLookup ( double  x,
double  y 
) const

Definition at line 574 of file Interpol2D.cpp.

References interpolate(), table_, xmax_, xmin_, ymax_, and ymin_.

Referenced by HHGate2D::lookupA(), HHGate2D::lookupB(), HHGate2D::lookupBoth(), and lookupReturn().

575 {
576  if ( table_.size() == 0 )
577  return 0.0;
578 
579  if ( x < xmin_ ) {
580  x = xmin_;
581  }
582  if ( x > xmax_ ) {
583  x = xmax_;
584  }
585  if ( y < ymin_ ) {
586  y = ymin_;
587  }
588  if ( y > ymax_ ) {
589  y = ymax_;
590  }
591  return interpolate( x, y );
592 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double interpolate(double x, double y) const
Definition: Interpol2D.cpp:508

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double Interpol2D::interpolate ( double  x,
double  y 
) const

Performs bi-linear interpolation.

Modified by Vishaka Datta S, 2011, NCBS. Interpolation now performs bounds checking.

Definition at line 508 of file Interpol2D.cpp.

References invDx_, invDy_, table_, xmin_, and ymin_.

Referenced by getInterpolatedValue(), and innerLookup().

509 {
510  bool isEndOfX = false;
511  bool isEndOfY = false;
512  double z00=0.0, z01=0.0, z10=0.0, z11=0.0;
513  assert( table_.size() > 1 );
514 
515  double xv = ( x - xmin_ ) * invDx_;
516  unsigned long xInteger = static_cast< unsigned long >(xv);
517  if (xInteger >= table_.size()){
518  xInteger = table_.size() - 1;
519  }
520  if (xInteger == table_.size() - 1){
521  isEndOfX = true;
522  }
523 
524  assert(xInteger >= 0);
525  double xFraction = xv - xInteger;
526  double yv = ( y - ymin_ ) * invDy_;
527  unsigned long yInteger = static_cast< unsigned long >(yv);
528  if (yInteger >= table_[xInteger].size()){
529  yInteger = table_[xInteger].size() - 1;
530  }
531  assert(yInteger >= 0);
532  if (yInteger == table_[xInteger].size() - 1){
533  isEndOfY = true;
534  }
535  double yFraction = yv - yInteger;
536  double xFyF = xFraction * yFraction;
537  //If the value being looked up is at the boundary, we dont want to read past
538  //the boundary for the x interpolation.
539  // vector< vector< double > >::const_iterator iz0 = table_.begin() + xInteger;
540  // vector< double >::const_iterator iz00 = iz0->begin() + yInteger;
541  // vector< double >::const_iterator iz10;
542 
543  /* The following is the same as:
544  double z00 = table_[ xInteger ][ yInteger ];
545  double z01 = table_[ xInteger ][ yInteger + 1 ];
546  double z10 = table_[ xInteger + 1 ][ yInteger ];
547  double z11 = table_[ xInteger + 1 ][ yInteger + 1 ];
548  */
549  z00 = table_[xInteger][yInteger];
550  if (!isEndOfX){
551  z10 = table_[xInteger+1][yInteger];
552  if (!isEndOfY){
553  z11 = table_[xInteger+1][yInteger+1];
554  z01 = table_[xInteger][yInteger+1];
555  }
556  } else if (!isEndOfY){
557  z01 = table_[xInteger][yInteger+1];
558  }
559 
560  /* The following is the same as:
561  return (
562  z00 * ( 1 - xFraction ) * ( 1 - yFraction ) +
563  z10 * xFraction * ( 1 - yFraction ) +
564  z01 * ( 1 - xFraction ) * yFraction +
565  z11 * xFraction * yFraction );
566  */
567  return (
568  z00 * ( 1 - xFraction - yFraction + xFyF ) +
569  z10 * ( xFraction - xFyF ) +
570  z01 * ( yFraction - xFyF ) +
571  z11 * xFyF );
572 }
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105

+ Here is the caller graph for this function:

double Interpol2D::invDy ( ) const
inline

Definition at line 76 of file Interpol2D.h.

References invDy_.

76  {
77  return invDy_;
78  }
double invDy_
Definition: Interpol2D.h:108
void Interpol2D::load ( const string &  fname,
unsigned int  skiplines 
)

Definition at line 699 of file Interpol2D.cpp.

References invDx_, invDy_, table_, moose::trim(), xdivs(), xmax_, xmin_, ydivs(), ymax_, and ymin_.

700 {
701  // Checking if xdivs/ydivs are different from default values. If they are,
702  // then issue a warning.
703  if ( xdivs() != 1 || ydivs() != 1 )
704  cerr << "Warning: Interpol2D::innerLoad: Loading 2-D table from '" <<
705  fname << "'. " <<
706  "'xdivs' and 'ydivs' need not be specified. If you have set these fields, "
707  "then they will be overridden while loading.\n";
708 
709  vector< double >::iterator i;
710  std::ifstream fin( fname.c_str() );
711  string line;
712  if ( fin.good() ) {
713  unsigned int i;
714  for ( i = 0; i < skiplines; i++ ) {
715  if ( fin.good () ){
716  getline( fin, line );
717  line = moose::trim(line);
718  } else {
719  break;
720  }
721  }
722  if ( !fin.good() )
723  return;
724 
725  table_.clear( );
726  unsigned int lastWidth = ~0u;
727  double y;
728  while( fin.good() ) {
729  table_.resize( table_.size() + 1 );
730 
731  getline( fin, line );
732  line = moose::trim(line);
733  istringstream sstream( line );
734  while( sstream >> y )
735  table_.back().push_back( y );
736 
737  /*
738  * In case the last line of a file is blank.
739  */
740  if ( table_.back().empty() ) {
741  table_.pop_back();
742  break;
743  }
744 
745  if ( lastWidth != ~0u &&
746  table_.back().size() != lastWidth )
747  {
748  cerr << "Error: Interpol2D::innerLoad: " <<
749  "In file " << fname <<
750  ", line " << table_.size() <<
751  ", row widths are not uniform! Will stop loading now.\n";
752  table_.clear();
753  return;
754  }
755 
756  lastWidth = table_.back().size();
757  }
758 
759  invDx_ = xdivs() / ( xmax_ - xmin_ );
760  invDy_ = ydivs() / ( ymax_ - ymin_ );
761  } else {
762  cerr << "Error: Interpol2D::innerLoad: Failed to open file " <<
763  fname << endl;
764  }
765 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

void Interpol2D::lookup ( double  v1,
double  v2 
)

Referenced by initCinfo().

+ Here is the caller graph for this function:

void Interpol2D::lookupReturn ( const Eref e,
double  v1,
double  v2 
)

Looks up table value based on indices v1 and v2, and sends value back on the 'lookupOut' message.

lookupReturn uses its argument to do an interpolating lookup of the table. It sends a return message to the originating object with the looked up value. This should be avoided, instead use the fastGet function.

Definition at line 478 of file Interpol2D.cpp.

References innerLookup(), and lookupOut().

Referenced by initCinfo().

479 {
480  double ret = innerLookup( v1, v2 );
481  lookupOut()->send( e, ret );
482 }
double innerLookup(double x, double y) const
Definition: Interpol2D.cpp:574
static SrcFinfo1< double > * lookupOut()
Definition: Interpol2D.cpp:18

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Interpol2D::operator< ( const Interpol2D other) const

Definition at line 604 of file Interpol2D.cpp.

References table_.

605 {
606  if ( table_.size() < other.table_.size() )
607  return 1;
608 
609  if ( table_.size() > other.table_.size() )
610  return 0;
611 
612  for ( size_t i = 0; i < table_.size(); i++ ) {
613  for ( size_t j = 0; j < table_[ i ].size(); j++ ) {
614  if ( table_[ i ][ j ] < other.table_[ i ][ j ] )
615  return 1;
616  if ( table_[ i ][ j ] > other.table_[ i ][ j ] )
617  return 0;
618  }
619  }
620 
621  return 0;
622 }
vector< vector< double > > table_
Definition: Interpol2D.h:110
bool Interpol2D::operator== ( const Interpol2D other) const

Definition at line 594 of file Interpol2D.cpp.

References table_, xmax_, xmin_, ymax_, and ymin_.

595 {
596  return (
597  xmin_ == other.xmin_ &&
598  xmax_ == other.xmax_ &&
599  ymin_ == other.ymin_ &&
600  ymax_ == other.ymax_ &&
601  table_ == other.table_ );
602 }
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
void Interpol2D::print ( const string &  fname,
bool  doAppend 
) const

Definition at line 680 of file Interpol2D.cpp.

References table_.

681 {
682  std::ofstream fout;
683  if ( appendFlag )
684  fout.open( fname.c_str(), std::ios::app );
685  else
686  fout.open( fname.c_str(), std::ios::trunc );
687 
688  vector< vector< double > >::const_iterator i;
689  vector< double >::const_iterator j;
690  for ( i = table_.begin(); i != table_.end(); i++ ) {
691  for ( j = i->begin(); j != i->end(); j++ )
692  fout << *j << "\t";
693  fout << "\n";
694  }
695 
696  fout.close();
697 }
vector< vector< double > > table_
Definition: Interpol2D.h:110
void Interpol2D::resize ( unsigned int  xsize,
unsigned int  ysize,
double  init = 0.0 
)

Resizes 2-D vector. If either argument is zero, it remains unchanged

Definition at line 200 of file Interpol2D.cpp.

References invDx_, invDy_, table_, xdivs(), xmax_, xmin_, ydivs(), ymax_, and ymin_.

Referenced by Interpol2D(), setDx(), setXdivs(), and setYdivs().

201 {
202  unsigned int oldx = table_.size();
203  unsigned int oldy = 0;
204  if ( oldx > 0 )
205  oldy = table_[0].size();
206  if ( xsize == 0 ) xsize = oldx;
207  if ( ysize == 0 ) ysize = oldy;
208 
209  if ( xsize != oldx ) {
210  table_.resize( xsize );
211  if ( xsize > oldx ) {
212  for ( unsigned int i = oldx; i < xsize; ++i )
213  table_[i].resize( ysize, init );
214  }
215  }
216 
217  if ( ysize != oldy ) {
218  for ( unsigned int i = 0; i < xsize; ++i )
219  table_[i].resize( ysize, init );
220  }
221  invDx_ = xdivs() / ( xmax_ - xmin_ );
222  invDy_ = ydivs() / ( ymax_ - ymin_ );
223 }
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setDx ( double  value)

Definition at line 268 of file Interpol2D.cpp.

References doubleEq(), MAX_DIVS, resize(), value, xdivs(), xmax_, and xmin_.

Referenced by initCinfo().

268  {
269  if ( !doubleEq( value, 0.0 ) ) {
270  unsigned int xdivs = static_cast< unsigned int >(
271  0.5 + fabs( xmax_ - xmin_ ) / value );
272  if ( xdivs < 1 || xdivs > MAX_DIVS ) {
273  cerr <<
274  "Error: Interpol2D::localSetDx Out of range:" <<
275  xdivs + 1 << " entries in table.\n";
276  return;
277  }
278  resize( xdivs + 1, 0 );
279  }
280 }
uint32_t value
Definition: moosemodule.h:42
double xmax_
Definition: Interpol2D.h:104
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
double xmin_
Definition: Interpol2D.h:103
static const unsigned int MAX_DIVS
Definition: Interpol2D.h:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setDy ( double  value)

Definition at line 336 of file Interpol2D.cpp.

References doubleEq(), invDy_, MAX_DIVS, setYdivs(), value, ydivs(), ymax_, and ymin_.

Referenced by initCinfo().

336  {
337  if ( !doubleEq( value, 0.0 ) ) {
338  unsigned int ydivs = static_cast< unsigned int >(
339  0.5 + fabs( ymax_ - ymin_ ) / value );
340  if ( ydivs < 1 || ydivs > MAX_DIVS ) {
341  cerr <<
342  "Error: Interpol2D::localSetDy Out of range:" <<
343  ydivs + 1 << " entries in table.\n";
344  return;
345  }
346 
347  setYdivs( ydivs );
348  invDy_ = ydivs / ( ymax_ - ymin_ );
349  }
350 }
uint32_t value
Definition: moosemodule.h:42
void setYdivs(unsigned int value)
Definition: Interpol2D.cpp:321
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
static const unsigned int MAX_DIVS
Definition: Interpol2D.h:101

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setSy ( double  value)

Definition at line 364 of file Interpol2D.cpp.

References doubleEq(), sy_, table_, and value.

364  {
365  if ( !doubleEq( value, 0.0 ) ) {
366  double ratio = value / sy_;
367  vector< vector< double > >::iterator i;
368  vector< double >::iterator j;
369  for ( i = table_.begin(); i != table_.end(); i++ )
370  for ( j = i->begin(); j != i->end(); j++ )
371  *j *= ratio;
372  sy_ = value;
373  } else {
374  cerr << "Error: Interpol2D::localSetSy: sy too small:" <<
375  value << "\n";
376  }
377 }
uint32_t value
Definition: moosemodule.h:42
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
vector< vector< double > > table_
Definition: Interpol2D.h:110
double sy_
Definition: Interpol2D.h:109

+ Here is the call graph for this function:

void Interpol2D::setTableValue ( vector< unsigned int >  index,
double  value 
)

Definition at line 384 of file Interpol2D.cpp.

References table_.

Referenced by initCinfo().

385 {
386  assert( index.size() == 2 );
387  unsigned int i0 = index[ 0 ];
388  unsigned int i1 = index[ 1 ];
389 
390  if ( i0 < table_.size() && i1 < table_[ 0 ].size() )
391  table_[ i0 ][ i1 ] = value;
392  else
393  cerr << "Error: Interpol2D::setTableValue: Index out of bounds!\n";
394 }
uint32_t value
Definition: moosemodule.h:42
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

void Interpol2D::setTableVector ( vector< vector< double > >  value)

Definition at line 420 of file Interpol2D.cpp.

References invDx_, invDy_, table_, value, xdivs(), xmax_, xmin_, ydivs(), ymax_, and ymin_.

Referenced by initCinfo(), HHGate2D::setTableA(), and HHGate2D::setTableB().

421 {
422  table_ = value;
423  invDx_ = xdivs() / ( xmax_ - xmin_ );
424  invDy_ = ydivs() / ( ymax_ - ymin_ );
425 }
uint32_t value
Definition: moosemodule.h:42
double xmax_
Definition: Interpol2D.h:104
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
unsigned int ydivs() const
Definition: Interpol2D.cpp:434
vector< vector< double > > table_
Definition: Interpol2D.h:110
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setXdivs ( unsigned int  value)

Definition at line 257 of file Interpol2D.cpp.

References resize().

Referenced by initCinfo(), HHGate2D::setXdivsA(), and HHGate2D::setXdivsB().

258 {
259  resize( value + 1, 0 );
260 }
uint32_t value
Definition: moosemodule.h:42
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setXmax ( double  value)

Definition at line 243 of file Interpol2D.cpp.

References doubleApprox(), invDx_, value, xdivs(), xmax_, and xmin_.

Referenced by initCinfo(), HHGate2D::setXmaxA(), and HHGate2D::setXmaxB().

243  {
244  if ( !doubleApprox( xmin_, value ) ) {
245  xmax_ = value;
246  invDx_ = xdivs() / ( xmax_ - xmin_ );
247  } else {
248  cerr << "Error: Interpol2D::setXmax: Xmin ~= Xmax : Assignment failed\n";
249  }
250 }
uint32_t value
Definition: moosemodule.h:42
double xmax_
Definition: Interpol2D.h:104
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setXmin ( double  value)

Definition at line 229 of file Interpol2D.cpp.

References doubleApprox(), invDx_, value, xdivs(), xmax_, and xmin_.

Referenced by initCinfo(), HHGate2D::setXminA(), and HHGate2D::setXminB().

229  {
230  if ( !doubleApprox( xmax_, value ) ) {
231  xmin_ = value;
232  invDx_ = xdivs() / ( xmax_ - xmin_ );
233  } else {
234  cerr << "Error: Interpol2D::setXmin: Xmin ~= Xmax : Assignment failed\n";
235  }
236 }
uint32_t value
Definition: moosemodule.h:42
double xmax_
Definition: Interpol2D.h:104
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
unsigned int xdivs() const
Definition: Interpol2D.cpp:427
double xmin_
Definition: Interpol2D.h:103
double invDx_
Definition: Interpol2D.h:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setYdivs ( unsigned int  value)

Definition at line 321 of file Interpol2D.cpp.

References resize().

Referenced by initCinfo(), setDy(), HHGate2D::setYdivsA(), and HHGate2D::setYdivsB().

321  {
322  resize( 0, value + 1 );
323 }
uint32_t value
Definition: moosemodule.h:42
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setYmax ( double  value)

Definition at line 307 of file Interpol2D.cpp.

References doubleApprox(), invDy_, value, ydivs(), ymax_, and ymin_.

Referenced by initCinfo(), HHGate2D::setYmaxA(), and HHGate2D::setYmaxB().

307  {
308  if ( !doubleApprox( ymin_, value ) ) {
309  ymax_ = value;
310  invDy_ = ydivs() / ( ymax_ - ymin_ );
311  } else {
312  cerr << "Error: Interpol2D::setYmax: Ymin ~= Ymax : Assignment failed\n";
313  }
314 }
uint32_t value
Definition: moosemodule.h:42
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
unsigned int ydivs() const
Definition: Interpol2D.cpp:434

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void Interpol2D::setYmin ( double  value)

Definition at line 293 of file Interpol2D.cpp.

References doubleApprox(), invDy_, value, ydivs(), ymax_, and ymin_.

Referenced by initCinfo(), HHGate2D::setYminA(), and HHGate2D::setYminB().

293  {
294  if ( !doubleApprox( ymax_, value ) ) {
295  ymin_ = value;
296  invDy_ = ydivs() / ( ymax_ - ymin_ );
297  } else {
298  cerr << "Error: Interpol2D::setYmin: Ymin ~= Ymax : Assignment failed\n";
299  }
300 }
uint32_t value
Definition: moosemodule.h:42
double ymax_
Definition: Interpol2D.h:107
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
unsigned int ydivs() const
Definition: Interpol2D.cpp:434

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

unsigned int Interpol2D::xdivs ( ) const

Definition at line 427 of file Interpol2D.cpp.

References table_.

Referenced by getDx(), initCinfo(), load(), resize(), setDx(), setTableVector(), setXmax(), and setXmin().

428 {
429  if ( table_.empty() )
430  return 0;
431  return table_.size() - 1;
432 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

unsigned int Interpol2D::ydivs ( ) const

Definition at line 434 of file Interpol2D.cpp.

References table_.

Referenced by getDy(), initCinfo(), load(), resize(), setDy(), setTableVector(), setYmax(), and setYmin().

435 {
436  if ( table_.empty() || table_[0].empty() )
437  return 0;
438  return table_[0].size() - 1;
439 }
vector< vector< double > > table_
Definition: Interpol2D.h:110

+ Here is the caller graph for this function:

Friends And Related Function Documentation

istream& operator>> ( istream &  ,
Interpol2D  
)
friend

Member Data Documentation

double Interpol2D::invDx_
private
double Interpol2D::invDy_
private
const unsigned int Interpol2D::MAX_DIVS = 100000
static

Definition at line 101 of file Interpol2D.h.

Referenced by setDx(), and setDy().

double Interpol2D::sy_
private

Definition at line 109 of file Interpol2D.h.

Referenced by getSy(), and setSy().

double Interpol2D::xmax_
private
double Interpol2D::ymax_
private

The documentation for this class was generated from the following files: