From bc3d1664d8a74bdea47fc46848fb31126c734cec Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 24 Jul 2024 15:38:33 -0500 Subject: [PATCH 1/5] use keep_packaging in resbuf --- CHANGELOG.rst | 1 + src/toolkit/res_buf.h | 15 +++++++++++---- tests/toolkit/res_buf_tests.cc | 4 ++++ tests/toolkit/res_buf_tests.h | 26 ++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 12108f4ce9..14e799eaf6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -19,6 +19,7 @@ Since last release * Material sell policy can package materials (#1749, #1774) * Use miniforge for conda CI builds instead of miniconda (#1763) * Warning and limits on number of packages that can be created from a resource at once (#1771) +* Use keep_packaging instead of unpackaged in ResBuf (#1778) **Removed:** diff --git a/src/toolkit/res_buf.h b/src/toolkit/res_buf.h index db182efc5d..cb1d295dec 100644 --- a/src/toolkit/res_buf.h +++ b/src/toolkit/res_buf.h @@ -61,7 +61,7 @@ typedef std::vector ProdVec; template class ResBuf { public: - ResBuf(bool is_bulk=false, bool unpackaged=true) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk), unpackaged_(unpackaged) { } + ResBuf(bool is_bulk=false, bool keep_packaging=false) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk), keep_packaging_(keep_packaging) { } virtual ~ResBuf() {} @@ -85,6 +85,13 @@ class ResBuf { cap_ = cap; } + /// Sets whether the buffer should keep packaged resources + void keep_packaging(bool keep_packaging) { + keep_packaging_ = keep_packaging; + } + + bool keep_packaging() const { return keep_packaging_; } + /// Returns the total number of constituent resource objects /// in the buffer. Never throws. inline int count() const { return rs_.size(); } @@ -267,7 +274,7 @@ class ResBuf { if (!is_bulk_ || rs_.size() == 0) { // strip package id and set as default - if (unpackaged_) { + if (!keep_packaging_) { m->ChangePackage(); } rs_.push_back(m); @@ -319,7 +326,7 @@ class ResBuf { for (int i = 0; i < rss.size(); i++) { if (!is_bulk_ || rs_.size() == 0) { - if (unpackaged_) { + if (!keep_packaging_) { rss[i]->ChangePackage(); } rs_.push_back(rss[i]); @@ -359,7 +366,7 @@ class ResBuf { bool is_bulk_; /// Whether materials should be stripped of their packaging before being /// pushed onto the resbuf. If res_buf is bulk, this is assumed true. - bool unpackaged_; + bool keep_packaging_; /// List of constituent resource objects forming the buffer's inventory std::list rs_; diff --git a/tests/toolkit/res_buf_tests.cc b/tests/toolkit/res_buf_tests.cc index 9b6615835b..7e71737f57 100644 --- a/tests/toolkit/res_buf_tests.cc +++ b/tests/toolkit/res_buf_tests.cc @@ -439,6 +439,10 @@ TEST_F(MaterialBufTest, BulkTest) { } +TEST_F(MaterialBufTest, KeepPackaging) { + keep_pkg_store_.Push(mat4_pkgd_); + ASSERT_EQ(keep_pkg_store_.Pop()->package_name(), pkg_name_); +} } // namespace toolkit } // namespace cyclus diff --git a/tests/toolkit/res_buf_tests.h b/tests/toolkit/res_buf_tests.h index ef83068111..8edb08fc89 100644 --- a/tests/toolkit/res_buf_tests.h +++ b/tests/toolkit/res_buf_tests.h @@ -10,10 +10,20 @@ #include "composition.h" #include "material.h" #include "toolkit/res_buf.h" +#include "context.h" +#include "recorder.h" +#include "timer.h" +#include "region.h" namespace cyclus { namespace toolkit { +class Dummy : public cyclus::Region { + public: + Dummy(cyclus::Context* ctx) : cyclus::Region(ctx) {} + Dummy* Clone() { return NULL; } +}; + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class ProductBufTest : public ::testing::Test { protected: @@ -70,13 +80,21 @@ class MaterialBufTest : public ::testing::Test { ResBuf mat_store_; // default constructed mat store ResBuf bulk_store_ = ResBuf(true); + ResBuf keep_pkg_store_ = ResBuf(false, true); Nuc sr89_, fe59_; - Material::Ptr mat1a_, mat1b_, mat2a_, mat2b_, mat3_; + Material::Ptr mat1a_, mat1b_, mat2a_, mat2b_, mat3_, mat4_pkgd_; Composition::Ptr test_comp1_, test_comp2_, test_comp3_; + std::string pkg_name_ = "keep"; + double cap_; + cyclus::Timer ti; + cyclus::Recorder rec; + cyclus::Context* ctx = new cyclus::Context(&ti, &rec); + cyclus::Agent* dummy = new Dummy(ctx); + virtual void SetUp() { try { @@ -94,13 +112,17 @@ class MaterialBufTest : public ::testing::Test { test_comp3_ = Composition::CreateFromMass(w); double mat_size = 5 * units::g; - mat1a_ = Material::CreateUntracked(mat_size, test_comp1_); mat1b_ = Material::CreateUntracked(mat_size, test_comp1_); mat2a_ = Material::CreateUntracked(mat_size, test_comp2_); mat2b_ = Material::CreateUntracked(mat_size, test_comp2_); mat3_ = Material::CreateUntracked(mat_size, test_comp3_); + ctx->AddPackage(pkg_name_, mat_size, mat_size); + cyclus::Package::Ptr pkg = ctx->GetPackage(pkg_name_); + mat4_pkgd_ = Material::Create(dummy, mat_size, test_comp1_, pkg_name_); + mat4_pkgd_->ChangePackage(pkg_name_); + cap_ = 10 * mat_size; mat_store_.capacity(cap_); From 7a7e9c0889e7af910a487b35ab58964373737ca4 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Fri, 26 Jul 2024 12:05:25 -0500 Subject: [PATCH 2/5] resbuf can either be bulk or keep_packaging, not both --- src/toolkit/res_buf.h | 6 +++++- tests/toolkit/res_buf_tests.cc | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/toolkit/res_buf.h b/src/toolkit/res_buf.h index cb1d295dec..8857f8b73f 100644 --- a/src/toolkit/res_buf.h +++ b/src/toolkit/res_buf.h @@ -61,7 +61,11 @@ typedef std::vector ProdVec; template class ResBuf { public: - ResBuf(bool is_bulk=false, bool keep_packaging=false) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk), keep_packaging_(keep_packaging) { } + ResBuf(bool is_bulk=false, bool keep_packaging=false) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk), keep_packaging_(keep_packaging) { + if (is_bulk_ && keep_packaging_) { + throw ValueError("bulk storage resbufs cannot keep packaging. Only one of the two options can be true."); + } + } virtual ~ResBuf() {} diff --git a/tests/toolkit/res_buf_tests.cc b/tests/toolkit/res_buf_tests.cc index 7e71737f57..65595525a5 100644 --- a/tests/toolkit/res_buf_tests.cc +++ b/tests/toolkit/res_buf_tests.cc @@ -444,5 +444,10 @@ TEST_F(MaterialBufTest, KeepPackaging) { ASSERT_EQ(keep_pkg_store_.Pop()->package_name(), pkg_name_); } +TEST_F(MaterialBufTest, BulkKeepPackaging) { + EXPECT_THROW(ResBuf(true, true), ValueError); +} + + } // namespace toolkit } // namespace cyclus From fc3aa793139cd57d63353a4f5682a006b883a138 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Fri, 26 Jul 2024 15:06:15 -0500 Subject: [PATCH 3/5] test change keep_packaging --- tests/toolkit/res_buf_tests.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/toolkit/res_buf_tests.cc b/tests/toolkit/res_buf_tests.cc index 65595525a5..0f81bf7e38 100644 --- a/tests/toolkit/res_buf_tests.cc +++ b/tests/toolkit/res_buf_tests.cc @@ -444,6 +444,15 @@ TEST_F(MaterialBufTest, KeepPackaging) { ASSERT_EQ(keep_pkg_store_.Pop()->package_name(), pkg_name_); } +TEST_F(MaterialBufTest, ChangeKeepPackaging) { + keep_pkg_store_.Push(mat4_pkgd_); + ASSERT_EQ(keep_pkg_store_.Pop()->package_name(), pkg_name_); + + keep_pkg_store_.keep_packaging(false); + keep_pkg_store_.Push(mat4_pkgd_); + ASSERT_EQ(keep_pkg_store_.Pop()->package_name(), cyclus::Package::unpackaged_name()); +} + TEST_F(MaterialBufTest, BulkKeepPackaging) { EXPECT_THROW(ResBuf(true, true), ValueError); } From 973ae957a2da0e08ab5f9d7d5347b0509b5783aa Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Fri, 26 Jul 2024 16:30:26 -0500 Subject: [PATCH 4/5] call capacity and keep_packaging in constructor --- src/toolkit/res_buf.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/toolkit/res_buf.h b/src/toolkit/res_buf.h index 8857f8b73f..2959324d59 100644 --- a/src/toolkit/res_buf.h +++ b/src/toolkit/res_buf.h @@ -61,7 +61,9 @@ typedef std::vector ProdVec; template class ResBuf { public: - ResBuf(bool is_bulk=false, bool keep_packaging=false) : cap_(INFINITY), qty_(0), is_bulk_(is_bulk), keep_packaging_(keep_packaging) { + ResBuf(bool is_bulk=false, bool keep_pkg=false) : qty_(0), is_bulk_(is_bulk) { + capacity(INFINITY); + keep_packaging(keep_pkg); if (is_bulk_ && keep_packaging_) { throw ValueError("bulk storage resbufs cannot keep packaging. Only one of the two options can be true."); } @@ -80,6 +82,10 @@ class ResBuf { /// @throws ValueError the new capacity is lower (by eps_rsrc()) than the /// quantity of resources that exist in the buffer. void capacity(double cap) { + if (cap < 0) { + throw ValueError("capacity must not be negative"); + } + if (quantity() - cap > eps_rsrc()) { std::stringstream ss; ss << std::setprecision(17) << "new capacity " << cap From 070202c5547ac4359e5968e77639aa159d192cfb Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Sat, 27 Jul 2024 16:18:14 -0500 Subject: [PATCH 5/5] check for bulk and keep_keep packaging in keep_packaging method --- src/toolkit/res_buf.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/toolkit/res_buf.h b/src/toolkit/res_buf.h index 2959324d59..76da2a00b6 100644 --- a/src/toolkit/res_buf.h +++ b/src/toolkit/res_buf.h @@ -64,9 +64,6 @@ class ResBuf { ResBuf(bool is_bulk=false, bool keep_pkg=false) : qty_(0), is_bulk_(is_bulk) { capacity(INFINITY); keep_packaging(keep_pkg); - if (is_bulk_ && keep_packaging_) { - throw ValueError("bulk storage resbufs cannot keep packaging. Only one of the two options can be true."); - } } virtual ~ResBuf() {} @@ -97,6 +94,9 @@ class ResBuf { /// Sets whether the buffer should keep packaged resources void keep_packaging(bool keep_packaging) { + if (is_bulk_ && keep_packaging) { + throw ValueError("bulk storage resbufs cannot keep packaging. Only one of the two options can be true."); + } keep_packaging_ = keep_packaging; }