Class uniform_grid (o2scl)¶
-
template<class
data_t
= double>
classo2scl
::
uniform_grid
¶ A class representing a uniform linear or logarithmic grid.
This class should work for any floating-point type compatible with std::pow() .
- Note
This class has no public constructors and is to be instantiated through its children.
Empty grids are those for which g_n_bins is zero.
The first and last bin are always exactly equal to the originally specified values of “start” and “end”, but finite-precision errors may affect the inner grid points.
- Idea for Future:
Implement operator==, etc?
Public Functions
-
uniform_grid
()¶ Default constructor.
-
size_t
get_nbins
() const¶ Get the number of bins (regions in between grid points)
This function returns zero if the grid is “empty”.
-
size_t
get_npoints
() const¶ Get the number of points in the grid (always get_nbins()+1)
This function will throw an exception if the grid is empty.
-
bool
is_log
() const¶ Return true if the grid is logarithmic.
This function will throw an exception if the grid is empty.
-
double
get_start
()¶ Get the first grid point.
-
double
get_end
()¶ Get the last grid point.
-
double
get_width
()¶ Get the interval between grid points.
-
template<class
resize_vec_t
>
voidvector
(resize_vec_t &v) const¶ Fill a vector with the specified grid.
If the vector is not big enough to hold the grid, it is automatically resized.
This function will throw an exception if the grid is empty.
-
const data_t
operator[]
(size_t i) const¶ Get the grid point with index
i
( \( i \in [0,\mathrm{n_{bins}}] \))
-
uniform_grid
(const uniform_grid &ug)¶ Copy constructor.
-
uniform_grid &
operator=
(const uniform_grid &ug)¶ Copy from = operator.
Protected Functions
-
uniform_grid
(data_t start, data_t end, data_t width, size_t n_bins, bool log = false)¶ Construct a grid with specified values.
- Note
This function is not public because it might create grids that are non-sensical. We require users to create grid objects using one of the children which don’t allow non-sensical grids.
Protected Attributes
-
data_t
g_width
¶ The width of each bin.
This should be always positive and non-zero for linear grids and always greater than 1 for logarithmic grids.
-
size_t
g_n_bins
¶ The number of bins.
-
bool
g_log
¶ If true, use a logarithmic scale.
Friends
-
friend void
hdf_output
(o2scl_hdf::hdf_file &hf, uniform_grid<double> &ug, std::string name)¶
-
friend void
hdf_input
(o2scl_hdf::hdf_file &hf, uniform_grid<double> &ug, std::string name)¶