Skip to content

Commit

Permalink
always check quantity against eps_rsrc() instead of zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Sep 11, 2024
1 parent 7335591 commit 45e8af9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void Material::Transmute(Composition::Ptr c) {
}

Resource::Ptr Material::PackageExtract(double qty, std::string new_package_name) {
if (qty > qty_) {
if ((qty - qty_) > eps_rsrc()) {
throw ValueError("Attempted to extract more quantity than exists.");
}

Expand All @@ -155,7 +155,7 @@ Resource::Ptr Material::PackageExtract(double qty, std::string new_package_name)
// this call to res_tracker must come first before the parent resource
// state id gets modified
other->tracker_.Package(&tracker_);
if (qty_ > cyclus::eps_rsrc()) {
if (qty_ > eps_rsrc()) {
tracker_.Modify();
}
return boost::static_pointer_cast<Resource>(other);
Expand Down
3 changes: 2 additions & 1 deletion src/package.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "package.h"
#include "error.h"
#include "cyc_limits.h"

namespace cyclus {

Expand Down Expand Up @@ -30,7 +31,7 @@ Package::Ptr& Package::unpackaged() {
}

std::pair<double, int> Package::GetFillMass(double qty) {
if (qty < fill_min_) {
if ((qty - fill_min_) < -eps_rsrc()) {
// less than one pkg of material available
return std::pair<double, int> (0, 0);
}
Expand Down
3 changes: 2 additions & 1 deletion src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <boost/shared_ptr.hpp>

#include "package.h"
#include "cyc_limits.h"

class SimInitTest;

Expand Down Expand Up @@ -151,7 +152,7 @@ std::vector<typename T::Ptr> Resource::Package(Package::Ptr pkg) {
int approx_num_pkgs = fill.second;
Package::ExceedsSplitLimits(approx_num_pkgs);

while (quantity() > 0 && quantity() >= pkg->fill_min()) {
while (quantity() > 0 && (quantity() - pkg->fill_min()) >= -eps_rsrc()) {
double pkg_fill = std::min(quantity(), fill_mass);
t_pkgd = boost::dynamic_pointer_cast<T>(PackageExtract(pkg_fill, pkg->name()));
ts_pkgd.push_back(t_pkgd);
Expand Down
2 changes: 1 addition & 1 deletion src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ void MatlBuyPolicy::AcceptMatlTrades(
// check if cumulative cap has been reached. If yes, then sample for dormant
// length and reset cycle_total_inv
if (use_cumulative_capacity() && (
(cumulative_cap_ - cycle_total_inv_) < eps())) {
(cumulative_cap_ - cycle_total_inv_) < eps_rsrc())) {
SetNextDormantTime();
LGH(INFO3) << "cycle cumulative inventory has been reached. Dormant period will end at " << next_dormant_end_ << std::endl;
cycle_total_inv_ = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/toolkit/matl_sell_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void MatlSellPolicy::GetMatlTrades(
if (shippable_pkgs > 0){
qty = it->amt;
LGH(INFO3) << " sending " << qty << " kg of " << it->request->commodity();
Material::Ptr mat = buf_->Pop(qty, cyclus::eps_rsrc());
Material::Ptr mat = buf_->Pop(qty, eps_rsrc());
Material::Ptr trade_mat;

// don't go through packaging if you don't need to. packaging always bumps
Expand All @@ -274,7 +274,7 @@ void MatlSellPolicy::GetMatlTrades(
if (package_->name() != mat->package_name()) { // packaging needed
std::vector<Material::Ptr> mat_pkgd = mat->Package<Material>(package_);

if (mat->quantity() > eps()) {
if (mat->quantity() > eps_rsrc()) {
// push any extra material that couldn't be packaged back onto buffer
// don't push unless there's leftover material
buf_->Push(mat);
Expand Down

0 comments on commit 45e8af9

Please sign in to comment.