Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
s99table.h
1#ifndef S99TABLE_H
2#define S99TABLE_H
3
4#include <string>
5#include <utility> // std::move
6#include <vector>
7
8#include "../utils/error_handling.h"
9
10namespace feedback
11{
12
13/* kinds of starburst99 datatables used by cholla */
14enum class S99TabKind { supernova, stellar_wind };
15
16/* Class that represents a parsed starburst99 table. This is a little over the top, but it's
17 * probably fine. We just use this when reading the data out of the table
18 */
20{
21 public:
22 S99Table(std::vector<std::string> col_names, std::vector<double> data, std::size_t ncols, std::size_t nrows)
23 : col_names_(std::move(col_names)), data_(std::move(data)), ncols_(ncols), nrows_(nrows)
24 {
25 }
26
27 /* number of rows in the table */
28 std::size_t nrows() const noexcept { return nrows_; }
29
30 /* number of columns in the table */
31 std::size_t ncols() const noexcept { return ncols_; }
32
33 /* access an entry in the table */
34 double operator()(std::size_t col_ind, std::size_t row_ind) const noexcept
35 {
36 // probably could remove this check...
37 if ((col_ind >= ncols_) or (row_ind >= nrows_)) {
38 CHOLLA_ERROR(
39 "invalid index col_ind, %zu, must be less than %zu and row_ind, %zu, must be "
40 "less than %zu",
41 col_ind, ncols_, row_ind, nrows_);
42 }
43 return data_[row_ind * ncols_ + col_ind];
44 }
45
46 /* query the name of a given column */
47 std::string col_name(std::size_t col_ind) const noexcept
48 {
49 if (col_ind < ncols_) return col_names_[col_ind];
50 return "";
51 }
52
53 /* Returns the index of the specified column. */
54 std::size_t col_index(const std::string& col_name) const noexcept
55 {
56 for (std::size_t i = 0; i < ncols_; i++) {
57 if (col_names_[i] == col_name) return i;
58 }
59 CHOLLA_ERROR("the table doesn't hold a column called: \"%s\"", col_name.c_str());
60 }
61
62 private: // attributes
63 std::vector<std::string> col_names_;
64 std::vector<double> data_;
65 std::size_t ncols_;
66 std::size_t nrows_;
67};
68
69} // namespace feedback
70
71/* Parse a Starburst99 table
72 *
73 * TODO: put this back into the feedback namespace
74 */
75feedback::S99Table parse_s99_table(const std::string& fname, feedback::S99TabKind kind);
76
77#endif /* S99TABLE_H */
Definition s99table.h:20