1+ #include " conversion_tests.h"
2+
3+ #include < gtest/gtest.h>
4+
5+ #include < sstream>
6+
7+ #include " cyc_limits.h"
8+ #include " resource_helpers.h"
9+ #include " test_context.h"
10+ #include " pyne.h"
11+
12+ using pyne::nucname::id;
13+
14+ namespace cycamore {
15+
16+ void ConversionTest::SetUp () {
17+ conv_facility = new cycamore::Conversion (tc.get ());
18+ trader = tc.trader ();
19+ InitParameters ();
20+ SetUpConversion ();
21+ conv_facility->Build (NULL );
22+ }
23+
24+ void ConversionTest::TearDown () {
25+ delete conv_facility;
26+ }
27+
28+ void ConversionTest::InitParameters () {
29+ throughput_val = DEFAULT_THROUGHPUT;
30+ input_capacity_val = DEFAULT_INPUT_CAPACITY;
31+
32+ cyclus::CompMap v;
33+ v[id (" u235" )] = 1 ;
34+ recipe = cyclus::Composition::CreateFromAtom (v);
35+ tc.get ()->AddRecipe (" test_recipe" , recipe);
36+ }
37+
38+ void ConversionTest::SetUpConversion () {
39+ std::vector<std::string> incommods_vec;
40+ incommods_vec.push_back (INCOMMOD1);
41+
42+ incommods (conv_facility, incommods_vec);
43+ outcommod (conv_facility, OUTCOMMOD_NAME);
44+ throughput (conv_facility, throughput_val);
45+ input_capacity (conv_facility, input_capacity_val);
46+
47+ // Set the actual buffer capacity
48+ set_input_capacity (conv_facility, input_capacity_val);
49+ }
50+
51+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52+ TEST_F (ConversionTest, Clone) {
53+ cycamore::Conversion* cloned_fac = dynamic_cast <cycamore::Conversion*>
54+ (conv_facility->Clone ());
55+
56+ EXPECT_EQ (incommods (conv_facility), incommods (cloned_fac));
57+ EXPECT_EQ (outcommod (conv_facility), outcommod (cloned_fac));
58+ EXPECT_EQ (throughput (conv_facility), throughput (cloned_fac));
59+ EXPECT_EQ (input_capacity (conv_facility), input_capacity (cloned_fac));
60+
61+ delete cloned_fac;
62+ }
63+
64+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65+ TEST_F (ConversionTest, Print) {
66+ EXPECT_NO_THROW (std::string s = conv_facility->str ());
67+ }
68+
69+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70+ TEST_F (ConversionTest, InitialState) {
71+ conv_facility->EnterNotify ();
72+
73+ EXPECT_EQ (throughput_val, throughput (conv_facility));
74+ EXPECT_EQ (input_capacity_val, input_capacity (conv_facility));
75+ EXPECT_EQ (OUTCOMMOD_NAME, outcommod (conv_facility));
76+
77+ std::vector<std::string> expected_incommods;
78+ expected_incommods.push_back (INCOMMOD1);
79+ EXPECT_EQ (expected_incommods, incommods (conv_facility));
80+ }
81+
82+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83+ TEST_F (ConversionTest, AvailableFeedstockCapacity) {
84+ conv_facility->EnterNotify ();
85+
86+ // Initially, capacity should be full
87+ EXPECT_DOUBLE_EQ (input_capacity_val, conv_facility->AvailableFeedstockCapacity ());
88+
89+ // Add some material to input buffer
90+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
91+ input_push (conv_facility, mat);
92+
93+ // Capacity should be reduced
94+ EXPECT_DOUBLE_EQ (input_capacity_val - TEST_QUANTITY, conv_facility->AvailableFeedstockCapacity ());
95+ }
96+
97+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98+ TEST_F (ConversionTest, GetMatlRequests) {
99+ using cyclus::RequestPortfolio;
100+ using cyclus::Material;
101+ using cyclus::CapacityConstraint;
102+
103+ conv_facility->EnterNotify ();
104+
105+ std::set<RequestPortfolio<Material>::Ptr> ports =
106+ conv_facility->GetMatlRequests ();
107+
108+ ASSERT_EQ (1 , ports.size ());
109+
110+ RequestPortfolio<Material>::Ptr port = *ports.begin ();
111+ EXPECT_EQ (conv_facility, port->requester ());
112+
113+ // Check the portfolio for the request for incommod1 (should be the only one)
114+ EXPECT_EQ (1 , port->requests ().size ());
115+
116+ const std::set<CapacityConstraint<Material> >& constrs = port->constraints ();
117+ ASSERT_EQ (1 , constrs.size ());
118+ EXPECT_EQ (CapacityConstraint<Material>(input_capacity_val), *constrs.begin ());
119+ }
120+
121+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
122+ TEST_F (ConversionTest, GetMatlRequestsWhenFull) {
123+ using cyclus::RequestPortfolio;
124+ using cyclus::Material;
125+
126+ conv_facility->EnterNotify ();
127+
128+ // Fill the input buffer
129+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (input_capacity_val);
130+ input_push (conv_facility, mat);
131+
132+ std::set<RequestPortfolio<Material>::Ptr> ports =
133+ conv_facility->GetMatlRequests ();
134+
135+ // Should have no requests when buffer is full
136+ EXPECT_EQ (0 , ports.size ());
137+ }
138+
139+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140+ TEST_F (ConversionTest, GetMatlBids) {
141+ using cyclus::BidPortfolio;
142+ using cyclus::Material;
143+ using cyclus::CapacityConstraint;
144+ using cyclus::CommodMap;
145+
146+ conv_facility->EnterNotify ();
147+
148+ // Add some material to output buffer
149+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
150+ output_push (conv_facility, mat);
151+
152+ // Create commodity requests
153+ CommodMap<Material>::type commod_requests;
154+ cyclus::Material::Ptr req_mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
155+ cyclus::Request<Material>* req = cyclus::Request<Material>::Create (
156+ req_mat, trader, OUTCOMMOD_NAME);
157+ commod_requests[OUTCOMMOD_NAME].push_back (req);
158+
159+ std::set<BidPortfolio<Material>::Ptr> ports =
160+ conv_facility->GetMatlBids (commod_requests);
161+
162+ // Should have one portfolio
163+ ASSERT_EQ (1 , ports.size ());
164+
165+ BidPortfolio<Material>::Ptr port = *ports.begin ();
166+ EXPECT_EQ (conv_facility, port->bidder ());
167+
168+ // Should have one bid
169+ EXPECT_EQ (1 , port->bids ().size ());
170+
171+ // Check capacity constraint
172+ const std::set<CapacityConstraint<Material> >& constrs = port->constraints ();
173+ ASSERT_EQ (1 , constrs.size ());
174+ EXPECT_EQ (CapacityConstraint<Material>(TEST_QUANTITY), *constrs.begin ());
175+
176+ delete req;
177+ }
178+
179+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180+ TEST_F (ConversionTest, GetMatlBidsWhenEmpty) {
181+ using cyclus::BidPortfolio;
182+ using cyclus::Material;
183+ using cyclus::CommodMap;
184+
185+ conv_facility->EnterNotify ();
186+
187+ // Create commodity requests
188+ CommodMap<Material>::type commod_requests;
189+ cyclus::Material::Ptr req_mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
190+ cyclus::Request<Material>* req = cyclus::Request<Material>::Create (
191+ req_mat, trader, OUTCOMMOD_NAME);
192+ commod_requests[OUTCOMMOD_NAME].push_back (req);
193+
194+ std::set<BidPortfolio<Material>::Ptr> ports =
195+ conv_facility->GetMatlBids (commod_requests);
196+
197+ // Should have no bids when output buffer is empty
198+ EXPECT_EQ (0 , ports.size ());
199+
200+ delete req;
201+ }
202+
203+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
204+ TEST_F (ConversionTest, AcceptMatlTrades) {
205+ using cyclus::Material;
206+ using cyclus::Trade;
207+ using cyclus::Request;
208+ using cyclus::Bid;
209+
210+ conv_facility->EnterNotify ();
211+
212+ // Create a trade
213+ Material::Ptr mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
214+ Request<Material>* req = Request<Material>::Create (mat, trader, INCOMMOD1);
215+ Bid<Material>* bid = Bid<Material>::Create (req, mat, trader);
216+ Trade<Material> trade (req, bid, TEST_QUANTITY);
217+
218+ std::vector<std::pair<Trade<Material>, Material::Ptr> > responses;
219+ responses.push_back (std::make_pair (trade, mat));
220+
221+ // Accept the trade
222+ conv_facility->AcceptMatlTrades (responses);
223+
224+ // Check that material was added to input buffer
225+ EXPECT_DOUBLE_EQ (TEST_QUANTITY, input_quantity (conv_facility));
226+
227+ delete req;
228+ delete bid;
229+ }
230+
231+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232+ TEST_F (ConversionTest, GetMatlTrades) {
233+ using cyclus::Material;
234+ using cyclus::Trade;
235+ using cyclus::Request;
236+ using cyclus::Bid;
237+
238+ conv_facility->EnterNotify ();
239+
240+ // Add material to output buffer
241+ Material::Ptr mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
242+ output_push (conv_facility, mat);
243+
244+ // Create a trade
245+ Material::Ptr req_mat = cyclus::NewBlankMaterial (TEST_QUANTITY);
246+ Request<Material>* req = Request<Material>::Create (req_mat, trader, OUTCOMMOD_NAME);
247+ Bid<Material>* bid = Bid<Material>::Create (req, req_mat, trader);
248+ Trade<Material> trade (req, bid, TEST_QUANTITY);
249+
250+ std::vector<Trade<Material> > trades;
251+ trades.push_back (trade);
252+
253+ std::vector<std::pair<Trade<Material>, Material::Ptr> > responses;
254+
255+ // Get the trade
256+ conv_facility->GetMatlTrades (trades, responses);
257+
258+ // Check response
259+ ASSERT_EQ (1 , responses.size ());
260+ EXPECT_DOUBLE_EQ (TEST_QUANTITY, responses[0 ].second ->quantity ());
261+
262+ // Check that material was removed from output buffer
263+ EXPECT_DOUBLE_EQ (0.0 , output_quantity (conv_facility));
264+
265+ delete req;
266+ delete bid;
267+ }
268+
269+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
270+ TEST_F (ConversionTest, Convert) {
271+ conv_facility->EnterNotify ();
272+
273+ // Add material to input buffer (more than throughput)
274+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (DEFAULT_THROUGHPUT * 2 );
275+ input_push (conv_facility, mat);
276+
277+ // Convert material
278+ conv_facility->Convert ();
279+
280+ // Check that material was moved from input to output
281+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT, input_quantity (conv_facility));
282+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT, output_quantity (conv_facility));
283+ }
284+
285+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
286+ TEST_F (ConversionTest, ConvertWithLessThanThroughput) {
287+ conv_facility->EnterNotify ();
288+
289+ // Add material to input buffer (less than throughput)
290+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (DEFAULT_THROUGHPUT / 2 );
291+ input_push (conv_facility, mat);
292+
293+ // Convert material
294+ conv_facility->Convert ();
295+
296+ // Check that all material was moved from input to output
297+ EXPECT_DOUBLE_EQ (0.0 , input_quantity (conv_facility));
298+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT / 2 , output_quantity (conv_facility));
299+ }
300+
301+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
302+ TEST_F (ConversionTest, ConvertWithEmptyInput) {
303+ conv_facility->EnterNotify ();
304+
305+ // Convert with empty input buffer
306+ conv_facility->Convert ();
307+
308+ // Check that nothing happened
309+ EXPECT_DOUBLE_EQ (0.0 , input_quantity (conv_facility));
310+ EXPECT_DOUBLE_EQ (0.0 , output_quantity (conv_facility));
311+ }
312+
313+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
314+ TEST_F (ConversionTest, Tick) {
315+ conv_facility->EnterNotify ();
316+
317+ // Add material to input buffer (more than throughput)
318+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (DEFAULT_THROUGHPUT * 2 );
319+ input_push (conv_facility, mat);
320+
321+ // Tick should trigger conversion
322+ conv_facility->Tick ();
323+
324+ // Check that material was converted
325+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT, input_quantity (conv_facility));
326+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT, output_quantity (conv_facility));
327+ }
328+
329+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
330+ TEST_F (ConversionTest, Tock) {
331+ conv_facility->EnterNotify ();
332+
333+ // Add material to input buffer
334+ cyclus::Material::Ptr mat = cyclus::NewBlankMaterial (DEFAULT_THROUGHPUT);
335+ input_push (conv_facility, mat);
336+
337+ // Tock should not trigger conversion
338+ conv_facility->Tock ();
339+
340+ // Check that no conversion happened
341+ EXPECT_DOUBLE_EQ (DEFAULT_THROUGHPUT, input_quantity (conv_facility));
342+ EXPECT_DOUBLE_EQ (0.0 , output_quantity (conv_facility));
343+ }
344+
345+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
346+ TEST_F (ConversionTest, PositionInitialize) {
347+ std::string config = DEFAULT_CONFIG;
348+ int simdur = SIMULATION_DURATION;
349+ cyclus::MockSim sim (cyclus::AgentSpec (" :cycamore:Conversion" ), config, simdur);
350+ int id = sim.Run ();
351+
352+ cyclus::QueryResult qr = sim.db ().Query (" AgentPosition" , NULL );
353+ EXPECT_EQ (qr.GetVal <double >(" Latitude" ), DEFAULT_POSITION);
354+ EXPECT_EQ (qr.GetVal <double >(" Longitude" ), DEFAULT_POSITION);
355+ }
356+
357+ // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
358+ TEST_F (ConversionTest, PositionWithCoordinates) {
359+ std::string config = DEFAULT_CONFIG +
360+ " <latitude>" + std::to_string (TEST_POSITION) + " </latitude>"
361+ " <longitude>" + std::to_string (TEST_POSITION) + " </longitude>" ;
362+ int simdur = SIMULATION_DURATION;
363+ cyclus::MockSim sim (cyclus::AgentSpec (" :cycamore:Conversion" ), config, simdur);
364+ int id = sim.Run ();
365+
366+ cyclus::QueryResult qr = sim.db ().Query (" AgentPosition" , NULL );
367+ EXPECT_EQ (qr.GetVal <double >(" Latitude" ), TEST_POSITION);
368+ EXPECT_EQ (qr.GetVal <double >(" Longitude" ), TEST_POSITION);
369+ }
370+
371+ } // namespace cycamore
0 commit comments