CYCLUS
Loading...
Searching...
No Matches
res_tracker.cc
Go to the documentation of this file.
1#include "res_tracker.h"
2
3#include "recorder.h"
4#include "cyc_limits.h"
5
6namespace cyclus {
7
9 : tracked_(true), res_(r), ctx_(ctx), parent1_(0), parent2_(0) {}
10
12 tracked_ = false;
13}
14
15void ResTracker::Create(Agent* creator) {
16 if (!tracked_) {
17 return;
18 }
19
20 parent1_ = 0;
21 parent2_ = 0;
22 bool bumpId = false;
23 Record(bumpId);
24 ctx_->NewDatum("ResCreators")
25 ->AddVal("ResourceId", res_->state_id())
26 ->AddVal("AgentId", creator->id())
27 ->Record();
28}
29
31 if (!tracked_) {
32 return;
33 }
34
35 parent1_ = res_->state_id();
36 parent2_ = 0;
37 Record();
38}
39
41 if (!tracked_) {
42 return;
43 }
44
45 if (res_->quantity() > eps_rsrc()) {
46 parent1_ = res_->state_id();
47 parent2_ = 0;
48 }
49
50 // removed parent must be set before the resource is recorded, otherwise
51 // removed ends up with parent1 of the other child (which is this resource
52 // after being bumped)
53 removed->parent1_ = res_->state_id();
54 removed->parent2_ = 0;
55 removed->tracked_ = tracked_;
56 removed->Record();
57
58 if (res_->quantity() > eps_rsrc()) {
59 Record();
60 }
61}
62
64 if (!tracked_) {
65 return;
66 }
67
68 parent1_ = res_->state_id();
69 parent2_ = absorbed->res_->state_id();
70 Record();
71}
72
74 if (!tracked_) {
75 return;
76 }
77 parent2_ = 0;
78 tracked_ = tracked_;
79 package_name_ = res_->package_name();
80
81 if (parent != NULL) {
82 parent1_ = parent->res_->state_id();
83
84 // Resource was just created, with packaging info, and assigned a state id.
85 // Do not need to bump again
86 bool bumpId = false;
87 Record(bumpId);
88 } else {
89 // Resource was not just created. It is being re-packaged. It needs to be
90 // bumped to get a new state id.
91 parent1_ = res_->state_id();
92 Record();
93 }
94}
95
96void ResTracker::Record(bool bumpId) {
97 if (bumpId) {
98 res_->BumpStateId();
99 }
100 ctx_->NewDatum("Resources")
101 ->AddVal("ResourceId", res_->state_id())
102 ->AddVal("ObjId", res_->obj_id())
103 ->AddVal("Type", res_->type())
104 ->AddVal("TimeCreated", ctx_->time())
105 ->AddVal("Quantity", res_->quantity())
106 ->AddVal("Units", res_->units())
107 ->AddVal("UnitValue", res_->UnitValue())
108 ->AddVal("QualId", res_->qual_id())
109 ->AddVal("PackageName", res_->package_name())
110 ->AddVal("Parent1", parent1_)
111 ->AddVal("Parent2", parent2_)
112 ->Record();
113 res_->Record(ctx_);
114}
115
116} // namespace cyclus
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:50
virtual const int id() const
The agent instance's unique ID within a simulation.
Definition agent.h:349
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:146
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition context.cc:351
virtual int time()
Returns the current simulation timestep.
Definition context.cc:314
Datum * AddVal(const char *field, boost::spirit::hold_any val, std::vector< int > *shape=NULL)
Add an arbitrary field-value pair to the datum.
Definition datum.cc:21
void Record()
Record this datum to its Recorder.
Definition datum.cc:34
void Create(Agent *creator)
Should be called when a resource instance is newly created.
void Modify()
Should be called when the state of a resource changes (e.g.
void Extract(ResTracker *removed)
Should be called when a resource has some quantity removed from it (e.g.
void Package(ResTracker *parent=NULL)
Should be called when a resource's package gets modified.
void Absorb(ResTracker *absorbed)
Should be called when a resource is combined with another.
ResTracker(Context *ctx, Resource *r)
Create a new tracker following r.
Definition res_tracker.cc:8
void DontTrack()
Prevent a resource's heritage from being tracked and recorded.
Resource defines an abstract interface implemented by types that are offered, requested,...
Definition resource.h:22
double UnitValue() const
Returns the unit value of this resource.
Definition resource.h:40
const int state_id() const
Returns the unique id corresponding to this resource and its current state.
Definition resource.h:49
virtual const ResourceType type() const =0
A unique type/name for the concrete resource implementation.
virtual std::string units() const =0
Returns the units this resource is based in (e.g. "kg").
virtual void Record(Context *ctx) const =0
Records the resource's state to the output database.
virtual double quantity() const =0
Returns the quantity of this resource with dimensions as specified by the return value of units().
const int obj_id() const
Returns the unique id corresponding to this resource object.
Definition resource.h:37
virtual std::string package_name()
Returns the package id.
Definition resource.h:105
void BumpStateId()
Assigns a new, unique internal id to this resource and its state.
Definition resource.cc:8
virtual int qual_id() const =0
Returns an id representing the specific resource implementation's internal state that is not accessib...
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
double eps_rsrc()
an epsilon value to be used by resources
Definition cyc_limits.h:19