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

#include <TableBase.h>

+ Inheritance diagram for TableBase:
+ Collaboration diagram for TableBase:

Public Member Functions

void clearVec ()
 
void compareVec (vector< double > other, string op)
 
void compareXplot (string fname, string plotname, string op)
 
const vector< double > & data ()
 
double getOutputValue () const
 
string getPlotDump () const
 
vector< double > getVec () const
 
unsigned int getVecSize () const
 
double getY (unsigned int index) const
 
double interpolate (double x, double xmin, double xmax) const
 
void linearTransform (double scale, double offset)
 
void loadCSV (string fname, int startLine, int colNum, char separator)
 
void loadXplot (string fname, string plotname)
 
void loadXplotRange (string fname, string plotname, unsigned int start, unsigned int end)
 
double * lookupVec (unsigned int index)
 
void plainPlot (string file)
 
void setOutputValue (double val)
 
void setPlotDump (string v)
 
void setVec (vector< double > val)
 
void setVecSize (unsigned int num)
 
 TableBase ()
 
void xplot (string file, string plotname)
 

Static Public Member Functions

static const CinfoinitCinfo ()
 

Protected Member Functions

vector< double > & vec ()
 

Private Attributes

double output_
 
vector< double > vec_
 

Detailed Description

Base class for table operations. Provides basics for looking up table and interpolation, but no process or messaging. Derived classes deal with these.

Definition at line 19 of file TableBase.h.

Constructor & Destructor Documentation

TableBase::TableBase ( )

Definition at line 158 of file TableBase.cpp.

158  : output_( 0 )
159 {
160 }
double output_
Definition: TableBase.h:72

Member Function Documentation

void TableBase::clearVec ( )

Definition at line 414 of file TableBase.cpp.

References vec_.

Referenced by initCinfo(), Table::process(), Table::reinit(), Streamer::zipWithTime(), and Table::~Table().

