Public Types | Public Member Functions | List of all members
o2scl::table3d Class Reference

A data structure containing one or more slices of two-dimensional data points defined on a grid. More...

#include <table3d.h>

Detailed Description

Idea for Future:

Improve interpolation and derivative caching, possibly through non-const versions of the interpolation functions.

Should there be a clear_grid() function separate from clear_data() and clear()?

Allow the user to more clearly probe 'size_set' vs. 'xy_set'? (AWS 07/18: This is apparently resolved.)

Definition at line 78 of file table3d.h.

Public Types

typedef boost::numeric::ublas::vector< double > ubvector
 
typedef boost::numeric::ublas::matrix< double > ubmatrix
 
typedef boost::numeric::ublas::matrix_row< const ubmatrixubmatrix_row
 
typedef boost::numeric::ublas::matrix_column< const ubmatrixubmatrix_column
 

Public Member Functions

 table3d ()
 Create a new 3D table.
 
 table3d (o2scl::table_units<> &t, std::string colx, std::string coly)
 Create a table3d object from a table, assuming scolx and scoly store the x- and y-grid data, respectively.
 
 table3d (const table3d &t)
 Copy constructor.
 
table3doperator= (const table3d &t)
 Copy constructor.
 
Initialization
template<class vec_t , class vec2_t >
void set_xy (std::string x_name, size_t nx, const vec_t &x, std::string y_name, size_t ny, const vec2_t &y)
 Initialize the x-y grid. More...
 
void set_xy (std::string x_name, uniform_grid< double > gx, std::string y_name, uniform_grid< double > gy)
 Initialize the x-y grid with uniform_grid objects. More...
 
void set_size (size_t nx, size_t ny)
 Initialize table size. More...
 
On-grid get and set methods
void set (size_t ix, size_t iy, std::string name, double val)
 Set element in slice name at location ix,iy to value val.
 
void set (size_t ix, size_t iy, size_t z, double val)
 Set element in slice of index z at location ix,iy to value val .
 
double & get (size_t ix, size_t iy, std::string name)
 Get element in slice name at location ix,iy
 
const double & get (size_t ix, size_t iy, std::string name) const
 Get element in slice name at location ix,iy (const version)
 
double & get (size_t ix, size_t iy, size_t z)
 Get element in slice of index z at location ix,iy
 
const double & get (size_t ix, size_t iy, size_t z) const
 Get element in slice of index z at location ix,iy (const version)
 
Off-grid get and set methods

These methods return the value of a slice on the grid point nearest to a user-specified location. For interpolation into a point off the grid, use table3d::interp().

void set_val (double x, double y, std::string name, double val)
 Set element in slice name at the nearest location to x,y to value val.
 
void set_val (double x, double y, size_t z, double val)
 Set element in slice of index z at the nearest location to x,y to value val.
 
double & get_val (double x, double y, std::string name)
 Get element in slice name at location closest to x,y
 
const double & get_val (double x, double y, std::string name) const
 Get element in slice name at location closest to x,y
 
double & get_val (double x, double y, size_t z)
 Get element in slice of index z at location closest to x,y
 
const double & get_val (double x, double y, size_t z) const
 Get element in slice of index z at location closest to x,y
 
template<class vec_t >
void set_slices (double x, double y, size_t nv, vec_t &vals)
 Set elements in the first nv slices at the nearest location to x,y to value val.
 
template<class vec_t >
void get_slices (double x, double y, size_t nv, vec_t &v)
 Get the data for every slice at the nearest location to x,y
 
Off-grid get and set methods returning nearest point
void set_val_ret (double &x, double &y, std::string name, double val)
 Set element in slice name at the nearest location to x,y to value val.
 
void set_val_ret (double &x, double &y, size_t z, double val)
 Set element in slice of index z at the nearest location to x,y to value val.
 
double & get_val_ret (double &x, double &y, std::string name)
 Get element in slice name at location closest to x,y, and also return the corresponding values of x and y.
 
const double & get_val_ret (double &x, double &y, std::string name) const
 Get element in slice name at location closest to x,y, and also return the corresponding values of x and y.
 
double & get_val_ret (double &x, double &y, size_t z)
 Get element in slice of index z at location closest to x,y, and also return the corresponding values of x and y.
 
const double & get_val_ret (double &x, double &y, size_t z) const
 Get element in slice of index z at location closest to x,y, and also return the corresponding values of x and y.
 
void add_slice_from_table (table3d &source, std::string slice, std::string dest_slice="")
 This function adds a slice from a different table3d object, interpolating the results into the current table3d object.
 
