From 2078619bb150d30e0f124b6061d74404cf976ace Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 9 Oct 2023 13:38:13 -0500 Subject: [PATCH 1/5] optional active and dormant buying periods in Storage --- src/storage.cc | 11 +++++++-- src/storage.h | 27 +++++++++++++++++++++ src/storage_tests.cc | 58 ++++++++++++++++++++++++++++++++++++++++++++ src/storage_tests.h | 2 +- 4 files changed, 95 insertions(+), 3 deletions(-) diff --git a/src/storage.cc b/src/storage.cc index 46cc3577dc..7824526771 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -49,7 +49,7 @@ void Storage::InitFrom(cyclus::QueryableBackend* b) { //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void Storage::EnterNotify() { cyclus::Facility::EnterNotify(); - buy_policy.Init(this, &inventory, std::string("inventory")); + buy_policy.Init(this, &inventory, std::string("inventory"), throughput, active_buying, dormant_buying); // dummy comp, use in_recipe if provided cyclus::CompMap v; @@ -158,8 +158,15 @@ void Storage::Tock() { std::vector::iterator result; result = std::max_element(in_commod_prefs.begin(), in_commod_prefs.end()); int maxindx = std::distance(in_commod_prefs.begin(), result); - cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, + + if (manager()->context()->time() % (active_buying + dormant_buying) < active_buying) { + cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, current_capacity()); + } + else { + cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, 0); + } + // Multiple commodity tracking is not supported, user can only // provide one value for out_commods, despite it being a vector of strings. cyclus::toolkit::RecordTimeSeries("supply"+out_commods[0], this, diff --git a/src/storage.h b/src/storage.h index ace678874f..2e7286dda4 100644 --- a/src/storage.h +++ b/src/storage.h @@ -35,6 +35,10 @@ namespace cycamore { /// sell_quantity restricts selling to only integer multiples of this value /// max_inv_size is the maximum capacity of the inventory storage /// throughput is the maximum processing capacity per timestep +/// active_buying is the number of time steps in a row where the agent +/// exhibits default behavior +/// dormant_buying is the number of time steps in a row where the agent is +/// not requesting any new material /// /// @section detailed Detailed Behavior /// @@ -202,6 +206,29 @@ class Storage "uilabel":"Batch Handling"} bool discrete_handling; + #pragma cyclus var {"default": 1,\ + "tooltip": "Length of the active buying "\ + "period",\ + "doc":"During the length of the active buying "\ + "period, agent exhibits regular behavior. "\ + "If paired with dormant buying period, "\ + "alternates between buying and not buying, "\ + "regardless if space is available",\ + "uilabel":"Active Buying Period"} + int active_buying; + + #pragma cyclus var {"default": 0,\ + "tooltip": "Length of the active buying "\ + "period",\ + "doc":"During the length of the dormant buying "\ + "period, agent will not request any new "\ + "material from the DRE. Paired with active "\ + "buying period, alternates between buying "\ + "and not buying, regardless if space is "\ + "available",\ + "uilabel":"Dormant (No Buying) Period"} + int dormant_buying; + #pragma cyclus var {"tooltip":"Incoming material buffer"} cyclus::toolkit::ResBuf inventory; diff --git a/src/storage_tests.cc b/src/storage_tests.cc index 609c11a7c2..37f2ad1614 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -23,6 +23,9 @@ void StorageTest::InitParameters(){ max_inv_size = 200; throughput = 20; discrete_handling = 0; + // Active period longer than any of the residence time related-tests needs + active_buying = 20; + dormant_buying = 1; cyclus::CompMap v; v[922350000] = 1; @@ -39,6 +42,8 @@ void StorageTest::SetUpStorage(){ src_facility_->max_inv_size = max_inv_size; src_facility_->throughput = throughput; src_facility_->discrete_handling = discrete_handling; + src_facility_->active_buying = active_buying; + src_facility_->dormant_buying = dormant_buying; } void StorageTest::TestInitState(Storage* fac){ @@ -455,6 +460,59 @@ TEST_F(StorageTest, MultipleCommods){ EXPECT_EQ(1, n_trans2) << "expected 1 transactions, got " << n_trans; } + TEST_F(StorageTest, ActiveDormant){ + std::string config = + " spent_fuel " + " dry_spent " + " 1" + " 0" + " 1" + " 1"; + + int simdur = 2; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + + sim.AddSource("spent_fuel").capacity(5).Finalize(); + sim.AddSink("dry_spent").Finalize(); + + int id = sim.Run(); + + // return all transactions where our storage facility is the acceptor + std::vector conds; + conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel"))); + cyclus::QueryResult qr = sim.db().Query("Transactions", &conds); + int n_trans = qr.rows.size(); + EXPECT_EQ(1, n_trans) << "expected 1 transactions, got " << n_trans; + } + + TEST_F(StorageTest, NoDormant){ + // Verify Storage behavior + + std::string config = + " spent_fuel " + " dry_spent " + " 1" + " 10" + " 1"; + + int simdur = 2; + + cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); + + sim.AddSource("spent_fuel").Finalize(); + sim.AddSink("dry_spent").Finalize(); + + int id = sim.Run(); + + // return all transactions where our sstorage facility is the sender + std::vector conds; + conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent"))); + cyclus::QueryResult qr = sim.db().Query("Transactions", &conds); + int n_trans = qr.rows.size(); + EXPECT_EQ(2, n_trans) << "expected 2 transactions, got " << n_trans; + } + TEST_F(StorageTest, PositionInitialize){ // Verify Storage behavior diff --git a/src/storage_tests.h b/src/storage_tests.h index f010869e98..83ba5f3453 100644 --- a/src/storage_tests.h +++ b/src/storage_tests.h @@ -33,7 +33,7 @@ class StorageTest : public ::testing::Test { std::vector in_c1, out_c1; std::string in_r1; - int residence_time; + int residence_time, active_buying, dormant_buying; double throughput, max_inv_size; bool discrete_handling; }; From fac3c16b305af09e65fd7fb36dc97203f7b1b031 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 27 Nov 2023 15:59:18 -0700 Subject: [PATCH 2/5] working nodormant test --- src/storage_tests.cc | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/storage_tests.cc b/src/storage_tests.cc index 37f2ad1614..4892642c83 100644 --- a/src/storage_tests.cc +++ b/src/storage_tests.cc @@ -460,12 +460,13 @@ TEST_F(StorageTest, MultipleCommods){ EXPECT_EQ(1, n_trans2) << "expected 1 transactions, got " << n_trans; } - TEST_F(StorageTest, ActiveDormant){ +// Should get one transaction in a 2 step simulation when agent is active for +// one step and dormant for one step +TEST_F(StorageTest, ActiveDormant){ std::string config = " spent_fuel " " dry_spent " " 1" - " 0" " 1" " 1"; @@ -486,28 +487,26 @@ TEST_F(StorageTest, MultipleCommods){ EXPECT_EQ(1, n_trans) << "expected 1 transactions, got " << n_trans; } - TEST_F(StorageTest, NoDormant){ - // Verify Storage behavior - + // Should get two transactions in a 2 step simulation when there is no + // dormant period, i.e. agent is always active +TEST_F(StorageTest, NoDormant){ std::string config = " spent_fuel " " dry_spent " - " 1" - " 10" + " 1" " 1"; int simdur = 2; cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur); - sim.AddSource("spent_fuel").Finalize(); + sim.AddSource("spent_fuel").capacity(5).Finalize(); sim.AddSink("dry_spent").Finalize(); int id = sim.Run(); - // return all transactions where our sstorage facility is the sender std::vector conds; - conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent"))); + conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel"))); cyclus::QueryResult qr = sim.db().Query("Transactions", &conds); int n_trans = qr.rows.size(); EXPECT_EQ(2, n_trans) << "expected 2 transactions, got " << n_trans; From c24f1a7f99d95c4ff89cf13f74c23b52cd38a5ba Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 27 Nov 2023 20:36:06 -0700 Subject: [PATCH 3/5] Update src/storage.cc Co-authored-by: Paul Wilson --- src/storage.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/storage.cc b/src/storage.cc index 7824526771..88e7efb553 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -158,14 +158,12 @@ void Storage::Tock() { std::vector::iterator result; result = std::max_element(in_commod_prefs.begin(), in_commod_prefs.end()); int maxindx = std::distance(in_commod_prefs.begin(), result); - + double demand = 0; if (manager()->context()->time() % (active_buying + dormant_buying) < active_buying) { - cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, - current_capacity()); + demand = current_capacity()); } - else { - cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, 0); - } + + cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, demand); // Multiple commodity tracking is not supported, user can only // provide one value for out_commods, despite it being a vector of strings. From a0068c00d636d545bdb2faa30a59ee32f6e6fcd2 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 27 Nov 2023 20:36:25 -0700 Subject: [PATCH 4/5] Update src/storage.h Co-authored-by: Paul Wilson --- src/storage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage.h b/src/storage.h index 2e7286dda4..77575b8102 100644 --- a/src/storage.h +++ b/src/storage.h @@ -218,7 +218,7 @@ class Storage int active_buying; #pragma cyclus var {"default": 0,\ - "tooltip": "Length of the active buying "\ + "tooltip": "Length of the dormant buying "\ "period",\ "doc":"During the length of the dormant buying "\ "period, agent will not request any new "\ From 121de1827b795c8d8f4c1074e2a9fff6cb96b812 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 27 Nov 2023 20:53:24 -0700 Subject: [PATCH 5/5] extraneous ) --- src/storage.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage.cc b/src/storage.cc index 88e7efb553..2e75cdf831 100644 --- a/src/storage.cc +++ b/src/storage.cc @@ -160,7 +160,7 @@ void Storage::Tock() { int maxindx = std::distance(in_commod_prefs.begin(), result); double demand = 0; if (manager()->context()->time() % (active_buying + dormant_buying) < active_buying) { - demand = current_capacity()); + demand = current_capacity(); } cyclus::toolkit::RecordTimeSeries("demand"+in_commods[maxindx], this, demand);