CYCAMORE
Loading...
Searching...
No Matches
build/cycamore/storage_tests.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
3#include "storage_tests.h"
4
5namespace cycamore {
6
7// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 src_facility_ = new Storage(tc_.get());
12}
13
15 delete src_facility_;
16}
17
19 in_r1 = "in_r1";
20 in_c1.push_back("in_c1");
21 out_c1.push_back("out_c1");
22 residence_time = 10;
23 max_inv_size = 200;
24 throughput = 20;
26 package = "foo";
27 // Active period longer than any of the residence time related-tests needs
28
29
30 cyclus::CompMap v;
31 v[922350000] = 1;
32 v[922380000] = 2;
33 cyclus::Composition::Ptr recipe = cyclus::Composition::CreateFromAtom(v);
34 tc_.get()->AddRecipe(in_r1, recipe);
35}
36
48
50 EXPECT_EQ(residence_time, fac->residence_time);
51 EXPECT_EQ(max_inv_size, fac->max_inv_size);
52 EXPECT_EQ(throughput, fac->throughput);
53 EXPECT_EQ(in_r1, fac->in_recipe);
54 EXPECT_EQ(package, fac->package);
55}
56
58 cyclus::Material::Ptr mat){
59 double amt = mat->quantity();
60 double before = fac->inventory.quantity();
61 fac->AddMat_(mat);
62 double after = fac->inventory.quantity();
63 EXPECT_EQ(amt, after - before);
64}
65
66void StorageTest::TestBuffers(Storage* fac, double inv,
67 double proc, double ready, double stocks){
68 double t = tc_.get()->time();
69
70 EXPECT_EQ(inv, fac->inventory.quantity());
71 EXPECT_EQ(proc, fac->processing.quantity());
72 EXPECT_EQ(stocks, fac->stocks.quantity());
73 EXPECT_EQ(ready, fac->ready.quantity());
74}
75
76void StorageTest::TestStocks(Storage* fac, cyclus::CompMap v){
77
78 cyclus::toolkit::ResBuf<cyclus::Material>* buffer = &fac->stocks;
79 Material::Ptr final_mat = cyclus::ResCast<Material>(buffer->PopBack());
80 cyclus::CompMap final_comp = final_mat->comp()->atom();
81 EXPECT_EQ(final_comp,v);
82
83}
84
85void StorageTest::TestCurrentCap(Storage* fac, double inv){
86
87 EXPECT_EQ(inv, fac->current_capacity());
88}
89
91
92 EXPECT_EQ(t, fac->ready_time());
93}
94
95// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97 Storage* cloned_fac =
98 dynamic_cast<Storage*> (src_facility_->Clone());
99 TestInitState(cloned_fac);
100}
101
102// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
103TEST_F(StorageTest, InitialState) {
104 // Test things about the initial state of the facility here
106}
107
108// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109TEST_F(StorageTest, CurrentCapacity){
111 max_inv_size = cyclus::CY_LARGE_DOUBLE;
112 SetUpStorage();
114}
115
116// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118 EXPECT_NO_THROW(std::string s = src_facility_->str());
119 // Test Storage specific aspects of the print method here
120}
121
122// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124 double cap = max_inv_size;
125 cyclus::Material::Ptr mat = cyclus::NewBlankMaterial(0.5*cap);
127
128 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
129 cyclus::Material::Ptr recmat = cyclus::Material::CreateUntracked(0.5*cap, rec);
130 TestAddMat(src_facility_, recmat);
131}
132
133// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
135 ASSERT_NO_THROW(src_facility_->Tick());
136 // Test Storage specific behaviors of the Tick function here
137}
138
139// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
141
142 // initially, nothing in the buffers
143 TestBuffers(src_facility_,0,0,0,0);
144
145 double cap = throughput;
146 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
147 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(cap, rec);
149
150 // affter add, the inventory has the material
151 TestBuffers(src_facility_,cap,0,0,0);
152
153 EXPECT_NO_THROW(src_facility_->Tock());
154
155 // after tock, the processing buffer has the material
156 TestBuffers(src_facility_,0,cap,0,0);
157
158 EXPECT_EQ(0, tc_.get()->time());
159 for( int i = 1; i < residence_time-1; ++i){
160 tc_.get()->time(i);
161 EXPECT_NO_THROW(src_facility_->Tock());
162 TestBuffers(src_facility_,0,cap,0,0);
163 }
164
165 tc_.get()->time(residence_time);
166 EXPECT_EQ(residence_time, tc_.get()->time());
169 TestBuffers(src_facility_,0,0,0,cap);
170
171 tc_.get()->time(residence_time+1);
174 TestBuffers(src_facility_,0,0,0,cap);
175
176}
177
178// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
179TEST_F(StorageTest, NoProcessTime) {
180 // tests what happens when the process time is zero
181 residence_time = 0;
182 SetUpStorage();
183 EXPECT_EQ(0, residence_time);
184
185 double cap = throughput;
186 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
187 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(cap, rec);
189
190 // affter add, the inventory has the material
191 TestBuffers(src_facility_,cap,0,0,0);
192
193 EXPECT_NO_THROW(src_facility_->Tock());
194
195 // affter tock, the stocks have the material
196 TestBuffers(src_facility_,0,0,0,cap);
197}
198
199TEST_F(StorageTest, NoConvert) {
200// Make sure no conversion occurs
201 double cap = throughput;
202 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
203 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(cap, rec);
205
206 EXPECT_NO_THROW(src_facility_->Tock());
207
208 tc_.get()->time(residence_time);
210 EXPECT_NO_THROW(src_facility_->Tock());
211 TestBuffers(src_facility_,0,0,0,cap);
212 cyclus::CompMap in_rec;
213 in_rec[922350000] = 1;
214 in_rec[922380000] = 2;
216}
217
218TEST_F(StorageTest, MultipleSmallBatches) {
219 // Add first small batch
220 double cap = throughput;
221 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
222 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(0.2*cap, rec);
224
225 // After add, material is in inventory
226 TestBuffers(src_facility_,0.2*cap,0,0,0);
227
228 // Move first batch into processing
230 TestBuffers(src_facility_,0,0.2*cap,0,0);
231
232 // Add second small batch
233 tc_.get()->time(2);
235 cyclus::Material::Ptr mat1 = cyclus::Material::CreateUntracked(0.3*cap, rec);
237 TestBuffers(src_facility_,0.3*cap,0.2*cap,0,0);
238
239 // Move second batch into processing
240 EXPECT_NO_THROW(src_facility_->Tock());
241 TestBuffers(src_facility_,0,0.5*cap,0,0);
242
243 // Move first batch to stocks
244 tc_.get()->time(residence_time);
246 EXPECT_NO_THROW(src_facility_->Tock());
247 TestBuffers(src_facility_,0,0.3*cap,0,0.2*cap);
248
249 tc_.get()->time(residence_time+2);
250 EXPECT_NO_THROW(src_facility_->Tock());
251 TestBuffers(src_facility_,0,0,0,0.5*cap);
252}
253
254
255TEST_F(StorageTest, ChangeCapacity) {
256 // src_facility_->discrete_handling_(0);
257 max_inv_size = 10000;
258 // Set throughput, add first batch
259 throughput = 300;
260 SetUpStorage();
261 double cap1 = throughput;
262 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
263 cyclus::Material::Ptr mat1 = cyclus::Material::CreateUntracked(cap1, rec);
265 EXPECT_NO_THROW(src_facility_->Tock());
266 TestBuffers(src_facility_,0,cap1,0,0);
267
268 // Increase throughput, add second and third batches
269 tc_.get()->time(2);
270 throughput = 500;
271 SetUpStorage();
272 double cap2 = throughput;
273 cyclus::Material::Ptr mat2 = cyclus::Material::CreateUntracked(cap2,rec);
275 EXPECT_NO_THROW(src_facility_->Tock());
276 TestBuffers(src_facility_,0,cap2+cap1,0,0);
277 tc_.get()->time(3);
278 cyclus::Material::Ptr mat3 = cyclus::Material::CreateUntracked(cap2,rec);
280 EXPECT_NO_THROW(src_facility_->Tock());
281 TestBuffers(src_facility_,0,cap2*2+cap1,0,0);
282
283 // Move first batch to stocks
284 tc_.get()->time(residence_time);
285 EXPECT_NO_THROW(src_facility_->Tock());
286 TestBuffers(src_facility_,0,2*cap2,0,cap1);
287
288 // Decrease throughput and move portion of second batch to stocks
289 throughput = 400;
290 SetUpStorage();
291 tc_.get()->time(residence_time+2);
292 EXPECT_EQ(400, throughput);
293 EXPECT_NO_THROW(src_facility_->Tock());
294 TestBuffers(src_facility_,0,cap2,100,cap1+400);
295
296 // Continue to move second batch // and portion of third
297 tc_.get()->time(residence_time+3);
298 EXPECT_NO_THROW(src_facility_->Tock());
299 TestBuffers(src_facility_,0,0,200,cap1+cap2+300);
300
301 // Move remainder of third batch
302 tc_.get()->time(residence_time+4);
303 EXPECT_NO_THROW(src_facility_->Tock());
304 TestBuffers(src_facility_,0,0,0,cap1+cap2+cap2);
305
306}
307
308TEST_F(StorageTest, TwoBatchSameTime) {
309 // Add first small batch
310 double cap = throughput;
311 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
312 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(0.2*cap, rec);
314
315 // After add, material is in inventory
316 TestBuffers(src_facility_,0.2*cap,0,0,0);
317 cyclus::Material::Ptr mat1 = cyclus::Material::CreateUntracked(0.2*cap, rec);
319 TestBuffers(src_facility_,0.4*cap,0,0,0);
320
321 EXPECT_NO_THROW(src_facility_->Tock());
322 TestBuffers(src_facility_,0,0.4*cap,0,0);
323
324 // Move material to stocks
325 tc_.get()->time(residence_time);
326 EXPECT_NO_THROW(src_facility_->Tock());
327 TestBuffers(src_facility_,0,0,0,0.4*cap);
328}
329
330TEST_F(StorageTest,ChangeProcessTime){
331 // Initialize process time variable and add first batch
332 int proc_time1 = residence_time;
333 double cap = throughput;
334 cyclus::Composition::Ptr rec = tc_.get()->GetRecipe(in_r1);
335 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(cap, rec);
337 TestBuffers(src_facility_,cap,0,0,0);
338
339 // Move material to processing
340 EXPECT_NO_THROW(src_facility_->Tock());
341 TestBuffers(src_facility_,0,cap,0,0);
342
343 // Add second batch
344 cyclus::Material::Ptr mat1 = cyclus::Material::CreateUntracked(cap,rec);
345 tc_.get()->time(8);
347 TestBuffers(src_facility_,cap,cap,0,0);
348 EXPECT_NO_THROW(src_facility_->Tock());
349 TestBuffers(src_facility_,0,2*cap,0,0);
350
351 // Increase process time
352 residence_time = proc_time1+5;
353 SetUpStorage();
354 // src_facility_->residence_time = proc_time1+5;
355 EXPECT_EQ(residence_time,proc_time1+5);
356 EXPECT_EQ(residence_time,15);
357 int proc_time2 = residence_time;
358
359 // Make sure material doesn't move before new process time
360 for( int i=proc_time1; i < proc_time2 - 1; ++i){
361 tc_.get()->time(i);
362 EXPECT_NO_THROW(src_facility_->Tock());
363 TestBuffers(src_facility_,0,2*cap,0,0);
364 }
365
366 // Move first batch to stocks
367 tc_.get()->time(proc_time2);
368 EXPECT_NO_THROW(src_facility_->Tock());
369 TestBuffers(src_facility_,0,cap,0,cap);
370
371 // Decrease process time
372 residence_time = proc_time2-3;
373 SetUpStorage();
374 int proc_time3 = residence_time;
375
376 // Move second batch to stocks
377 tc_.get()->time(proc_time3 +8);
378 EXPECT_NO_THROW(src_facility_->Tock());
379 TestBuffers(src_facility_,0,0,0,2*cap);
380
381}
382
383TEST_F(StorageTest,DifferentRecipe){
384 // Initialize material with different recipe than in_recipe
385 double cap = throughput;
386 cyclus::CompMap v;
387 v[922350000] = 3;
388 v[922380000] = 1;
389 cyclus::Composition::Ptr rec = cyclus::Composition::CreateFromAtom(v);
390 cyclus::Material::Ptr mat = cyclus::Material::CreateUntracked(cap, rec);
391
392 // Move material through the facility
394 TestBuffers(src_facility_,cap,0,0,0);
395 EXPECT_NO_THROW(src_facility_->Tock());
396 TestBuffers(src_facility_,0,cap,0,0);
397 tc_.get()->time(residence_time);
398 EXPECT_NO_THROW(src_facility_->Tock());
399 TestBuffers(src_facility_,0,0,0,cap);
400}
401
402TEST_F(StorageTest, BehaviorTest){
403 // Verify Storage behavior
404
405 std::string config =
406 " <in_commods> <val>spent_fuel</val> </in_commods> "
407 " <out_commods> <val>dry_spent</val> </out_commods> "
408 " <residence_time>1</residence_time>"
409 " <max_inv_size>10</max_inv_size>";
410
411 int simdur = 3;
412
413 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
414
415 sim.AddSource("spent_fuel").Finalize();
416 sim.AddSink("dry_spent").Finalize();
417
418 int id = sim.Run();
419
420 // return all transactions where our sstorage facility is the sender
421 std::vector<cyclus::Cond> conds;
422 conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent")));
423 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
424 int n_trans = qr.rows.size();
425 EXPECT_EQ(1, n_trans) << "expected 1 transactions, got " << n_trans;
426
427}
428
429TEST_F(StorageTest, MultipleCommods){
430 // Verify Storage accepting Multiple Commods
431
432 std::string config =
433 " <in_commods> <val>spent_fuel</val>"
434 " <val>spent_fuel2</val> </in_commods>"
435 " <in_commod_prefs> <val>1</val>"
436 " <val>1</val> </in_commod_prefs>"
437 " <out_commods> <val>dry_spent</val> </out_commods> "
438 " <max_inv_size>10</max_inv_size>";
439
440 int simdur = 2;
441
442 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
443
444 sim.AddSource("spent_fuel").capacity(5).Finalize();
445 sim.AddSource("spent_fuel2").capacity(5).Finalize();
446 sim.AddSink("dry_spent").Finalize();
447
448 int id = sim.Run();
449
450 // return all transactions where our sstorage facility is the acceptor
451 std::vector<cyclus::Cond> conds;
452 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
453 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
454 int n_trans = qr.rows.size();
455 EXPECT_EQ(1, n_trans) << "expected 1 transactions, got " << n_trans;
456
457 std::vector<cyclus::Cond> conds2;
458 conds2.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel2")));
459 cyclus::QueryResult qr2 = sim.db().Query("Transactions", &conds2);
460 int n_trans2 = qr2.rows.size();
461 EXPECT_EQ(1, n_trans2) << "expected 1 transactions, got " << n_trans;
462}
463
464
465// Should get one transaction in a 2 step simulation when agent is active for
466// one step and dormant for one step
467TEST_F(StorageTest, ActiveDormant){
468 std::string config =
469 " <in_commods> <val>spent_fuel</val> </in_commods> "
470 " <out_commods> <val>dry_spent</val> </out_commods> "
471 " <throughput>1</throughput>"
472 " <active_buying_val>1</active_buying_val>"
473 " <dormant_buying_val>1</dormant_buying_val>";
474
475 int simdur = 2;
476
477 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
478
479 sim.AddSource("spent_fuel").capacity(5).Finalize();
480 sim.AddSink("dry_spent").Finalize();
481
482 int id = sim.Run();
483
484 // return all transactions where our storage facility is the acceptor
485 std::vector<cyclus::Cond> conds;
486 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
487 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
488 int n_trans = qr.rows.size();
489 EXPECT_EQ(1, n_trans) << "expected 1 transactions, got " << n_trans;
490 }
491
492 // Should get two transactions in a 2 step simulation when there is no
493 // dormant period, i.e. agent is always active
494TEST_F(StorageTest, NoDormant){
495 std::string config =
496 " <in_commods> <val>spent_fuel</val> </in_commods> "
497 " <out_commods> <val>dry_spent</val> </out_commods> "
498 " <throughput>1</throughput>"
499 " <active_buying_frequency_type>Fixed</active_buying_frequency_type>"
500 " <active_buying_val>1</active_buying_val>"
501 " <dormant_buying_frequency_type>Fixed</dormant_buying_frequency_type>"
502 " <dormant_buying_val>-1</dormant_buying_val>";
503
504 int simdur = 3;
505
506 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
507
508 sim.AddSource("spent_fuel").capacity(5).Finalize();
509 sim.AddSink("dry_spent").Finalize();
510
511 int id = sim.Run();
512
513 std::vector<cyclus::Cond> conds;
514 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
515 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
516 int n_trans = qr.rows.size();
517 EXPECT_EQ(3, n_trans) << "expected 3 transactions, got " << n_trans;
518 }
519
520TEST_F(StorageTest, UniformActiveNormalDormant){
521 std::string config =
522 " <in_commods> <val>spent_fuel</val> </in_commods> "
523 " <out_commods> <val>dry_spent</val> </out_commods> "
524 " <throughput>1</throughput>"
525 " <active_buying_frequency_type>Uniform</active_buying_frequency_type>"
526 " <active_buying_min>2</active_buying_min>"
527 " <active_buying_max>3</active_buying_max>"
528 " <dormant_buying_frequency_type>Normal</dormant_buying_frequency_type>"
529 " <dormant_buying_mean>5</dormant_buying_mean>"
530 " <dormant_buying_stddev>1</dormant_buying_stddev>";
531
532 int simdur = 20;
533
534 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
535
536 sim.AddSource("spent_fuel").capacity(5).Finalize();
537 sim.AddSink("dry_spent").Finalize();
538
539 int id = sim.Run();
540
541 std::vector<cyclus::Cond> conds;
542 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
543 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
544 // confirm that transactions are only occurring during active periods
545 // first cycle includes time steps 0 and 1
546 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
547 EXPECT_EQ(1, qr.GetVal<int>("Time", 1));
548 // second cycle (lines 2, 3 and 4) includes time steps 7, 8, and 9
549 EXPECT_EQ(7, qr.GetVal<int>("Time", 2));
550 EXPECT_EQ(8, qr.GetVal<int>("Time", 3));
551 EXPECT_EQ(9, qr.GetVal<int>("Time", 4));
552}
553
554TEST_F(StorageTest, BinomialActiveDormant) {
555 std::string config =
556 " <in_commods> <val>commod</val> </in_commods> "
557 " <out_commods> <val>commod1</val> </out_commods> "
558 " <throughput>1</throughput>"
559 " <active_buying_frequency_type>Binomial</active_buying_frequency_type>"
560 " <active_buying_end_probability>0.2</active_buying_end_probability>"
561 " <dormant_buying_frequency_type>Binomial</dormant_buying_frequency_type>"
562 " <dormant_buying_end_probability>0.3</dormant_buying_end_probability>";
563
564 int simdur = 30;
565
566 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
567 sim.AddSource("commod").capacity(5).Finalize();
568
569 int id = sim.Run();
570
571 std::vector<cyclus::Cond> conds;
572 conds.push_back(cyclus::Cond("Commodity", "==", std::string("commod")));
573 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
574 // confirm that transactions are only occurring during active periods
575 // first active length = 7
576 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
577 EXPECT_EQ(1, qr.GetVal<int>("Time", 1));
578 // ... end of active
579 EXPECT_EQ(6, qr.GetVal<int>("Time", 6));
580 // transactions resume at time 10
581 EXPECT_EQ(10, qr.GetVal<int>("Time", 7));
582}
583
584TEST_F(StorageTest, DisruptionActiveDormant) {
585 std::string config =
586 " <in_commods><val>commod</val></in_commods>"
587 " <out_commods><val>commod1</val></out_commods>"
588 " <throughput>1</throughput>"
589 " <active_buying_frequency_type>FixedWithDisruption</active_buying_frequency_type>"
590 " <active_buying_disruption_probability>0.4</active_buying_disruption_probability>"
591 " <active_buying_val>2</active_buying_val>"
592 " <active_buying_disruption>5</active_buying_disruption>"
593 " <dormant_buying_frequency_type>FixedWithDisruption</dormant_buying_frequency_type>"
594 " <dormant_buying_disruption_probability>0.5</dormant_buying_disruption_probability>"
595 " <dormant_buying_val>1</dormant_buying_val>"
596 " <dormant_buying_disruption>10</dormant_buying_disruption>";
597
598 int simdur = 50;
599
600 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
601 sim.AddSource("commod").capacity(5).Finalize();
602 int id = sim.Run();
603
604 cyclus::QueryResult qr = sim.db().Query("Transactions", NULL);
605 // confirm that transactions are only occurring during active periods
606 // first active length = 5 (disrupted)
607 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
608 EXPECT_EQ(1, qr.GetVal<int>("Time", 1)); // ... end of active
609
610 // first dormant length = 1 (not disrupted)
611 // second active length = 2 (not disrupted)
612 EXPECT_EQ(3, qr.GetVal<int>("Time", 2)); // ... end of dormant
613 EXPECT_EQ(4, qr.GetVal<int>("Time", 3));
614
615 // second dormant length = 10 (disrupted)
616 // third active length = 2 (not disrupted)
617 EXPECT_EQ(15, qr.GetVal<int>("Time", 4)); // ... end of second active
618}
619
620TEST_F(StorageTest, FixedBuyingSize){
621 std::string config =
622 " <in_commods> <val>spent_fuel</val> </in_commods> "
623 " <out_commods> <val>dry_spent</val> </out_commods> "
624 " <throughput>1</throughput>"
625 " <buying_size_type>Fixed</buying_size_type>"
626 " <buying_size_val>0.5</buying_size_val>";
627
628 int simdur = 2;
629
630 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
631
632 sim.AddSource("spent_fuel").Finalize();
633 int id = sim.Run();
634
635 cyclus::QueryResult qr = sim.db().Query("Resources", NULL);
636 EXPECT_NEAR(0.5, qr.GetVal<double>("Quantity", 0), 0.00001);
637 EXPECT_NEAR(0.5, qr.GetVal<double>("Quantity", 1), 0.00001);
638}
639
640TEST_F(StorageTest, UniformBuyingSize){
641 std::string config =
642 " <in_commods> <val>spent_fuel</val> </in_commods> "
643 " <out_commods> <val>dry_spent</val> </out_commods> "
644 " <throughput>1</throughput>"
645 " <buying_size_type>Uniform</buying_size_type>"
646 " <buying_size_min>0.5</buying_size_min>"
647 " <buying_size_max>0.7</buying_size_max>";
648
649 int simdur = 2;
650
651 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
652
653 sim.AddSource("spent_fuel").Finalize();
654 int id = sim.Run();
655
656 cyclus::QueryResult qr = sim.db().Query("Resources", NULL);
657 EXPECT_NEAR(0.56393, qr.GetVal<double>("Quantity", 0), 0.00001);
658 EXPECT_NEAR(0.68825, qr.GetVal<double>("Quantity", 1), 0.00001);
659}
660
661TEST_F(StorageTest, NormalBuyingSize){
662 std::string config =
663 " <in_commods> <val>spent_fuel</val> </in_commods> "
664 " <out_commods> <val>dry_spent</val> </out_commods> "
665 " <throughput>1</throughput>"
666 " <buying_size_type>Normal</buying_size_type>"
667 " <buying_size_mean>0.5</buying_size_mean>"
668 " <buying_size_stddev>0.1</buying_size_stddev>";
669
670 int simdur = 2;
671
672 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
673
674 sim.AddSource("spent_fuel").Finalize();
675
676 int id = sim.Run();
677
678 cyclus::QueryResult qr = sim.db().Query("Resources", NULL);
679 EXPECT_NEAR(0.64083, qr.GetVal<double>("Quantity", 0), 0.00001);
680 EXPECT_NEAR(0.32648, qr.GetVal<double>("Quantity", 1), 0.00001);
681}
682
683TEST_F(StorageTest, NormalActiveDormantBuyingSize){
684 std::string config =
685 " <in_commods> <val>spent_fuel</val> </in_commods> "
686 " <out_commods> <val>dry_spent</val> </out_commods> "
687 " <throughput>1</throughput>"
688 " <active_buying_frequency_type>Normal</active_buying_frequency_type>"
689 " <active_buying_mean>3</active_buying_mean>"
690 " <active_buying_stddev>1</active_buying_stddev>"
691 " <dormant_buying_frequency_type>Normal</dormant_buying_frequency_type>"
692 " <dormant_buying_mean>2</dormant_buying_mean>"
693 " <dormant_buying_stddev>1</dormant_buying_stddev>"
694 " <buying_size_type>Normal</buying_size_type>"
695 " <buying_size_mean>0.5</buying_size_mean>"
696 " <buying_size_stddev>0.1</buying_size_stddev>";
697
698 int simdur = 15;
699
700 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
701
702 sim.AddSource("spent_fuel").capacity(5).Finalize();
703 sim.AddSink("dry_spent").Finalize();
704
705 int id = sim.Run();
706
707 std::vector<cyclus::Cond> conds;
708 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
709 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
710 int n_trans = qr.rows.size();
711 EXPECT_EQ(10, n_trans) << "expected 10 transactions, got " << n_trans;
712 // confirm that transactions are only occurring during active periods
713 // first cycle includes time steps 0 - 3
714 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
715 EXPECT_EQ(3, qr.GetVal<int>("Time", 3));
716 // second cycle (rows 4 and 4) include time steps 6 and 7
717 EXPECT_EQ(6, qr.GetVal<int>("Time", 4));
718 EXPECT_EQ(7, qr.GetVal<int>("Time", 5));
719 // third cycle (row 6) includes time step 8 -9
720 EXPECT_EQ(8, qr.GetVal<int>("Time", 6));
721 EXPECT_EQ(9, qr.GetVal<int>("Time", 7));
722 // fourth cycle (rows 8, 9) includes time steps 13 - 14
723 EXPECT_EQ(13, qr.GetVal<int>("Time", 8));
724 EXPECT_EQ(14, qr.GetVal<int>("Time", 9));
725
726 qr = sim.db().Query("Resources", NULL);
727 EXPECT_NEAR(0.61256, qr.GetVal<double>("Quantity", 0), 0.00001);
728 EXPECT_NEAR(0.62217, qr.GetVal<double>("Quantity", 1), 0.00001);
729 EXPECT_NEAR(0.39705, qr.GetVal<double>("Quantity", 2), 0.00001);
730}
731
732TEST_F(StorageTest, IncorrectBuyPolSetupUniform) {
733 // uniform missing min and max
734 std::string config_uniform =
735 " <in_commods> <val>spent_fuel</val> </in_commods> "
736 " <out_commods> <val>dry_spent</val> </out_commods> "
737 " <throughput>1</throughput>"
738 " <active_buying_frequency_type>Uniform</active_buying_frequency_type>";
739
740 int simdur = 15;
741
742 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config_uniform,
743 simdur);
744 EXPECT_THROW(sim.Run(), cyclus::ValueError);
745}
746
747TEST_F(StorageTest, IncorrectBuyPolSetupNormal) {
748 // normal missing mean and std dev
749 std::string config_normal =
750 " <in_commods> <val>spent_fuel</val> </in_commods> "
751 " <out_commods> <val>dry_spent</val> </out_commods> "
752 " <throughput>1</throughput>"
753 " <active_buying_frequency_type>Normal</active_buying_frequency_type>";
754 int simdur = 15;
755
756 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config_normal,
757 simdur);
758 EXPECT_THROW(sim.Run(), cyclus::ValueError);
759}
760
761TEST_F(StorageTest, IncorrectBuyPolSetupMinMax) {
762 // tries to set min > max
763 std::string config_uniform_min_bigger_max =
764 " <in_commods> <val>spent_fuel</val> </in_commods> "
765 " <out_commods> <val>dry_spent</val> </out_commods> "
766 " <throughput>1</throughput>"
767 " <active_buying_frequency_type>Uniform</active_buying_frequency_type>"
768 " <active_buying_min>3</active_buying_min>"
769 " <active_buying_max>2</active_buying_max>";
770
771 int simdur = 15;
772
773 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"),
774 config_uniform_min_bigger_max, simdur);
775 EXPECT_THROW(sim.Run(), cyclus::ValueError);
776}
777
778TEST_F(StorageTest, PositionInitialize){
779 // Verify Storage behavior
780
781 std::string config =
782 " <in_commods> <val>spent_fuel</val> </in_commods> "
783 " <out_commods> <val>dry_spent</val> </out_commods> "
784 " <residence_time>1</residence_time>"
785 " <max_inv_size>10</max_inv_size>";
786
787 int simdur = 3;
788
789 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
790
791 sim.AddSource("spent_fuel").Finalize();
792 sim.AddSink("dry_spent").Finalize();
793
794 int id = sim.Run();
795
796 cyclus::QueryResult qr = sim.db().Query("AgentPosition", NULL);
797 EXPECT_EQ(qr.GetVal<double>("Latitude"), 0.0);
798 EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
799}
800
801TEST_F(StorageTest, Longitude){
802 // Verify Storage behavior
803
804 std::string config =
805 " <in_commods> <val>spent_fuel</val> </in_commods> "
806 " <out_commods> <val>dry_spent</val> </out_commods> "
807 " <residence_time>1</residence_time>"
808 " <max_inv_size>10</max_inv_size>"
809 " <latitude>50.0</latitude> "
810 " <longitude>35.0</longitude> ";
811
812 int simdur = 3;
813
814 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
815
816 sim.AddSource("spent_fuel").Finalize();
817 sim.AddSink("dry_spent").Finalize();
818
819 int id = sim.Run();
820
821 cyclus::QueryResult qr = sim.db().Query("AgentPosition", NULL);
822 EXPECT_EQ(qr.GetVal<double>("Latitude"), 50.0);
823 EXPECT_EQ(qr.GetVal<double>("Longitude"), 35.0);
824}
825
826TEST_F(StorageTest, RQ_Inventory_Invalid) {
827 std::string config =
828 " <in_commods> <val>spent_fuel</val> </in_commods> "
829 " <out_commods> <val>dry_spent</val> </out_commods> "
830 " <max_inv_size>5</max_inv_size>"
831 " <reorder_point>2</reorder_point>"
832 " <reorder_quantity>10</reorder_quantity>";
833
834 int simdur = 2;
835
836 cyclus::MockSim sim(cyclus::AgentSpec(":cycamore:Storage"), config, simdur);
837
838 EXPECT_THROW(int id = sim.Run(), cyclus::ValueError);
839}
840
841TEST_F(StorageTest, RQ_Inventory) {
842 std::string config =
843 " <in_commods> <val>spent_fuel</val> </in_commods> "
844 " <out_commods> <val>dry_spent</val> </out_commods> "
845 " <max_inv_size>5</max_inv_size>"
846 " <reorder_point>2</reorder_point>"
847 " <reorder_quantity>3</reorder_quantity>";
848
849 int simdur = 5;
850
851 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
852
853 sim.AddSource("spent_fuel").capacity(5).Finalize();
854 sim.AddSink("dry_spent").Finalize();
855
856 int id = sim.Run();
857
858 std::vector<cyclus::Cond> conds;
859 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
860 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
861 int n_trans = qr.rows.size();
862
863 EXPECT_EQ(3, n_trans) << "expected 3 transactions, got " << n_trans;
864 // check that the transactions occur at the expected time (0, 2, 4)
865 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
866 EXPECT_EQ(2, qr.GetVal<int>("Time", 1));
867 EXPECT_EQ(4, qr.GetVal<int>("Time", 2));
868
869 // check that all transactions are of size 3
870 qr = sim.db().Query("Resources", NULL);
871 EXPECT_EQ(3, qr.GetVal<double>("Quantity", 0));
872}
873
874TEST_F(StorageTest, sS_Inventory) {
875 std::string config =
876 " <in_commods> <val>spent_fuel</val> </in_commods> "
877 " <out_commods> <val>dry_spent</val> </out_commods> "
878 " <max_inv_size>5</max_inv_size>"
879 " <reorder_point>2</reorder_point>";
880
881 int simdur = 5;
882
883 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
884
885 sim.AddSource("spent_fuel").capacity(5).Finalize();
886 sim.AddSink("dry_spent").Finalize();
887
888 int id = sim.Run();
889
890 std::vector<cyclus::Cond> conds;
891 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
892 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
893 int n_trans = qr.rows.size();
894 EXPECT_EQ(3, n_trans) << "expected 3 transactions, got " << n_trans;
895 // check that the transactions occur at the expected time (0, 2, 4)
896 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
897 EXPECT_EQ(2, qr.GetVal<int>("Time", 1));
898 EXPECT_EQ(4, qr.GetVal<int>("Time", 2));
899
900 // check that all transactions are of size 5
901 qr = sim.db().Query("Resources", NULL);
902 EXPECT_EQ(5, qr.GetVal<double>("Quantity", 0));
903}
904
905TEST_F(StorageTest, CCap_Inventory) {
906 std::string config =
907 " <in_commods> <val>spent_fuel</val> </in_commods> "
908 " <out_commods> <val>dry_spent</val> </out_commods> "
909 " <throughput>1</throughput> "
910 " <cumulative_cap>2</cumulative_cap> "
911 " <dormant_buying_frequency_type>Fixed</dormant_buying_frequency_type> "
912 " <dormant_buying_val>2</dormant_buying_val> ";
913
914 int simdur = 9;
915
916 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
917
918 sim.AddSource("spent_fuel").capacity(5).Finalize();
919 sim.AddSink("dry_spent").Finalize();
920
921 int id = sim.Run();
922
923 std::vector<cyclus::Cond> conds;
924 conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
925 cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
926 int n_trans = qr.rows.size();
927 EXPECT_EQ(5, n_trans) << "expected 5 transactions, got " << n_trans;
928 // check that the transactions occur at the expected time (0, 1, 4, 5, 8)
929 EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
930 EXPECT_EQ(1, qr.GetVal<int>("Time", 1));
931 EXPECT_EQ(4, qr.GetVal<int>("Time", 2));
932 EXPECT_EQ(5, qr.GetVal<int>("Time", 3));
933 EXPECT_EQ(8, qr.GetVal<int>("Time", 4));
934
935 // check that transactions are of size 1
936 qr = sim.db().Query("Resources", NULL);
937 EXPECT_EQ(1, qr.GetVal<double>("Quantity", 0));
938 EXPECT_EQ(1, qr.GetVal<double>("Quantity", 4));
939}
940
941TEST_F(StorageTest, PackageExactly) {
942 // resource can be packaged without splitting or merging
943 std::string config =
944 " <in_commods> <val>spent_fuel</val> </in_commods> "
945 " <out_commods> <val>dry_spent</val> </out_commods> "
946 " <package>foo</package>";
947
948 int simdur = 3;
949
950 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
951 sim.context()->AddPackage("foo", 1, 2, "first");
952 cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
953
954 sim.AddSource("spent_fuel").capacity(2).Finalize();
955 sim.AddSink("dry_spent").Finalize();
956
957 int id = sim.Run();
958
959 std::vector<cyclus::Cond> tr_conds;
960 tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent")));
961 cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
962 // two transactions out of storage, happening at time 1 and 2
963 EXPECT_EQ(2, qr_trans.rows.size());
964
965 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
966 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 1));
967
968 std::vector<cyclus::Cond> res_conds;
969 res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
970 cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
971 // two resources that have been packaged, each of size two
972 EXPECT_EQ(qr_res.rows.size(), 2);
973 EXPECT_EQ(qr_res.GetVal<double>("Quantity", 0), 2);
974 EXPECT_EQ(qr_res.GetVal<double>("Quantity", 1), 2);
975}
976
977TEST_F(StorageTest, PackageSplitEqual) {
978 // Resources must be split into two to package. Packaging strategy equal
979 std::string config =
980 " <in_commods> <val>commodity</val> </in_commods> "
981 " <out_commods> <val>commodity1</val> </out_commods> "
982 " <package>foo</package>";
983
984 int simdur = 3;
985
986 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
987 sim.context()->AddPackage("foo", 1, 2, "equal");
988 cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
989
990 sim.AddSource("commodity").capacity(3).Finalize();
991 sim.AddSink("commodity1").Finalize();
992
993 int id = sim.Run();
994
995 std::vector<cyclus::Cond> tr_conds;
996 tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));
997 cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
998 // four transactions out of storage. Each resource is split, so two
999 // transactions at time 1, two at time 2
1000 EXPECT_EQ(4, qr_trans.rows.size());
1001
1002 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
1003 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
1004 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));
1005 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 3));
1006
1007 std::vector<cyclus::Cond> res_conds;
1008 res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
1009 cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
1010 // because package does split-equally, resources are all of size 1.5 (3/2)
1011 EXPECT_EQ(qr_res.rows.size(), 4);
1012 EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 0));
1013 EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 1));
1014 EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 2));
1015 EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 3));
1016}
1017
1018TEST_F(StorageTest, PackageSplitFirst) {
1019 // Resources must be split into two to package. Packaging strategy first
1020 std::string config =
1021 " <in_commods> <val>commodity</val> </in_commods> "
1022 " <out_commods> <val>commodity1</val> </out_commods> "
1023 " <package>foo</package>";
1024
1025 int simdur = 3;
1026
1027 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
1028 sim.context()->AddPackage("foo", 1, 2, "first");
1029 cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
1030
1031 sim.AddSource("commodity").capacity(3).Finalize();
1032 sim.AddSink("commodity1").Finalize();
1033
1034 int id = sim.Run();
1035
1036 std::vector<cyclus::Cond> tr_conds;
1037 tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));
1038 cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
1039 // four transactions out of storage. Each resource is split, so two
1040 // transactions at time 1, two at time 2
1041 EXPECT_EQ(4, qr_trans.rows.size());
1042
1043 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
1044 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
1045 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));
1046 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 3));
1047
1048 std::vector<cyclus::Cond> res_conds;
1049 res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
1050 cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
1051 // because package does split-first, resources are size 2 and 1
1052 EXPECT_EQ(qr_res.rows.size(), 4);
1053
1054 // order of trade execution is not guaranteed. Therefore, create vector,
1055 // sort by size, and then check values
1056 std::vector<double> pkgd_t0 = {qr_res.GetVal<double>("Quantity", 0),
1057 qr_res.GetVal<double>("Quantity", 1)};
1058 std::sort(pkgd_t0.begin(), pkgd_t0.end(), std::greater<double>());
1059 std::vector<double> exp_t0 = {2, 1};
1060
1061 EXPECT_EQ(exp_t0, pkgd_t0);
1062
1063 std::vector<double> pkgd_t1 = {qr_res.GetVal<double>("Quantity", 2),
1064 qr_res.GetVal<double>("Quantity", 3)};
1065 std::sort(pkgd_t1.begin(), pkgd_t1.end(), std::greater<double>());
1066 std::vector<double> exp_t1 = {2, 1};
1067
1068 EXPECT_EQ(exp_t1, pkgd_t1);
1069}
1070
1071TEST_F(StorageTest, PackageMerge) {
1072 std::string config =
1073 " <in_commods> <val>commodity</val> </in_commods> "
1074 " <out_commods> <val>commodity1</val> </out_commods> "
1075 " <throughput>1</throughput> "
1076 " <package>foo</package>";
1077
1078 int simdur = 5;
1079
1080 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
1081 sim.context()->AddPackage("foo", 1, 2, "first");
1082 cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
1083
1084 sim.AddSource("commodity").capacity(0.5).Finalize();
1085 sim.AddSink("commodity1").Finalize();
1086
1087 int id = sim.Run();
1088
1089 std::vector<cyclus::Cond> tr_conds;
1090 tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));
1091
1092 cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
1093 // two transactions out of storage. Because the source only provides 0.5 each
1094 // time step, it takes two time steps to acquire enough material to package.
1095 // Therefore transactions at time 2 and 4
1096 EXPECT_EQ(2, qr_trans.rows.size());
1097
1098 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 0));
1099 EXPECT_EQ(4, qr_trans.GetVal<int>("Time", 1));
1100
1101 std::vector<cyclus::Cond> res_conds;
1102 res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
1103 cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
1104 // Combines two 0.5 mass resources to make packages with mass 1
1105 EXPECT_EQ(2, qr_res.rows.size());
1106 EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 0));
1107 EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 1));
1108}
1109
1110TEST_F(StorageTest, TransportUnit) {
1111 std::string config =
1112 " <in_commods> <val>commodity</val> </in_commods> "
1113 " <out_commods> <val>commodity1</val> </out_commods> "
1114 " <throughput>3</throughput> "
1115 " <package>foo</package>"
1116 " <transport_unit>bar</transport_unit>";
1117
1118 int simdur = 3;
1119
1120 cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
1121 sim.context()->AddPackage("foo", 1, 1, "first");
1122 cyclus::Package::Ptr p = sim.context()->GetPackage("foo");
1123 sim.context()->AddTransportUnit("bar", 2, 2, "first");
1124
1125 sim.AddSource("commodity").Finalize();
1126 sim.AddSink("commodity1").Finalize();
1127
1128 int id = sim.Run();
1129
1130 std::vector<cyclus::Cond> tr_conds;
1131 tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));
1132
1133 cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
1134 // 6 transactions. While all three units could be packaged in one time step,
1135 // the transport unit only allows two packages to be transported. Therefore,
1136 // zero transactions the first timestep (material coming to storage from
1137 // source). Then only two packages can be shipped at time step 1. Then the
1138 // two packages plus the leftover material is able to ship four packages,
1139 // two transport units in time 2
1140 EXPECT_EQ(6, qr_trans.rows.size());
1141
1142 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
1143 EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
1144 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));
1145 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 3));
1146 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 4));
1147 EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 5));
1148
1149 std::vector<cyclus::Cond> res_conds;
1150 res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
1151 cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
1152 // All pkgd resources are size 1
1153 EXPECT_EQ(6, qr_res.rows.size());
1154
1155 EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 0));
1156 EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 5));
1157}
1158
1159} // namespace cycamore
1160
1161// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1162cyclus::Agent* StorageConstructor(cyclus::Context* ctx) {
1163 return new cycamore::Storage(ctx);
1164}
1165
1166// required to get functionality in cyclus agent unit tests library
1167#ifndef CYCLUS_AGENT_TESTS_CONNECTED
1170#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected
1171#endif // CYCLUS_AGENT_TESTS_CONNECTED
1172
1173// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1174INSTANTIATE_TEST_SUITE_P(StorageFac, FacilityTests,
1175 ::testing::Values(&StorageConstructor));
1176
1177INSTANTIATE_TEST_SUITE_P(StorageFac, AgentTests,
1178 ::testing::Values(&StorageConstructor));
static int cyclus_agent_tests_connected
INSTANTIATE_TEST_SUITE_P(DeployInst, InstitutionTests, Values(&DeployInstitutionConstructor))
int ConnectAgentTests()
cyclus::Agent * StorageConstructor(cyclus::Context *ctx)
std::vector< std::string > out_c1
void TestInitState(cycamore::Storage *fac)
void TestBuffers(cycamore::Storage *fac, double inv, double proc, double ready, double stocks)
void TestReadyTime(cycamore::Storage *fac, int t)
std::vector< std::string > in_c1
void TestStocks(cycamore::Storage *fac, cyclus::CompMap v)
void TestCurrentCap(cycamore::Storage *fac, double inv)
void TestAddMat(cycamore::Storage *fac, cyclus::Material::Ptr mat)
This Facility is intended to hold materials for a user specified amount of time in order to model a s...
void AddMat_(cyclus::Material::Ptr mat)
adds a material into the incoming commodity inventory
virtual std::string str()
A verbose printer for the Storage Facility.
double current_capacity()
current maximum amount that can be added to processing
cyclus::toolkit::ResBuf< cyclus::Material > ready
cyclus::toolkit::ResBuf< cyclus::Material > processing
cyclus::toolkit::TotalInvTracker inventory_tracker
virtual cyclus::Agent * Clone()
std::vector< std::string > in_commods
virtual void Tock()
The handleTick function specific to the Storage.
cyclus::toolkit::ResBuf< cyclus::Material > inventory
int ready_time()
returns the time key for ready materials
std::vector< std::string > out_commods
cyclus::toolkit::ResBuf< cyclus::Material > stocks
virtual void Tick()
The handleTick function specific to the Storage.
TEST_F(EnrichmentTest, RequestQty)