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
24 boost::shared_ptr<Product> Ptr;
25 static const ResourceType kType;
26
27 /// Creates a new product that is "live" and tracked. creator is a
28 /// pointer to the agent creating the resource (usually will be the caller's
29 /// "this" pointer). All future output data recorded will be done using the
30 /// creator's context.
31 static Ptr Create(Agent* creator, double quantity, std::string quality, std::string package_name = Package::unpackaged_name());
32
33 /// Creates a new product that does not actually exist as part of
34 /// the simulation and is untracked.
35 static Ptr CreateUntracked(double quantity, std::string quality);
36
37 /// Returns 0 (for now).
38 virtual int qual_id() const {
39 return qualids_[quality_];
40 }
41
42 /// Returns Product::kType.
43 virtual const ResourceType type() const {
44 return kType;
45 }
46
47 virtual Resource::Ptr Clone() const;
48
49 virtual void Record(Context* ctx) const {}
50
51 virtual std::string units() const { return "NONE"; }
52
53 virtual double quantity() const {
54 return quantity_;
55 }
56
57 /// Returns the quality of this resource (e.g. bananas, human labor, water, etc.).
58 virtual const std::string& quality() const {
59 return quality_;
60 }
61
62 virtual Resource::Ptr ExtractRes(double quantity);
63
64 /// Extracts the specified mass from this resource and returns it as a
65 /// new product object with the same quality/type.
66 ///
67 /// @throws ValueError tried to extract more than exists.
69
70 /// Absorbs the contents of the given 'other' resource into this resource.
71 /// @throws ValueError 'other' resource is of different quality
73
74 /// Returns the package id.
75 virtual std::string package_name();
76
77 virtual Resource::Ptr PackageExtract(double qty, std::string new_package_name = Package::unpackaged_name());
78
79 /// Changes the product's package id
80 virtual void ChangePackage(std::string new_package_name = Package::unpackaged_name());
81
82 private:
83 /// @param ctx the simulation context
84 /// @param quantity is a double indicating the quantity
85 /// @param quality the resource quality
86 Product(Context* ctx, double quantity, std::string quality,
88
89 // map<quality, quality_id>
90 static std::map<std::string, int> qualids_;
91 static int next_qualid_;
92
93 Context* ctx_;
94 std::string quality_;
95 double quantity_;
96 ResTracker tracker_;
97 std::string package_name_;
98};
99
100} // namespace cyclus
101
102#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:49
A simulation context provides access to necessary simulation-global functions and state.
Definition context.h:145
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:40
virtual double quantity() const
Returns the quantity of this resource with dimensions as specified by the return value of units().
Definition product.h:53
virtual std::string units() const
Returns the units this resource is based in (e.g. "kg").
Definition product.h:51
static Ptr Create(Agent *creator, double quantity, std::string quality, std::string package_name=Package::unpackaged_name())
Creates a new product that is "live" and tracked.
Definition product.cc:15
virtual std::string package_name()
Returns the package id.
Definition product.cc:76
virtual int qual_id() const
Returns 0 (for now).
Definition product.h:38
boost::shared_ptr< Product > Ptr
Definition product.h:24
virtual const std::string & quality() const
Returns the quality of this resource (e.g. bananas, human labor, water, etc.).
Definition product.h:58
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:32
virtual Resource::Ptr PackageExtract(double qty, std::string new_package_name=Package::unpackaged_name())
Definition product.cc:80
void Absorb(Product::Ptr other)
Absorbs the contents of the given 'other' resource into this resource.
Definition product.cc:48
virtual const ResourceType type() const
Returns Product::kType.
Definition product.h:43
static const ResourceType kType
Definition product.h:25
virtual void Record(Context *ctx) const
Records the resource's state to the output database.
Definition product.h:49
virtual void ChangePackage(std::string new_package_name=Package::unpackaged_name())
Changes the product's package id.
Definition product.cc:97
virtual Resource::Ptr ExtractRes(double quantity)
Splits the resource and returns the extracted portion as a new resource object.
Definition product.cc:72
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:59
Tracks and records the state and parent-child relationships of resources as they are changed.
Definition res_tracker.h:21
Resource defines an abstract interface implemented by types that are offered, requested,...
Definition resource.h:22
boost::shared_ptr< Resource > Ptr
Definition resource.h:27
Handles initialization of a simulation from the output database.
Definition sim_init.h:24
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::string ResourceType
Definition resource.h:17