Go to the documentation of this file.
23 #ifndef O2SCL_TABLE3D_H
24 #define O2SCL_TABLE3D_H
37 #include <boost/numeric/ublas/vector.hpp>
38 #include <boost/numeric/ublas/vector_proxy.hpp>
39 #include <boost/numeric/ublas/matrix.hpp>
40 #include <boost/numeric/ublas/matrix_proxy.hpp>
42 #include <o2scl/misc.h>
43 #include <o2scl/err_hnd.h>
44 #include <o2scl/search_vec.h>
45 #include <o2scl/uniform_grid.h>
46 #include <o2scl/interp.h>
47 #include <o2scl/table_units.h>
48 #include <o2scl/contour.h>
49 #include <o2scl/shunting_yard.h>
50 #include <o2scl/vector.h>
61 void hdf_output(hdf_file &hf,
o2scl::table3d &t, std::string name);
64 #ifndef DOXYGEN_NO_O2NS
86 typedef boost::numeric::ublas::matrix_row<const ubmatrix> ubmatrix_row;
87 typedef boost::numeric::ublas::matrix_column<const ubmatrix>
119 template<
class vec_t,
class vec2_t>
120 void set_xy(std::string x_name,
size_t nx,
const vec_t &x,
121 std::string y_name,
size_t ny,
const vec2_t &y) {
124 O2SCL_ERR(
"Size cannot be reset in table3d::set_xy().",
138 for(
size_t i=0;i<nx;i++) (
xval)[i]=x[i];
139 for(
size_t i=0;i<ny;i++) (
yval)[i]=y[i];
165 void set_size(
size_t nx,
size_t ny);
175 void set(
size_t ix,
size_t iy, std::string name,
double val);
180 void set(
size_t ix,
size_t iy,
size_t z,
double val);
185 double &
get(
size_t ix,
size_t iy, std::string name);
190 const double &
get(
size_t ix,
size_t iy, std::string name)
const;
195 double &
get(
size_t ix,
size_t iy,
size_t z);
200 const double &
get(
size_t ix,
size_t iy,
size_t z)
const;
216 void set_val(
double x,
double y, std::string name,
double val);
221 void set_val(
double x,
double y,
size_t z,
double val);
226 double &
get_val(
double x,
double y, std::string name);
231 const double &
get_val(
double x,
double y, std::string name)
const;
236 double &
get_val(
double x,
double y,
size_t z);
241 const double &
get_val(
double x,
double y,
size_t z)
const;
246 template<
class vec_t>
247 void set_slices(
double x,
double y,
size_t nv, vec_t &vals) {
252 for(
size_t i=0;i<nv && i<
list.size();i++) {
253 list[i](ix,iy)=vals[i];
261 template<
class vec_t>
269 for(
size_t i=0;i<nv && i<
list.size();i++) {
284 void set_val_ret(
double &x,
double &y, std::string name,
double val);
289 void set_val_ret(
double &x,
double &y,
size_t z,
double val);
295 double &
get_val_ret(
double &x,
double &y, std::string name);
301 const double &
get_val_ret(
double &x,
double &y, std::string name)
const;
307 double &
get_val_ret(
double &x,
double &y,
size_t z);
313 const double &
get_val_ret(
double &x,
double &y,
size_t z)
const;
320 std::string dest_slice=
"");
325 template<
class vec_t>
333 for(
size_t i=0;i<nv && i<
list.size();i++) {
334 list[i](ix,iy)=vals[i];
342 template<
class vec_t>
351 for(
size_t i=0;i<nv && i<
list.size();i++) {
352 vals[i]=
list[i](ix,iy);
398 void get_size(
size_t &nx,
size_t &ny)
const;
441 bool is_slice(std::string name,
size_t &ix)
const;
454 void copy_slice(std::string src, std::string dest);
461 void init_slice(std::string scol,
double val);
484 const std::vector<ubmatrix> &
get_data();
491 template<
class mat_t>
493 for(
size_t i=0;i<
numx;i++) {
494 for(
size_t j=0;j<
numy;j++) {
495 this->
set(i,j,slice_name,m(i,j));
507 void lookup_x(
double val,
size_t &ix)
const;
511 void lookup_y(
double val,
size_t &iy)
const;
515 void lookup(
double val, std::string slice,
size_t &ix,
533 double interp(
double x,
double y, std::string name)
const;
538 double deriv_x(
double x,
double y, std::string name)
const;
543 double deriv_y(
double x,
double y, std::string name)
const;
548 double deriv_xy(
double x,
double y, std::string name)
const;
553 double integ_x(
double x1,
double x2,
double y, std::string name)
const;
558 double integ_y(
double x,
double y1,
double y2, std::string name)
const;
563 template<
class vec_t>
566 for (
size_t i=0;i<
list.size();i++) {
577 void deriv_x(std::string fname, std::string fpname);
582 void deriv_y(std::string fname, std::string fpname);
632 void summary(std::ostream *out,
int ncol=79)
const;
655 template<
class vec_t>
657 std::vector<contour_line> &clines) {
676 virtual void add_constant(std::string name,
double val);
692 bool err_on_notfound=
true);
728 int read_gen3_list(std::istream &fin,
int verbose=0,
double eps=1.0e-12);
733 template<
class vec_t>
735 std::string xname2=
"", std::string yname2=
"",
736 double empty_value=0.0,
int verbose=0,
737 bool err_on_fail=
true,
double eps=1.0e-12) {
751 if (xname2.length()==0) {
759 if (yname2.length()==0) {
768 const vec_t &xdata=tab[xname2];
769 const vec_t &ydata=tab[yname2];
771 std::vector<double> xgrid, ygrid;
780 for(
size_t j=0;j<xgrid.size();j++) {
781 if (fabs(xdata[i]-xgrid[j])/fabs(xgrid[j])<eps) {
788 xgrid.push_back(xdata[i]);
793 for(
size_t j=0;j<ygrid.size();j++) {
794 if (fabs(ydata[i]-ygrid[j])/fabs(ygrid[j])<eps) {
801 ygrid.push_back(ydata[i]);
806 std::cout <<
"X grid: " << std::endl;
807 for(
size_t k=0;k<xgrid.size();k++) {
808 std::cout << k <<
" " << xgrid[k] << std::endl;
810 std::cout <<
"Y grid: " << std::endl;
811 for(
size_t k=0;k<ygrid.size();k++) {
812 std::cout << k <<
" " << ygrid[k] << std::endl;
821 set_xy(xname2,xgrid.size(),xgrid,yname2,ygrid.size(),ygrid);
824 std::vector<std::string> sl_names;
829 std::cout <<
"New slice: " << sl << std::endl;
831 sl_names.push_back(sl);
851 virtual const char *
type() {
return "table3d"; }
869 template<
class resize_mat_t>
871 bool throw_on_err=
true) {
874 std::map<std::string,double> vars;
876 std::map<std::string,double>::const_iterator mit;
878 vars[mit->first]=mit->second;
881 calc.
compile(
function.c_str(),&vars);
883 if (mat.size1()!=
numx || mat.size2()!=
numy) {
887 for(
size_t i=0;i<
numx;i++) {
888 for(
size_t j=0;j<
numy;j++) {
892 for(
size_t k=0;k<
list.size();k++) {
896 mat(i,j)=calc.
eval(&vars);
916 bool log_x,
size_t ypts,
bool log_y);
922 size_t ypts,
bool log_y);
924 #ifdef O2SCL_NEVER_DEFINED
928 template<
class vec_t>
929 void test_uniform_grid_log(std::string slice,
bool &log_x,
bool &log_y,
930 vec_t &x, vec_t &y, vec_t &s) {
931 vector<double> dev_x;
932 for(
size_t i=0;i<
numx-1;i++) {
939 if (stddev<1.0e-8*fabs(avg)) {
941 for(
size_t i=0;i<
numx;i++) {
947 for(
size_t i=0;i<
numx-1;i++) {
952 if (stddev<1.0e-8*fabs(avg)) {
954 for(
size_t i=0;i<
numx;i++) {
970 #ifndef DOXYGEN_INTERNAL
974 typedef std::map<std::string,size_t,
975 std::greater<std::string> >::iterator map_iter;
976 typedef std::map<std::string,size_t,
977 std::greater<std::string> >::const_iterator map_const_iter;
992 std::map<std::string,size_t,std::greater<std::string> >
tree;
1038 #ifndef DOXYGEN_NO_O2NS
virtual bool is_constant(std::string name) const
Test if name is a constant.
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.
void set_levels(size_t nlevels, vec_t &ulevels)
Set the contour levels.
size_t get_nlines() const
Return the number of lines.
map_iter end()
Return the end of the slice tree.
void extract_y(double y, table<> &t)
Extract a table at a fixed y grid point.
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 lookup(double val, std::string slice, size_t &ix, size_t &iy) const
Look for a value in a specified slice.
void extract_x(double x, table<> &t)
Extract a table at a fixed x grid point.
map_const_iter const_end() const
Return the end of the slice tree.
void line_of_names(std::string names)
Create a set of new slices specified in the string names.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
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 new_slice(std::string name)
Add a new slice.
std::string get_y_name() const
Get the name of the y grid variable.
double & get_val(double x, double y, std::string name)
Get element in slice name at location closest to x,y
std::string get_x_name() const
Get the name of the x grid variable.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
double vector_mean(size_t n, const vec_t &data)
Compute the mean of the first n elements of a vector.
virtual double get_constant(std::string name)
Get a constant.
virtual size_t get_nconsts() const
Get the number of constants.
double integ_y(double x, double y1, double y2, std::string name) const
Interpolate the integral of the data respect to the y grid.
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 nam...
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.
Calculate contour lines from a two-dimensional data set.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
const ubvector & get_y_data() const
Get a const reference to the full y grid.
static const double x2[5]
void copy_to_slice(mat_t &m, std::string slice_name)
Copy to a slice from a generic matrix object.
double integ_x(double x1, double x2, double y, std::string name) const
Interpolate the integral of the data respect to the x grid.
bool size_set
True if the size of the grid has been set.
void compile(const char *expr, std::map< std::string, double > *vars=0, bool debug=false, std::map< std::string, int > opPrec=opPrecedence)
Compile expression expr using variables specified in vars and return an integer to indicate success o...
Data table table class with units.
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
table3d()
Create a new 3D table table .
std::string yname
The name for the y grid.
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 curren...
double vector_stddev(size_t n, const vec_t &data)
Standard deviation with specified mean.
size_t numy
The size of the y grid.
bool xy_set
True if the grid has been set.
static const double x1[5]
void zero_table()
Zero the data entries but keep the slice names and grid.
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 init_slice(std::string scol, double val)
Initialize all values of slice named scol to val.
void set_size(size_t nx, size_t ny)
Initialize table table size.
@ exc_einval
invalid argument supplied by user
Evaluate a mathematical expression in a string.
void set_grid_x(size_t ix, double val)
Set x grid point at index ix.
std::map< std::string, double > constants
The list of constants.
void set_grid_y(size_t iy, double val)
Set y grid point at index iy.
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 nam...
std::map< std::string, size_t, std::greater< std::string > > tree
A tree connecting column names to list indexes.
const ubvector & get_x_data() const
Get a const reference to the full x grid.
size_t get_nx() const
Get the x size.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
void calc_contours(std::vector< contour_line > &clines)
Calculate the contours.
void clear_data()
Remove all of the data by setting the number of lines to zero.
double & get(size_t ix, size_t iy, std::string name)
Get element in slice name at location ix,iy
double get_grid_x(size_t ix) const
Get x grid point at index ix.
void set_interp_type(size_t interp_type)
Specify the interpolation type.
void clear()
Clear everything.
std::string get_slice_name(size_t z) const
Returns the name of slice with index z.
void lookup_x(double val, size_t &ix) const
Look for a value in the x grid.
map_iter begin()
Return the beginning of the slice tree.
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.
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.
double interp(double x, double y, std::string name) const
Interpolate 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.
size_t get_ncolumns() const
Return the number of columns.
size_t get_nslices() const
Get the number of slices.
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.
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 interpola...
map_const_iter const_begin() const
Return the beginning of the slice tree.
void set_y_name(std::string name)
Set the name of the y grid variable.
bool is_size_set() const
True if the size of the table has been set.
int function_matrix(std::string function, resize_mat_t &mat, bool throw_on_err=true)
Fill a matrix from the function specified in function.
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.
bool is_slice(std::string name, size_t &ix) const
Return true if slice is already present.
size_t lookup_slice(std::string name) const
Find the index for slice named name.
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.
bool is_xy_set() const
True if the grid has been set.
void vector_sort_double(size_t n, vec_t &data)
Sort a vector of doubles (in increasing order)
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
size_t get_ny() const
Get the y size.
void set_slice_all(std::string name, double val)
Set all of the values in slice name to val.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
void get_size(size_t &nx, size_t &ny) const
Get the size of the slices.
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 ...
void summary(std::ostream *out, int ncol=79) const
Output a summary of the information stored.
double get_grid_y(size_t iy) const
Get y grid point at index iy.
double eval(std::map< std::string, double > *vars=0)
Evalate the previously compiled expression using variables specified in vars.
size_t numx
The size of the x grid.
void function_slice(std::string function, std::string col)
Make a column from function and add it to the table.
virtual void add_constant(std::string name, double val)
Add a constant, or if the constant already exists, change its value.
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 a...
const ubmatrix & get_slice(std::string scol) const
Return a constant reference to a slice.
std::string xname
The name for the x grid.
double get(std::string scol, size_t row) const
Get value from row row of column named col. .
bool has_slice
True if the table has at least one slice.
virtual void remove_constant(std::string name)
Remove a constant.
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.
void set_data(size_t sizex, size_t sizey, const vec_t &x_fun, const vec_t &y_fun, const mat_t &udata)
Set the data.
void lookup_y(double val, size_t &iy) const
Look for a value in the y grid.
void set_x_name(std::string name)
Set the name of the x grid variable.
size_t itype
The interpolation type.
std::vector< ubmatrix > list
The pointers to the matrices.
table3d & operator=(const table3d &t)
Copy constructor.
A data structure containing one or more slices of two-dimensional data points defined on a grid.
std::string get_column_name(size_t icol) const
Returns the name of column col .
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.
size_t get_interp_type() const
Get the interpolation type.
void rename_slice(std::string olds, std::string news)
Rename slice named olds to news.
virtual const char * type()
Return the type, "table3d".
const std::vector< ubmatrix > & get_data()
Return a constant reference to all the slice data.
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.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).