diff --git a/input/reactor_pref_change.xml b/input/reactor_pref_change.xml new file mode 100755 index 000000000..e323c1aca --- /dev/null +++ b/input/reactor_pref_change.xml @@ -0,0 +1,138 @@ + + + + 4 + 1 + 2022 + + + + agents NullRegion + cycamore DeployInst + cycamore Source + cycamore Reactor + cycamore Sink + + + + Region + + + + Inst + + + + Source1 + Source2 + Reactor + Waste + Reactor + + + 1 + 1 + 1 + 1 + 1 + + + 1 + 1 + 1 + 1 + 3 + + + + + + + + Source1 + + + Fuel1 + Fuel1_recipe + + + + + + Source2 + + + Fuel2 + Fuel2_recipe + + + + + + Reactor + + + + Fuel1 + Fuel2 + + + SpentFuel + SpentFuel + + + Fuel1_recipe + Fuel2_recipe + + + SpentFuel_recipe + SpentFuel_recipe + + + 2 + 1 + + 2 + Fuel2 + 3 + 1 + 0 + 1000 + 1 + 1 + + + + + + Waste + + + SpentFuel + + + + + + Fuel1_recipe + mass + U235 0.03 + U238 0.97 + + + + Fuel2_recipe + mass + U235 0.05 + U238 0.95 + + + + SpentFuel_recipe + mass + U235 0.01 + U238 0.98 + Pu239 0.01 + + + diff --git a/src/reactor.cc b/src/reactor.cc index 7c6ae2852..63788598f 100644 --- a/src/reactor.cc +++ b/src/reactor.cc @@ -167,7 +167,7 @@ void Reactor::Tick() { // update preferences for (int i = 0; i < pref_change_times.size(); i++) { int change_t = pref_change_times[i]; - if (t != change_t) { + if (t < change_t) { continue; } diff --git a/src/reactor_tests.cc b/src/reactor_tests.cc index 663e82ea8..ffe2099eb 100644 --- a/src/reactor_tests.cc +++ b/src/reactor_tests.cc @@ -490,6 +490,62 @@ TEST(ReactorTests, PrefChange) { EXPECT_EQ(25, qr.rows.size()) << "failed to adjust preferences properly"; } +TEST(ReactorTests, PrefChange2) { + std::string config = + " uox_fresh mox_fresh " + " uox_spent mox_spent " + " uox mox " + " uox_waste mox_waste " + " 2 1 " + "" + " 1 " + " 0 " + " 300 " + " 1 " + " 1 " + "" + " 2 3 " + " mox mox " + " 3 1 "; + + int simdur = 4; + cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:Reactor"), config, simdur); + sim.AddSource("uox").Finalize(); + sim.AddSource("mox").Finalize(); + sim.AddRecipe("uox_fresh", c_uox()); + sim.AddRecipe("uox_spent", c_spentuox()); + sim.AddRecipe("mox_fresh", c_mox()); + sim.AddRecipe("mox_spent", c_spentmox()); + int aid = sim.Run(); + + std::vector conds; + int resid; + + conds.clear(); + conds.push_back(Cond("Time", "==", 1)); + conds.push_back(Cond("ReceiverId", "==", aid)); + resid = sim.db().Query("Transactions", &conds).GetVal("ResourceId"); + MatQuery mq = MatQuery(sim.GetMaterial(resid)); + EXPECT_TRUE(0 < mq.qty()); + EXPECT_TRUE(0 == mq.mass(id("pu239"))); + + conds.clear(); + conds.push_back(Cond("Time", "==", 2)); + conds.push_back(Cond("ReceiverId", "==", aid)); + resid = sim.db().Query("Transactions", &conds).GetVal("ResourceId"); + mq = MatQuery(sim.GetMaterial(resid)); + EXPECT_TRUE(0 < mq.qty()); + EXPECT_TRUE(0 < mq.mass(id("pu239"))); + + conds.clear(); + conds.push_back(Cond("Time", "==", 3)); + conds.push_back(Cond("ReceiverId", "==", aid)); + resid = sim.db().Query("Transactions", &conds).GetVal("ResourceId"); + mq = MatQuery(sim.GetMaterial(resid)); + EXPECT_TRUE(0 < mq.qty()); + EXPECT_TRUE(0 == mq.mass(id("pu239"))); +} + TEST(ReactorTests, RecipeChange) { // it is important that the fuel_prefs not be present in the config below. std::string config = diff --git a/tests/test_regression.py b/tests/test_regression.py index ec4f2aa53..47126be96 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -510,6 +510,51 @@ def test_deployment(self): assert_equal(enter_time[np.where(agent_ids == source_id[0])], 1) assert_equal(enter_time[np.where(agent_ids == sink_id[0])], 0) +class TestReactorPrefChange(TestRegression): + """This class tests the ../input/reactor_pref_change.xml + + Tests commodity preference changes in the reactor over a 4-time step + simulation. + + A DeployInst is used to define that 2 Sources, 1 Sink, and 1 Reactor are to + be deployed at time t=1 within a Null Region. The reactor commodity + preference change occurs at time t=2. At time t=3, a second reactor with + the same configuration is deployed. This input is used to test that the + second reactor retains the fuel preference change even though it deploys + after the time step in which the preference change occured. + + """ + def __init__(self, *args, **kwargs): + super(TestReactorPrefChange, self).__init__(*args, **kwargs) + self.inf = "../input/reactor_pref_change.xml" + + def setUp(self): + super(TestReactorPrefChange, self).setUp() + rxtr_ids = self.find_ids(":cycamore:Reactor", self.agent_entry) + self.r1, self.r2 = tuple(rxtr_ids) + self.agent_ids = self.to_ary(self.agent_entry, "AgentId") + self.enter_time = self.to_ary(self.agent_entry, "EnterTime") + self.rec_ids = self.to_ary(self.transactions, "ReceiverId") + self.trans_time = self.to_ary(self.transactions, "Time") + self.trans_commod = self.to_ary(self.transactions, "Commodity") + + def tearDown(self): + super(TestReactorPrefChange, self).tearDown() + + def test_rxtr1_prefs(self): + assert_equal(self.enter_time[np.where(self.agent_ids == self.r1)], 1) + rec_n_time = (self.rec_ids == self.r1) & (self.trans_time == 1) + assert_equal(self.trans_commod[np.where(rec_n_time)], "Fuel1") + rec_n_time = (self.rec_ids == self.r1) & (self.trans_time == 2) + assert_equal(self.trans_commod[np.where(rec_n_time)], "Fuel2") + rec_n_time = (self.rec_ids == self.r1) & (self.trans_time == 3) + assert_equal(self.trans_commod[np.where(rec_n_time)], "Fuel2") + + def test_rxtr2_prefs(self): + assert_equal(self.enter_time[np.where(self.agent_ids == self.r2)], 3) + rec_n_time = (self.rec_ids == self.r2) & (self.trans_time == 3) + assert_equal(self.trans_commod[np.where(rec_n_time)], "Fuel2") + class _Recycle(TestRegression): """This class tests the input/recycle.xml file. """