CYCLUS
Loading...
Searching...
No Matches
timeseries.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_TOOLKIT_TIMESERIES_H_
2#define CYCLUS_SRC_TOOLKIT_TIMESERIES_H_
3
4#include <functional>
5#include <map>
6#include <string>
7#include <vector>
8
9#include "boost/variant.hpp"
10#include "boost/variant/get.hpp"
11
12#include "agent.h"
13#include "any.hpp"
14#include "context.h"
15
16namespace cyclus {
17namespace toolkit {
18
19/// Time series types to be used in the RecordTimeSeries() functions.
20/// These types have the following units which *must* be adhered to strictly:
21/// - POWER [MWe]
22/// - ENRICH_SWU [kg SWU]
23/// - ENRICH_FEED [kg]
29
30/// Stores global information for the time series call backs.
31typedef boost::variant<
32 std::function<void(cyclus::Agent*, int, bool, std::string)>,
33 std::function<void(cyclus::Agent*, int, int, std::string)>,
34 std::function<void(cyclus::Agent*, int, float, std::string)>,
35 std::function<void(cyclus::Agent*, int, double, std::string)>,
36 std::function<void(cyclus::Agent*, int, std::string, std::string)>
38
39extern std::map<std::string, std::vector<time_series_listener_t>> TIME_SERIES_LISTENERS;
40
41/// Records a per-time step quantity for a given type
42template <TimeSeriesType T>
43void RecordTimeSeries(cyclus::Agent* agent, double value,
44 std::string units = "");
45
46/// Records a per-time step quantity for a string
47template <typename T>
48void RecordTimeSeries(std::string tsname, cyclus::Agent* agent, T value,
49 std::string units = "") {
50 std::string tblname = "TimeSeries" + tsname;
51 int time = agent->context()->time();
52 agent->context()
54 ->AddVal("AgentId", agent->id())
55 ->AddVal("Time", time)
56 ->AddVal("Value", value)
57 ->AddVal("Units", units)
58 ->Record();
59 std::vector<time_series_listener_t> vec = TIME_SERIES_LISTENERS[tsname];
60 for (auto f=vec.begin(); f != vec.end(); ++f){
61 std::function<void(cyclus::Agent*, int, T, std::string)> fn = boost::get<std::function<void(cyclus::Agent*, int, T, std::string)> >(*f);
62 fn(agent, time, value, tsname);
63 }
64 PyCallListeners(tsname, agent, agent->context(), time, value);
65}
66
67} // namespace toolkit
68} // namespace cyclus
69
70#endif // CYCLUS_SRC_TOOLKIT_TIMESERIES_H_
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
Context * context() const
Returns this agent's simulation context.
Definition agent.h:367
virtual const int id() const
The agent instance's unique ID within a simulation.
Definition agent.h:352
Datum * NewDatum(std::string title)
See Recorder::NewDatum documentation.
Definition context.cc:351
virtual int time()
Returns the current simulation timestep.
Definition context.cc:313
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:22
void Record()
Record this datum to its Recorder.
Definition datum.cc:35
TimeSeriesType
Time series types to be used in the RecordTimeSeries() functions.
Definition timeseries.h:24
void PyCallListeners(std::string tsname, Agent *agent, void *cpp_ctx, int time, boost::spirit::hold_any value)
Calls the Python listeners.
Definition pyhooks.cc:100
boost::variant< std::function< void(cyclus::Agent *, int, bool, std::string)>, std::function< void(cyclus::Agent *, int, int, std::string)>, std::function< void(cyclus::Agent *, int, float, std::string)>, std::function< void(cyclus::Agent *, int, double, std::string)>, std::function< void(cyclus::Agent *, int, std::string, std::string)> time_series_listener_t)
Stores global information for the time series call backs.
Definition timeseries.h:37
std::map< std::string, std::vector< time_series_listener_t > > TIME_SERIES_LISTENERS
Definition timeseries.cc:6
void RecordTimeSeries(cyclus::Agent *agent, double value, std::string units="")
Records a per-time step quantity for a given type.
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