1#ifndef CYCLUS_SRC_TOOLKIT_TOTAL_INV_TRACKER_H_
2#define CYCLUS_SRC_TOOLKIT_TOTAL_INV_TRACKER_H_
43 TotalInvTracker() : max_inv_size_(
std::numeric_limits<double>::max()), qty_(0) {};
45 TotalInvTracker(std::vector<ResBuf<Material>*> bufs,
46 double max_inv_size = std::numeric_limits<double>::max()) {
47 Init(bufs, max_inv_size);
50 ~TotalInvTracker() {};
54 void Init(std::vector<ResBuf<Material>*> bufs,
55 double max_inv_size = std::numeric_limits<double>::max()) {
56 if (bufs.size() == 0) {
57 throw ValueError(
"TotalInvTracker must be initialized with at least one ResBuf");
60 if (max_inv_size <= 0) {
61 throw ValueError(
"TotalInvTracker must be initialized with a positive capacity");
63 max_inv_size_ = max_inv_size;
68 inline double quantity() {
71 for (
int i = 0; i < num; i++) {
72 qty_ += bufs_[i]->quantity();
80 inline double capacity() {
81 return std::min(total_capacity_bufs(), max_inv_size_);
86 inline double total_capacity_bufs() {
89 for (
int i = 0; i < num; i++) {
90 cap += bufs_[i]->capacity();
96 inline double tracker_capacity() {
return max_inv_size_; }
99 inline double space() {
return std::max(0.0, capacity() - quantity()); }
103 inline double constrained_buf_space(ResBuf<Material>* buf) {
104 return std::min(buf->space(), space());
108 inline bool empty() {
return quantity() == 0; }
112 inline int num_bufs() {
113 int num = bufs_.size();
115 throw ValueError(
"TotalInvTracker has not been initialized, no buffers to track");
123 void set_capacity(
double cap) {
124 if (quantity() - cap >
eps_rsrc()) {
125 std::stringstream ss;
126 ss << std::setprecision(17) <<
"new capacity " << cap <<
127 " lower than existing quantity " << quantity();
128 throw ValueError(ss.str());
133 bool buf_in_tracker(ResBuf<Material>* buf) {
134 for (
int i = 0; i < num_bufs(); i++) {
135 if (bufs_[i] == buf) {
return true; }
141 double max_inv_size_;
143 std::vector<ResBuf<Material>*> bufs_;
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
double eps_rsrc()
an epsilon value to be used by resources
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters