From a24831421212d65d9f31c52914bb1863106a3483 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 13 May 2024 16:47:50 -0500 Subject: [PATCH 1/6] storage inits sell pol with package --- src/storage.cc | 3 ++- src/storage.h | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/storage.cc b/src/storage.cc index 96487b44c..bbc306e76 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -182,8 +182,9 @@ void Storage::EnterNotify() { } buy_policy.Start(); + int package_id_ = context()->GetPackageByName(package)->id(); if (out_commods.size() == 1) { - sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false, sell_quantity) + sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false, sell_quantity, package_id_) .Set(out_commods.front()) .Start(); diff --git a/src/storage.h b/src/storage.h index 0e8f0c7b5..01186fdf4 100644 --- a/src/storage.h +++ b/src/storage.h @@ -58,6 +58,7 @@ namespace cycamore { /// buying_size_max is the maximum size of the buy request if buying_size_type is Uniform (required) or Normal (optional) /// buying_size_mean is the mean size of the buy request if buying_size_type is Normal /// buying_size_stddev is the standard deviation of the buy request if buying_size_type is Normal +/// package is the name of the package type to ship /// /// @section detailed Detailed Behavior /// @@ -429,6 +430,13 @@ class Storage "uilabel": "Cumulative Cap"} double cumulative_cap; + #pragma cyclus var {"default": "unpackaged", \ + "tooltip": "Output package", \ + "doc": "Outgoing material will be packaged when trading.", \ + "uitype": "package", \ + "uilabel": "Package"} + std::string package; + #pragma cyclus var {"tooltip":"Incoming material buffer"} cyclus::toolkit::ResBuf inventory; From e7241aa2fc254e5386cbefa79eca98df83906562 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Thu, 23 May 2024 12:59:29 -0500 Subject: [PATCH 2/6] package tests for storage --- src/storage_tests.cc | 110 +++++++++++++++++++++++++++++++++++++++++++ src/storage_tests.h | 1 + 2 files changed, 111 insertions(+) diff --git a/src/storage_tests.cc b/src/storage_tests.cc index e2579886d..b81ce13e3 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -23,6 +23,7 @@ void StorageTest::InitParameters(){ max_inv_size = 200; throughput = 20; discrete_handling = 0; + package = "foo"; // Active period longer than any of the residence time related-tests needs @@ -42,6 +43,7 @@ void StorageTest::SetUpStorage(){ src_facility_->inventory_tracker.set_capacity(max_inv_size); src_facility_->throughput = throughput; src_facility_->discrete_handling = discrete_handling; + src_facility_->package = package; } void StorageTest::TestInitState(Storage* fac){ @@ -49,6 +51,7 @@ void StorageTest::TestInitState(Storage* fac){ EXPECT_EQ(max_inv_size, fac->max_inv_size); EXPECT_EQ(throughput, fac->throughput); EXPECT_EQ(in_r1, fac->in_recipe); + EXPECT_EQ(package, fac->package); } void StorageTest::TestAddMat(Storage* fac, @@ -869,6 +872,113 @@ TEST_F(StorageTest, CCap_Inventory) { EXPECT_EQ(1, qr.GetVal("Quantity", 4)); } +TEST_F(StorageTest, PackageExactly) { + std::string config = + " spent_fuel " + " dry_spent " + " 10 " + " foo"; + + int simdur = 3; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + sim.context()->AddPackage("foo", 1, 2, "first"); + cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + + sim.AddSource("spent_fuel").capacity(2).Finalize(); + sim.AddSink("dry_spent").Finalize(); + + int id = sim.Run(); + + std::vector tr_conds; + tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent"))); + cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + EXPECT_EQ(2, qr_trans.rows.size()); + + EXPECT_EQ(1, qr_trans.GetVal("Time", 0)); + EXPECT_EQ(2, qr_trans.GetVal("Time", 1)); + + std::vector res_conds; + res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + EXPECT_EQ(qr_res.rows.size(), 2); + // Given the PRNG with default seed, the resource should have mass 9.41273 + EXPECT_EQ(qr_res.GetVal("Quantity", 0), 2); + EXPECT_EQ(qr_res.GetVal("Quantity", 1), 2); +} + +TEST_F(StorageTest, PackageSplitEqual) { + std::string config = + " commodity " + " commodity1 " + " 10 " + " foo"; + + int simdur = 3; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + sim.context()->AddPackage("foo", 1, 2, "equal"); + cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + + sim.AddSource("commodity").capacity(3).Finalize(); + sim.AddSink("commodity1").Finalize(); + + int id = sim.Run(); + + std::vector tr_conds; + tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1"))); + cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + EXPECT_EQ(4, qr_trans.rows.size()); + + EXPECT_EQ(1, qr_trans.GetVal("Time", 0)); + EXPECT_EQ(1, qr_trans.GetVal("Time", 1)); + EXPECT_EQ(2, qr_trans.GetVal("Time", 2)); + EXPECT_EQ(2, qr_trans.GetVal("Time", 3)); + + std::vector res_conds; + res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + EXPECT_EQ(qr_res.rows.size(), 4); + EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1.5); + EXPECT_EQ(qr_res.GetVal("Quantity", 1), 1.5); + EXPECT_EQ(qr_res.GetVal("Quantity", 2), 1.5); + EXPECT_EQ(qr_res.GetVal("Quantity", 2), 1.5); +} + +TEST_F(StorageTest, PackageMerge) { + std::string config = + " commodity " + " commodity1 " + " 1 " + " foo"; + + int simdur = 5; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + sim.context()->AddPackage("foo", 1, 2, "first"); + cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + + sim.AddSource("commodity").capacity(0.5).Finalize(); + sim.AddSink("commodity1").Finalize(); + + int id = sim.Run(); + + std::vector tr_conds; + tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1"))); + + cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + EXPECT_EQ(2, qr_trans.rows.size()); + + EXPECT_EQ(2, qr_trans.GetVal("Time", 0)); + EXPECT_EQ(4, qr_trans.GetVal("Time", 1)); + + std::vector res_conds; + res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + EXPECT_EQ(qr_res.rows.size(), 2); + EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1); + EXPECT_EQ(qr_res.GetVal("Quantity", 1), 1); +} } // namespace cycamore diff --git a/src/storage_tests.h b/src/storage_tests.h index f010869e9..610ef066c 100644 --- a/src/storage_tests.h +++ b/src/storage_tests.h @@ -36,6 +36,7 @@ class StorageTest : public ::testing::Test { int residence_time; double throughput, max_inv_size; bool discrete_handling; + std::string package; }; } // namespace cycamore #endif // STORAGE_TESTS_H_ From 28bdce08db8d0cbb46bbd8f404343dd3862cf99b Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Thu, 23 May 2024 13:02:21 -0500 Subject: [PATCH 3/6] changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 58084fcd5..fe7a87908 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,7 @@ Since last release * Rely on ``python3`` in environment instead of ``python`` (#602) * Link against ``libxml++`` imported target in CMake instead of ``LIBXMLXX_LIBRARIES`` (#608) * Cleaned up ``using`` declarations throughout archetypes (#610) +* Added package parameter to storage (#603) **Fixed:** From c6d0e2de539c88006ce1b96af78c4fc087fa777b Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Sun, 26 May 2024 21:42:54 -0500 Subject: [PATCH 4/6] remove package id --- src/storage.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/storage.cc b/src/storage.cc index bbc306e76..bacc4033b 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -182,9 +182,10 @@ void Storage::EnterNotify() { } buy_policy.Start(); - int package_id_ = context()->GetPackageByName(package)->id(); + int package_name_ = context()->GetPackageByName(package)->name(); if (out_commods.size() == 1) { - sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false, sell_quantity, package_id_) + sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false, + sell_quantity, package_name_) .Set(out_commods.front()) .Start(); From ee403a8ff37b2e504c035ac5dd596d45afed929c Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Tue, 28 May 2024 10:06:33 -0500 Subject: [PATCH 5/6] update syntax for retrieval of package --- src/storage.cc | 2 +- src/storage_tests.cc | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/storage.cc b/src/storage.cc index bacc4033b..9fc563e17 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -182,7 +182,7 @@ void Storage::EnterNotify() { } buy_policy.Start(); - int package_name_ = context()->GetPackageByName(package)->name(); + std::string package_name_ = context()->GetPackage(package)->name(); if (out_commods.size() == 1) { sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false, sell_quantity, package_name_) diff --git a/src/storage_tests.cc b/src/storage_tests.cc index b81ce13e3..a8d14f47c 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -883,7 +883,7 @@ TEST_F(StorageTest, PackageExactly) { cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); sim.context()->AddPackage("foo", 1, 2, "first"); - cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + cyclus::Package::Ptr p = sim.context()->GetPackage("foo"); sim.AddSource("spent_fuel").capacity(2).Finalize(); sim.AddSink("dry_spent").Finalize(); @@ -899,7 +899,7 @@ TEST_F(StorageTest, PackageExactly) { EXPECT_EQ(2, qr_trans.GetVal("Time", 1)); std::vector res_conds; - res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); EXPECT_EQ(qr_res.rows.size(), 2); // Given the PRNG with default seed, the resource should have mass 9.41273 @@ -918,7 +918,7 @@ TEST_F(StorageTest, PackageSplitEqual) { cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); sim.context()->AddPackage("foo", 1, 2, "equal"); - cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + cyclus::Package::Ptr p = sim.context()->GetPackage("foo"); sim.AddSource("commodity").capacity(3).Finalize(); sim.AddSink("commodity1").Finalize(); @@ -936,7 +936,7 @@ TEST_F(StorageTest, PackageSplitEqual) { EXPECT_EQ(2, qr_trans.GetVal("Time", 3)); std::vector res_conds; - res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); EXPECT_EQ(qr_res.rows.size(), 4); EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1.5); @@ -956,7 +956,7 @@ TEST_F(StorageTest, PackageMerge) { cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); sim.context()->AddPackage("foo", 1, 2, "first"); - cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo"); + cyclus::Package::Ptr p = sim.context()->GetPackage("foo"); sim.AddSource("commodity").capacity(0.5).Finalize(); sim.AddSink("commodity1").Finalize(); @@ -973,7 +973,7 @@ TEST_F(StorageTest, PackageMerge) { EXPECT_EQ(4, qr_trans.GetVal("Time", 1)); std::vector res_conds; - res_conds.push_back(cyclus::Cond("PackageId", "==", p->id())); + res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); EXPECT_EQ(qr_res.rows.size(), 2); EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1); From 0d2c74c16592ac3194690b74c4556350cb69cfcc Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Thu, 30 May 2024 10:58:03 -0500 Subject: [PATCH 6/6] more comments on testing --- src/storage_tests.cc | 63 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/storage_tests.cc b/src/storage_tests.cc index a8d14f47c..d85c90765 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -873,10 +873,10 @@ TEST_F(StorageTest, CCap_Inventory) { } TEST_F(StorageTest, PackageExactly) { + // resource can be packaged without splitting or merging std::string config = " spent_fuel " " dry_spent " - " 10 " " foo"; int simdur = 3; @@ -893,6 +893,7 @@ TEST_F(StorageTest, PackageExactly) { std::vector tr_conds; tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent"))); cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + // two transactions out of storage, happening at time 1 and 2 EXPECT_EQ(2, qr_trans.rows.size()); EXPECT_EQ(1, qr_trans.GetVal("Time", 0)); @@ -901,17 +902,17 @@ TEST_F(StorageTest, PackageExactly) { std::vector res_conds; res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + // two resources that have been packaged, each of size two EXPECT_EQ(qr_res.rows.size(), 2); - // Given the PRNG with default seed, the resource should have mass 9.41273 EXPECT_EQ(qr_res.GetVal("Quantity", 0), 2); EXPECT_EQ(qr_res.GetVal("Quantity", 1), 2); } TEST_F(StorageTest, PackageSplitEqual) { + // Resources must be split into two to package. Packaging strategy equal std::string config = " commodity " " commodity1 " - " 10 " " foo"; int simdur = 3; @@ -928,6 +929,8 @@ TEST_F(StorageTest, PackageSplitEqual) { std::vector tr_conds; tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1"))); cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + // four transactions out of storage. Each resource is split, so two + // transactions at time 1, two at time 2 EXPECT_EQ(4, qr_trans.rows.size()); EXPECT_EQ(1, qr_trans.GetVal("Time", 0)); @@ -938,11 +941,53 @@ TEST_F(StorageTest, PackageSplitEqual) { std::vector res_conds; res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + // because package does split-equally, resources are all of size 1.5 (3/2) EXPECT_EQ(qr_res.rows.size(), 4); - EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1.5); - EXPECT_EQ(qr_res.GetVal("Quantity", 1), 1.5); - EXPECT_EQ(qr_res.GetVal("Quantity", 2), 1.5); - EXPECT_EQ(qr_res.GetVal("Quantity", 2), 1.5); + EXPECT_EQ(1.5, qr_res.GetVal("Quantity", 0)); + EXPECT_EQ(1.5, qr_res.GetVal("Quantity", 1)); + EXPECT_EQ(1.5, qr_res.GetVal("Quantity", 2)); + EXPECT_EQ(1.5, qr_res.GetVal("Quantity", 3)); +} + +TEST_F(StorageTest, PackageSplitFirst) { + // Resources must be split into two to package. Packaging strategy first + std::string config = + " commodity " + " commodity1 " + " foo"; + + int simdur = 3; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + sim.context()->AddPackage("foo", 1, 2, "first"); + cyclus::Package::Ptr p = sim.context()->GetPackage("foo"); + + sim.AddSource("commodity").capacity(3).Finalize(); + sim.AddSink("commodity1").Finalize(); + + int id = sim.Run(); + + std::vector tr_conds; + tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1"))); + cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + // four transactions out of storage. Each resource is split, so two + // transactions at time 1, two at time 2 + EXPECT_EQ(4, qr_trans.rows.size()); + + EXPECT_EQ(1, qr_trans.GetVal("Time", 0)); + EXPECT_EQ(1, qr_trans.GetVal("Time", 1)); + EXPECT_EQ(2, qr_trans.GetVal("Time", 2)); + EXPECT_EQ(2, qr_trans.GetVal("Time", 3)); + + std::vector res_conds; + res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); + cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + // because package does split-first, resources are size 2 and 1 + EXPECT_EQ(qr_res.rows.size(), 4); + EXPECT_EQ(2, qr_res.GetVal("Quantity", 0)); + EXPECT_EQ(1, qr_res.GetVal("Quantity", 1)); + EXPECT_EQ(2, qr_res.GetVal("Quantity", 2)); + EXPECT_EQ(1, qr_res.GetVal("Quantity", 3)); } TEST_F(StorageTest, PackageMerge) { @@ -967,6 +1012,9 @@ TEST_F(StorageTest, PackageMerge) { tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1"))); cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds); + // two transactions out of storage. Because the source only provides 0.5 each + // time step, it takes two time steps to acquire enough material to package. + // Therefore transactions at time 2 and 4 EXPECT_EQ(2, qr_trans.rows.size()); EXPECT_EQ(2, qr_trans.GetVal("Time", 0)); @@ -975,6 +1023,7 @@ TEST_F(StorageTest, PackageMerge) { std::vector res_conds; res_conds.push_back(cyclus::Cond("PackageName", "==", p->name())); cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds); + // Combines two 0.5 mass resources to make packages with mass 1 EXPECT_EQ(qr_res.rows.size(), 2); EXPECT_EQ(qr_res.GetVal("Quantity", 0), 1); EXPECT_EQ(qr_res.GetVal("Quantity", 1), 1);