template<class vec_t >
void set_slices_ret (double &x, double &y, size_t nv, vec_t &vals)
 Set elements in the first nv slices at the nearest location to x,y to values vals.
 
template<class vec_t >
void get_slices_ret (double &x, double &y, size_t nv, vec_t &vals)
 Get elements in the first nv slices at the nearest location to x,y to value val.
 
Grid information get and set methods
void set_grid_x (size_t ix, double val)
 Set x grid point at index ix.
 
void set_grid_y (size_t iy, double val)
 Set y grid point at index iy.
 
double get_grid_x (size_t ix) const
 Get x grid point at index ix.
 
double get_grid_y (size_t iy) const
 Get y grid point at index iy.
 
std::string get_x_name () const
 Get the name of the x grid variable.
 
std::string get_y_name () const
 Get the name of the y grid variable.
 
void set_x_name (std::string name)
 Set the name of the x grid variable.
 
void set_y_name (std::string name)
 Set the name of the y grid variable.
 
const ubvectorget_x_data () const
 Get a const reference to the full x grid.
 
const ubvectorget_y_data () const
 Get a const reference to the full y grid.
 
Size get methods
void get_size (size_t &nx, size_t &ny) const
 Get the size of the slices.
 
size_t get_nx () const
 Get the x size.
 
size_t get_ny () const
 Get the y size.
 
size_t get_nslices () const
 Get the number of slices.
 
bool is_size_set () const
 True if the size of the table has been set.
 
bool is_xy_set () const
 True if the grid has been set.
 
Slice manipulation
void line_of_names (std::string names)
 Create a set of new slices specified in the string names.
 
std::string get_slice_name (size_t z) const
 Returns the name of slice with index z.
 
void new_slice (std::string name)
 Add a new slice.
 
void set_slice_all (std::string name, double val)
 Set all of the values in slice name to val.
 
size_t lookup_slice (std::string name) const
 Find the index for slice named name.
 
bool is_slice (std::string name, size_t &ix) const
 Return true if slice is already present.
 
void rename_slice (std::string olds, std::string news)
 Rename slice named olds to news. More...
 
void copy_slice (std::string src, std::string dest)
 Make a new slice named dest which is a copy of the slice with name given in src.
 
void init_slice (std::string scol, double val)
 Initialize all values of slice named scol to val. More...
 
const ubmatrixget_slice (std::string scol) const
 Return a constant reference to a slice.
 
const ubmatrixget_slice (size_t iz) const
 Return a constant reference to a slice.
 
ubmatrixget_slice (std::string scol)
 Return a constant reference to a slice.
 
ubmatrixget_slice (size_t iz)
 Return a constant reference to a slice.
 
const std::vector< ubmatrix > & get_data ()
 Return a constant reference to all the slice data. More...
 
template<class mat_t >
void copy_to_slice (mat_t &m, std::string slice_name)
 Copy to a slice from a generic matrix object. More...
 
Lookup and search methods
void lookup_x (double val, size_t &ix) const
 Look for a value in the x grid.
 
void lookup_y (double val, size_t &iy) const
 Look for a value in the y grid.
 
void lookup (double val, std::string slice, size_t &ix, size_t &iy) const
 Look for a value in a specified slice.
 
Interpolation, differentiation, and integration
void set_interp_type (size_t interp_type)
 Specify the interpolation type.
 
size_t get_interp_type () const
 Get the interpolation type.
 
double interp (double x, double y, std::string name) const
 Interpolate x and y in slice named name.
 
double deriv_x (double x, double y, std::string name) const
 Interpolate the derivative of the data with respect to the x grid at point x and y in slice named name.
 
double deriv_y (double x, double y, std::string name) const
 Interpolate the derivative of the data with respect to the y grid at point x and y in slice named name.
 
double deriv_xy (double x, double y, std::string name) const
 Interpolate the mixed second derivative of the data at point x and y in slice named name.
 
double integ_x (double x1, double x2, double y, std::string name) const
 Interpolate the integral of the data respect to the x grid.
 
double integ_y (double x, double y1, double y2, std::string name) const
 Interpolate the integral of the data respect to the y grid.
 
template<class vec_t >
void interp_slices (double x, double y, size_t nv, vec_t &v)
 Fill a vector of interpolated values from each slice at the point x,y
 
void deriv_x (std::string fname, std::string fpname)
 Create a new slice, named fpname, containing the derivative of fname with respect to the x coordinate.
 
