@@ -13,22 +13,22 @@ Source::Source(cyclus::Context* ctx)
13
13
inventory_size(std::numeric_limits<double >::max()),
14
14
latitude(0.0 ),
15
15
longitude(0.0 ),
16
+ package(cyclus::Package::unpackaged_name()),
17
+ transport_unit(cyclus::TransportUnit::unrestricted_name()),
16
18
coordinates(latitude, longitude) {}
17
19
18
20
Source::~Source () {}
19
21
20
22
void Source::InitFrom (Source* m) {
21
23
#pragma cyclus impl initfromcopy cycamore::Source
22
24
cyclus::toolkit::CommodityProducer::Copy (m);
23
- RecordPosition ();
24
25
}
25
26
26
27
void Source::InitFrom (cyclus::QueryableBackend* b) {
27
28
#pragma cyclus impl initfromdb cycamore::Source
28
29
namespace tk = cyclus::toolkit;
29
30
tk::CommodityProducer::Add (tk::Commodity (outcommod),
30
31
tk::CommodInfo (throughput, throughput));
31
- RecordPosition ();
32
32
}
33
33
34
34
std::string Source::str () {
@@ -47,18 +47,39 @@ std::string Source::str() {
47
47
<< " commod producer members: "
48
48
<< " produces " << outcommod << " ?: " << ans
49
49
<< " throughput: " << cyclus::toolkit::CommodityProducer::Capacity (outcommod)
50
+ << " with package type: " << package
51
+ << " and transport unit type: " << transport_unit
50
52
<< " cost: " << cyclus::toolkit::CommodityProducer::Cost (outcommod);
51
53
return ss.str ();
52
54
}
53
55
56
+ void Source::EnterNotify () {
57
+ using cyclus::CompMap;
58
+ using cyclus::Composition;
59
+ using cyclus::Material;
60
+ cyclus::Facility::EnterNotify ();
61
+ RecordPosition ();
62
+
63
+ // create all source inventory and place into buf
64
+ cyclus::Material::Ptr all_inv;
65
+ Composition::Ptr blank_comp = Composition::CreateFromMass (CompMap ());
66
+
67
+ all_inv = (outrecipe.empty () || context () == NULL ) ? \
68
+ Material::Create (this , inventory_size, blank_comp) : \
69
+ Material::Create (this , inventory_size, context ()->GetRecipe (outrecipe));
70
+ inventory.Push (all_inv);
71
+ }
72
+
54
73
std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr > Source::GetMatlBids (
55
74
cyclus::CommodMap<cyclus::Material>::type& commod_requests) {
56
75
using cyclus::BidPortfolio;
57
76
using cyclus::CapacityConstraint;
58
77
using cyclus::Material;
78
+ using cyclus::Package;
59
79
using cyclus::Request;
80
+ using cyclus::TransportUnit;
60
81
61
- double max_qty = std::min (throughput, inventory_size );
82
+ double max_qty = std::min (throughput, inventory. quantity () );
62
83
cyclus::toolkit::RecordTimeSeries<double >(" supply" +outcommod, this ,
63
84
max_qty);
64
85
LOG (cyclus::LEV_INFO3, " Source" ) << prototype () << " is bidding up to "
@@ -79,11 +100,35 @@ std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr> Source::GetMatlBids(
79
100
Request<Material>* req = *it;
80
101
Material::Ptr target = req->target ();
81
102
double qty = std::min (target->quantity (), max_qty);
82
- Material::Ptr m = Material::CreateUntracked (qty, target->comp ());
83
- if (!outrecipe.empty ()) {
84
- m = Material::CreateUntracked (qty, context ()->GetRecipe (outrecipe));
103
+
104
+ // calculate packaging
105
+ double bid_qty = context ()->GetPackage (package)->GetFillMass (qty);
106
+ int n_full_bids = static_cast <int >(std::floor (qty / bid_qty));
107
+ Package::ExceedsSplitLimits (n_full_bids);
108
+
109
+ std::vector<double > bids;
110
+ bids.assign (n_full_bids, bid_qty);
111
+
112
+ double remaining_qty = qty - (n_full_bids * bid_qty);
113
+ if ((remaining_qty > cyclus::eps ()) && (remaining_qty >= context ()->GetPackage (package)->fill_min ())) {
114
+ bids.push_back (remaining_qty);
115
+ }
116
+
117
+ // calculate transport units
118
+ int shippable_pkgs = context ()->GetTransportUnit (transport_unit)
119
+ ->MaxShippablePackages (bids.size ());
120
+ if (shippable_pkgs < bids.size ()) {
121
+ bids.erase (bids.begin () + shippable_pkgs, bids.end ());
122
+ }
123
+
124
+ std::vector<double >::iterator bit;
125
+ for (bit = bids.begin (); bit != bids.end (); ++bit) {
126
+ Material::Ptr m;
127
+ m = outrecipe.empty () ? \
128
+ Material::CreateUntracked (*bit, target->comp ()) : \
129
+ Material::CreateUntracked (*bit, context ()->GetRecipe (outrecipe));
130
+ port->AddBid (req, m, this );
85
131
}
86
- port->AddBid (req, m, this );
87
132
}
88
133
89
134
CapacityConstraint<Material> cc (max_qty);
@@ -99,20 +144,41 @@ void Source::GetMatlTrades(
99
144
using cyclus::Material;
100
145
using cyclus::Trade;
101
146
147
+ int shippable_trades = context ()->GetTransportUnit (transport_unit)
148
+ ->MaxShippablePackages (trades.size ());
149
+
102
150
std::vector<Trade<Material> >::const_iterator it;
103
151
for (it = trades.begin (); it != trades.end (); ++it) {
104
- double qty = it->amt ;
105
- inventory_size -= qty;
106
-
107
- Material::Ptr response;
108
- if (!outrecipe.empty ()) {
109
- response = Material::Create (this , qty, context ()->GetRecipe (outrecipe));
110
- } else {
111
- response = Material::Create (this , qty, it->request ->target ()->comp ());
152
+ if (shippable_trades > 0 ) {
153
+ double qty = it->amt ;
154
+
155
+ Material::Ptr m = inventory.Pop (qty);
156
+
157
+ std::vector<Material::Ptr > m_pkgd = m->Package <Material>(context ()->GetPackage (package));
158
+
159
+ if (m->quantity () > cyclus::eps ()) {
160
+ // If not all material is packaged successfully, return the excess
161
+ // amount to the inventory
162
+ inventory.Push (m);
163
+ }
164
+
165
+ Material::Ptr response;
166
+ if (m_pkgd.size () > 0 ) {
167
+ // Because we responded (in GetMatlBids) with individual package-sized
168
+ // bids, each packaged vector is guaranteed to have no more than one
169
+ // package in it. This single packaged resource is our response
170
+ response = m_pkgd[0 ];
171
+ shippable_trades -= 1 ;
172
+ }
173
+
174
+ if (outrecipe.empty () && response->comp () != it->request ->target ()->comp ()) {
175
+ response->Transmute (it->request ->target ()->comp ());
176
+ }
177
+
178
+ responses.push_back (std::make_pair (*it, response));
179
+ LOG (cyclus::LEV_INFO5, " Source" ) << prototype () << " sent an order"
180
+ << " for " << response->quantity () << " of " << outcommod;
112
181
}
113
- responses.push_back (std::make_pair (*it, response));
114
- LOG (cyclus::LEV_INFO5, " Source" ) << prototype () << " sent an order"
115
- << " for " << qty << " of " << outcommod;
116
182
}
117
183
}
118
184
0 commit comments