CYCAMORE
Loading...
Searching...
No Matches
src/deploy_inst.cc
Go to the documentation of this file.
1// Implements the DeployInst class
2#include "deploy_inst.h"
3
4namespace cycamore {
5
6DeployInst::DeployInst(cyclus::Context* ctx)
7 : cyclus::Institution(ctx) {}
8
9DeployInst::~DeployInst() {}
10
11void DeployInst::Build(cyclus::Agent* parent) {
12 cyclus::Institution::Build(parent);
13 BuildSched::iterator it;
14 std::set<std::string> protos;
15 for (int i = 0; i < prototypes.size(); i++) {
16 std::string proto = prototypes[i];
17
18 std::stringstream ss;
19 ss << proto;
20
21 if (lifetimes.size() == prototypes.size()) {
22 cyclus::Agent* a = context()->CreateAgent<Agent>(proto);
23 if (a->lifetime() != lifetimes[i]) {
24 a->lifetime(lifetimes[i]);
25
26 if (lifetimes[i] == -1) {
27 ss << "_life_forever";
28 } else {
29 ss << "_life_" << lifetimes[i];
30 }
31 proto = ss.str();
32 if (protos.count(proto) == 0) {
33 protos.insert(proto);
34 context()->AddPrototype(proto, a);
35 }
36 }
37 }
38
39 int t = build_times[i];
40 for (int j = 0; j < n_build[i]; j++) {
41 context()->SchedBuild(this, proto, t);
42 }
43 }
44}
45
46void DeployInst::EnterNotify() {
47 cyclus::Institution::EnterNotify();
48 int n = prototypes.size();
49 if (build_times.size() != n) {
50 std::stringstream ss;
51 ss << "prototype '" << prototype() << "' has " << build_times.size()
52 << " build_times vals, expected " << n;
53 throw cyclus::ValueError(ss.str());
54 } else if (n_build.size() != n) {
55 std::stringstream ss;
56 ss << "prototype '" << prototype() << "' has " << n_build.size()
57 << " n_build vals, expected " << n;
58 throw cyclus::ValueError(ss.str());
59 } else if (lifetimes.size() > 0 && lifetimes.size() != n) {
60 std::stringstream ss;
61 ss << "prototype '" << prototype() << "' has " << lifetimes.size()
62 << " lifetimes vals, expected " << n;
63 throw cyclus::ValueError(ss.str());
64 }
65
66 InitializePosition();
67}
68
69void DeployInst::BuildNotify(Agent* a) {
70 Register_(a);
71}
72
73void DeployInst::DecomNotify(Agent* a) {
74 Unregister_(a);
75}
76
77void DeployInst::Register_(Agent* a) {
78 using cyclus::toolkit::CommodityProducer;
79 using cyclus::toolkit::CommodityProducerManager;
80
81 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
82 if (cp_cast != NULL) {
83 LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
84 << a->prototype() << a->id()
85 << " as a commodity producer.";
86 CommodityProducerManager::Register(cp_cast);
87 }
88}
89
90void DeployInst::Unregister_(Agent* a) {
91 using cyclus::toolkit::CommodityProducer;
92 using cyclus::toolkit::CommodityProducerManager;
93
94 CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
95 if (cp_cast != NULL)
96 CommodityProducerManager::Unregister(cp_cast);
97}
98
99// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100void DeployInst::WriteProducerInformation(
101 cyclus::toolkit::CommodityProducer* producer) {
102 using std::set;
103 set<cyclus::toolkit::Commodity,
104 cyclus::toolkit::CommodityCompare> commodities =
105 producer->ProducedCommodities();
106 set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
107 iterator it;
108
109 LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
110 << " commodities.";
111 for (it = commodities.begin(); it != commodities.end(); it++) {
112 LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
113 LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
114 producer->Capacity(*it);
115 LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
116 producer->Cost(*it);
117 }
118}
119
120extern "C" cyclus::Agent* ConstructDeployInst(cyclus::Context* ctx) {
121 return new DeployInst(ctx);
122}
123
124} // namespace cycamore
DeployInst(cyclus::Context *ctx)
cyclus::Agent * ConstructDeployInst(cyclus::Context *ctx)
void Unregister_(cyclus::Agent *agent)
unregister a child
void Register_(cyclus::Agent *agent)
register a child