void deriv_y (std::string fname, std::string fpname)
 Create a new slice, named fpname, containing the derivative of fname with respect to the y coordinate.
 
Extract 2-dimensional tables
void extract_x (double x, table<> &t)
 Extract a table at a fixed x grid point. More...
 
void extract_y (double y, table<> &t)
 Extract a table at a fixed y grid point. More...
 
Clear methods
void zero_table ()
 Zero the data entries but keep the slice names and grid.
 
void clear ()
 Clear everything.
 
void clear_data ()
 Remove all of the data by setting the number of lines to zero. More...
 
Contour lines method
template<class vec_t >
void slice_contours (std::string name, size_t nlev, vec_t &levs, std::vector< contour_line > &clines)
 Create contour lines from the slice named name. More...
 
Manipulating constants
virtual void add_constant (std::string name, double val)
 Add a constant, or if the constant already exists, change its value.
 
virtual void remove_constant (std::string name)
 Remove a constant.
 
virtual int set_constant (std::string name, double val, bool err_on_notfound=true)
 Set a constant equal to a value, but don't add it if not already present. More...
 
virtual bool is_constant (std::string name) const
 Test if name is a constant.
 
virtual double get_constant (std::string name)
 Get a constant.
 
virtual void get_constant (size_t ix, std::string &name, double &val) const
 Get a constant by index.
 
virtual size_t get_nconsts () const
 Get the number of constants.
 
Miscellaneous methods
int read_gen3_list (std::istream &fin, int verbose=0, double eps=1.0e-12)
 Read a generic table3d object specified as a text file. More...
 
template<class vec_t >
int read_table (const o2scl::table< vec_t > &tab, std::string xname2="", std::string yname2="", double empty_value=0.0, int verbose=0, bool err_on_fail=true, double eps=1.0e-12)
 Set the current table3d object by reading a o2scl::table. More...
 
virtual const char * type ()
 Return the type, "table3d".
 
Parsing mathematical functions specified as strings
template<class resize_mat_t >
int function_matrix (std::string function, resize_mat_t &mat, bool throw_on_err=true)
 Fill a matrix from the function specified in function. More...
 
void function_slice (std::string function, std::string col)
 Make a column from function and add it to the table. More...
 
table3d slice_to_uniform_grid (std::string slice, size_t xpts, bool log_x, size_t ypts, bool log_y)
 Copy slice named slice to a new o2scl::table3d object with a uniform grid using the current interpolation type.
 
table3d table_to_uniform_grid (size_t xpts, bool log_x, size_t ypts, bool log_y)
 Copy entire table to a new o2scl::table3d object with a uniform grid using the current interpolation type.
 

Protected Types

Iterator types
typedef std::map< std::string, size_t, std::greater< std::string > >::iterator map_iter
 
typedef std::map< std::string, size_t, std::greater< std::string > >::const_iterator map_const_iter
 

Protected Member Functions

Tree iterator boundaries
map_iter begin ()
 Return the beginning of the slice tree.
 
map_iter end ()
 Return the end of the slice tree.
 
map_const_iter const_begin () const
 Return the beginning of the slice tree.
 
map_const_iter const_end () const
 Return the end of the slice tree.
 

Protected Attributes

Data storage
std::map< std::string, double > constants
 The list of constants.
 
size_t numx
 The size of the x grid.
 
size_t numy
 The size of the y grid.
 
std::map< std::string, size_t, std::greater< std::string > > tree
 A tree connecting column names to list indexes.
 
std::string xname
 The name for the x grid.
 
std::string yname
 The name for the y grid.
 
std::vector< ubmatrixlist
 The pointers to the matrices.
 
ubvector xval
 The x grid.
 
ubvector yval
 The y grid.
 
bool xy_set
 True if the grid has been set.
 
bool size_set
 True if the size of the grid has been set.
 
bool has_slice
 True if the table has at least one slice.
 
size_t itype
 The interpolation type.
 

Summary method

void summary (std::ostream *out, int ncol=79) const
 Output a summary of the information stored. More...
 
void o2scl_hdf::hdf_output (o2scl_hdf::hdf_file &hf, table3d &t, std::string name)
 
void o2scl_hdf::hdf_input (o2scl_hdf::hdf_file &hf, table3d &t, std::string name)
 

Member Function Documentation

◆ clear_data()

void o2scl::table3d::clear_data ( )

This leaves the column names intact and does not remove the constants.

◆ copy_to_slice()

template<class mat_t >
void o2scl::table3d::copy_to_slice ( mat_t &  m,
std::string  slice_name 
)
inline

The type mat_t can be any type with an operator(,) method.

Definition at line 492 of file table3d.h.

◆ extract_x()

void o2scl::table3d::extract_x ( double  x,
table<> &  t 
)
Note
All of the information previously stored in t will be lost.

◆ extract_y()

void o2scl::table3d::extract_y ( double  y,
table<> &  t 
)
Note
All of the information previously stored in t will be lost.

◆ function_matrix()

template<class resize_mat_t >
int o2scl::table3d::function_matrix ( std::string  function,
resize_mat_t &  mat,
bool  throw_on_err = true 
)
inline

Definition at line 870 of file table3d.h.

◆ function_slice()

void o2scl::table3d::function_slice ( std::string  function,
std::string  col 
)

If the column already exists, the data already present is overwritten with the result.

◆ get_data()

const std::vector<ubmatrix>& o2scl::table3d::get_data ( )

◆ init_slice()

void o2scl::table3d::init_slice ( std::string  scol,
double  val 
)
Note
This will call the error handler if the value val is not finite (i.e. either Inf or NaN).

◆ read_gen3_list()

int o2scl::table3d::read_gen3_list ( std::istream &  fin,
int  verbose = 0,
double  eps = 1.0e-12 
)

This function reads a set of columns of numerical values, presuming that the first column is the x-grid value, the second column is the y-grid value, and the remaining columns are slices to be added. If the first row appears to be strings rather than numerical values, then the first row is used for the x name, y name, and slice names. Values in the first two columns which differ by less than eps are assumed to refer to the same grid point. If not all combinations of x and y are found, then those entries are left unchanged in all slices.

Idea for Future:
It would be great to add a function which generates a text file in this format as well.

◆ read_table()

template<class vec_t >
int o2scl::table3d::read_table ( const o2scl::table< vec_t > &  tab,
std::string  xname2 = "",
std::string  yname2 = "",
double  empty_value = 0.0,
int  verbose = 0,
bool  err_on_fail = true,
double  eps = 1.0e-12 
)
inline

Definition at line 734 of file table3d.h.

◆ rename_slice()

void o2scl::table3d::rename_slice ( std::string  olds,
std::string  news 
)

This is slow since we have to delete the column and re-insert it. This process in turn mangles all of the iterators in the list.

◆ set_constant()

virtual int o2scl::table3d::set_constant ( std::string  name,
double  val,
bool  err_on_notfound = true 
)
virtual

If err_on_notfound is true (the default), then this function throws an exception if a constant with name name is not found. If err_on_notfound is false, then if a constant with name name is not found this function just silently returns o2scl::exc_enotfound.

◆ set_size()

void o2scl::table3d::set_size ( size_t  nx,
size_t  ny 
)

This function will not allow you to resize the table if it already has data or if the size has already been set with the set_xy() function, unless you clear the data with clear_data() or the table with clear_table() first.

◆ set_xy() [1/2]

template<class vec_t , class vec2_t >
void o2scl::table3d::set_xy ( std::string  x_name,
size_t  nx,
const vec_t &  x,
std::string  y_name,
size_t  ny,
const vec2_t &  y 
)
inline

This function will not allow you to redefine the grid when there is data in the table if a grid of a different size was already set from a previous call to either set_xy() or set_size(). However, you may freely redefine the grid after a call to clear_data() or clear_table(). You may change individual grid points at any time with set_grid_x() and set_grid_y().

Definition at line 120 of file table3d.h.

◆ set_xy() [2/2]

void o2scl::table3d::set_xy ( std::string  x_name,
uniform_grid< double >  gx,
std::string  y_name,
uniform_grid< double >  gy 
)

This function will not allow you to redefine the grid when there is data in the table if a grid of a different size was already set from a previous call to either set_xy() or set_size(). However, you may freely redefine the grid after a call to clear_data() or clear_table(). You may change individual grid points at any time with set_grid_x() and set_grid_y().

◆ slice_contours()

template<class vec_t >
void o2scl::table3d::slice_contours ( std::string  name,
size_t  nlev,
vec_t &  levs,
std::vector< contour_line > &  clines 
)
inline

This uses contour to compute contour lines (stored in clines) from slice name given nlev contour levels in levs .

Definition at line 656 of file table3d.h.

◆ summary()

void o2scl::table3d::summary ( std::ostream *  out,
int  ncol = 79 
) const

Outputs the number of constants, the grid information, and a list of the slice names


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

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).