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  /// sends the decision signal to all agents recieving time
89  /// notifications.
90  void DoDecision();
91 
92  void RecordInventories(Agent* a);
93  void RecordInventory(Agent* a, std::string name, Material::Ptr m);
94 
95  /// decommissions all agents queued for the current timestep.
96  void DoDecom();
97 
98  Context* ctx_;
99 
100  /// The current time, measured in months from when the simulation
101  /// started.
102  int time_;
103 
104  SimInfo si_;
105 
106  bool want_snapshot_;
107  bool want_kill_;
108 
109  /// Concrete agents that desire to receive tick and tock notifications
110  std::map<int, TimeListener*> tickers_;
111 
112  // std::map<time,std::vector<std::pair<prototype, parent> > >
113  std::map<int, std::vector<std::pair<std::string, Agent*> > > build_queue_;
114 
115  // std::map<time,std::vector<config> >
116  std::map<int, std::vector<Agent*> > decom_queue_;
117 };
118 
119 } // namespace cyclus
120 
121 #endif // CYCLUS_SRC_TIMER_H_
void RegisterTimeListener(TimeListener *agent)
Registers an agent to receive tick/tock notifications every timestep.
Definition: timer.cc:182
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:186
int dur()
Returns the duration of the simulation this Timer&#39;s timing.
Definition: timer.cc:254
void Reset()
resets all data (registered listeners, etc.) to empty or initial state
Definition: timer.cc:232
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:239
int time()
Returns the current time, in months since the simulation started.
Definition: timer.cc:228
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:16
Container for a static simulation-global parameters that both describe the simulation and affect its ...
Definition: context.h:39
A simulation context provides access to necessary simulation-global functions and state...
Definition: context.h:130
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:190
void SchedDecom(Agent *m, int time)
Schedules the given Agent to be decommissioned at the specified timestep t.
Definition: timer.cc:197
Controls simulation timestepping and inter-timestep phases.
Definition: timer.h:22