CYCLUS
timer.h
Go to the documentation of this file.
1 #ifndef CYCLUS_SRC_TIMER_H_
2 #define CYCLUS_SRC_TIMER_H_
3 
4 #include <utility>
5 #include <vector>
6 
7 #include "context.h"
8 #include "exchange_manager.h"
9 #include "product.h"
10 #include "material.h"
11 #include "infile_tree.h"
12 #include "time_listener.h"
13 #include "comp_math.h"
14 
15 class SimInitTest;
16 
17 namespace cyclus {
18 
19 class Agent;
20 
21 /// Controls simulation timestepping and inter-timestep phases.
22 class Timer {
23  friend class ::SimInitTest;
24  public:
25  Timer();
26 
27  /// Sets intial time-related parameters for the simulation.
28  ///
29  /// @param ctx simulation context
30  void Initialize(Context* ctx, SimInfo si);
31 
32  /// resets all data (registered listeners, etc.) to empty or initial state
33  void Reset();
34 
35  /// Runs the simulation.
36  void RunSim();
37 
38  /// Registers an agent to receive tick/tock notifications every timestep.
39  /// Agents should register from their Deploy method.
41 
42  /// Removes an agent from receiving tick/tock notifications.
43  /// Agents should unregister from their Decommission method.
45 
46 
47  /// Schedules the named prototype to be built for the specified parent at
48  /// timestep t.
49  void SchedBuild(Agent* parent, std::string proto_name, int t);
50 
51  /// Schedules the given Agent to be decommissioned at the specified
52  /// timestep t.
53  void SchedDecom(Agent* m, int time);
54 
55  /// Schedules a snapshot of simulation state to output database to occur at
56  /// the beginning of the next timestep.
57  void Snapshot() { want_snapshot_ = true; }
58 
59  /// Schedules the simulation to be terminated at the end of this timestep.
60  void KillSim() { want_kill_ = true; }
61 
62  /// Returns the current time, in months since the simulation started.
63  ///
64  /// @return the current time
65  int time();
66 
67  /// Returns the duration of the simulation this Timer's timing.
68  ///
69  /// @return the duration, in months
70  int dur();
71 
72  private:
73  /// builds all agents queued for the current timestep.
74  void DoBuild();
75 
76  /// sends the tick signal to all of the agents receiving time
77  /// notifications.
78  void DoTick();
79 
80  /// Runs the resource exchange process for all traders.
81  void DoResEx(ExchangeManager<Material>* matmgr,
82  ExchangeManager<Product>* genmgr);
83 
84  /// sends the tock signal to all of the agents receiving time
85  /// notifications.
86  void DoTock();
87 
88  void RecordInventories(Agent* a);
89  void RecordInventory(Agent* a, std::string name, Material::Ptr m);
90 
91  /// decommissions all agents queued for the current timestep.
92  void DoDecom();
93 
94  Context* ctx_;
95 
96  /// The current time, measured in months from when the simulation
97  /// started.
98  int time_;
99 
100  SimInfo si_;
101 
102  bool want_snapshot_;
103  bool want_kill_;
104 
105  /// Concrete agents that desire to receive tick and tock notifications
106  std::map<int, TimeListener*> tickers_;
107 
108  // std::map<time,std::vector<std::pair<prototype, parent> > >
109  std::map<int, std::vector<std::pair<std::string, Agent*> > > build_queue_;
110 
111  // std::map<time,std::vector<config> >
112  std::map<int, std::vector<Agent*> > decom_queue_;
113 };
114 
115 } // namespace cyclus
116 
117 #endif // CYCLUS_SRC_TIMER_H_
void RegisterTimeListener(TimeListener *agent)
Registers an agent to receive tick/tock notifications every timestep.
Definition: timer.cc:165
boost::shared_ptr< Material > Ptr
Definition: material.h:75
std::string name(int nuc)
Definition: pyne.cc:2940
void Snapshot()
Schedules a snapshot of simulation state to output database to occur at the beginning of the next tim...
Definition: timer.h:57
The ExchangeManager is designed to house all of the internals involved in executing a resource exchan...
void UnregisterTimeListener(TimeListener *tl)
Removes an agent from receiving tick/tock notifications.
Definition: timer.cc:169
int dur()
Returns the duration of the simulation this Timer&#39;s timing.
Definition: timer.cc:237
void Reset()
resets all data (registered listeners, etc.) to empty or initial state
Definition: timer.cc:215
int parent(int nuc, unsigned int rx, std::string z="n")
Definition: pyne.cc:6621
void Initialize(Context *ctx, SimInfo si)
Sets intial time-related parameters for the simulation.
Definition: timer.cc:222
int time()
Returns the current time, in months since the simulation started.
Definition: timer.cc:211
The TimeListener class is an inheritable class for any Agent that requires knowlege of ticks and tock...
Definition: time_listener.h:23
void RunSim()
Runs the simulation.
Definition: timer.cc:14
Container for a static simulation-global parameters that both describe the simulation and affect its ...
Definition: context.h:37
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:128
The abstract base class used by all types of agents that live and interact in a simulation.
Definition: agent.h:51
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Definition: agent.cc:14
void KillSim()
Schedules the simulation to be terminated at the end of this timestep.
Definition: timer.h:60
void SchedBuild(Agent *parent, std::string proto_name, int t)
Schedules the named prototype to be built for the specified parent at timestep t. ...
Definition: timer.cc:173
void SchedDecom(Agent *m, int time)
Schedules the given Agent to be decommissioned at the specified timestep t.
Definition: timer.cc:180
Controls simulation timestepping and inter-timestep phases.
Definition: timer.h:22