3#include "agent_tests.h"
6#include "equality_helpers.h"
7#include "facility_tests.h"
9#include <gtest/gtest.h>
11using cyclus::QueryResult;
18 std::pair<std::pair<double, double>, std::map<std::string, double> > >
22 using pyne::nucname::id;
29 return cyclus::Composition::CreateFromMass(m);
33 using pyne::nucname::id;
36 m[id(
"u235")] = 0.007;
37 m[id(
"u238")] = 0.993;
38 return cyclus::Composition::CreateFromMass(m);
41cyclus::Composition::Ptr
c_uox() {
42 using pyne::nucname::id;
47 return cyclus::Composition::CreateFromMass(m);
52 typedef cyclus::toolkit::ResBuf<cyclus::Material>
InvBuffer;
54 cyclus::TestContext
tc_;
60 std::vector<std::map<std::string, double> > in_commods;
62 std::map<std::string, double> in_com;
63 in_com.insert(std::pair<std::string, double>(
"in_c1", 1));
64 in_commods.push_back(in_com);
67 std::map<std::string, double> in_com;
68 in_com.insert(std::pair<std::string, double>(
"in_c2", 1));
69 in_commods.push_back(in_com);
72 std::map<std::string, double> in_com;
73 in_com.insert(std::pair<std::string, double>(
"in_c3", 1));
74 in_commods.push_back(in_com);
77 std::vector<double> in_ratios = {1, 1, 1};
78 std::vector<double> in_caps = {30, 20, 10};
85 std::vector<std::map<std::string, double> >
in_coms;
104 for (
int i = 0; i < streams.size(); i++) {
105 in_frac.push_back(streams[i].first.first);
106 in_cap.push_back(streams[i].first.second);
110 void SetIn_stream(std::vector<std::map<std::string, double> > in_stream,
111 std::vector<double> ratios, std::vector<double> caps) {
113 for (
int i = 0; i < in_stream.size(); i++) {
114 std::pair<double, double> info_mtp =
115 std::pair<double, double>(ratios[i], caps[i]);
116 instream_tmp.push_back(
117 std::pair<std::pair<double, double>, std::map<std::string, double> >(
118 info_mtp, in_stream[i]));
124 for (
int i = 0; i < new_ratios.size(); i++) {
132 for (
int i = 0; i < new_caps.size(); i++) {
150 for (
int i = 0; i < mat.size(); i++) {
151 std::string name =
"in_stream_" + std::to_string(i);
178 SetOutStream_capacity(50);
179 SetThroughput(cyclus::CY_LARGE_DOUBLE);
180 mf_facility_->EnterNotify();
182 double ext_val = 1.0 / 3.0;
183 std::vector<double> strm_ratio_ = GetStream_ratio();
186 for (
int i = 0; i < in_coms.size(); i++) {
187 EXPECT_DOUBLE_EQ(ext_val, strm_ratio_[i]);
194 std::vector<double> in_cap_ = {30, 20, 10};
195 std::vector<double> in_frac_ = {2, 1, 5};
196 in_cap_ = {30, 20, 10};
198 SetStream_ratio(in_frac_);
199 SetStream_capacity(in_cap_);
200 SetOutStream_capacity(50);
201 SetThroughput(cyclus::CY_LARGE_DOUBLE);
202 mf_facility_->EnterNotify();
204 std::vector<double> strm_ratio_ = GetStream_ratio();
206 for (
int i = 0; i < strm_ratio_.size(); i++) {
207 sum += strm_ratio_[i];
210 EXPECT_DOUBLE_EQ(sum, 1) <<
"Ratios normalized incorrectly: want 1, got "
214 in_frac_ = {0.1, 0.2, 0.5};
215 SetOutStream_capacity(50);
216 SetThroughput(cyclus::CY_LARGE_DOUBLE);
218 SetStream_ratio(in_frac_);
219 mf_facility_->EnterNotify();
220 strm_ratio_ = GetStream_ratio();
223 for (
int i = 0; i < strm_ratio_.size(); i++) {
224 sum += strm_ratio_[i];
227 EXPECT_DOUBLE_EQ(sum, 1) <<
"Ratios normalized incorrectly: want 1, got "
233 using cyclus::Material;
235 std::vector<double> in_frac_ = {0.80, 0.15, 0.05};
236 SetStream_ratio(in_frac_);
238 SetOutStream_capacity(50);
240 SetThroughput(cyclus::CY_LARGE_DOUBLE);
242 std::vector<Material::Ptr> mat;
243 mat.push_back(Material::CreateUntracked(in_cap[0],
c_natu()));
244 mat.push_back(Material::CreateUntracked(in_cap[1],
c_pustream()));
245 mat.push_back(Material::CreateUntracked(in_cap[2],
c_uox()));
248 mf_facility_->Tick();
250 cyclus::CompMap v_0 =
c_natu()->mass();
251 cyclus::compmath::Normalize(&v_0, in_frac_[0]);
253 cyclus::compmath::Normalize(&v_1, in_frac_[1]);
254 cyclus::CompMap v_2 =
c_uox()->mass();
255 cyclus::compmath::Normalize(&v_2, in_frac_[2]);
256 cyclus::CompMap v = v_0;
257 v = cyclus::compmath::Add(v, v_1);
258 v = cyclus::compmath::Add(v, v_2);
260 InvBuffer* buffer = GetOutPutBuffer();
261 Material::Ptr final_mat = cyclus::ResCast<Material>(buffer->PopBack());
262 cyclus::CompMap final_comp = final_mat->comp()->mass();
265 cyclus::compmath::Normalize(&v, 1);
266 cyclus::compmath::Normalize(&final_comp, 1);
268 cyclus::CompMap sum_v = cyclus::compmath::Add(v, final_comp);
270 cyclus::CompMap::iterator it;
271 for (it = sum_v.begin(); it != sum_v.end(); it++) {
272 EXPECT_DOUBLE_EQ(final_comp[it->first], v[it->first])
273 <<
"Unexpected difference on nuclide " << it->first <<
".";
279 using cyclus::Material;
281 std::vector<double> in_frac_ = {0.80, 0.15, 0.05};
283 SetStream_ratio(in_frac_);
285 SetOutStream_capacity(50);
289 std::vector<Material::Ptr> mat;
290 mat.push_back(Material::CreateUntracked(in_cap[0],
c_natu()));
291 mat.push_back(Material::CreateUntracked(in_cap[1],
c_pustream()));
292 mat.push_back(Material::CreateUntracked(in_cap[2],
c_uox()));
295 mf_facility_->Tick();
297 std::vector<double> cap;
298 for (
int i = 0; i < in_coms.size(); i++) {
299 cap.push_back(in_cap[i] - 0.5 * in_frac[i]);
302 std::map<std::string, InvBuffer> streambuf = GetStreamBuffer();
304 for (
int i = 0; i < in_coms.size(); i++) {
305 std::string name =
"in_stream_" + std::to_string(i);
306 double buf_size = in_cap[i];
307 double buf_ratio = in_frac[i];
308 double buf_inv = streambuf[name].quantity();
312 EXPECT_EQ(buf_size - 0.5 * buf_ratio, buf_inv)
313 <<
" one (or more) input "
314 "buffer inventory was not drawn from in the correct ratio.";
318 EXPECT_EQ(throughput, GetOutPutBuffer()->quantity())
319 <<
" mixing was not "
320 "correctly constrained by throughput.";
325TEST(MixerTests, MultipleFissStreams) {
330 "<mixing_ratio>0.8</mixing_ratio>"
331 "<buf_size>2.5</buf_size>"
335 "<commodity>stream1</commodity>"
342 "<mixing_ratio>0.15</mixing_ratio>"
343 "<buf_size>3</buf_size>"
347 "<commodity>stream2</commodity>"
354 "<mixing_ratio>0.05</mixing_ratio>"
355 "<buf_size>5</buf_size>"
359 "<commodity>stream3</commodity>"
365 "<out_commod>mixedstream</out_commod>"
366 "<outputbuf_size>0</outputbuf_size>"
367 "<throughput>0</throughput>";
369 cyclus::MockSim sim(cyclus::AgentSpec(
":cycamore:Mixer"), config, simdur);
370 sim.AddSource(
"stream1").recipe(
"unatstream").capacity(1).Finalize();
371 sim.AddSource(
"stream2").recipe(
"uoxstream").capacity(1).Finalize();
372 sim.AddSource(
"stream3").recipe(
"pustream").capacity(1).Finalize();
373 sim.AddRecipe(
"unatstream",
c_natu());
375 sim.AddRecipe(
"pustream",
c_uox());
379 QueryResult qr = sim.db().Query(
"Transactions", NULL);
380 EXPECT_EQ(3, qr.rows.size());
383 std::vector<cyclus::Cond> conds;
384 conds.push_back(cyclus::Cond(
"Commodity",
"==", std::string(
"stream1")));
385 qr = sim.db().Query(
"Transactions", &conds);
386 EXPECT_EQ(1, qr.rows.size());
388 conds[0] = cyclus::Cond(
"Commodity",
"==", std::string(
"stream2"));
389 qr = sim.db().Query(
"Transactions", &conds);
390 EXPECT_EQ(1, qr.rows.size());
392 conds[0] = cyclus::Cond(
"Commodity",
"==", std::string(
"stream3"));
393 qr = sim.db().Query(
"Transactions", &conds);
394 EXPECT_EQ(1, qr.rows.size());
399TEST(MixerTests, CompleteMixingProcess) {
404 "<mixing_ratio>0.8</mixing_ratio>"
405 "<buf_size>2.5</buf_size>"
409 "<commodity>stream1</commodity>"
416 "<mixing_ratio>0.15</mixing_ratio>"
417 "<buf_size>3</buf_size>"
421 "<commodity>stream2</commodity>"
428 "<mixing_ratio>0.05</mixing_ratio>"
429 "<buf_size>5</buf_size>"
433 "<commodity>stream3</commodity>"
439 "<out_commod>mixedstream</out_commod>"
440 "<outputbuf_size>10</outputbuf_size>"
441 "<throughput>1</throughput>";
443 cyclus::MockSim sim(cyclus::AgentSpec(
":cycamore:Mixer"), config, simdur);
444 sim.AddSource(
"stream1").recipe(
"unatstream").capacity(1).Finalize();
445 sim.AddSource(
"stream2").recipe(
"uoxstream").capacity(1).Finalize();
446 sim.AddSource(
"stream3").recipe(
"pustream").capacity(1).Finalize();
447 sim.AddRecipe(
"unatstream",
c_natu());
449 sim.AddRecipe(
"pustream",
c_uox());
451 sim.AddSink(
"mixedstream").capacity(10).Finalize();
455 std::vector<cyclus::Cond> conds;
456 conds.push_back(cyclus::Cond(
"Commodity",
"==", std::string(
"mixedstream")));
457 QueryResult qr = sim.db().Query(
"Transactions", &conds);
458 EXPECT_EQ(1, qr.rows.size());
460 cyclus::Material::Ptr m = sim.GetMaterial(qr.GetVal<
int>(
"ResourceId"));
461 EXPECT_DOUBLE_EQ(1., m->quantity());
464TEST(MixerTests, PositionInitialize) {
469 "<mixing_ratio>0.8</mixing_ratio>"
470 "<buf_size>2.5</buf_size>"
474 "<commodity>stream1</commodity>"
481 "<mixing_ratio>0.15</mixing_ratio>"
482 "<buf_size>3</buf_size>"
486 "<commodity>stream2</commodity>"
493 "<mixing_ratio>0.05</mixing_ratio>"
494 "<buf_size>5</buf_size>"
498 "<commodity>stream3</commodity>"
504 "<out_commod>mixedstream</out_commod>"
505 "<outputbuf_size>0</outputbuf_size>"
506 "<throughput>0</throughput>";
508 cyclus::MockSim sim(cyclus::AgentSpec(
":cycamore:Mixer"), config, simdur);
509 sim.AddSource(
"stream1").recipe(
"unatstream").capacity(1).Finalize();
510 sim.AddSource(
"stream2").recipe(
"uoxstream").capacity(1).Finalize();
511 sim.AddSource(
"stream3").recipe(
"pustream").capacity(1).Finalize();
512 sim.AddRecipe(
"unatstream",
c_natu());
514 sim.AddRecipe(
"pustream",
c_uox());
517 QueryResult qr = sim.db().Query(
"AgentPosition", NULL);
518 EXPECT_EQ(qr.GetVal<
double>(
"Latitude"), 0.0);
519 EXPECT_EQ(qr.GetVal<
double>(
"Longitude"), 0.0);
std::vector< std::map< std::string, double > > in_coms
void SetIn_stream(std::vector< std::map< std::string, double > > in_stream, std::vector< double > ratios, std::vector< double > caps)
void SetInputInv(std::vector< cyclus::Material::Ptr > mat)
void SetThroughput(double thpt)
void SetOutStream_comds(std::string com)
void SetIn_stream(t_instream streams)
std::string GetOutStream_comds()
void SetStream_ratio(std::vector< double > new_ratios)
std::vector< double > GetStream_ratio()
void SetStream_capacity(std::vector< double > new_caps)
cyclus::toolkit::ResBuf< cyclus::Material > InvBuffer
double GetOutStream_capacity()
std::vector< double > in_cap
std::vector< double > GetStream_capacity()
std::map< std::string, InvBuffer > GetStreamBuffer()
void SetOutStream_capacity(double cap)
InvBuffer * GetOutPutBuffer()
std::vector< double > in_frac
Mixer mixes N streams with fixed, static, user-specified ratios into a single output stream.
std::map< std::string, cyclus::toolkit::ResBuf< cyclus::Material > > streambufs
std::vector< double > mixing_ratios
cyclus::toolkit::ResBuf< cyclus::Material > output
std::vector< double > in_buf_sizes
std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > streams_
TEST(MixerTests, MultipleFissStreams)
cyclus::Composition::Ptr c_pustream()
cyclus::Composition::Ptr c_uox()
cyclus::Composition::Ptr c_natu()
std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > t_instream
TEST_F(EnrichmentTest, RequestQty)