CYCAMORE
src/separations_tests.cc
Go to the documentation of this file.
1 #include "separations.h"
2 
3 #include <gtest/gtest.h>
4 #include <sstream>
5 #include "cyclus.h"
6 
7 using pyne::nucname::id;
8 using cyclus::Composition;
9 using cyclus::CompMap;
10 using cyclus::Material;
11 using cyclus::QueryResult;
12 using cyclus::Cond;
13 using cyclus::toolkit::MatQuery;
14 
15 namespace cycamore {
16 
17 TEST(SeparationsTests, SepMaterial) {
18  CompMap comp;
19  comp[id("U235")] = 10;
20  comp[id("U238")] = 90;
21  comp[id("Pu239")] = 1;
22  comp[id("Pu240")] = 2;
23  comp[id("Am241")] = 3;
24  comp[id("Am242")] = 2.8;
25  double qty = 100;
26  Composition::Ptr c = Composition::CreateFromMass(comp);
27  Material::Ptr mat = Material::CreateUntracked(qty, c);
28 
29  std::map<int, double> effs;
30  effs[id("U")] = .7;
31  effs[id("Pu")] = .4;
32  effs[id("Am241")] = .4;
33 
34  Material::Ptr sep = SepMaterial(effs, mat);
35  MatQuery mqorig(mat);
36  MatQuery mqsep(sep);
37 
38  EXPECT_DOUBLE_EQ(effs[id("U")] * mqorig.mass("U235"), mqsep.mass("U235"));
39  EXPECT_DOUBLE_EQ(effs[id("U")] * mqorig.mass("U238"), mqsep.mass("U238"));
40  EXPECT_DOUBLE_EQ(effs[id("Pu")] * mqorig.mass("Pu239"), mqsep.mass("Pu239"));
41  EXPECT_DOUBLE_EQ(effs[id("Pu")] * mqorig.mass("Pu240"), mqsep.mass("Pu240"));
42  EXPECT_DOUBLE_EQ(effs[id("Am241")] * mqorig.mass("Am241"), mqsep.mass("Am241"));
43  EXPECT_DOUBLE_EQ(0, mqsep.mass("Am242"));
44 }
45 
46 
47 // Check that cumulative separations efficiency for a single nuclide of less than or equal to one does not trigger an error.
48 TEST(SeparationsTests, SeparationEfficiency) {
49 
50  int simdur = 2;
51  std::string config =
52  "<streams>"
53  " <item>"
54  " <commod>stream1</commod>"
55  " <info>"
56  " <buf_size>-1</buf_size>"
57  " <efficiencies>"
58  " <item><comp>Pu239</comp> <eff>.2</eff></item>"
59  " </efficiencies>"
60  " </info>"
61  " </item>"
62  " <item>"
63  " <commod>stream1</commod>"
64  " <info>"
65  " <buf_size>-1</buf_size>"
66  " <efficiencies>"
67  " <item><comp>Pu239</comp> <eff>.1</eff></item>"
68  " </efficiencies>"
69  " </info>"
70  " </item>"
71  " <item>"
72  " <commod>stream1</commod>"
73  " <info>"
74  " <buf_size>-1</buf_size>"
75  " <efficiencies>"
76  " <item><comp>Pu239</comp> <eff>.5</eff></item>"
77  " </efficiencies>"
78  " </info>"
79  " </item>"
80  "</streams>"
81  ""
82  "<leftover_commod>waste</leftover_commod>"
83  "<throughput>100</throughput>"
84  "<feedbuf_size>100</feedbuf_size>"
85  "<feed_commods> <val>feed</val> </feed_commods>"
86  ;
87 
88 
89  cyclus::MockSim sim1(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
90 
91  EXPECT_NO_THROW(sim1.Run()) << "Cumulative separation efficiency smaler than 1 is throwing an error but should not.";
92 
93 
94  config =
95  "<streams>"
96  " <item>"
97  " <commod>stream1</commod>"
98  " <info>"
99  " <buf_size>-1</buf_size>"
100  " <efficiencies>"
101  " <item><comp>U</comp> <eff>0.1</eff></item>"
102  " <item><comp>Pu239</comp> <eff>.2</eff></item>"
103  " </efficiencies>"
104  " </info>"
105  " </item>"
106  " <item>"
107  " <commod>stream1</commod>"
108  " <info>"
109  " <buf_size>-1</buf_size>"
110  " <efficiencies>"
111  " <item><comp>U</comp> <eff>0.2</eff></item>"
112  " <item><comp>Pu239</comp> <eff>.1</eff></item>"
113  " </efficiencies>"
114  " </info>"
115  " </item>"
116  " <item>"
117  " <commod>stream1</commod>"
118  " <info>"
119  " <buf_size>-1</buf_size>"
120  " <efficiencies>"
121  " <item><comp>U</comp> <eff>0.7</eff></item>"
122  " <item><comp>Pu239</comp> <eff>.5</eff></item>"
123  " </efficiencies>"
124  " </info>"
125  " </item>"
126  "</streams>"
127  ""
128  "<leftover_commod>waste</leftover_commod>"
129  "<throughput>100</throughput>"
130  "<feedbuf_size>100</feedbuf_size>"
131  "<feed_commods> <val>feed</val> </feed_commods>"
132  ;
133 
134 
135  cyclus::MockSim sim2(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
136 
137  EXPECT_NO_THROW(sim2.Run()) << "Cumulative separation efficiency of 1 is throwing an error but should not.";
138 }
139 
140 // Check that an error is correctly thrown when separations efficiency of greater than one.
141 TEST(SeparationsTests, SeparationEfficiencyThrowing) {
142  int simdur = 2;
143 
144  // Check that single separations efficiency for a single nuclide of greater than one does not trigger an error.
145  std::string config =
146  "<streams>"
147  " <item>"
148  " <commod>stream1</commod>"
149  " <info>"
150  " <buf_size>-1</buf_size>"
151  " <efficiencies>"
152  " <item><comp>U</comp> <eff>1.6</eff></item>"
153  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
154  " </efficiencies>"
155  " </info>"
156  " </item>"
157  "</streams>"
158  ""
159  "<leftover_commod>waste</leftover_commod>"
160  "<throughput>100</throughput>"
161  "<feedbuf_size>100</feedbuf_size>"
162  "<feed_commods> <val>feed</val> </feed_commods>"
163  ;
164 
165  cyclus::MockSim sim1(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
166 
167  EXPECT_THROW(sim1.Run(), cyclus::ValueError) << "Direct separation efficiency greater than 1 is not throwing an error but should.";
168 
169 // Check if a cumulative separation efficiency greater than 1 for a unique nuclide throw an error as expected.
170  config =
171  "<streams>"
172  " <item>"
173  " <commod>stream1</commod>"
174  " <info>"
175  " <buf_size>-1</buf_size>"
176  " <efficiencies>"
177  " <item><comp>U</comp> <eff>0.6</eff></item>"
178  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
179  " </efficiencies>"
180  " </info>"
181  " </item>"
182  " <item>"
183  " <commod>stream2</commod>"
184  " <info>"
185  " <buf_size>-1</buf_size>"
186  " <efficiencies>"
187  " <item><comp>U</comp> <eff>0.1</eff></item>"
188  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
189  " </efficiencies>"
190  " </info>"
191  " </item>"
192  "</streams>"
193  ""
194  "<leftover_commod>waste</leftover_commod>"
195  "<throughput>100</throughput>"
196  "<feedbuf_size>100</feedbuf_size>"
197  "<feed_commods> <val>feed</val> </feed_commods>"
198  ;
199 
200  cyclus::MockSim sim2(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
201 
202  EXPECT_THROW(sim2.Run(), cyclus::ValueError) << "Single cumulative separation efficiency greater than 1 is not throwing an error but should.";
203 // Check if a cumulative separation efficiency greater than 1 for multiple nuclides throw an error as expected.
204  config =
205  "<streams>"
206  " <item>"
207  " <commod>stream1</commod>"
208  " <info>"
209  " <buf_size>-1</buf_size>"
210  " <efficiencies>"
211  " <item><comp>U</comp> <eff>0.6</eff></item>"
212  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
213  " </efficiencies>"
214  " </info>"
215  " </item>"
216  " <item>"
217  " <commod>stream2</commod>"
218  " <info>"
219  " <buf_size>-1</buf_size>"
220  " <efficiencies>"
221  " <item><comp>U</comp> <eff>0.6</eff></item>"
222  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
223  " </efficiencies>"
224  " </info>"
225  " </item>"
226  "</streams>"
227  ""
228  "<leftover_commod>waste</leftover_commod>"
229  "<throughput>100</throughput>"
230  "<feedbuf_size>100</feedbuf_size>"
231  "<feed_commods> <val>feed</val> </feed_commods>"
232  ;
233 
234  cyclus::MockSim sim3(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
235 
236  EXPECT_THROW(sim3.Run(), cyclus::ValueError) << "Multiple cumulative separation efficiencies greater than 1 are not throwing an error but should.";
237 }
238 
239 TEST(SeparationsTests, SepMixElemAndNuclide) {
240  std::string config =
241  "<streams>"
242  " <item>"
243  " <commod>stream1</commod>"
244  " <info>"
245  " <buf_size>-1</buf_size>"
246  " <efficiencies>"
247  " <item><comp>U</comp> <eff>0.6</eff></item>"
248  " <item><comp>Pu239</comp> <eff>.7</eff></item>"
249  " </efficiencies>"
250  " </info>"
251  " </item>"
252  "</streams>"
253  ""
254  "<leftover_commod>waste</leftover_commod>"
255  "<throughput>100</throughput>"
256  "<feedbuf_size>100</feedbuf_size>"
257  "<feed_commods> <val>feed</val> </feed_commods>"
258  ;
259 
260  CompMap m;
261  m[id("u235")] = 0.08;
262  m[id("u238")] = 0.9;
263  m[id("Pu239")] = .01;
264  m[id("Pu240")] = .01;
265  Composition::Ptr c = Composition::CreateFromMass(m);
266 
267  int simdur = 2;
268  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:Separations"), config, simdur);
269  sim.AddSource("feed").recipe("recipe1").Finalize();
270  sim.AddSink("stream1").capacity(100).Finalize();
271  sim.AddRecipe("recipe1", c);
272  int id = sim.Run();
273 
274  std::vector<Cond> conds;
275  conds.push_back(Cond("SenderId", "==", id));
276  int resid = sim.db().Query("Transactions", &conds).GetVal<int>("ResourceId");
277  MatQuery mq (sim.GetMaterial(resid));
278  EXPECT_DOUBLE_EQ(m[922350000]*0.6*100, mq.mass("U235"));
279  EXPECT_DOUBLE_EQ(m[922380000]*0.6*100, mq.mass("U238"));
280  EXPECT_DOUBLE_EQ(m[942390000]*0.7*100, mq.mass("Pu239"));
281  EXPECT_DOUBLE_EQ(0, mq.mass("Pu240"));
282 }
283 
284 TEST(SeparationsTests, Retire) {
285  std::string config =
286  "<streams>"
287  " <item>"
288  " <commod>stream1</commod>"
289  " <info>"
290  " <buf_size>-1</buf_size>"
291  " <efficiencies>"
292  " <item><comp>U235</comp> <eff>1.0</eff></item>"
293  " </efficiencies>"
294  " </info>"
295  " </item>"
296  "</streams>"
297  ""
298  "<leftover_commod>waste</leftover_commod>"
299  "<throughput>100</throughput>"
300  "<feedbuf_size>100</feedbuf_size>"
301  "<feed_commods> <val>feed</val> </feed_commods>"
302  ;
303 
304  CompMap m;
305  m[id("u235")] = 0.1;
306  m[id("u238")] = 0.9;
307  Composition::Ptr c = Composition::CreateFromMass(m);
308 
309  int simdur = 5;
310  int life = 2;
311 
312  cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:Separations"),
313  config, simdur, life);
314  sim.AddSource("feed").recipe("recipe1").Finalize();
315  sim.AddSink("stream1").capacity(100).Finalize();
316  sim.AddSink("waste").capacity(70).Finalize();
317  sim.AddRecipe("recipe1", c);
318  int id = sim.Run();
319 
320  // Separations should stop requesting material at its lifetime
321  // (it is smart enough to not request material on its last timestep because
322  // it knows it won't be able to process it)
323  std::vector<Cond> conds;
324  conds.push_back(Cond("ReceiverId", "==", id));
325  QueryResult qr = sim.db().Query("Transactions", &conds);
326  EXPECT_EQ(life - 1, qr.rows.size())
327  << "failed to stop ordering near retirement";
328 
329  // Separations should discharge all material before decomissioning
330  conds.clear();
331  conds.push_back(Cond("SenderId", "==", id));
332  qr = sim.db().Query("Transactions", &conds);
333  double tot_mat = 0;
334  for (int i = 0; i < qr.rows.size(); i++) {
335  cyclus::Material::Ptr m = sim.GetMaterial(qr.GetVal<int>("ResourceId", i));
336  tot_mat += m->quantity();
337  }
338  EXPECT_EQ(100, tot_mat)
339  << "total material traded away does not equal total material separated";
340  EXPECT_EQ(3.0, qr.rows.size())
341  << "failed to discharge all material before decomissioning";
342  }
343 } // namespace cycamore
344 
cycamore::GrowthRegion string
TEST(MixerTests, MultipleFissStreams)
Material::Ptr SepMaterial(std::map< int, double > effs, Material::Ptr mat)