All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
table3d.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2014, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_TABLE3D_H
24 #define O2SCL_TABLE3D_H
25 
26 /** \file table3d.h
27  \brief File defining \ref o2scl::table3d
28 */
29 
30 #include <iostream>
31 #include <fstream>
32 #include <vector>
33 #include <string>
34 #include <cmath>
35 #include <sstream>
36 
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>
41 
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 
50 // Forward definition of the table3d class for HDF I/O
51 namespace o2scl {
52  class table3d;
53 }
54 
55 // Forward definition of HDF I/O to extend friendship
56 namespace o2scl_hdf {
57  class hdf_file;
58  void hdf_input(hdf_file &hf, o2scl::table3d &t, std::string name);
59  void hdf_output(hdf_file &hf, o2scl::table3d &t, std::string name);
60 }
61 
62 #ifndef DOXYGEN_NO_O2NS
63 namespace o2scl {
64 #endif
65 
66  /** \brief A data structure containing many slices of two-dimensional
67  data points defined on a grid
68 
69  \future Improve interpolation and derivative caching
70  \future Make a 'const' version of the interpolation functions
71  \future Should there be a clear_grid() function separate from
72  clear_data() and clear_table()?
73  \future Allow the user to more clearly probe 'size_set' vs.
74  'xy_set'?
75  */
76  class table3d {
77 
78  public:
79 
82  typedef boost::numeric::ublas::matrix_row<ubmatrix> ubmatrix_row;
83  typedef boost::numeric::ublas::matrix_column<ubmatrix> ubmatrix_column;
84 
85  /** \brief Create a new 3D \table
86  */
87  table3d();
88 
89  virtual ~table3d();
90 
91  /** \brief Create a table3d object from a table, assuming \c scolx
92  and \c scoly store the x- and y-grid data, respectively.
93  */
94  table3d(o2scl::table_units<> &t, std::string colx, std::string coly);
95 
96  /// \name Initialization
97  //@{
98  /** \brief Initialize the x-y grid
99 
100  This function will not allow you to redefine the grid when
101  there is data in the \table if a grid of a different size was
102  already set from a previous call to either set_xy() or
103  set_size(). However, you may freely redefine the grid after a
104  call to clear_data() or clear_table(). You may change
105  individual grid points at any time with set_grid_x() and
106  set_grid_y().
107  */
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) {
111 
112  if (has_slice && (size_set || xy_set) && (nx!=numx || ny!=numy)) {
113  O2SCL_ERR("Size cannot be reset in table3d::set_xy().",
115  return;
116  }
117  if (xy_set) {
118  xval.clear();
119  yval.clear();
120  }
121  numx=nx;
122  numy=ny;
123  xname=x_name;
124  yname=y_name;
125  xval.resize(nx);
126  yval.resize(ny);
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];
129  size_set=true;
130  xy_set=true;
131  return;
132  }
133 
134  /** \brief Initialize the x-y grid with \ref uniform_grid objects
135 
136  This function will not allow you to redefine the grid when
137  there is data in the \table if a grid of a different size was
138  already set from a previous call to either set_xy() or
139  set_size(). However, you may freely redefine the grid after a
140  call to clear_data() or clear_table(). You may change
141  individual grid points at any time with set_grid_x() and
142  set_grid_y().
143  */
144  void set_xy(std::string x_name, uniform_grid<double> gx,
145  std::string y_name, uniform_grid<double> gy) {
146 
147  if (has_slice && (size_set || xy_set) &&
148  (gx.get_npoints()!=numx || gy.get_npoints()!=numy)) {
149  O2SCL_ERR("Size cannot be reset in table3d::set_xy().",
151  return;
152  }
153 
154  if (xy_set) {
155  xval.clear();
156  yval.clear();
157  }
158  numx=gx.get_npoints();
159  numy=gy.get_npoints();
160  xname=x_name;
161  yname=y_name;
162  xval.resize(numx);
163  yval.resize(numy);
164  gx.vector(xval);
165  gy.vector(yval);
166  size_set=true;
167  xy_set=true;
168  }
169 
170  /** \brief Initialize \table size
171 
172  This function will not allow you to resize the \table if it
173  already has data or if the size has already been set with the
174  set_xy() function, unless you clear the data with clear_data()
175  or the \table with clear_table() first.
176  */
177  void set_size(size_t nx, size_t ny);
178  //@}
179 
180  // --------------------------------------------------------
181  /// \name On-grid get and set methods
182  //@{
183 
184  /** \brief Set element in slice \c name at location <tt>ix,iy</tt>
185  to value \c val
186  */
187  void set(size_t ix, size_t iy, std::string name, double val);
188 
189  /** \brief Set element in slice of index \c z at location
190  <tt>ix,iy</tt> to value \c val .
191  */
192  void set(size_t ix, size_t iy, size_t z, double val);
193 
194  /** \brief Get element in slice \c name at location
195  <tt>ix,iy</tt>
196  */
197  double &get(size_t ix, size_t iy, std::string name);
198 
199  /** \brief Get element in slice \c name at location
200  <tt>ix,iy</tt> (const version)
201  */
202  const double &get(size_t ix, size_t iy, std::string name) const;
203 
204  /** \brief Get element in slice of index \c z at location
205  <tt>ix,iy</tt>
206  */
207  double &get(size_t ix, size_t iy, size_t z);
208 
209  /** \brief Get element in slice of index \c z at location
210  <tt>ix,iy</tt> (const version)
211  */
212  const double &get(size_t ix, size_t iy, size_t z) const;
213  //@}
214 
215  // --------------------------------------------------------
216  /** \name Off-grid get and set methods
217 
218  These methods return the value of a slice on the grid
219  point nearest to a user-specified location. For
220  interpolation into a point off the grid, use
221  \ref table3d::interp().
222  */
223  //@{
224 
225  /** \brief Set element in slice \c name at the nearest location to
226  <tt>x,y</tt> to value \c val
227  */
228  void set_val(double x, double y, std::string name, double val);
229 
230  /** \brief Set element in slice of index \c z at the nearest
231  location to <tt>x,y</tt> to value \c val
232  */
233  void set_val(double x, double y, size_t z, double val);
234 
235  /** \brief Get element in slice \c name at location closest to
236  <tt>x,y</tt>
237  */
238  double &get_val(double x, double y, std::string name);
239 
240  /** \brief Get element in slice \c name at location closest to
241  <tt>x,y</tt>
242  */
243  const double &get_val(double x, double y, std::string name) const;
244 
245  /** \brief Get element in slice of index \c z at location closest
246  to <tt>x,y</tt>
247  */
248  double &get_val(double x, double y, size_t z);
249 
250  /** \brief Get element in slice of index \c z at location closest
251  to <tt>x,y</tt>
252  */
253  const double &get_val(double x, double y, size_t z) const;
254 
255  /** \brief Set elements in the first <tt>nv</tt> slices at the
256  nearest location to <tt>x,y</tt> to value \c val
257  */
258  template<class vec_t>
259  void set_slices(double x, double y, size_t nv, vec_t &vals) {
260  size_t ix, iy;
261  lookup_x(x,ix);
262  lookup_y(y,iy);
263 
264  for(size_t i=0;i<nv && i<list.size();i++) {
265  list[i](ix,iy)=vals[i];
266  }
267  return;
268  }
269 
270  /** \brief Get the data for every slice at the nearest location to
271  <tt>x,y</tt>
272  */
273  template<class vec_t>
274  void get_slices(double x, double y, size_t nv, vec_t &v) {
275 
276  size_t ix, iy;
277 
278  lookup_x(x,ix);
279  lookup_y(y,iy);
280 
281  for(size_t i=0;i<nv && i<list.size();i++) {
282  v[i]=list[i](ix,iy);
283  }
284 
285  return;
286  }
287  //@}
288 
289  // --------------------------------------------------------
290  /// \name Off-grid get and set methods returning nearest point
291  //@{
292 
293  /** \brief Set element in slice \c name at the nearest location to
294  <tt>x,y</tt> to value \c val
295  */
296  void set_val_ret(double &x, double &y, std::string name, double val);
297 
298  /** \brief Set element in slice of index \c z at the nearest
299  location to <tt>x,y</tt> to value \c val
300  */
301  void set_val_ret(double &x, double &y, size_t z, double val);
302 
303  /** \brief Get element in slice \c name at location closest to
304  <tt>x,y</tt>, and also return the corresponding values of \c x
305  and \c y
306  */
307  double &get_val_ret(double &x, double &y, std::string name);
308 
309  /** \brief Get element in slice \c name at location closest to
310  <tt>x,y</tt>, and also return the corresponding values of \c x
311  and \c y
312  */
313  const double &get_val_ret(double &x, double &y, std::string name) const;
314 
315  /** \brief Get element in slice of index \c z at location closest
316  to <tt>x,y</tt>, and also return the corresponding values of
317  \c x and \c y
318  */
319  double &get_val_ret(double &x, double &y, size_t z);
320 
321  /** \brief Get element in slice of index \c z at location closest
322  to <tt>x,y</tt>, and also return the corresponding values of
323  \c x and \c y
324  */
325  const double &get_val_ret(double &x, double &y, size_t z) const;
326 
327  /** \brief Desc
328  */
329  void add_slice_from_table(table3d &source, std::string slice,
330  std::string dest_slice="") {
331 
332  if (dest_slice.length()==0) dest_slice=slice;
333 
334  if (xy_set==false) {
335  set_xy(source.get_x_name(),source.get_nx(),source.get_x_data(),
336  source.get_y_name(),source.get_ny(),source.get_y_data());
337  new_slice(dest_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));
341  }
342  }
343  return;
344  }
345 
346  size_t szt_tmp;
347  if (!is_slice(dest_slice,szt_tmp)) new_slice(dest_slice);
348  for(size_t i=0;i<numx;i++) {
349  for(size_t j=0;j<numx;j++) {
350  set(i,j,dest_slice,source.interp(get_grid_x(i),get_grid_y(j),
351  slice));
352  }
353  }
354  return;
355  }
356 
357  /** \brief Set elements in the first <tt>nv</tt> slices at the
358  nearest location to <tt>x,y</tt> to values \c vals
359  */
360  template<class vec_t>
361  void set_slices_ret(double &x, double &y, size_t nv, vec_t &vals) {
362  size_t ix, iy;
363  lookup_x(x,ix);
364  lookup_y(y,iy);
365  x=xval[ix];
366  y=yval[iy];
367 
368  for(size_t i=0;i<nv && i<list.size();i++) {
369  list[i](ix,iy)=vals[i];
370  }
371  return;
372  }
373 
374  /** \brief Get elements in the first <tt>nv</tt> slices at the
375  nearest location to <tt>x,y</tt> to value \c val
376  */
377  template<class vec_t>
378  void get_slices_ret(double &x, double &y, size_t nv, vec_t &vals) {
379 
380  size_t ix, iy;
381  lookup_x(x,ix);
382  lookup_y(y,iy);
383  x=xval[ix];
384  y=yval[iy];
385 
386  for(size_t i=0;i<nv && i<list.size();i++) {
387  vals[i]=list[i](ix,iy);
388  }
389  return;
390  }
391 
392  //@}
393 
394  // --------------------------------------------------------
395  /// \name Grid information get and set methods
396  //@{
397 
398  /// Set x grid point at index \c ix
399  void set_grid_x(size_t ix, double val);
400 
401  /// Set y grid point at index \c iy
402  void set_grid_y(size_t iy, double val);
403 
404  /// Get x grid point at index \c ix
405  double get_grid_x(size_t ix);
406 
407  /// Get y grid point at index \c iy
408  double get_grid_y(size_t iy);
409 
410  /// Get the name of the x grid variable
411  std::string get_x_name() const {
412  return xname;
413  }
414 
415  /// Get the name of the y grid variable
416  std::string get_y_name() const {
417  return yname;
418  }
419 
420  /// Set the name of the x grid variable
421  void set_x_name(std::string name) {
422  xname=name;
423  return;
424  }
425 
426  /// Set the name of the y grid variable
427  void set_y_name(std::string name) {
428  yname=name;
429  return;
430  }
431 
432  /// Get a const reference to the full x grid
433  const ubvector &get_x_data() const { return xval; }
434 
435  /// Get a const reference to the full y grid
436  const ubvector &get_y_data() const { return yval; }
437 
438  //@}
439 
440  // --------------------------------------------------------
441  /// \name Size get methods
442  //@{
443 
444  /// Get the size of the slices
445  void get_size(size_t &nx, size_t &ny) const;
446 
447  /// Get the x size
448  size_t get_nx() const {
449  return numx;
450  }
451 
452  /// Get the y size
453  size_t get_ny() const {
454  return numy;
455  }
456 
457  /// Get the number of slices
458  size_t get_nslices() const;
459  //@}
460 
461  // --------------------------------------------------------
462  /// \name Slice manipulation
463  //@{
464 
465  /// Create a set of new slices specified in the string \c names
466  void line_of_names(std::string names);
467 
468  /** \brief Returns the name of slice with index \c z
469  */
470  std::string get_slice_name(size_t z) const;
471 
472  /** \brief Add a new slice
473  */
474  void new_slice(std::string name);
475 
476  /** \brief Set all of the values in slice \c name to \c val
477  */
478  void set_slice_all(std::string name, double val);
479 
480  /** \brief Find the index for column named \c name
481  */
482  size_t lookup_slice(std::string name) const;
483 
484  /** \brief Return true if slice is already present
485  */
486  bool is_slice(std::string name, size_t &ix) const;
487 
488  /** \brief Rename slice named \c olds to \c news
489 
490  This is slow since we have to delete the column and re-insert
491  it. This process in turn mangles all of the iterators in the
492  list.
493  */
494  void rename_slice(std::string olds, std::string news);
495 
496  /** \brief Make a new slice named \c dest which is a copy
497  of the slice with name given in \c src.
498  */
499  void copy_slice(std::string src, std::string dest);
500 
501  /** \brief Initialize all values of slice named \c scol to \c val
502 
503  \note This will call the error handler if the value \c val is
504  not finite (i.e. either <tt>Inf</tt> or <tt>NaN</tt>).
505  */
506  void init_slice(std::string scol, double val);
507 
508  /// Return a constant reference to a slice
509  const ubmatrix &get_slice(std::string scol) const;
510 
511  /// Return a constant reference to a slice
512  const ubmatrix &get_slice(size_t iz) const;
513 
514  /// Return a constant reference to a slice
515  ubmatrix &get_slice(std::string scol);
516 
517  /// Return a constant reference to a slice
518  ubmatrix &get_slice(size_t iz);
519 
520  /** \brief Return a constant reference to all the slice data
521 
522  \comment
523  This isn't designated const, i.e. as
524  const std::vector<ubmatrix> &get_data() const;
525  because it would then have to be
526  const std::vector<const ubmatrix> &get_data() const;
527  \endcomment
528  */
529  const std::vector<ubmatrix> &get_data();
530  //@}
531 
532  // --------------------------------------------------------
533  /// \name Lookup and search methods
534  //@{
535  /** \brief Look for a value in the x grid
536  */
537  void lookup_x(double val, size_t &ix) const;
538 
539  /** \brief Look for a value in the y grid
540  */
541  void lookup_y(double val, size_t &iy) const;
542 
543  /** \brief Look for a value in a specified slice
544  */
545  void lookup(double val, std::string slice, size_t &ix, size_t &iy) const;
546  //@}
547 
548  // --------------------------------------------------------
549  /// \name Interpolation, differentiation, and integration
550  //@{
551 
552  /** \brief Specify the interpolation type
553  */
554  void set_interp_type(size_t interp_type);
555 
556  /** \brief Get the interpolation type
557  */
558  size_t get_interp_type() const;
559 
560  /** \brief Interpolate \c x and \c y in slice named \c name
561  */
562  double interp(double x, double y, std::string name);
563 
564  /** \brief Interpolate the derivative of the data with respect to
565  the x grid at point \c x and \c y in slice named \c name
566  */
567  double deriv_x(double x, double y, std::string name);
568 
569  /** \brief Interpolate the derivative of the data with respect to
570  the y grid at point \c x and \c y in slice named \c name
571  */
572  double deriv_y(double x, double y, std::string name);
573 
574  /** \brief Interpolate the mixed second derivative of the data at
575  point \c x and \c y in slice named \c name
576  */
577  double deriv_xy(double x, double y, std::string name);
578 
579  /** \brief Interpolate the integral of the data
580  respect to the x grid
581  */
582  double integ_x(double x1, double x2, double y, std::string name);
583 
584  /** \brief Interpolate the integral of the data
585  respect to the y grid
586  */
587  double integ_y(double x, double y1, double y2, std::string name);
588 
589  /** \brief Fill a vector of interpolated values from each slice at the
590  point <tt>x,y</tt>
591  */
592  template<class vec_t>
593  void interp_slices(double x, double y, size_t nv, vec_t &v) {
594 
595  for (size_t i=0;i<list.size();i++) {
596  std::string name=get_slice_name(i);
597  v[i]=interp(x,y,name);
598  }
599 
600  return;
601  }
602 
603  //@}
604 
605  // --------------------------------------------------------
606  /// \name Extract 2-dimensional tables
607  //@{
608  /** \brief Extract a table at a fixed x grid point
609 
610  \note All of the information previously stored in \c t will
611  be lost.
612  */
613  void extract_x(double x, table<> &t);
614 
615  /** \brief Extract a table at a fixed y grid point
616 
617  \note All of the information previously stored in \c t will
618  be lost.
619  */
620  void extract_y(double y, table<> &t);
621  //@}
622 
623  // --------------------------------------------------------
624  /// \name Clear methods
625  //@{
626  /** \brief Zero the data entries but keep the slice names
627  and grid
628  */
629  void zero_table();
630 
631  /** \brief Clear the table and the slice names
632  */
633  void clear_table();
634 
635  /** \brief Remove all of the data by setting the number
636  of lines to zero
637 
638  This leaves the column names intact and does not remove
639  the constants.
640  */
641  void clear_data();
642  //@}
643 
644  // --------------------------------------------------------
645  /// \name Summary method
646  //@{
647  /** \brief Output a summary of the information stored
648 
649  Outputs the number of constants, the grid information,
650  and a list of the slice names
651  */
652  void summary(std::ostream *out, int ncol=79) const;
653  //@}
654 
655  /// True if the size of the table has been set
656  bool is_size_set() const {
657  return size_set;
658  }
659 
660  /// True if the grid has been set
661  bool is_xy_set() const {
662  return xy_set;
663  }
664 
665  // ---------
666  // Allow HDF I/O functions to access table3d data
667 
668  friend void o2scl_hdf::hdf_output(o2scl_hdf::hdf_file &hf, table3d &t,
669  std::string name);
670 
671  friend void o2scl_hdf::hdf_input(o2scl_hdf::hdf_file &hf, table3d &t,
672  std::string name);
673 
674  // --------------------------------------------------------
675  /// \name Contour lines method
676  //@{
677 
678  /** \brief Create contour lines from the slice named \c name
679 
680  This uses \ref contour to compute contour lines (stored in \c
681  clines) from slice \c name given \c nlev contour levels in \c
682  levs .
683  */
684  template<class vec_t>
685  void slice_contours(std::string name, size_t nlev, vec_t &levs,
686  std::vector<contour_line> &clines) {
687 
688  size_t z=lookup_slice(name);
689 
690  contour co;
691  co.set_data(numx,numy,xval,yval,list[z]);
692  co.set_levels(nlev,levs);
693  co.calc_contours(clines);
694 
695  return;
696  }
697  //@}
698 
699  // --------------------------------------------------------
700  /// \name Manipulating constants
701  //@{
702  /// Add a constant
703  virtual void add_constant(std::string name, double val);
704 
705  /// Remove a constant
706  virtual void remove_constant(std::string name);
707 
708  /// Add a constant
709  virtual void set_constant(std::string name, double val);
710 
711  /// Get a constant
712  virtual double get_constant(std::string name);
713 
714  /// Get a constant by index
715  virtual void get_constant(size_t ix, std::string &name, double &val) const;
716 
717  /// Get the number of constants
718  virtual size_t get_nconsts() const {
719  return constants.size();
720  }
721  //@}
722 
723  /// Return the type, \c "table3d".
724  virtual const char *type() { return "table3d"; }
725 
726  /** \name Parsing mathematical functions specified as strings
727 
728  \comment
729  Note that doxygen doesn't format the documentation propertly
730  if the \name specification covers more than one line
731  \endcomment
732  */
733  //@{
734  /** \brief Make a column from <tt>formula</tt> and add it to the table.
735 
736  If the column already exists, the data already present is
737  overwritten with the result.
738  */
739  void function_slice(std::string formula, std::string col);
740  //@}
741 
742  protected:
743 
744 #ifndef DOXYGEN_INTERNAL
745 
746  /** \brief Internal function to set function parser constants equal to
747  internal constants
748  */
749  void set_fp_consts(FunctionParser &fp) const {
750  std::map<std::string,double>::const_iterator mit;
751  for(mit=constants.begin();mit!=constants.end();mit++) {
752  fp.AddConstant(mit->first,mit->second);
753  }
754  return;
755  }
756 
757  /// \name Interpolation data
758  //@{
759  /// The array of interp_sm pointers
761 
762  /// Matrices for interpolation
763  ubmatrix_column **aci;
764  //@}
765 
766  /// \name Iterator types
767  //@{
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
770  map_const_iter;
771  //@}
772 
773  /// \name Data storage
774  //@{
775  /// The list of constants
776  std::map<std::string,double> constants;
777 
778  /// The size of the x grid
779  size_t numx;
780 
781  /// The size of the y grid
782  size_t numy;
783 
784  /// A tree connecting column names to list indexes
785  std::map<std::string,size_t,string_comp> tree;
786 
787  /// The name for the x grid
788  std::string xname;
789 
790  /// The name for the y grid
791  std::string yname;
792 
793  /// The pointers to the matrices
794  std::vector<ubmatrix> list;
795 
796  /// The x grid
798 
799  /// The y grid
801 
802  /// True if the grid has been set
803  bool xy_set;
804 
805  /// True if the size of the grid has been set
806  bool size_set;
807 
808  /// True if the table has at least one slice
809  bool has_slice;
810  //@}
811 
812  /// \name Tree iterator boundaries
813  //@{
814  /// Return the beginning of the slice tree
815  map_iter begin() {return tree.begin();};
816  /// Return the end of the slice tree
817  map_iter end() {return tree.end();};
818  /// Return the beginning of the slice tree
819  map_const_iter const_begin() const {return tree.begin();};
820  /// Return the end of the slice tree
821  map_const_iter const_end() const {return tree.end();};
822  //@}
823 
824  size_t itype;
825 
826 #endif
827 
828  };
829 
830 #ifndef DOXYGEN_NO_O2NS
831 }
832 #endif
833 
834 #endif
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.
Definition: table3d.h:749
bool size_set
True if the size of the grid has been set.
Definition: table3d.h:806
size_t get_nslices() const
Get the number of slices.
Interpolation class for pre-specified vector.
Definition: interp.h:1420
virtual double get_constant(std::string name)
Get a constant.
virtual size_t get_nconsts() const
Get the number of constants.
Definition: table3d.h:718
Parse a mathematical function specified in a string.
Definition: fparser.h:29
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.
Definition: table3d.h:144
std::string get_y_name() const
Get the name of the y grid variable.
Definition: table3d.h:416
bool is_xy_set() const
True if the grid has been set.
Definition: table3d.h:661
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.
Definition: table3d.h:685
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.
Definition: table3d.h:782
interp_vec< ubvector > ** si
The array of interp_sm pointers.
Definition: table3d.h:760
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.
Definition: table3d.h:259
size_t get_nx() const
Get the x size.
Definition: table3d.h:448
double get_grid_x(size_t ix)
Get x grid point at index ix.
Data table table class.
Definition: table.h:47
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.
Definition: table3d.h:788
void set_interp_type(size_t interp_type)
Specify the interpolation type.
invalid argument supplied by user
Definition: err_hnd.h:59
const ubvector & get_y_data() const
Get a const reference to the full y grid.
Definition: table3d.h:436
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.
Definition: table3d.h:361
map_iter begin()
Return the beginning of the slice tree.
Definition: table3d.h:815
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.
Definition: contour.h:263
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.
Definition: table3d.h:779
bool has_slice
True if the table has at least one slice.
Definition: table3d.h:809
void set_y_name(std::string name)
Set the name of the y grid variable.
Definition: table3d.h:427
size_t get_ny() const
Get the y size.
Definition: table3d.h:453
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.
ubvector yval
The y grid.
Definition: table3d.h:800
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.
Definition: contour.h:237
std::vector< ubmatrix > list
The pointers to the matrices.
Definition: table3d.h:794
bool is_size_set() const
True if the size of the table has been set.
Definition: table3d.h:656
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".
Definition: table3d.h:724
void set_x_name(std::string name)
Set the name of the x grid variable.
Definition: table3d.h:421
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 vector(resize_vec_t &v) const
Fill a vector with the specified grid.
Definition: uniform_grid.h:206
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.
Definition: err_hnd.h:273
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.
Definition: table3d.h:817
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.
Definition: table_units.h:37
std::map< std::string, size_t, string_comp > tree
A tree connecting column names to list indexes.
Definition: table3d.h:785
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.
Definition: table3d.h:378
double get_grid_y(size_t iy)
Get y grid point at index iy.
bool xy_set
True if the grid has been set.
Definition: table3d.h:803
map_const_iter const_end() const
Return the end of the slice tree.
Definition: table3d.h:821
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.
A class representing a uniform linear or logarithmic grid.
Definition: uniform_grid.h:38
const ubvector & get_x_data() const
Get a const reference to the full x grid.
Definition: table3d.h:433
A data structure containing many slices of two-dimensional data points defined on a grid...
Definition: table3d.h:76
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.
Definition: table3d.h:411
Store data in an O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl...
Definition: hdf_file.h:93
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.
Definition: table3d.h:791
void init_slice(std::string scol, double val)
Initialize all values of slice named scol to val.
ubvector xval
The x grid.
Definition: table3d.h:797
void zero_table()
Zero the data entries but keep the slice names and grid.
std::map< std::string, double > constants
The list of constants.
Definition: table3d.h:776
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
Definition: table3d.h:593
void add_slice_from_table(table3d &source, std::string slice, std::string dest_slice="")
Desc.
Definition: table3d.h:329
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
Definition: table3d.h:274
void set_levels(size_t nlevels, vec_t &ulevels)
Set the contour levels.
Definition: contour.h:334
void set_grid_x(size_t ix, double val)
Set x grid point at index ix.
ubmatrix_column ** aci
Matrices for interpolation.
Definition: table3d.h:763
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]
Definition: inte_qng_gsl.h:66
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.
Definition: table3d.h:109
static const double x1[5]
Definition: inte_qng_gsl.h:48
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.
Definition: hdf_io.h:55
map_const_iter const_begin() const
Return the beginning of the slice tree.
Definition: table3d.h:819
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.
size_t get_npoints() const
Get the number of points in the grid (always get_nbins()+1)
Definition: uniform_grid.h:179

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).
Hosted at Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads..