Skip to content

Commit

Permalink
add transport units
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jul 18, 2024
1 parent 1a670d2 commit 920c1d9
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
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

0 comments on commit 920c1d9

Please sign in to comment.