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>>
41
42/// Records a per-time step quantity for a given type
43template <TimeSeriesType T>
44void RecordTimeSeries(cyclus::Agent* agent, double value,
45 std::string units = "");
46
47/// Records a per-time step quantity for a string
48template <typename T>
49void RecordTimeSeries(std::string tsname, cyclus::Agent* agent, T value,
50 std::string units = "") {
51 std::string tblname = "TimeSeries" + tsname;
52 int time = agent->context()->time();
53 agent->context()
54 ->NewDatum(tblname)
55 ->AddVal("AgentId", agent->id())
56 ->AddVal("Time", time)
57 ->AddVal("Value", value)
58 ->AddVal("Units", units)
59 ->Record();
60 std::vector<time_series_listener_t> vec = TIME_SERIES_LISTENERS[tsname];
61 for (auto f = vec.begin(); f != vec.end(); ++f) {
62 std::function<void(cyclus::Agent*, int, T, std::string)> fn =
63 boost::get<std::function<void(cyclus::Agent*, int, T, std::string)>>(
64 *f);
65 fn(agent, time, value, tsname);
66 }
67 PyCallListeners(tsname, agent, agent->context(), time, value);
68}
69
70} // namespace toolkit
71} // namespace cyclus
72
73#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:50
Context * context() const
Returns this agent's simulation context.
Definition agent.h:364
virtual const int id() const
The agent instance's unique ID within a simulation.
Definition agent.h:349
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
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:124
std::map< std::string, std::vector< time_series_listener_t > > TIME_SERIES_LISTENERS
Definition timeseries.cc:7
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
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