Class uniform_grid (o2scl)¶
-
template<class data_t = double>
class uniform_grid¶ A class representing a uniform linear or logarithmic grid.
This class should work for any floating-point type compatible with std::pow() .
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.
Todo
In class uniform_grid:
Future: Implement operator==, etc?
Note
This class has no public constructors and is to be instantiated through its children.
Subclassed by o2scl::uniform_grid_end< data_t >, o2scl::uniform_grid_end_width< data_t >, o2scl::uniform_grid_log_end< data_t >, o2scl::uniform_grid_log_end_width< data_t >, o2scl::uniform_grid_log_width< data_t >, o2scl::uniform_grid_width< data_t >
Public Functions
-
inline uniform_grid()¶
Default constructor.
-
inline size_t get_nbins() const¶
Get the number of bins (regions in between grid points)
This function returns zero if the grid is “empty”.
-
inline 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.
-
inline bool is_log() const¶
Return true if the grid is logarithmic.
This function will throw an exception if the grid is empty.
-
inline double get_start()¶
Get the first grid point.
-
inline double get_end()¶
Get the last grid point.
-
inline double get_width()¶
Get the interval between grid points.
-
template<class resize_vec_t>
inline void vector(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.
-
inline const data_t operator[](size_t i) const¶
Get the grid point with index
i
( \( i \in [0,\mathrm{n_{bins}}] \))
-
inline uniform_grid(const uniform_grid &ug)¶
Copy constructor.
-
inline uniform_grid &operator=(const uniform_grid &ug)¶
Copy from = operator.
Protected Functions
-
inline 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_n(o2scl_hdf::hdf_file &hf, uniform_grid<double> &ug, std::string &name)¶