Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding transport units to Storage #616

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Since last release
======================

**Added:**
* Added package parameter to storage (#603, #612)
* Added package parameter to storage (#603, #612, #616)
* Added package parameter to source (#613, #617)

**Changed:**
Expand Down
3 changes: 2 additions & 1 deletion src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ void Storage::EnterNotify() {
buy_policy.Start();

std::string package_name_ = context()->GetPackage(package)->name();
std::string tu_name_ = context()->GetTransportUnit(transport_unit)->name();
if (out_commods.size() == 1) {
sell_policy.Init(this, &stocks, std::string("stocks"), 1e+299, false,
sell_quantity, package_name_)
sell_quantity, package_name_, tu_name_)
.Set(out_commods.front())
.Start();

Expand Down
8 changes: 8 additions & 0 deletions src/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ class Storage
"uilabel": "Package"}
std::string package;

#pragma cyclus var {"default": "unrestricted", \
"tooltip": "Output transport unit", \
"doc": "Outgoing material, after packaging, will be "\
"further restricted by transport unit when trading.", \
"uitype": "transportunit", \
"uilabel": "Transport Unit"}
std::string transport_unit;

#pragma cyclus var {"tooltip":"Incoming material buffer"}
cyclus::toolkit::ResBuf<cyclus::Material> inventory;

Expand Down
53 changes: 53 additions & 0 deletions src/storage_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,59 @@ TEST_F(StorageTest, PackageMerge) {
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 1));
}

TEST_F(StorageTest, TransportUnit) {
std::string config =
" <in_commods> <val>commodity</val> </in_commods> "
" <out_commods> <val>commodity1</val> </out_commods> "
" <throughput>3</throughput> "
" <package>foo</package>"
" <transport_unit>bar</transport_unit>";

int simdur = 3;

cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
sim.context()->AddPackage("foo", 1, 1, "first");
cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
sim.context()->AddTransportUnit("bar", 2, 2, "first");

sim.AddSource("commodity").Finalize();
sim.AddSink("commodity1").Finalize();

int id = sim.Run();

std::vector<cyclus::Cond> tr_conds;
tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));

cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
// 6 transactions. While all three units could be packaged in one time step,
// the transport unit only allows two packages to be transported. Therefore,
// zero transactions the first timestep (material coming to storage from
// source). Then only two packages can be shipped at time step 1. Then the
// two packages plus the leftover material is able to ship four packages,
// two transport units in time 2
EXPECT_EQ(6, qr_trans.rows.size());

EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 3));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 4));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 5));

for (int i = 0; i < qr_trans.rows.size(); i++) {
std::cerr << "transaction " << i << "is at time " << qr_trans.GetVal<int>("Time", i) << std::endl;
}

std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// All pkgd resources are size 1
EXPECT_EQ(6, qr_res.rows.size());

EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 0));
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 5));
}

} // namespace cycamore

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Expand Down
Loading