CYCLUS
Loading...
Searching...
No Matches
cyclus::toolkit::ResBuf< T > Class Template Reference

Detailed Description

template<class T>
class cyclus::toolkit::ResBuf< T >

ResBuf is a helper class that provides semi-automated management of a collection of resources (e.g.

agent stocks and inventories). Constructed buffers have infinite capacity unless explicitly changed. Resource popping occurs in the order the resources were pushed (i.e. oldest resources are popped first), unless explicitly specified otherwise.

Typically, a ResBuf will be a member variable on an agent/archetype class. Resources can be added and retrieved from it as needed, and the buffer can be queried in various ways as done in the example below:

class MyAgent : public cyclus::Facility {
public:
Tick() {
double batch_size = 2703;
if (outventory_.space() < batch_size) {
return;
} else if (inventory_.quantity() < batch_size) {
return;
}
outventory_.Push(inventory_.Pop(batch_size));
}
... // resource exchange to fill up inventory_ buffer
private:
...
};
The Facility class is the abstract class/interface used by all facility agents.
Definition facility.h:68
ResBuf is a helper class that provides semi-automated management of a collection of resources (e....
Definition res_buf.h:62
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters

In this example, if there is sufficient material in inventory_, 2703 kg is removed as a single object that is then placed in another buffer (outventory_) each time step.

Definition at line 62 of file res_buf.h.

#include <res_buf.h>

Public Member Functions

double capacity () const
 
void capacity (double cap)
 
int count () const
 
void Decay (int curr_time=-1)
 
bool empty () const
 
bool keep_packaging () const
 
void keep_packaging (bool keep_packaging)
 
T::Ptr Peek ()
 
T::Ptr Pop ()
 
T::Ptr Pop (double qty)
 
T::Ptr Pop (double qty, double eps)
 
T::Ptr PopBack ()
 
std::vector< typename T::Ptr > PopN (int n)
 
ResVec PopNRes (int n)
 
std::vector< typename T::Ptr > PopVector (double qty)
 
void Push (Resource::Ptr r)
 
template<class B >
void Push (std::vector< B > rs)
 
double quantity () const
 
 ResBuf (bool is_bulk=false, bool keep_pkg=false)
 
double space () const
 
virtual ~ResBuf ()
 

Constructor & Destructor Documentation

◆ ResBuf()

template<class T >
cyclus::toolkit::ResBuf< T >::ResBuf ( bool is_bulk = false,
bool keep_pkg = false )
inline

Definition at line 64 of file res_buf.h.

◆ ~ResBuf()

template<class T >
virtual cyclus::toolkit::ResBuf< T >::~ResBuf ( )
inlinevirtual

Definition at line 69 of file res_buf.h.

Member Function Documentation

◆ capacity() [1/2]

template<class T >
double cyclus::toolkit::ResBuf< T >::capacity ( ) const
inline

Returns the maximum resource quantity this buffer can hold (units based on constituent resource objects' units).

Never throws.

Definition at line 74 of file res_buf.h.

◆ capacity() [2/2]

template<class T >
void cyclus::toolkit::ResBuf< T >::capacity ( double cap)
inline

Sets the maximum quantity this buffer can hold (units based on constituent resource objects' units).

Exceptions
ValueErrorthe new capacity is lower (by eps_rsrc()) than the quantity of resources that exist in the buffer.

Definition at line 81 of file res_buf.h.

◆ count()

template<class T >
int cyclus::toolkit::ResBuf< T >::count ( ) const
inline

Returns the total number of constituent resource objects in the buffer.

Never throws.

Definition at line 107 of file res_buf.h.

◆ Decay()

template<class T >
void cyclus::toolkit::ResBuf< T >::Decay ( int curr_time = -1)
inline

Decays all the materials in a resource buffer.

Parameters
curr_timetime to calculate decay inventory (default: -1 uses the current time of the context)

Definition at line 354 of file res_buf.h.

◆ empty()

template<class T >
bool cyclus::toolkit::ResBuf< T >::empty ( ) const
inline

Returns true if there are no resources in the buffer.

Definition at line 119 of file res_buf.h.

◆ keep_packaging() [1/2]

template<class T >
bool cyclus::toolkit::ResBuf< T >::keep_packaging ( ) const
inline

Definition at line 103 of file res_buf.h.

◆ keep_packaging() [2/2]

template<class T >
void cyclus::toolkit::ResBuf< T >::keep_packaging ( bool keep_packaging)
inline

Sets whether the buffer should keep packaged resources.

Definition at line 96 of file res_buf.h.

◆ Peek()

template<class T >
T::Ptr cyclus::toolkit::ResBuf< T >::Peek ( )
inline

Returns the next resource in line to be popped from the buffer without actually removing it from the buffer.

Definition at line 223 of file res_buf.h.

◆ Pop() [1/3]

template<class T >
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( )
inline

Pops one resource object from the buffer.

Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).

Exceptions
ValueErrorthe buffer is empty.

Definition at line 235 of file res_buf.h.

◆ Pop() [2/3]

template<class T >
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( double qty)
inline

Pops and returns the specified quantity from the buffer as a single resource object.

Resources are split if necessary in order to pop the exact quantity requested (within eps_rsrc()). Resources are retrieved in the order they were pushed (i.e. oldest first) and are squashed into a single object when returned.

Definition at line 171 of file res_buf.h.

◆ Pop() [3/3]

template<class T >
T::Ptr cyclus::toolkit::ResBuf< T >::Pop ( double qty,
double eps )
inline

Same behavior as Pop(double) except a non-zero eps may be specified.

eps is used only in cases where qty might be slightly larger than the buffer's current inventory quantity.

Definition at line 178 of file res_buf.h.

◆ PopBack()

template<class T >
T::Ptr cyclus::toolkit::ResBuf< T >::PopBack ( )
inline

Same as Pop, except it returns the most recently added resource.

Definition at line 249 of file res_buf.h.

◆ PopN()

template<class T >
std::vector< typename T::Ptr > cyclus::toolkit::ResBuf< T >::PopN ( int n)
inline

Pops the specified number of resource objects from the buffer.

Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).

Exceptions
ValueErrorthe specified n is larger than the buffer's current resource count or the specified number is negative.

Definition at line 198 of file res_buf.h.

◆ PopNRes()

template<class T >
ResVec cyclus::toolkit::ResBuf< T >::PopNRes ( int n)
inline

Same as PopN except returns the Resource-typed objects.

Definition at line 219 of file res_buf.h.

◆ PopVector()

template<class T >
std::vector< typename T::Ptr > cyclus::toolkit::ResBuf< T >::PopVector ( double qty)
inline

Pops and returns the specified quantity from the buffer as a vector of resources.

Resources are split if necessary in order to pop the exact quantity requested (within eps_rsrc()). Resources are retrieved in the order they were pushed (i.e. oldest first).

Exceptions
ValueErrorthe specified pop quantity is larger than the buffer's current inventory.

Definition at line 129 of file res_buf.h.

◆ Push() [1/2]

template<class T >
void cyclus::toolkit::ResBuf< T >::Push ( Resource::Ptr r)
inline

Pushes a single resource object to the buffer.

If not classified as a bulk storage buffer, resource objects are not combined in the buffer; they are stored as unique objects. The resource object is only pushed to the buffer if it does not cause the buffer to exceed its capacity.

Exceptions
ValueErrorthe pushing of the given resource object would cause the buffer to exceed its capacity.
KeyErrorthe resource object to be pushed is already present in the buffer.

Definition at line 272 of file res_buf.h.

◆ Push() [2/2]

template<class T >
template<class B >
void cyclus::toolkit::ResBuf< T >::Push ( std::vector< B > rs)
inline

Pushes one or more resource objects (as a std::vector) to the buffer.

If not classified as a bulk storage buffer, resource objects are not squashed in the buffer; they are stored as unique objects. The resource objects are only pushed to the buffer if they do not cause the buffer to exceed its capacity; otherwise none of the given resource objects are added to the buffer.

Exceptions
ValueErroradding the given resource objects would cause the buffer to exceed its capacity.
KeyErrorone or more of the resource objects to be added are already present in the buffer.

Definition at line 312 of file res_buf.h.

◆ quantity()

template<class T >
double cyclus::toolkit::ResBuf< T >::quantity ( ) const
inline

Returns the total resource quantity of constituent resource objects in the buffer.

Never throws.

Definition at line 111 of file res_buf.h.

◆ space()

template<class T >
double cyclus::toolkit::ResBuf< T >::space ( ) const
inline

Returns the quantity of space remaining in this buffer.

This is effectively the difference between the capacity and the quantity and is never negative. Never throws.

Definition at line 116 of file res_buf.h.


The documentation for this class was generated from the following file: