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

Reactor commodity preference change timestep comparison update #535

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
138 changes: 138 additions & 0 deletions input/reactor_pref_change.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<simulation>

<control>
<duration>4</duration>
<startmonth>1</startmonth>
<startyear>2022</startyear>
</control>

<archetypes>
<spec> <lib>agents</lib> <name>NullRegion</name> </spec>
<spec> <lib>cycamore</lib> <name>DeployInst</name> </spec>
<spec> <lib>cycamore</lib> <name>Source</name> </spec>
<spec> <lib>cycamore</lib> <name>Reactor</name> </spec>
<spec> <lib>cycamore</lib> <name>Sink</name> </spec>
</archetypes>

<region>
<name>Region</name>
<config> <NullRegion/> </config>

<institution>
<name>Inst</name>
<config>
<DeployInst>
<prototypes>
<val>Source1</val>
<val>Source2</val>
<val>Reactor</val>
<val>Waste</val>
<val>Reactor</val>
</prototypes>
<n_build>
<val>1</val>
<val>1</val>
<val>1</val>
<val>1</val>
<val>1</val>
</n_build>
<build_times>
<val>1</val>
<val>1</val>
<val>1</val>
<val>1</val>
<val>3</val>
</build_times>
</DeployInst>
</config>
</institution>
</region>

<facility>
<name>Source1</name>
<config>
<Source>
<outcommod>Fuel1</outcommod>
<outrecipe>Fuel1_recipe</outrecipe>
</Source>
</config>
</facility>

<facility>
<name>Source2</name>
<config>
<Source>
<outcommod>Fuel2</outcommod>
<outrecipe>Fuel2_recipe</outrecipe>
</Source>
</config>
</facility>

<facility>
<name>Reactor</name>
<config>
<Reactor>
<fuel_incommods>
<val>Fuel1</val>
<val>Fuel2</val>
</fuel_incommods>
<fuel_outcommods>
<val>SpentFuel</val>
<val>SpentFuel</val>
</fuel_outcommods>
<fuel_inrecipes>
<val>Fuel1_recipe</val>
<val>Fuel2_recipe</val>
</fuel_inrecipes>
<fuel_outrecipes>
<val>SpentFuel_recipe</val>
<val>SpentFuel_recipe</val>
</fuel_outrecipes>
<fuel_prefs>
<val>2</val>
<val>1</val>
</fuel_prefs>
<pref_change_times> <val>2</val> </pref_change_times>
<pref_change_commods> <val>Fuel2</val> </pref_change_commods>
<pref_change_values> <val>3</val> </pref_change_values>
<cycle_time>1</cycle_time>
<refuel_time>0</refuel_time>
<assem_size>1000</assem_size>
<n_assem_batch>1</n_assem_batch>
<n_assem_core>1</n_assem_core>
</Reactor>
</config>
</facility>

<facility>
<name>Waste</name>
<config>
<Sink>
<in_commods> <val>SpentFuel</val> </in_commods>
</Sink>
</config>
</facility>

<recipe>
<name>Fuel1_recipe</name>
<basis>mass</basis>
<nuclide> <id>U235</id> <comp>0.03</comp> </nuclide>
<nuclide> <id>U238</id> <comp>0.97</comp> </nuclide>
</recipe>

<recipe>
<name>Fuel2_recipe</name>
<basis>mass</basis>
<nuclide> <id>U235</id> <comp>0.05</comp> </nuclide>
<nuclide> <id>U238</id> <comp>0.95</comp> </nuclide>
</recipe>

<recipe>
<name>SpentFuel_recipe</name>
<basis>mass</basis>
<nuclide> <id>U235</id> <comp>0.01</comp> </nuclide>
<nuclide> <id>U238</id> <comp>0.98</comp> </nuclide>
<nuclide> <id>Pu239</id> <comp>0.01</comp> </nuclide>
</recipe>

</simulation>
2 changes: 1 addition & 1 deletion src/reactor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
56 changes: 56 additions & 0 deletions src/reactor_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,62 @@ TEST(ReactorTests, PrefChange) {
EXPECT_EQ(25, qr.rows.size()) << "failed to adjust preferences properly";
}

TEST(ReactorTests, PrefChange2) {
std::string config =
" <fuel_inrecipes> <val>uox_fresh</val> <val>mox_fresh</val> </fuel_inrecipes> "
" <fuel_outrecipes> <val>uox_spent</val> <val>mox_spent</val> </fuel_outrecipes> "
" <fuel_incommods> <val>uox</val> <val>mox</val> </fuel_incommods> "
" <fuel_outcommods> <val>uox_waste</val> <val>mox_waste</val> </fuel_outcommods> "
" <fuel_prefs> <val>2</val> <val>1</val> </fuel_prefs> "
""
" <cycle_time>1</cycle_time> "
" <refuel_time>0</refuel_time> "
" <assem_size>300</assem_size> "
" <n_assem_core>1</n_assem_core> "
" <n_assem_batch>1</n_assem_batch> "
""
" <pref_change_times> <val>2</val> <val>3</val> </pref_change_times> "
" <pref_change_commods> <val>mox</val> <val>mox</val> </pref_change_commods> "
" <pref_change_values> <val>3</val> <val>1</val> </pref_change_values> ";

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<Cond> conds;
int resid;

conds.clear();
conds.push_back(Cond("Time", "==", 1));
conds.push_back(Cond("ReceiverId", "==", aid));
resid = sim.db().Query("Transactions", &conds).GetVal<int>("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<int>("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<int>("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 =
Expand Down
45 changes: 45 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down