2#line 1 "/cycamore/src/mixer.cc"
10 : cyclus::Facility(ctx),
15 cyclus::Warn<cyclus::EXPERIMENTAL_WARNING>(
16 "the Mixer archetype is experimental");
21 cyclus::Inventories invs;
26 invs[
"output-inv-name"] =
output.PopNRes(
output.count());
27 output.Push(invs[
"output-inv-name"]);
29 std::map<std::string, cyclus::toolkit::ResBuf<cyclus::Material> >::iterator
32 invs[it->first] = it->second.PopNRes(it->second.count());
33 it->second.Push(invs[it->first]);
40 output.Push(inv[
"output-inv-name"]);
42 cyclus::Inventories::iterator it;
43 for (it = inv.begin(); it != inv.end(); ++it) {
49 cyclus::Facility::EnterNotify();
56 for (
int i = 0; i <
streams_.size(); i++) {
60 std::string name =
"in_stream_" + std::to_string(i);
71 ss <<
"prototype '" << prototype() <<
"' has " <<
mixing_ratios.size()
72 <<
" commodity fraction values, expected " <<
in_commods.size();
73 throw cyclus::ValidationError(ss.str());
76 double frac_sum = 0.0;
79 if (frac_sum != 1.0) {
81 ss <<
"prototype '" << prototype() <<
"': the sum of mixing fractions is "
82 "not 1, renormalization will be "
84 cyclus::Warn<cyclus::VALUE_WARNING>(ss.str());
102 double tgt_qty =
output.space();
105 std::string name =
"in_stream_" + std::to_string(i);
113 cyclus::Material::Ptr m;
115 std::string name =
"in_stream_" + std::to_string(i);
118 m =
streambufs[name].Pop(pop_qty, cyclus::eps_rsrc());
120 cyclus::Material::Ptr m_ =
121 streambufs[name].Pop(pop_qty, cyclus::eps_rsrc());
128 cyclus::toolkit::RecordTimeSeries<double>(
"supply"+
out_commod,
this,
output.quantity());
131std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
133 using cyclus::RequestPortfolio;
137 std::string name =
"in_stream_" + std::to_string(i);
138 std::map<std::string, double>::iterator it;
139 std::map<std::string, double>::iterator max_it =
in_commods[i].begin();
140 double prev_pref = 0;
143 cyclus::toolkit::RecordTimeSeries<double>(
"demand" + it->first,
this,
148 std::set<RequestPortfolio<cyclus::Material>::Ptr> ports;
151 std::string name =
"in_stream_" + std::to_string(i);
153 if (
streambufs[name].space() > cyclus::eps_rsrc()) {
154 RequestPortfolio<cyclus::Material>::Ptr port(
155 new RequestPortfolio<cyclus::Material>());
157 cyclus::Material::Ptr m;
158 m = cyclus::NewBlankMaterial(
streambufs[name].space());
160 std::vector<cyclus::Request<cyclus::Material>*> reqs;
162 std::map<std::string, double>::iterator it;
164 std::string commod = it->first;
165 double pref = it->second;
166 reqs.push_back(port->AddRequest(m,
this, commod , pref,
false));
169 port->AddMutualReqs(reqs);
177 const std::vector<std::pair<cyclus::Trade<cyclus::Material>,
178 cyclus::Material::Ptr> >& responses) {
179 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
180 cyclus::Material::Ptr> >::const_iterator trade;
182 for (trade = responses.begin(); trade != responses.end(); ++trade) {
183 cyclus::Request<cyclus::Material>* req = trade->first.request;
184 cyclus::Material::Ptr m = trade->second;
187 bool assigned =
false;
188 std::map<std::string, cyclus::toolkit::ResBuf<cyclus::Material> >::iterator
192 if (name == it->first) {
199 throw cyclus::ValueError(
"cycamore::Mixer was overmatched on requests");
207 std::string specification = spec();
209 ->NewDatum(
"AgentPosition")
210 ->AddVal(
"Spec", specification)
211 ->AddVal(
"Prototype", this->prototype())
212 ->AddVal(
"AgentId",
id())
219 return new Mixer(ctx);
Mixer mixes N streams with fixed, static, user-specified ratios into a single output stream.
std::map< std::string, cyclus::toolkit::ResBuf< cyclus::Material > > streambufs
std::map< cyclus::Request< cyclus::Material > *, std::string > req_inventories_
std::vector< double > mixing_ratios
void RecordPosition()
Records an agent's latitude and longitude to the output db.
virtual void EnterNotify()
cyclus::toolkit::MatlSellPolicy sell_policy
virtual cyclus::Inventories SnapshotInv()
virtual void InitInv(cyclus::Inventories &inv)
Mixer(cyclus::Context *ctx)
cyclus::toolkit::ResBuf< cyclus::Material > output
std::vector< std::map< std::string, double > > in_commods
virtual std::set< cyclus::RequestPortfolio< cyclus::Material >::Ptr > GetMatlRequests()
std::vector< double > in_buf_sizes
virtual void AcceptMatlTrades(const std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
std::vector< std::pair< std::pair< double, double >, std::map< std::string, double > > > streams_
cyclus::Agent * ConstructMixer(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates