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>
62 #ifndef DOXYGEN_NO_O2NS
82 typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
83 typedef boost::numeric::ublas::matrix_column<ubmatrix> ubmatrix_column;
108 template<
class vec_t,
class vec2_t>
109 void set_xy(std::string x_name,
size_t nx,
const vec_t &x,
110 std::string y_name,
size_t ny,
const vec2_t &y) {
113 O2SCL_ERR(
"Size cannot be reset in table3d::set_xy().",
127 for(
size_t i=0;i<nx;i++) (
xval)[i]=x[i];
128 for(
size_t i=0;i<ny;i++) (
yval)[i]=y[i];
149 O2SCL_ERR(
"Size cannot be reset in table3d::set_xy().",
177 void set_size(
size_t nx,
size_t ny);
187 void set(
size_t ix,
size_t iy, std::string name,
double val);
192 void set(
size_t ix,
size_t iy,
size_t z,
double val);
197 double &
get(
size_t ix,
size_t iy, std::string name);
202 const double &
get(
size_t ix,
size_t iy, std::string name)
const;
207 double &
get(
size_t ix,
size_t iy,
size_t z);
212 const double &
get(
size_t ix,
size_t iy,
size_t z)
const;
228 void set_val(
double x,
double y, std::string name,
double val);
233 void set_val(
double x,
double y,
size_t z,
double val);
238 double &
get_val(
double x,
double y, std::string name);
243 const double &
get_val(
double x,
double y, std::string name)
const;
248 double &
get_val(
double x,
double y,
size_t z);
253 const double &
get_val(
double x,
double y,
size_t z)
const;
258 template<
class vec_t>
259 void set_slices(
double x,
double y,
size_t nv, vec_t &vals) {
264 for(
size_t i=0;i<nv && i<
list.size();i++) {
265 list[i](ix,iy)=vals[i];
273 template<
class vec_t>
281 for(
size_t i=0;i<nv && i<
list.size();i++) {
296 void set_val_ret(
double &x,
double &y, std::string name,
double val);
301 void set_val_ret(
double &x,
double &y,
size_t z,
double val);
307 double &
get_val_ret(
double &x,
double &y, std::string name);
313 const double &
get_val_ret(
double &x,
double &y, std::string name)
const;
319 double &
get_val_ret(
double &x,
double &y,
size_t z);
325 const double &
get_val_ret(
double &x,
double &y,
size_t z)
const;
330 std::string dest_slice=
"") {
332 if (dest_slice.length()==0) dest_slice=slice;
338 for(
size_t i=0;i<
numx;i++) {
339 for(
size_t j=0;j<
numx;j++) {
340 set(i,j,dest_slice,source.
get(i,j,slice));
348 for(
size_t i=0;i<
numx;i++) {
349 for(
size_t j=0;j<
numx;j++) {
360 template<
class vec_t>
368 for(
size_t i=0;i<nv && i<
list.size();i++) {
369 list[i](ix,iy)=vals[i];
377 template<
class vec_t>
386 for(
size_t i=0;i<nv && i<
list.size();i++) {
387 vals[i]=
list[i](ix,iy);
445 void get_size(
size_t &nx,
size_t &ny)
const;
486 bool is_slice(std::string name,
size_t &ix)
const;
499 void copy_slice(std::string src, std::string dest);
506 void init_slice(std::string scol,
double val);
509 const ubmatrix &
get_slice(std::string scol)
const;
512 const ubmatrix &
get_slice(
size_t iz)
const;
529 const std::vector<ubmatrix> &
get_data();
537 void lookup_x(
double val,
size_t &ix)
const;
541 void lookup_y(
double val,
size_t &iy)
const;
545 void lookup(
double val, std::string slice,
size_t &ix,
size_t &iy)
const;
562 double interp(
double x,
double y, std::string name);
567 double deriv_x(
double x,
double y, std::string name);
572 double deriv_y(
double x,
double y, std::string name);
577 double deriv_xy(
double x,
double y, std::string name);
582 double integ_x(
double x1,
double x2,
double y, std::string name);
587 double integ_y(
double x,
double y1,
double y2, std::string name);
592 template<
class vec_t>
595 for (
size_t i=0;i<
list.size();i++) {
652 void summary(std::ostream *out,
int ncol=79)
const;
684 template<
class vec_t>
686 std::vector<contour_line> &clines) {
703 virtual void add_constant(std::string name,
double val);
709 virtual void set_constant(std::string name,
double val);
715 virtual void get_constant(
size_t ix, std::string &name,
double &val)
const;
724 virtual const char *
type() {
return "table3d"; }
744 #ifndef DOXYGEN_INTERNAL
750 std::map<std::string,double>::const_iterator mit;
752 fp.AddConstant(mit->first,mit->second);
768 typedef std::map<std::string,size_t, string_comp>::iterator map_iter;
769 typedef std::map<std::string,size_t, string_comp>::const_iterator
785 std::map<std::string,size_t,string_comp>
tree;
830 #ifndef DOXYGEN_NO_O2NS
double deriv_x(double x, double y, std::string name)
Interpolate the derivative of the data with respect to the x grid at point x and y in slice named nam...
void set_fp_consts(FunctionParser &fp) const
Internal function to set function parser constants equal to internal constants.
bool size_set
True if the size of the grid has been set.
size_t get_nslices() const
Get the number of slices.
Interpolation class for pre-specified vector.
virtual double get_constant(std::string name)
Get a constant.
virtual size_t get_nconsts() const
Get the number of constants.
Parse a mathematical function specified in a string.
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.
std::string get_y_name() const
Get the name of the y grid variable.
bool is_xy_set() const
True if the grid has been set.
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.
size_t lookup_slice(std::string name) const
Find the index for column named name.
void set_grid_y(size_t iy, double val)
Set y grid point at index iy.
bool is_slice(std::string name, size_t &ix) const
Return true if slice is already present.
void set_size(size_t nx, size_t ny)
Initialize table table size.
size_t numy
The size of the y grid.
interp_vec< ubvector > ** si
The array of interp_sm pointers.
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.
size_t get_nx() const
Get the x size.
double get_grid_x(size_t ix)
Get x grid point at index ix.
double deriv_xy(double x, double y, std::string name)
Interpolate the mixed second derivative of the data at point x and y in slice named name...
virtual void add_constant(std::string name, double val)
Add a constant.
double & get(size_t ix, size_t iy, std::string name)
Get element in slice name at location ix,iy
std::string xname
The name for the x grid.
void set_interp_type(size_t interp_type)
Specify the interpolation type.
invalid argument supplied by user
const ubvector & get_y_data() const
Get a const reference to the full y grid.
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.
map_iter begin()
Return the beginning of the slice tree.
void hdf_output(hdf_file &hf, o2scl::table3d &t, std::string name)
Output a o2scl::table3d object to a hdf_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.
virtual void remove_constant(std::string name)
Remove a constant.
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.
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...
size_t numx
The size of the x grid.
bool has_slice
True if the table has at least one slice.
void set_y_name(std::string name)
Set the name of the y grid variable.
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.
const ubmatrix & get_slice(std::string scol) const
Return a constant reference to a slice.
void function_slice(std::string formula, std::string col)
Make a column from formula and add it to the table.
void extract_y(double y, table<> &t)
Extract a table at a fixed y grid point.
void rename_slice(std::string olds, std::string news)
Rename slice named olds to news.
void summary(std::ostream *out, int ncol=79) const
Output a summary of the information stored.
Calculate contour lines from a two-dimensional data set.
std::vector< ubmatrix > list
The pointers to the matrices.
bool is_size_set() const
True if the size of the table has been set.
const std::vector< ubmatrix > & get_data()
Return a constant reference to all the slice data.
void lookup(double val, std::string slice, size_t &ix, size_t &iy) const
Look for a value in a specified slice.
virtual const char * type()
Return the type, "table3d".
void set_x_name(std::string name)
Set the name of the x grid variable.
virtual void set_constant(std::string name, double val)
Add a constant.
void get_size(size_t &nx, size_t &ny) const
Get the size of the slices.
void line_of_names(std::string names)
Create a set of new slices specified in the string names.
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.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
double deriv_y(double x, double y, std::string name)
Interpolate the derivative of the data with respect to the y grid at point x and y in slice named nam...
double & get_val(double x, double y, std::string name)
Get element in slice name at location closest to x,y
map_iter end()
Return the end of the slice tree.
double integ_y(double x, double y1, double y2, std::string name)
Interpolate the integral of the data respect to the y grid.
void extract_x(double x, table<> &t)
Extract a table at a fixed x grid point.
table3d()
Create a new 3D table table .
Data table table class with units.
std::map< std::string, size_t, string_comp > tree
A tree connecting column names to list indexes.
void clear_table()
Clear the table and the slice names.
size_t get_interp_type() const
Get the interpolation type.
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.
double get_grid_y(size_t iy)
Get y grid point at index iy.
bool xy_set
True if the grid has been set.
map_const_iter const_end() const
Return the end of the slice tree.
void lookup_y(double val, size_t &iy) const
Look for a value in the y grid.
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_x(double val, size_t &ix) const
Look for a value in the x grid.
const ubvector & get_x_data() const
Get a const reference to the full x grid.
A data structure containing many slices of two-dimensional data points defined on a grid...
double integ_x(double x1, double x2, double y, std::string name)
Interpolate the integral of the data respect to the x grid.
std::string get_x_name() const
Get the name of the x grid variable.
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl...
double interp(double x, double y, std::string name)
Interpolate x and y in slice named name.
void new_slice(std::string name)
Add a new slice.
std::string yname
The name for the y grid.
void init_slice(std::string scol, double val)
Initialize all values of slice named scol to val.
void zero_table()
Zero the data entries but keep the slice names and grid.
std::map< std::string, double > constants
The list of constants.
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 add_slice_from_table(table3d &source, std::string slice, std::string dest_slice="")
Desc.
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
void set_levels(size_t nlevels, vec_t &ulevels)
Set the contour levels.
void set_grid_x(size_t ix, double val)
Set x grid point at index ix.
ubmatrix_column ** aci
Matrices for interpolation.
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.
static const double x2[5]
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.
static const double x1[5]
std::string get_slice_name(size_t z) const
Returns the name of slice with index z.
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
map_const_iter const_begin() const
Return the beginning of the slice tree.
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.