8 : cyclus::Facility(ctx),
13 cyclus::Warn<cyclus::EXPERIMENTAL_WARNING>(
14 "the Mixer archetype is experimental");
18cyclus::Inventories Mixer::SnapshotInv() {
19 cyclus::Inventories invs;
24 invs[
"output-inv-name"] = output.PopNRes(output.count());
25 output.Push(invs[
"output-inv-name"]);
27 std::map<std::string, cyclus::toolkit::ResBuf<cyclus::Material> >::iterator
29 for (it = streambufs.begin(); it != streambufs.end(); ++it) {
30 invs[it->first] = it->second.PopNRes(it->second.count());
31 it->second.Push(invs[it->first]);
36void Mixer::InitInv(cyclus::Inventories& inv) {
37 inv[
"output-inv-name"] = output.PopNRes(output.count());
38 output.Push(inv[
"output-inv-name"]);
40 cyclus::Inventories::iterator it;
41 for (it = inv.begin(); it != inv.end(); ++it) {
42 streambufs[it->first].Push(it->second);
46void Mixer::EnterNotify() {
47 cyclus::Facility::EnterNotify();
49 mixing_ratios.clear();
54 for (
int i = 0; i < streams_.size(); i++) {
55 mixing_ratios.push_back(streams_[i].first.first);
56 in_buf_sizes.push_back(streams_[i].first.second);
58 std::string name =
"in_stream_" + std::to_string(i);
59 double cap = in_buf_sizes[i];
61 streambufs[name].capacity(cap);
63 in_commods.push_back(streams_[i].second);
67 if (mixing_ratios.size() != in_commods.size()) {
69 ss <<
"prototype '" << prototype() <<
"' has " << mixing_ratios.size()
70 <<
" commodity fraction values, expected " << in_commods.size();
71 throw cyclus::ValidationError(ss.str());
74 double frac_sum = 0.0;
75 for (
int i = 0; i < mixing_ratios.size(); i++) frac_sum += mixing_ratios[i];
77 if (frac_sum != 1.0) {
79 ss <<
"prototype '" << prototype() <<
"': the sum of mixing fractions is "
80 "not 1, renormalization will be "
82 cyclus::Warn<cyclus::VALUE_WARNING>(ss.str());
85 for (
int i = 0; i < mixing_ratios.size(); i++) {
86 mixing_ratios[i] *= 1.0 / frac_sum;
89 for (
int i = 0; i < mixing_ratios.size(); i++) {
90 mixing_ratios[i] = 1.0 / (mixing_ratios.size());
95 sell_policy.Init(
this, &output,
"output").Set(out_commod).Start();
99 if (output.quantity() < output.capacity()) {
100 double tgt_qty = output.space();
102 for (
int i = 0; i < mixing_ratios.size(); i++) {
103 std::string name =
"in_stream_" + std::to_string(i);
105 std::min(tgt_qty, streambufs[name].quantity() / mixing_ratios[i]);
108 tgt_qty = std::min(tgt_qty, throughput);
111 cyclus::Material::Ptr m;
112 for (
int i = 0; i < mixing_ratios.size(); i++) {
113 std::string name =
"in_stream_" + std::to_string(i);
114 double pop_qty = mixing_ratios[i] * tgt_qty;
116 m = streambufs[name].Pop(pop_qty, cyclus::eps_rsrc());
118 cyclus::Material::Ptr m_ =
119 streambufs[name].Pop(pop_qty, cyclus::eps_rsrc());
126 cyclus::toolkit::RecordTimeSeries<double>(
"supply"+out_commod,
this, output.quantity());
129std::set<cyclus::RequestPortfolio<cyclus::Material>::Ptr>
130Mixer::GetMatlRequests() {
131 using cyclus::RequestPortfolio;
133 for (
int i = 0; i < mixing_ratios.size(); i++)
135 std::string name =
"in_stream_" + std::to_string(i);
136 std::map<std::string, double>::iterator it;
137 std::map<std::string, double>::iterator max_it = in_commods[i].begin();
138 double prev_pref = 0;
139 for (it = in_commods[i].begin(); it != in_commods[i].end(); it++)
141 cyclus::toolkit::RecordTimeSeries<double>(
"demand" + it->first,
this,
142 streambufs[name].space());
146 std::set<RequestPortfolio<cyclus::Material>::Ptr> ports;
148 for (
int i = 0; i < in_commods.size(); i++) {
149 std::string name =
"in_stream_" + std::to_string(i);
151 if (streambufs[name].space() > cyclus::eps_rsrc()) {
152 RequestPortfolio<cyclus::Material>::Ptr port(
153 new RequestPortfolio<cyclus::Material>());
155 cyclus::Material::Ptr m;
156 m = cyclus::NewBlankMaterial(streambufs[name].space());
158 std::vector<cyclus::Request<cyclus::Material>*> reqs;
160 std::map<std::string, double>::iterator it;
161 for (it = in_commods[i].begin() ; it != in_commods[i].end(); it++) {
162 std::string commod = it->first;
163 double pref = it->second;
164 reqs.push_back(port->AddRequest(m,
this, commod , pref,
false));
165 req_inventories_[reqs.back()] = name;
167 port->AddMutualReqs(reqs);
174void Mixer::AcceptMatlTrades(
175 const std::vector<std::pair<cyclus::Trade<cyclus::Material>,
176 cyclus::Material::Ptr> >& responses) {
177 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
178 cyclus::Material::Ptr> >::const_iterator trade;
180 for (trade = responses.begin(); trade != responses.end(); ++trade) {
181 cyclus::Request<cyclus::Material>* req = trade->first.request;
182 cyclus::Material::Ptr m = trade->second;
184 std::string name = req_inventories_[req];
185 bool assigned =
false;
186 std::map<std::string, cyclus::toolkit::ResBuf<cyclus::Material> >::iterator
189 for (it = streambufs.begin(); it != streambufs.end(); it++) {
190 if (name == it->first) {
197 throw cyclus::ValueError(
"cycamore::Mixer was overmatched on requests");
201 req_inventories_.clear();
204void Mixer::RecordPosition() {
205 std::string specification = spec();
207 ->NewDatum(
"AgentPosition")
208 ->AddVal(
"Spec", specification)
209 ->AddVal(
"Prototype", this->prototype())
210 ->AddVal(
"AgentId",
id())
211 ->AddVal(
"Latitude", latitude)
212 ->AddVal(
"Longitude", longitude)
217 return new Mixer(ctx);
Mixer(cyclus::Context *ctx)
void RecordPosition()
Records an agent's latitude and longitude to the output db.
cyclus::Agent * ConstructMixer(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates