CYCAMORE
src/source.cc
Go to the documentation of this file.
1 #include "source.h"
2 
3 #include <sstream>
4 #include <limits>
5 
6 #include <boost/lexical_cast.hpp>
7 
8 namespace cycamore {
9 
10 Source::Source(cyclus::Context* ctx)
11  : cyclus::Facility(ctx),
12  throughput(std::numeric_limits<double>::max()),
13  inventory_size(std::numeric_limits<double>::max()) {}
14 
15 Source::~Source() {}
16 
17 void Source::InitFrom(Source* m) {
18  #pragma cyclus impl initfromcopy cycamore::Source
19  cyclus::toolkit::CommodityProducer::Copy(m);
20 }
21 
22 void Source::InitFrom(cyclus::QueryableBackend* b) {
23  #pragma cyclus impl initfromdb cycamore::Source
24  namespace tk = cyclus::toolkit;
25  tk::CommodityProducer::Add(tk::Commodity(outcommod),
26  tk::CommodInfo(throughput, throughput));
27 }
28 
30  namespace tk = cyclus::toolkit;
31  std::stringstream ss;
32  std::string ans;
33  if (cyclus::toolkit::CommodityProducer::Produces(
34  cyclus::toolkit::Commodity(outcommod))) {
35  ans = "yes";
36  } else {
37  ans = "no";
38  }
39  ss << cyclus::Facility::str() << " supplies commodity '" << outcommod
40  << "' with recipe '" << outrecipe << "' at a throughput of "
41  << throughput << " kg per time step "
42  << " commod producer members: "
43  << " produces " << outcommod << "?: " << ans
44  << " throughput: " << cyclus::toolkit::CommodityProducer::Capacity(outcommod)
45  << " cost: " << cyclus::toolkit::CommodityProducer::Cost(outcommod);
46  return ss.str();
47 }
48 
49 std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr> Source::GetMatlBids(
50  cyclus::CommodMap<cyclus::Material>::type& commod_requests) {
51  using cyclus::Bid;
52  using cyclus::BidPortfolio;
53  using cyclus::CapacityConstraint;
54  using cyclus::Material;
55  using cyclus::Request;
56 
57  double max_qty = std::min(throughput, inventory_size);
58  LOG(cyclus::LEV_INFO3, "Source") << prototype() << " is bidding up to "
59  << max_qty << " kg of " << outcommod;
60  LOG(cyclus::LEV_INFO5, "Source") << "stats: " << str();
61 
62  std::set<BidPortfolio<Material>::Ptr> ports;
63  if (max_qty < cyclus::eps()) {
64  return ports;
65  } else if (commod_requests.count(outcommod) == 0) {
66  return ports;
67  }
68 
69  BidPortfolio<Material>::Ptr port(new BidPortfolio<Material>());
70  std::vector<Request<Material>*>& requests = commod_requests[outcommod];
71  std::vector<Request<Material>*>::iterator it;
72  for (it = requests.begin(); it != requests.end(); ++it) {
73  Request<Material>* req = *it;
74  Material::Ptr target = req->target();
75  double qty = std::min(target->quantity(), max_qty);
76  Material::Ptr m = Material::CreateUntracked(qty, target->comp());
77  if (!outrecipe.empty()) {
78  m = Material::CreateUntracked(qty, context()->GetRecipe(outrecipe));
79  }
80  port->AddBid(req, m, this);
81  }
82 
83  CapacityConstraint<Material> cc(max_qty);
84  port->AddConstraint(cc);
85  ports.insert(port);
86  return ports;
87 }
88 
90  const std::vector<cyclus::Trade<cyclus::Material> >& trades,
91  std::vector<std::pair<cyclus::Trade<cyclus::Material>,
92  cyclus::Material::Ptr> >& responses) {
93  using cyclus::Material;
94  using cyclus::Trade;
95 
96  std::vector<cyclus::Trade<cyclus::Material> >::const_iterator it;
97  for (it = trades.begin(); it != trades.end(); ++it) {
98  double qty = it->amt;
99  inventory_size -= qty;
100 
101  Material::Ptr response;
102  if (!outrecipe.empty()) {
103  response = Material::Create(this, qty, context()->GetRecipe(outrecipe));
104  } else {
105  response = Material::Create(this, qty, it->request->target()->comp());
106  }
107  responses.push_back(std::make_pair(*it, response));
108  LOG(cyclus::LEV_INFO5, "Source") << prototype() << " sent an order"
109  << " for " << qty << " of " << outcommod;
110  }
111 }
112 
113 extern "C" cyclus::Agent* ConstructSource(cyclus::Context* ctx) {
114  return new Source(ctx);
115 }
116 
117 } // namespace cycamore
cyclus::Agent * ConstructSource(cyclus::Context *ctx)
virtual std::set< cyclus::BidPortfolio< cyclus::Material >::Ptr > GetMatlBids(cyclus::CommodMap< cyclus::Material >::type &commod_requests)
home mouginot work app cyclus cycamore _tmp_build cycamore reactor cc
cycamore::GrowthRegion string
virtual std::string str()
virtual void InitFrom(Source *m)
Source(cyclus::Context *ctx)
virtual void GetMatlTrades(const std::vector< cyclus::Trade< cyclus::Material > > &trades, std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)