5#include <boost/lexical_cast.hpp>
13 : cyclus::Facility(ctx),
14 capacity(std::numeric_limits<double>::max()),
19 SetMaxInventorySize(std::numeric_limits<double>::max());}
24#pragma cyclus def schema cycamore::Sink
26#pragma cyclus def annotations cycamore::Sink
28#pragma cyclus def infiletodb cycamore::Sink
30#pragma cyclus def snapshot cycamore::Sink
32#pragma cyclus def snapshotinv cycamore::Sink
34#pragma cyclus def initinv cycamore::Sink
36#pragma cyclus def clone cycamore::Sink
38#pragma cyclus def initfromdb cycamore::Sink
40#pragma cyclus def initfromcopy cycamore::Sink
43void Sink::EnterNotify() {
44 cyclus::Facility::EnterNotify();
45 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
" using random behavior " << random_size_type;
47 inventory.keep_packaging(keep_packaging);
49 if (in_commod_prefs.size() == 0) {
50 for (
int i = 0; i < in_commods.size(); ++i) {
51 in_commod_prefs.push_back(cyclus::kDefaultPref);
53 }
else if (in_commod_prefs.size() != in_commods.size()) {
55 ss <<
"in_commod_prefs has " << in_commod_prefs.size()
56 <<
" values, expected " << in_commods.size();
57 throw cyclus::ValueError(ss.str());
64 if (random_size_type !=
"None") {
65 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
66 <<
" is using random behavior "
68 <<
" for determining request size.";
70 if (random_frequency_type !=
"None") {
71 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
72 <<
" is using random behavior "
73 << random_frequency_type
74 <<
" for determining request frequency.";
80std::string Sink::str() {
84 ss << cyclus::Facility::str();
87 msg +=
"accepts commodities ";
88 for (vector<string>::iterator commod = in_commods.begin();
89 commod != in_commods.end();
91 msg += (commod == in_commods.begin() ?
"{" :
", ");
94 msg +=
"} until its inventory is full at ";
95 ss << msg << inventory.capacity() <<
" kg.";
100std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
101Sink::GetMatlRequests() {
102 using cyclus::Material;
103 using cyclus::RequestPortfolio;
104 using cyclus::Request;
105 using cyclus::Composition;
107 std::set<RequestPortfolio<Material>::Ptr> ports;
108 RequestPortfolio<Material>::Ptr port(
new RequestPortfolio<Material>());
112 if (requestAmt > SpaceAvailable()) {
116 if (recipe_name.empty()) {
117 mat = cyclus::NewBlankMaterial(requestAmt);
119 Composition::Ptr rec = this->context()->GetRecipe(recipe_name);
120 mat = cyclus::Material::CreateUntracked(requestAmt, rec);
123 if (requestAmt > cyclus::eps()) {
124 std::vector<Request<Material>*> mutuals;
125 for (
int i = 0; i < in_commods.size(); i++) {
126 mutuals.push_back(port->AddRequest(mat,
this, in_commods[i], in_commod_prefs[i]));
129 port->AddMutualReqs(mutuals);
136std::set<cyclus::RequestPortfolio<cyclus::Product>::Ptr>
137Sink::GetGenRsrcRequests() {
138 using cyclus::CapacityConstraint;
139 using cyclus::Product;
140 using cyclus::RequestPortfolio;
142 std::set<RequestPortfolio<Product>::Ptr> ports;
143 RequestPortfolio<Product>::Ptr
144 port(
new RequestPortfolio<Product>());
146 if (requestAmt > cyclus::eps()) {
147 CapacityConstraint<Product> cc(requestAmt);
148 port->AddConstraint(cc);
150 std::vector<std::string>::const_iterator it;
151 for (it = in_commods.begin(); it != in_commods.end(); ++it) {
152 std::string quality =
"";
153 Product::Ptr rsrc = Product::CreateUntracked(requestAmt, quality);
154 port->AddRequest(rsrc,
this, *it);
163void Sink::AcceptMatlTrades(
164 const std::vector< std::pair<cyclus::Trade<cyclus::Material>,
165 cyclus::Material::Ptr> >& responses) {
166 std::vector< std::pair<cyclus::Trade<cyclus::Material>,
167 cyclus::Material::Ptr> >::const_iterator it;
168 for (it = responses.begin(); it != responses.end(); ++it) {
169 inventory.Push(it->second);
174void Sink::AcceptGenRsrcTrades(
175 const std::vector< std::pair<cyclus::Trade<cyclus::Product>,
176 cyclus::Product::Ptr> >& responses) {
177 std::vector< std::pair<cyclus::Trade<cyclus::Product>,
178 cyclus::Product::Ptr> >::const_iterator it;
179 for (it = responses.begin(); it != responses.end(); ++it) {
180 inventory.Push(it->second);
188 LOG(cyclus::LEV_INFO3,
"SnkFac") <<
"Sink " << this->id() <<
" is ticking {";
190 if (nextBuyTime == -1) {
193 else if (nextBuyTime == context()->time()) {
197 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
198 <<
" has reached buying time. The next buy time will be time step " << nextBuyTime;
205 if (requestAmt > cyclus::eps()) {
206 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
207 <<
" has request amount " << requestAmt
208 <<
" kg of " << in_commods[0] <<
".";
209 for (vector<string>::iterator commod = in_commods.begin();
210 commod != in_commods.end();
212 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
213 <<
" will request " << requestAmt
214 <<
" kg of " << *commod <<
".";
215 cyclus::toolkit::RecordTimeSeries<double>(
"demand"+*commod,
this,
219 LOG(cyclus::LEV_INFO3,
"SnkFac") <<
"}";
224 LOG(cyclus::LEV_INFO3,
"SnkFac") << prototype() <<
" is tocking {";
229 LOG(cyclus::LEV_INFO4,
"SnkFac") <<
"Sink " << this->id()
230 <<
" is holding " << inventory.quantity()
231 <<
" units of material at the close of timestep "
232 << context()->time() <<
".";
233 LOG(cyclus::LEV_INFO3,
"SnkFac") <<
"}";
236void Sink::RecordPosition() {
237 std::string specification = this->spec();
239 ->NewDatum(
"AgentPosition")
240 ->AddVal(
"Spec", specification)
241 ->AddVal(
"Prototype", this->prototype())
242 ->AddVal(
"AgentId",
id())
243 ->AddVal(
"Latitude", latitude)
244 ->AddVal(
"Longitude", longitude)
248void Sink::SetRequestAmt() {
249 double amt = SpaceAvailable();
250 if (amt < cyclus::eps()) {
254 if (random_size_type ==
"None") {
257 else if (random_size_type ==
"UniformReal") {
258 requestAmt = context()->random_uniform_real(0, amt);
260 else if (random_size_type ==
"NormalReal") {
261 requestAmt = context()->random_normal_real(amt * random_size_mean,
262 amt * random_size_stddev,
271void Sink::SetNextBuyTime() {
272 if (random_frequency_type ==
"None") {
275 else if (random_frequency_type ==
"UniformInt") {
276 nextBuyTime = context()->time() + context()->random_uniform_int(random_frequency_min, random_frequency_max);
278 else if (random_frequency_type ==
"NormalInt") {
279 nextBuyTime = context()->time() + context()->random_normal_int(random_frequency_mean, random_frequency_stddev, random_frequency_min, random_frequency_max);
288extern "C" cyclus::Agent*
ConstructSink(cyclus::Context* ctx) {
289 return new Sink(ctx);
Sink(cyclus::Context *ctx)
void RecordPosition()
Records an agent's latitude and longitude to the output db.
cyclus::Agent * ConstructSink(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates