MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Interpol2D.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-2011 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 <fstream>
11 #include <sstream>
12 #include "header.h"
13 #include "../utility/strutil.h"
14 #include "Interpol2D.h"
15 
16 const unsigned int Interpol2D::MAX_DIVS = 100000;
17 
19 {
20  static SrcFinfo1< double > lookupOut( "lookupOut",
21  "respond to a request for a value lookup" );
22  return &lookupOut;
23 }
24 
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 }
155 
157 
158 // static const Slot lookupReturnSlot = initInterpol2DCinfo()->getSlot( "lookupReturn2D.lookupOut" );
160 // Constructors
162 
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 }
172 
174  unsigned int xdivs, double xmin, double xmax,
175  unsigned int ydivs, double ymin, double ymax )
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 }
192 
194 // Here we set up Interpol2D value fields
196 
200 void Interpol2D::resize( unsigned int xsize, unsigned int ysize, double init )
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 }
224 
226 // X dimension access funcs
228 
229 void Interpol2D::setXmin( double value ) {
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 }
237 
238 double Interpol2D::getXmin() const
239 {
240  return xmin_;
241 }
242 
243 void Interpol2D::setXmax( double value ) {
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 }
251 
252 double Interpol2D::getXmax() const
253 {
254  return xmax_;
255 }
256 
257 void Interpol2D::setXdivs( unsigned int value )
258 {
259  resize( value + 1, 0 );
260 }
261 
262 unsigned int Interpol2D::getXdivs( ) const {
263  if ( table_.empty() )
264  return 0;
265  return table_.size() - 1;
266 }
267 
268 void Interpol2D::setDx( double value ) {
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 }
281 
282 double Interpol2D::getDx() const {
283  if ( xdivs() == 0 )
284  return 0.0;
285  else
286  return ( xmax_ - xmin_ ) / xdivs();
287 }
288 
290 // Y dimension access funcs
292 
293 void Interpol2D::setYmin( double value ) {
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 }
301 
302 double Interpol2D::getYmin() const
303 {
304  return ymin_;
305 }
306 
307 void Interpol2D::setYmax( double value ) {
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 }
315 
316 double Interpol2D::getYmax() const
317 {
318  return ymax_;
319 }
320 
321 void Interpol2D::setYdivs( unsigned int value ) {
322  resize( 0, value + 1 );
323 }
324 
325 unsigned int Interpol2D::getYdivs( ) const {
326  if ( table_.size() > 0 )
327  if ( table_[0].size() > 0 )
328  return table_[0].size() - 1;
329  return 0;
330 }
331 
336 void Interpol2D::setDy( double value ) {
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 }
351 
352 double Interpol2D::getDy() const {
353  if ( ydivs() == 0 )
354  return 0.0;
355  else
356  return ( ymax_ - ymin_ ) / ydivs();
357 }
358 
359 double Interpol2D::getSy() const
360 {
361  return sy_;
362 }
363 
364 void Interpol2D::setSy( double value ) {
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 }
378 
379 vector< vector< double > > Interpol2D::getTableVector() const
380 {
381  return table_;
382 }
383 
384 void Interpol2D::setTableValue( vector< unsigned int > index, double value )
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 }
395 
397 //Modified by Vishaka Datta S, 2011, NCBS.
398 //When a single index is out of bounds, the last element along that
399 //respective dimension is returned.
400 //Modification was needed for the MarkovSolver base class.
402 double Interpol2D::getTableValue( vector< unsigned int > index ) const
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 }
417 
418 // This sets the whole thing up: values, xdivs, dx and so on. Only xmin
419 // and xmax are unknown to the input vector.
420 void Interpol2D::setTableVector( vector< vector< double > > value )
421 {
422  table_ = value;
423  invDx_ = xdivs() / ( xmax_ - xmin_ );
424  invDy_ = ydivs() / ( ymax_ - ymin_ );
425 }
426 
427 unsigned int Interpol2D::xdivs() const
428 {
429  if ( table_.empty() )
430  return 0;
431  return table_.size() - 1;
432 }
433 
434 unsigned int Interpol2D::ydivs() const
435 {
436  if ( table_.empty() || table_[0].empty() )
437  return 0;
438  return table_[0].size() - 1;
439 }
440 
441 // This is a wrapper around interpolate to retrieve value by vector
442 // containing x and y.
443 double Interpol2D::getInterpolatedValue(vector <double> xy) const
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 }
467 
469 // Here we set up Interpol2D Destination functions
471 
478 void Interpol2D::lookupReturn( const Eref& e, double v1, double v2 )
479 {
480  double ret = innerLookup( v1, v2 );
481  lookupOut()->send( e, ret );
482 }
483 
485 // Here we set up private Interpol2D class functions.
487 
488 
489 double Interpol2D::indexWithoutCheck( double x, double y ) const
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 }
501 
508 double Interpol2D::interpolate( double x, double y ) const
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 }
573 
574 double Interpol2D::innerLookup( double x, double y ) const
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 }
593 
594 bool Interpol2D::operator==( const Interpol2D& other ) const
595 {
596  return (
597  xmin_ == other.xmin_ &&
598  xmax_ == other.xmax_ &&
599  ymin_ == other.ymin_ &&
600  ymax_ == other.ymax_ &&
601  table_ == other.table_ );
602 }
603 
604 bool Interpol2D::operator<( const Interpol2D& other ) const
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 }
623 
624 //Added by Vishaka Datta S, 2011, NCBS.
625 //Overloading this operator was necessary to be able to pass in
626 //Interpol2D arguments to the SrcFinfo templates, in order for the Conv
627 //class to pull off its pointer typecasting kung fu.
628 istream& operator>>( istream& in, Interpol2D& int2dTable )
629 {
630  in >> int2dTable.xmin_;
631  in >> int2dTable.xmax_;
632  in >> int2dTable.invDx_;
633  in >> int2dTable.ymin_;
634  in >> int2dTable.ymax_;
635  in >> int2dTable.invDy_;
636 
637  for ( unsigned int i = 0; i < int2dTable.table_.size(); ++i )
638  {
639  for ( unsigned int j = 0; j < int2dTable.table_.size(); ++j )
640  in >> int2dTable.table_[i][j];
641  }
642 
643  return in;
644 }
645 
646 // This sets the whole thing up: values, xdivs, dx and so on. Only xmin
647 // and xmax are unknown to the input vector.
649  const vector< vector< double > >& value )
650 {
651  if ( value.empty() )
652  return;
653 
654  unsigned int ysize = value[ 0 ].size();
655  vector< vector< double > >::const_iterator i;
656  for ( i = value.begin() + 1; i != value.end(); i++ )
657  if ( i->size() != ysize ) {
658  ysize = ~0u;
659  break;
660  }
661 
662  if ( ysize == ~0u ) {
663  cerr <<
664  "Error: Interpol2D::localAppendTableVector: All rows should have a "
665  "uniform width. Not changing anything.\n";
666  return;
667  }
668 
669  if ( ! table_.empty() && ysize != table_[ 0 ].size() ) {
670  cerr <<
671  "Error: Interpol2D: localAppendTableVector: Table widths must match. "
672  "Not changing anything.\n";
673  return;
674  }
675 
676  table_.insert( table_.end(), value.begin(), value.end() );
677  invDx_ = xdivs() / ( xmax_ - xmin_ );
678 }
679 
680 void Interpol2D::print( const string& fname, bool appendFlag ) const
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 }
698 
699 void Interpol2D::load( const string& fname, unsigned int skiplines )
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 }
766 
767 #ifdef DO_UNIT_TESTS
768 void testInterpol2D()
769 {
770 /*
771  static const unsigned int XDIVS = 100;
772  cout << "\nDoing Interpol2D tests";
773 
774  Element* i1 = interpol2DCinfo->create( Id::scratchId(), "i1" );
775  Element* i2 = interpol2DCinfo->create( Id::scratchId(), "i2" );
776  unsigned int i;
777  double ret = 0;
778 
779  set< int >( i1, "xdivs", XDIVS );
780 
781  set< double >( i1, "xmin", 0 );
782  get< double >( i1, "xmin", ret );
783  ASSERT( ret == 0.0, "testInterpol2D" );
784 
785  set< double >( i1, "xmax", 20 );
786  get< double >( i1, "xmax", ret );
787  ASSERT( ret == 20.0, "testInterpol2D" );
788 
789  for ( i = 0; i <= XDIVS; i++ )
790  lookupSet< double, unsigned int >(
791  i1, "table", i * 10.0 - 100.0, i );
792 
793  for ( i = 0; i <= XDIVS; i++ ) {
794  lookupGet< double, unsigned int >( i1, "table", ret, i );
795  assert ( ret == i * 10.0 - 100.0 );
796  }
797  cout << ".";
798 
799  set< int >( i2, "xdivs", XDIVS );
800  set< double >( i2, "xmin", 0 );
801  set< double >( i2, "xmax", 10000.0 );
802 
803  // Here we use i2 as a dummy dest for the
804  // lookup operation, which takes place on i1.
805 
806  ASSERT(
807  Eref( i1 ).add( "lookupSrc", i2, "xmin" ), "connecting interpol2Ds" );
808 
809  // i1->findFinfo( "lookupSrc" )->add( i1, i2, i2->findFinfo( "xmin" ) ), "connecting interpol2Ds"
810 
811  set< double >( i1, "lookup", -10.0 );
812  get< double >( i2, "xmin", ret );
813  ASSERT( ret == -100.0, "Lookup minimum" );
814 
815  set< double >( i1, "lookup", 0.0 );
816  get< double >( i2, "xmin", ret );
817  ASSERT( ret == -100.0, "Lookup minimum" );
818 
819  set< double >( i1, "lookup", 2.0 );
820  get< double >( i2, "xmin", ret );
821  ASSERT( ret == 0.0, "Lookup middle" );
822 
823  set< double >( i1, "lookup", 2.1 );
824  get< double >( i2, "xmin", ret );
825  ASSERT( fabs( ret - 5.0 ) < 1.0e-10, "Lookup interpolation" );
826  // ASSERT( ret == 5.0, "Lookup interpolation" );
827 
828  set< double >( i1, "lookup", 10.0 );
829  get< double >( i2, "xmin", ret );
830  ASSERT( ret == 400.0, "Lookup middle" );
831 
832  set< double >( i1, "lookup", 12.0 );
833  get< double >( i2, "xmin", ret );
834  ASSERT( ret == 500.0, "Lookup middle" );
835 
836  set< double >( i1, "lookup", 20.0 );
837  get< double >( i2, "xmin", ret );
838  ASSERT( ret == 900.0, "Lookup max" );
839 
840  set< double >( i1, "lookup", 20000.0 );
841  get< double >( i2, "xmin", ret );
842  ASSERT( ret == 900.0, "Lookup max" );
843 */
844 }
845 
846 #endif // DO_UNIT_TESTS
void lookupReturn(const Eref &e, double v1, double v2)
Definition: Interpol2D.cpp:478
Id init(int argc, char **argv, bool &doUnitTests, bool &doRegressionTests, unsigned int &benchmark)
Definition: main.cpp:150
bool operator<(const Interpol2D &other) const
Definition: Interpol2D.cpp:604
uint32_t value
Definition: moosemodule.h:42
double getTableValue(vector< unsigned int > index) const
Definition: Interpol2D.cpp:402
void lookup(double v1, double v2)
void load(const string &fname, unsigned int skiplines)
Definition: Interpol2D.cpp:699
void setXmin(double value)
Definition: Interpol2D.cpp:229
double xmax_
Definition: Interpol2D.h:104
void setYdivs(unsigned int value)
Definition: Interpol2D.cpp:321
double ymax_
Definition: Interpol2D.h:107
Definition: Dinfo.h:60
double ymin_
Definition: Interpol2D.h:106
double invDy_
Definition: Interpol2D.h:108
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
void setSy(double value)
Definition: Interpol2D.cpp:364
unsigned int getXdivs() const
Definition: Interpol2D.cpp:262
void resize(unsigned int xsize, unsigned int ysize, double init=0.0)
Definition: Interpol2D.cpp:200
static const Cinfo * interpol2DCinfo
Definition: Interpol2D.cpp:156
double indexWithoutCheck(double x, double y) const
Definition: Interpol2D.cpp:489
bool doubleApprox(double x, double y)
Definition: doubleEq.cpp:24
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
double getSy() const
Definition: Interpol2D.cpp:359
double getInterpolatedValue(vector< double > xy) const
Definition: Interpol2D.cpp:443
istream & operator>>(istream &in, Interpol2D &int2dTable)
Definition: Interpol2D.cpp:628
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
Definition: Eref.h:26
double innerLookup(double x, double y) const
Definition: Interpol2D.cpp:574
void appendTableVector(vector< vector< double > > value)
vector< vector< double > > table_
Definition: Interpol2D.h:110
void print(const string &fname, bool doAppend) const
Definition: Interpol2D.cpp:680
static const Cinfo * initCinfo()
Definition: Interpol2D.cpp:25
bool operator==(const Interpol2D &other) const
Definition: Interpol2D.cpp:594
double xmin_
Definition: Interpol2D.h:103
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 interpolate(double x, double y) const
Definition: Interpol2D.cpp:508
double getDy() const
Definition: Interpol2D.cpp:352
static const unsigned int MAX_DIVS
Definition: Interpol2D.h:101
double sy_
Definition: Interpol2D.h:109
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void setYmin(double value)
Definition: Interpol2D.cpp:293
std::string trim(const std::string myString, const string &delimiters)
Definition: strutil.cpp:53
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
double invDx_
Definition: Interpol2D.h:105
Definition: Finfo.h:12