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> 50 #include <o2scl/shunting_yard.h> 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>
114 int read_gen3_list(std::istream &fin,
int verbose=0);
128 template<
class vec_t,
class vec2_t>
129 void set_xy(std::string x_name,
size_t nx,
const vec_t &x,
130 std::string y_name,
size_t ny,
const vec2_t &y) {
132 if (has_slice && (size_set || xy_set) && (nx!=numx || ny!=numy)) {
133 O2SCL_ERR(
"Size cannot be reset in table3d::set_xy().",
147 for(
size_t i=0;i<nx;i++) (xval)[i]=x[i];
148 for(
size_t i=0;i<ny;i++) (yval)[i]=y[i];
167 if (has_slice && (size_set || xy_set) &&
169 O2SCL_ERR(
"Size cannot be reset in table3d::set_xy().",
197 void set_size(
size_t nx,
size_t ny);
207 void set(
size_t ix,
size_t iy, std::string name,
double val);
212 void set(
size_t ix,
size_t iy,
size_t z,
double val);
217 double &
get(
size_t ix,
size_t iy, std::string name);
222 const double &
get(
size_t ix,
size_t iy, std::string name)
const;
227 double &
get(
size_t ix,
size_t iy,
size_t z);
232 const double &
get(
size_t ix,
size_t iy,
size_t z)
const;
248 void set_val(
double x,
double y, std::string name,
double val);
253 void set_val(
double x,
double y,
size_t z,
double val);
258 double &get_val(
double x,
double y, std::string name);
263 const double &get_val(
double x,
double y, std::string name)
const;
268 double &get_val(
double x,
double y,
size_t z);
273 const double &get_val(
double x,
double y,
size_t z)
const;
278 template<
class vec_t>
279 void set_slices(
double x,
double y,
size_t nv, vec_t &vals) {
284 for(
size_t i=0;i<nv && i<list.size();i++) {
285 list[i](ix,iy)=vals[i];
293 template<
class vec_t>
301 for(
size_t i=0;i<nv && i<list.size();i++) {
316 void set_val_ret(
double &x,
double &y, std::string name,
double val);
321 void set_val_ret(
double &x,
double &y,
size_t z,
double val);
327 double &get_val_ret(
double &x,
double &y, std::string name);
333 const double &get_val_ret(
double &x,
double &y, std::string name)
const;
339 double &get_val_ret(
double &x,
double &y,
size_t z);
345 const double &get_val_ret(
double &x,
double &y,
size_t z)
const;
352 std::string dest_slice=
"") {
354 if (dest_slice.length()==0) dest_slice=slice;
359 new_slice(dest_slice);
360 for(
size_t i=0;i<numx;i++) {
361 for(
size_t j=0;j<numx;j++) {
362 set(i,j,dest_slice,source.
get(i,j,slice));
369 if (!is_slice(dest_slice,szt_tmp)) new_slice(dest_slice);
370 for(
size_t i=0;i<numx;i++) {
371 for(
size_t j=0;j<numx;j++) {
372 set(i,j,dest_slice,source.
interp(get_grid_x(i),get_grid_y(j),
382 template<
class vec_t>
390 for(
size_t i=0;i<nv && i<list.size();i++) {
391 list[i](ix,iy)=vals[i];
399 template<
class vec_t>
408 for(
size_t i=0;i<nv && i<list.size();i++) {
409 vals[i]=list[i](ix,iy);
421 void set_grid_x(
size_t ix,
double val);
424 void set_grid_y(
size_t iy,
double val);
427 double get_grid_x(
size_t ix);
430 double get_grid_y(
size_t iy);
467 void get_size(
size_t &nx,
size_t &ny)
const;
480 size_t get_nslices()
const;
488 void line_of_names(std::string names);
492 std::string get_slice_name(
size_t z)
const;
496 void new_slice(std::string name);
500 void set_slice_all(std::string name,
double val);
504 size_t lookup_slice(std::string name)
const;
508 bool is_slice(std::string name,
size_t &ix)
const;
516 void rename_slice(std::string olds, std::string news);
521 void copy_slice(std::string src, std::string dest);
528 void init_slice(std::string scol,
double val);
531 const ubmatrix &get_slice(std::string scol)
const;
534 const ubmatrix &get_slice(
size_t iz)
const;
537 ubmatrix &get_slice(std::string scol);
540 ubmatrix &get_slice(
size_t iz);
551 const std::vector<ubmatrix> &get_data();
558 template<
class mat_t>
560 for(
size_t i=0;i<numx;i++) {
561 for(
size_t j=0;j<numy;j++) {
562 this->
set(i,j,scol,m(i,j));
574 void lookup_x(
double val,
size_t &ix)
const;
578 void lookup_y(
double val,
size_t &iy)
const;
582 void lookup(
double val, std::string slice,
size_t &ix,
size_t &iy)
const;
591 void set_interp_type(
size_t interp_type);
595 size_t get_interp_type()
const;
599 double interp(
double x,
double y, std::string name)
const;
604 double deriv_x(
double x,
double y, std::string name)
const;
609 double deriv_y(
double x,
double y, std::string name)
const;
614 double deriv_xy(
double x,
double y, std::string name)
const;
619 double integ_x(
double x1,
double x2,
double y, std::string name)
const;
624 double integ_y(
double x,
double y1,
double y2, std::string name)
const;
629 template<
class vec_t>
632 for (
size_t i=0;i<list.size();i++) {
633 std::string name=get_slice_name(i);
634 v[i]=interp(x,y,name);
643 void deriv_x(std::string fname, std::string fpname);
648 void deriv_y(std::string fname, std::string fpname);
660 void extract_x(
double x,
table<> &t);
667 void extract_y(
double y,
table<> &t);
699 void summary(std::ostream *out,
int ncol=79)
const;
731 template<
class vec_t>
733 std::vector<contour_line> &clines) {
735 size_t z=lookup_slice(name);
738 co.
set_data(numx,numy,xval,yval,list[z]);
752 virtual void add_constant(std::string name,
double val);
755 virtual void remove_constant(std::string name);
767 virtual int set_constant(std::string name,
double val,
768 bool err_on_notfound=
true);
771 virtual bool is_constant(std::string name)
const;
774 virtual double get_constant(std::string name);
777 virtual void get_constant(
size_t ix, std::string &name,
double &val)
const;
781 return constants.size();
786 virtual const char *
type() {
return "table3d"; }
803 template<
class resize_mat_t>
805 bool throw_on_err=
true) {
808 std::map<std::string,double> vars;
810 std::map<std::string,double>::const_iterator mit;
811 for(mit=constants.begin();mit!=constants.end();mit++) {
812 vars[mit->first]=mit->second;
815 calc.
compile(
function.c_str(),&vars);
817 if (mat.size1()!=numx || mat.size2()!=numy) {
818 mat.resize(numx,numy);
821 for(
size_t i=0;i<numx;i++) {
822 for(
size_t j=0;j<numy;j++) {
826 for(
size_t k=0;k<list.size();k++) {
827 vars[get_slice_name(k)]=list[k](i,j);
830 mat(i,j)=calc.
eval(&vars);
843 void function_slice(std::string
function, std::string col);
848 #ifndef DOXYGEN_INTERNAL 852 typedef std::map<std::string,size_t,
853 std::greater<std::string> >::iterator map_iter;
854 typedef std::map<std::string,size_t,
855 std::greater<std::string> >::const_iterator map_const_iter;
870 std::map<std::string,size_t,std::greater<std::string> >
tree;
900 map_iter
begin() {
return tree.begin();};
902 map_iter
end() {
return tree.end();};
915 #ifndef DOXYGEN_NO_O2NS bool size_set
True if the size of the grid has been set.
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.
map_const_iter const_begin() const
Return the beginning of the slice tree.
int function_matrix(std::string function, resize_mat_t &mat, bool throw_on_err=true)
Fill a matrix from the function specified in function.
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.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
const ubvector & get_x_data() const
Get a const reference to the full x grid.
size_t numy
The size of the y grid.
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.
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(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.
invalid argument supplied by user
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.
void copy_to_slice(mat_t &m, std::string scol)
Copy to a slice from a generic matrix object.
size_t numx
The size of the x grid.
double interp(double x, double y, std::string name) const
Interpolate x and y in slice named name.
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.
bool is_xy_set() const
True if the grid has been set.
Calculate contour lines from a two-dimensional data set.
size_t get_ny() const
Get the y size.
std::vector< ubmatrix > list
The pointers to the matrices.
virtual const char * type()
Return the type, "table3d".
void set_x_name(std::string name)
Set the name of the x grid variable.
The O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl namespace ...
double eval(std::map< std::string, double > *vars=0)
Evalate the previously compiled expression using variables specified in vars.
map_const_iter const_end() const
Return the end of the slice tree.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Evaluate a mathematical expression in a string.
map_iter end()
Return the end of the slice tree.
Data table table class with units.
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.
bool xy_set
True if the grid has been set.
A data structure containing many slices of two-dimensional data points defined on a grid...
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$sc...
std::string yname
The name for the y grid.
virtual size_t get_nconsts() const
Get the number of constants.
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="")
This function adds a slice from a different table3d object, interpolating the results into the curren...
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.
const ubvector & get_y_data() const
Get a const reference to the full y grid.
void calc_contours(std::vector< contour_line > &clines)
Calculate the contours.
void hdf_input(hdf_file &hf, o2scl::table3d &t, std::string name)
Input a o2scl::table3d object from a hdf_file.
std::map< std::string, size_t, std::greater< std::string > > tree
A tree connecting column names to list indexes.
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]
void hdf_input(hdf_file &hf, o2scl::table< vec_t > &t, std::string name)
Input a o2scl::table object from a hdf_file.
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.
bool is_size_set() const
True if the size of the table has been set.
Interpolation class for general vectors.