CYCLUS
Loading...
Searching...
No Matches
product.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_PRODUCT_H_
2#define CYCLUS_SRC_PRODUCT_H_
3
4#include <boost/shared_ptr.hpp>
5
6#include "context.h"
7#include "resource.h"
8#include "res_tracker.h"
9
10class SimInitTest;
11
12namespace cyclus {
13
14/// A Product is a general type of resource in the Cyclus simulation,
15/// and is a catch-all for non-standard resources. It implements the Resource
16/// class interface in a simple way usable for things such as: bananas,
17/// man-hours, water, buying power, etc.
18class Product : public Resource {
19 friend class SimInit;
20 friend class ::SimInitTest;
21
22 public:
23 typedef boost::shared_ptr<Product> Ptr;
24 static const ResourceType kType;
25
26 /// Creates a new product that is "live" and tracked. creator is a
27 /// pointer to the agent creating the resource (usually will be the caller's
28 /// "this" pointer). All future output data recorded will be done using the
29 /// creator's context.
30 static Ptr Create(Agent* creator, double quantity, std::string quality,
32 double unit_value = kUnsetUnitValue);
33
34 /// Creates a new product that does not actually exist as part of
35 /// the simulation and is untracked.
36 static Ptr CreateUntracked(double quantity, std::string quality);
37
38 /// Returns 0 (for now).
39 virtual int qual_id() const { return qualids_[quality_]; }
40
41 /// Returns Product::kType.
42 virtual const ResourceType type() const { return kType; }
43
44 virtual Resource::Ptr Clone() const;
45
46 virtual void Record(Context* ctx) const {}
47
48 virtual std::string units() const { return "NONE"; }
49
50 virtual double quantity() const { return quantity_; }
51
52 /// Returns the quality of this resource (e.g. bananas, human labor, water,
53 /// etc.).
54 virtual const std::string& quality() const { return quality_; }
55
56 virtual Resource::Ptr ExtractRes(double quantity);
57
58 /// Extracts the specified mass from this resource and returns it as a
59 /// new product object with the same quality/type.
60 ///
61 /// @throws ValueError tried to extract more than exists.
63
64 /// Absorbs the contents of the given 'other' resource into this resource.
65 /// @throws ValueError 'other' resource is of different quality
66 void Absorb(Product::Ptr other);
67
68 /// Returns the package id.
69 virtual std::string package_name();
70
72 double qty, std::string new_package_name = Package::unpackaged_name());
73
74 /// Changes the product's package id
75 virtual void ChangePackage(
76 std::string new_package_name = Package::unpackaged_name());
77
78 private:
79 /// @param ctx the simulation context
80 /// @param quantity is a double indicating the quantity
81 /// @param quality the resource quality
82 Product(Context* ctx, double quantity, std::string quality,
84 double unit_value = kUnsetUnitValue);
85
86 // map<quality, quality_id>
87 static std::map<std::string, int> qualids_;
88 static int next_qualid_;
89
90 Context* ctx_;
91 std::string quality_;
92 double quantity_;
93 ResTracker tracker_;
94 std::string package_name_;
95};
96
97} // namespace cyclus
98
99#endif // CYCLUS_SRC_PRODUCT_H_
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:50
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:146
static std::string unpackaged_name()
Definition package.h:68
A Product is a general type of resource in the Cyclus simulation, and is a catch-all for non-standard...
Definition product.h:18
virtual Resource::Ptr Clone() const
Returns an untracked (not part of the simulation) copy of the resource.
Definition product.cc:43
virtual double quantity() const
Returns the quantity of this resource with dimensions as specified by the return value of units().
Definition product.h:50
virtual std::string units() const
Returns the units this resource is based in (e.g. "kg").
Definition product.h:48
virtual std::string package_name()
Returns the package id.
Definition product.cc:85
virtual int qual_id() const
Returns 0 (for now).
Definition product.h:39
boost::shared_ptr< Product > Ptr
Definition product.h:23
virtual const std::string & quality() const
Returns the quality of this resource (e.g.
Definition product.h:54
static Ptr CreateUntracked(double quantity, std::string quality)
Creates a new product that does not actually exist as part of the simulation and is untracked.
Definition product.cc:35
virtual Resource::Ptr PackageExtract(double qty, std::string new_package_name=Package::unpackaged_name())
Definition product.cc:90
friend class SimInit
Definition product.h:19
void Absorb(Product::Ptr other)
Absorbs the contents of the given 'other' resource into this resource.
Definition product.cc:51
virtual const ResourceType type() const
Returns Product::kType.
Definition product.h:42
static const ResourceType kType
Definition product.h:24
virtual void Record(Context *ctx) const
Records the resource's state to the output database.
Definition product.h:46
static Ptr Create(Agent *creator, double quantity, std::string quality, std::string package_name=Package::unpackaged_name(), double unit_value=kUnsetUnitValue)
Creates a new product that is "live" and tracked.
Definition product.cc:15
virtual void ChangePackage(std::string new_package_name=Package::unpackaged_name())
Changes the product's package id.
Definition product.cc:109
virtual Resource::Ptr ExtractRes(double quantity)
Splits the resource and returns the extracted portion as a new resource object.
Definition product.cc:81
Product::Ptr Extract(double quantity)
Extracts the specified mass from this resource and returns it as a new product object with the same q...
Definition product.cc:67
Tracks and records the state and parent-child relationships of resources as they are changed.
Definition res_tracker.h:21
static constexpr double kUnsetUnitValue
Definition resource.h:119
boost::shared_ptr< Resource > Ptr
Definition resource.h:27
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
std::string ResourceType
Definition resource.h:17