415 {
416  vec_.resize( 0 );
417 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::compareVec ( vector< double >  other,
string  op 
)

Definition at line 395 of file TableBase.cpp.

References getRMSDiff(), getRMSRatio(), headop(), output_, and vec_.

Referenced by initCinfo().

396 {
397  // Note that this line below is illegal: it causes a race condition
398  // vector< double > temp = Field< vector< double > >::get( other, "vec" );
399 
400  string hop = headop( op );
401 
402  if ( hop == "rmsd" ) { // RMSDifference
403  output_ = getRMSDiff( vec_, temp );
404  }
405 
406  if ( hop == "rmsr" ) { // RMS ratio
407  output_ = getRMSRatio( vec_, temp );
408  }
409 
410  if ( hop == "dotp" )
411  cout << "TableBase::compareVec: DotProduct not yet done\n";
412 }
double getRMSDiff(const vector< double > &v1, const vector< double > &v2)
Definition: TableBase.cpp:326
static double op(double x)
vector< double > vec_
Definition: TableBase.h:73
string headop(const string &op)
Definition: TableBase.cpp:363
double getRMSRatio(const vector< double > &v1, const vector< double > &v2)
Definition: TableBase.cpp:352
double output_
Definition: TableBase.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TableBase::compareXplot ( string  fname,
string  plotname,
string  op 
)

Definition at line 374 of file TableBase.cpp.

References getRMSDiff(), getRMSRatio(), headop(), innerLoadXplot(), output_, and vec_.

Referenced by initCinfo().

375 {
376  vector< double > temp;
377  if ( !innerLoadXplot( fname, plotname, temp ) ) {
378  cout << "TableBase::compareXplot: unable to load data from file " << fname <<endl;
379  }
380 
381  string hop = headop( op );
382 
383  if ( hop == "rmsd" ) { // RMSDifference
384  output_ = getRMSDiff( vec_, temp );
385  }
386 
387  if ( hop == "rmsr" ) { // RMS ratio
388  output_ = getRMSRatio( vec_, temp );
389  }
390 
391  if ( hop == "dotp" )
392  cout << "TableBase::compareXplot: DotProduct not yet done\n";
393 }
double getRMSDiff(const vector< double > &v1, const vector< double > &v2)
Definition: TableBase.cpp:326
static double op(double x)
vector< double > vec_
Definition: TableBase.h:73
string headop(const string &op)
Definition: TableBase.cpp:363
double getRMSRatio(const vector< double > &v1, const vector< double > &v2)
Definition: TableBase.cpp:352
bool innerLoadXplot(string fname, string plotname, vector< double > &v)
Definition: TableBase.cpp:250
double output_
Definition: TableBase.h:72

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const vector< double > & TableBase::data ( )

Definition at line 498 of file TableBase.cpp.

References vec_.

Referenced by StreamerBase::writeToNPYFile().

499 {
500  return vec_;
501 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

double TableBase::getOutputValue ( ) const

Definition at line 423 of file TableBase.cpp.

References output_.

Referenced by initCinfo().

424 {
425  return output_;
426 }
double output_
Definition: TableBase.h:72

+ Here is the caller graph for this function:

string TableBase::getPlotDump ( ) const

Definition at line 503 of file TableBase.cpp.

Referenced by initCinfo().

504 {
505  static string ret = "plot.Dump";
506  return ret;
507 }

+ Here is the caller graph for this function:

vector< double > TableBase::getVec ( ) const

Definition at line 482 of file TableBase.cpp.

References vec_.

Referenced by initCinfo(), and Streamer::zipWithTime().

483 {
484  return vec_;
485 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

unsigned int TableBase::getVecSize ( ) const

Definition at line 477 of file TableBase.cpp.

References vec_.

Referenced by initCinfo(), Table::process(), and Streamer::process().

478 {
479  return vec_.size();
480 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

double TableBase::getY ( unsigned int  index) const

Definition at line 433 of file TableBase.cpp.

References vec_.

Referenced by initCinfo().

434 {
435  if ( index < vec_.size() )
436  return ( vec_[index] );
437  return 0;
438 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

const Cinfo * TableBase::initCinfo ( )
static

Definition at line 15 of file TableBase.cpp.

References clearVec(), compareVec(), compareXplot(), getOutputValue(), getPlotDump(), getVec(), getVecSize(), getY(), Neutral::initCinfo(), linearTransform(), loadCSV(), loadXplot(), loadXplotRange(), plainPlot(), setPlotDump(), setVec(), tableCinfo, vec(), and xplot().

Referenced by TimeTable::initCinfo(), StimulusTable::initCinfo(), Table::initCinfo(), Streamer::initCinfo(), and Interpol::initCinfo().

16 {
18  // Field Definitions
21  "vector",
22  "vector with all table entries",
25  );
26 
27  static ValueFinfo< TableBase, string > plotDump(
28  "plotDump",
29  "'File plotname' for dumpling an xplot, as a workaround for an error in the xplot python interface. Note separator is a space. The return value is a dummy.",
32  );
33 
34  static ReadOnlyValueFinfo< TableBase, double > outputValue(
35  "outputValue",
36  "Output value holding current table entry or output of a calculation",
38  );
39 
41  "size",
42  "size of table. Note that this is the number of x divisions +1"
43  "since it must represent the largest value as well as the"
44  "smallest",
46  );
47 
49  "y",
50  "Value of table at specified index",
52  );
53 
55  // MsgDest Definitions
57 
58  static DestFinfo linearTransform( "linearTransform",
59  "Linearly scales and offsets data. Scale first, then offset.",
61 
62  static DestFinfo xplot( "xplot",
63  "Dumps table contents to xplot-format file. "
64  "Argument 1 is filename, argument 2 is plotname",
66 
67  static DestFinfo plainPlot( "plainPlot",
68  "Dumps table contents to single-column ascii file. "
69  "Uses scientific notation. "
70  "Argument 1 is filename",
72 
73  static DestFinfo loadCSV( "loadCSV",
74  "Reads a single column from a CSV file. "
75  "Arguments: filename, column#, starting row#, separator",
77  &TableBase::loadCSV ) );
78 
79  static DestFinfo loadXplot( "loadXplot",
80  "Reads a single plot from an xplot file. "
81  "Arguments: filename, plotname"
82  "When the file has 2 columns, the 2nd column is loaded.",
85 
86  static DestFinfo loadXplotRange( "loadXplotRange",
87  "Reads a single plot from an xplot file, and selects a "
88  "subset of points from it. "
89  "Arguments: filename, plotname, startindex, endindex"
90  "Uses C convention: startindex included, endindex not included."
91  "When the file has 2 columns, the 2nd column is loaded.",
94 
95  static DestFinfo compareXplot( "compareXplot",
96  "Reads a plot from an xplot file and compares with contents of TableBase."
97  "Result is put in 'output' field of table."
98  "If the comparison fails (e.g., due to zero entries), the "
99  "return value is -1."
100  "Arguments: filename, plotname, comparison_operation"
101  "Operations: rmsd (for RMSDifference), rmsr (RMSratio ), "
102  "dotp (Dot product, not yet implemented).",
105 
106  static DestFinfo compareVec( "compareVec",
107  "Compares contents of TableBase with a vector of doubles."
108  "Result is put in 'output' field of table."
109  "If the comparison fails (e.g., due to zero entries), the "
110  "return value is -1."
111  "Arguments: Other vector, comparison_operation"
112  "Operations: rmsd (for RMSDifference), rmsr (RMSratio ), "
113  "dotp (Dot product, not yet implemented).",
114  new OpFunc2< TableBase, vector< double >, string >(
116 
117  static DestFinfo clearVec(
118  "clearVec",
119  "Handles request to clear the data vector",
121 
122 
123  static Finfo* tableBaseFinfos[] = {
124  &vec, // Value
125  &plotDump, // Value, used for debugging xplot function.
126  &outputValue, // ReadOnlyValue
127  &size, // ReadOnlyValue
128  &y, // ReadOnlyLookupValue
129  &linearTransform, // DestFinfo
130  &xplot, // DestFinfo
131  &plainPlot, // DestFinfo
132  &loadCSV, // DestFinfo
133  &loadXplot, // DestFinfo
134  &loadXplotRange, // DestFinfo
135  &compareXplot, // DestFinfo
136  &compareVec, // DestFinfo
137  &clearVec,
138  };
139 
140  static Dinfo< TableBase > dinfo;
141  static Cinfo tableCinfo (
142  "TableBase",
144  tableBaseFinfos,
145  sizeof( tableBaseFinfos ) / sizeof ( Finfo* ),
146  &dinfo
147  );
148 
149  return &tableCinfo;
150 }
void xplot(string file, string plotname)
Definition: TableBase.cpp:182
double getOutputValue() const
Definition: TableBase.cpp:423
vector< double > & vec()
Definition: TableBase.cpp:492
void linearTransform(double scale, double offset)
Definition: TableBase.cpp:166
void setVec(vector< double > val)
Definition: TableBase.cpp:487
Definition: Dinfo.h:60
Definition: OpFunc.h:56
vector< double > getVec() const
Definition: TableBase.cpp:482
void setPlotDump(string v)
Definition: TableBase.cpp:509
void clearVec()
Definition: TableBase.cpp:414
Definition: OpFunc.h:40
unsigned int getVecSize() const
Definition: TableBase.cpp:477
void loadCSV(string fname, int startLine, int colNum, char separator)
Definition: TableBase.cpp:320
void loadXplotRange(string fname, string plotname, unsigned int start, unsigned int end)
Definition: TableBase.cpp:302
Definition: OpFunc.h:27
void compareXplot(string fname, string plotname, string op)
Definition: TableBase.cpp:374
void plainPlot(string file)
Definition: TableBase.cpp:172
static const Cinfo * tableCinfo
Definition: Table.cpp:211
double getY(unsigned int index) const
Definition: TableBase.cpp:433
Definition: OpFunc.h:13
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
Definition: Cinfo.h:18
Definition: OpFunc.h:70
void loadXplot(string fname, string plotname)
Definition: TableBase.cpp:294
void compareVec(vector< double > other, string op)
Definition: TableBase.cpp:395
Definition: Finfo.h:12
string getPlotDump() const
Definition: TableBase.cpp:503

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double TableBase::interpolate ( double  x,
double  xmin,
double  xmax 
) const

Definition at line 440 of file TableBase.cpp.

References vec_.

Referenced by StimulusTable::process(), Interpol::process(), and StimulusTable::reinit().

442 {
443  if ( vec_.size() == 0 )
444  return 0;
445  if ( vec_.size() == 1 || input < xmin || xmin >= xmax )
446  return vec_[0];
447  if ( input > xmax )
448  return ( vec_.back() );
449 
450  unsigned int xdivs = vec_.size() - 1;
451 
452  double fraction = ( input - xmin ) / ( xmax - xmin );
453  if ( fraction < 0 )
454  return vec_[0];
455 
456  unsigned int j = xdivs * fraction;
457  if ( j >= ( vec_.size() - 1 ) )
458  return vec_.back();
459 
460  double dx = (xmax - xmin ) / xdivs;
461  double lowerBound = xmin + j * dx;
462  double subFraction = ( input - lowerBound ) / dx;
463 
464  double y = vec_[j] + ( vec_[j + 1] - vec_[j] ) * subFraction;
465  return y;
466 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::linearTransform ( double  scale,
double  offset 
)

Definition at line 166 of file TableBase.cpp.

References vec_.

Referenced by initCinfo().

167 {
168  for ( vector< double >::iterator i = vec_.begin(); i != vec_.end(); ++i)
169  *i = *i * scale + offset;
170 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::loadCSV ( string  fname,
int  startLine,
int  colNum,
char  separator 
)

Definition at line 320 of file TableBase.cpp.

Referenced by initCinfo().

322 {
323  cout << "TODO: Not implemented yet" << endl;
324 }

+ Here is the caller graph for this function:

void TableBase::loadXplot ( string  fname,
string  plotname 
)

Definition at line 294 of file TableBase.cpp.

References innerLoadXplot(), and vec_.

Referenced by initCinfo().

295 {
296  if ( !innerLoadXplot( fname, plotname, vec_ ) ) {
297  cout << "TableBase::loadXplot: unable to load data from file " << fname <<endl;
298  return;
299  }
300 }
vector< double > vec_
Definition: TableBase.h:73
bool innerLoadXplot(string fname, string plotname, vector< double > &v)
Definition: TableBase.cpp:250

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TableBase::loadXplotRange ( string  fname,
string  plotname,
unsigned int  start,
unsigned int  end 
)

Definition at line 302 of file TableBase.cpp.

References innerLoadXplot(), and vec_.

Referenced by initCinfo().

304 {
305  vector< double > temp;
306  if ( !innerLoadXplot( fname, plotname, temp ) ) {
307  cout << "TableBase::loadXplot: unable to load data from file " << fname <<endl;
308  return;
309  }
310  if ( start > end || end > temp.size() ) {
311  cout << "TableBase::loadXplotRange: Bad range (" << start <<
312  ", " << end << "] for table of size " << temp.size() <<
313  " from file " << fname << endl;
314  return;
315  }
316  vec_.clear();
317  vec_.insert( vec_.end(), temp.begin() + start, temp.begin() + end );
318 }
vector< double > vec_
Definition: TableBase.h:73
bool innerLoadXplot(string fname, string plotname, vector< double > &v)
Definition: TableBase.cpp:250

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

double* TableBase::lookupVec ( unsigned int  index)
void TableBase::plainPlot ( string  file)

Definition at line 172 of file TableBase.cpp.

References vec_.

Referenced by initCinfo().

173 {
174  ofstream fout( fname.c_str(), ios_base::out );
175  fout.precision( 18 );
176  fout.setf( ios::scientific, ios::floatfield );
177  for ( vector< double >::iterator i = vec_.begin(); i != vec_.end(); ++i)
178  fout << *i << endl;
179  fout << "\n";
180 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::setOutputValue ( double  val)

Definition at line 428 of file TableBase.cpp.

References output_.

Referenced by StimulusTable::process(), and StimulusTable::reinit().

429 {
430  output_ = v;
431 }
double output_
Definition: TableBase.h:72

+ Here is the caller graph for this function:

void TableBase::setPlotDump ( string  v)

Definition at line 509 of file TableBase.cpp.

References xplot().

Referenced by initCinfo().

510 {
511 
512  std::size_t pos = v.rfind(" ");
513  string fname = v.substr( 0, pos );
514  string plotname = "plot";
515  if ( pos != string::npos )
516  plotname = v.substr( pos );
517  // cout << "setPlotDump( " << fname << ", " << plotname << " ), " << v << "\n";
518  xplot( fname, plotname );
519 }
void xplot(string file, string plotname)
Definition: TableBase.cpp:182

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void TableBase::setVec ( vector< double >  val)

Definition at line 487 of file TableBase.cpp.

References vec_.

Referenced by initCinfo().

488 {
489  vec_ = val;
490 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::setVecSize ( unsigned int  num)

Definition at line 472 of file TableBase.cpp.

References vec_.

473 {
474  vec_.resize( num );
475 }
vector< double > vec_
Definition: TableBase.h:73
vector< double > & TableBase::vec ( )
protected

Definition at line 492 of file TableBase.cpp.

References vec_.

Referenced by initCinfo(), Table::input(), TimeTable::process(), Table::process(), Table::reinit(), TimeTable::setFilename(), Table::spike(), and Table::~Table().

493 {
494  return vec_;
495 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

void TableBase::xplot ( string  file,
string  plotname 
)

Definition at line 182 of file TableBase.cpp.

References vec_.

Referenced by initCinfo(), and setPlotDump().

183 {
184  ofstream fout( fname.c_str(), ios_base::app );
185  fout << "/newplot\n";
186  fout << "/plotname " << plotname << "\n";
187  for ( vector< double >::iterator i = vec_.begin(); i != vec_.end(); ++i)
188  fout << *i << endl;
189  fout << "\n";
190 }
vector< double > vec_
Definition: TableBase.h:73

+ Here is the caller graph for this function:

Member Data Documentation

double TableBase::output_
private

Definition at line 72 of file TableBase.h.

Referenced by compareVec(), compareXplot(), getOutputValue(), and setOutputValue().

vector< double > TableBase::vec_
private

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